Bootloader locking command seems to be done but

Hi,

I have an FP4 that was running LOS 23.1. I reflashed it to the original Fairphone state (https://support.fairphone.com/hc/en-us/articles/18896094650513-How-to-manually-install-Android-on-your-Fairphone#01HB8ZZ1BMMQNSNMFT3YXDBXA0). Everything went well.

However, I want to lock the bootloader. I followed these instructions: Re-lock the bootloader (optional) => https://support.fairphone.com/hc/en-us/articles/10492476238865-How-to-unlock-and-re-lock-the-bootloader

lool@lool-P52:~$ fastboot devices 4b418009 fastboot

lool@lool-P52:~$ fastboot flashing lock_critical OKAY [ 0.028s] Finished. Total time: 0.028s lool@lool-P52:~$

The phone restarted as if it had been factory reset (I had to reconfigure it as if it were starting up for the first time). But when I restart the phone, at boot I still get the message "The boot loader is unlock and software integrity… ".

If I switch back to fastboot mode and run the command again:

lool@lool-P52:~$ fastboot flashing lock_critical FAILED (remote: ' Device already: locked!') fastboot: error: Command failed lool@lool-P52:~$

as indicated, I get the message “Device already: locked!”

So I have conflicting information: bootloader locked??? bootloader unlocked???

Has anyone else encountered this situation?

The commands can be a bit confusing, fastboot flashing lock_critical locks the critical partitions from being modified, what you want is fastboot flashing lock to actually lock the bootloader.
You generally don’t need to lock the critical partitions, because those aren’t accessible with a locked bootloader anyway.

But make sure that fastboot flashing get_unlock_ability returns 1 before you lock the bootloader to give you a chance to recover from a brick.
If it doesn’t, reinstall the OS and don’t boot into Android before locking it (and also check get_unlock_ability again immediatelly before issuing the lock command!)

3 Likes

Thanks for your reply.
OK, I ran the command you recommended:

lool@lool-P52:~$ fastboot flashing get_unlock_ability
(bootloader) get_unlock_ability: 0
OKAY [ 0.001s]
Finished. Total time: 0.001s
lool@lool-P52:~$

So, if I understand correctly, I need to reinstall the stock ROM. But now the critical partitions are locked.

…
INFO: Looking for connected device(s)…
INFO: One Fairphone 4 in fastboot mode found (serial number: 4b418009).
ERROR: The critical partitions are not unlocked.
Please refer to our support articles for help.
ERROR: Aborting now (press Enter to terminate).
…

What is the correct procedure for unlocking the critical partitions?

I guess the reverse command should do the trick!?

fastboot flashing unlock_critical

Or should I request the unlock code from Fairphone? => Bootloader Unlocking Code for Fairphone - Fairphone

You won’t need a code since your bootloader is still unlocked, just fastboot flashing unlock_critical is enough.

Make sure to stop the phone from booting into Android after installation. I haven’t looked at the install bash script in a while if they still have the reboot step in there :thinking:

You can just take that line out, calculate the new hash for the script, and change the hash in the file with all the other hashes in the same folder (can’t remember what the file is called).
Or you hold one of the volume buttons when it tries to reboot after the installation.

1 Like

Do you mean after the installation of the stock rom or just after unlocking critical partitions ?

**************

I don’t understand… :face_with_diagonal_mouth:

After installation of stock rom. This avoids that system boots into “user land” (normal phone using mode) after installation, causing “unlock ability” to reset from “1” to “0”.

It describes how you can edit the installation script so that it does not directly boot after the installation.
If that seems too complicated to you, then you just can monitor the installation and press “vol-down” at the end of the installation process to start directly into fastboot instead of “user land”.

3 Likes

Apologies, I worded that badly, you can just take the route @Volker described, it’s easier :slightly_smiling_face:

What I meant in a bit more detail:

When you download & extract the factory images, there’s a flash_fp4_factory.command file in that directory. At the beginning of that file are a few options you can change, one of those is

REBOOT_TO_BOOTLOADER="false" # default value is "false"

If you change that to "true" the phone will reboot to the bootloader instead of Android userland when the installation is complete, which is what we want (and should be default).

But the installation script also compares all the extracted files against the checksums in the SHA256SUMS file to make sure none of the partitions that get flashed is wrong.
Since we modified the flash_fp4_factory.command file the checksums don’t match anymore and the installation fails.

So you have to run sha256sum flash_fp4_factory.command to generate a new checksum, then search for flash_fp4_factory.command in the SHA256SUMS file, and finally replace that line with the new checksum.

Way more complicated, buuut you don’t have to watch the phone to catch the reboot in time :nerd_face:

3 Likes

OK, I understand, that’s very clear.

So, to summarize:

1/ I switch to fastboot mode and unlock the critical partitions:
fastboot flashing unlock_critical

2/ I modify the flash_fp4_factory.command file and change the value of REBOOT_TO_BOOTLOADER from false to true.

3/ I run the checksum (sha256) on the new flash_fp4_factory.command file and replace the old checksum value in the SHA256SUMS file.

4/ I start installing the stock ROM.

5/ At the end of the installation, the phone remains in fastboot mode and I check that unlock ability has the value 1:
fastboot flashing get_unlock_ability

6/ If the value is 1, then I launch the bootloader lock:
fastboot flashing lock

7/ Once this is done, I restart the system in Android.

Please let me know if I made any mistakes.
I will keep you informed of the process.

In any case, thank you very much for your valuable help.

2 Likes

I didn’t spot any, you should be good to go, have fun :slightly_smiling_face:

1 Like

Well, this morning I started the procedure and got stuck at the first point:

lool@lool-P52:~$ fastboot devices
4b418009         fastboot

lool@lool-P52:~$  fastboot flashing unlock_critical
FAILED (remote: 'Flashing Unlock is not allowed
')
fastboot: error: Command failed
lool@lool-P52:~$

Right, I forgot that your get_unlock_ability is 0, and that’s needed for unlock_critical as well… It’s a weird state to be in :thinking:

If we go by the Fairphone instructions they first unlock OEM and then perform flashing unlock followed by flashing unlock_critical, which works because get_unlock_ability is only reset on first boot, so it stays on 1 during those reboots and the commands work.
However, since your bootloader is already unlocked, the OEM unlocking switch is greyed out in the settings, so we can’t just get it enabled again.

Check if you can toggle OEM unlocking in the developer options, if it’s greyed out we’ll have to take the Magisk route to make it toggleable again.

If that’s the case and I’m not back to the forum in the next few hours and you get bored, here are the (very old) instructions for the Magisk route:

You’ll need a patched root-enabled boot.img, so after the first step transfer the boot.img from your extracted factory images to your phone, open the Magisk app and patch it, transfer the patched one back to your PC and continue the next step with that image.

1 Like

I’m also busy for a few hours.

I’ve never used Magisk. I found it on FDroid, but it’s version 29.0; in your message, you mention version 24.3… is that a requirement?

I didn’t quite understand the boot.img manipulation you mention at the end of your last message.

I will wait your return. :slightly_smiling_face:

Many thanks.

The specific Magisk version isn’t important, that’s just what was available in April 22 when I wrote those steps, the F-Droid one is fine :slightly_smiling_face:

Don’t worry about the patching part, I uploaded you a patched boot.img for the latest Fairphone factory images.

But check the OEM toggle in developer options first, if it isn’t greyed out you can just switch it back on and skip the Magisk part (it should be greyed out, but doesn’t hurt to check).

I had already checked, and OEM unlocking is indeed not available.

I installed Magisk in the FP4 and downloaded your boot.img to my PC and then patched the boot.img on the FP 4 with Magisk that’s became magisk_patched-29000_VUj3I.img

I suppose that I have to replace the command you’ve gave me :

fastboot boot calyx-3.3.2_magisk_boot.img

by the name of the patched boot.img :

fastboot boot magisk_patched-29000_VUj3I.img

that’s it ?

The boot.img I uploaded was already patched and ready to go, you can just use it like that, not sure what happens if you patch it again, I guess we’ll find out :upside_down_face:

That should be it, yes

I’m still stuck:

lool@lool-P52:~/Bureau/boot_patch$ adb devices
List of devices attached
4b418009        device

lool@lool-P52:~/Bureau/boot_patch$ adb reboot bootloader
lool@lool-P52:~/Bureau/boot_patch$ fastboot boot boot.img
Sending 'boot.img' (98304 KB)                      OKAY [  0.380s]
Booting                                            OKAY [ 10.157s]
Finished. Total time: 10.604s
lool@lool-P52:~/Bureau/boot_patch$ adb shell
FP4:/ $ su -c 'resetprop ro.boot.flash.locked 1'
Permission denied
13|FP4:/ $ 

Thank you for your patience.

When you used su -c 'resetprop ro.boot.flash.locked 1', did you get a confirmation dialog on the phone screen? :thinking:

My guess is Magisk isn’t working properly, when you open the app does it indicate that you got root?
Have you tried both of the boot.imgs?

No, no messages on the phone.

In fact I don’t know, I never used this app. Have a look to the screenshot:

Yes, I tried with your own img.boot then with this img.boot patched with Magisk.

Maybe I don’t used Magisk as it should be… Anyway, you told me that your boot.img has been patched, so normally it doesn’t matter Magisk.

I think that after reboot the app indicates that I gaot root

Edit: I took to long with my reply, I meant the first screenshot.

That’s good news :tada:

Yeah, that screenshot seems to indicate you don’t have root, no idea why :thinking:

When you use fastboot boot boot.img does your phone boot normally?
If the boot process gets interupted and it reboots before reaching Android userland for some reason, that would load the boot partition on the phone instead, which isn’t rooted.

Maybe the phone rejects booting an external boot.img because critical partitions are locked, but I don’t recall that being an issue before, hmmm…

Either way we’ll have to find a way to solve this, I’ll have to think about it.
IIRC iodéOS specifically told people in their installation instructions not to unlock the critical partitions, so installing another ROM to reset get_unlock_ability might be an option, but I’d rather not risk it at this point, because if the system doesn’t boot anymore this could lead to a permanent brick.