[Xperia Z3 General] Mr.Tom_Tom:
Warm boot to FOTA recovery directly possible?

Let's revive this thread a bit. It is quite old but I am facing a challenge related to that and need some help from developers.

Question 1: Is there a way to trigger a warm boot to recovery (with ramdisk in FOTAKernel partition) directly from the bootloader, without the interim step of extracting the ramdisk in userspace first?

Question 2: If not, is there a way to boot the recovery image itself without decompressing it first (letting the kernel do that like during a normal boot process)?

Why all this?

Recently, our LineageOS 17.1 recovery images became so large that they don't fit into the 16MB FOTA partition anymore when the kernel image is compressed with GZIP. There are currently two options which provide better compression ratios and are supported by our ancient 3.4 kernel: LZMA and XZ xompression.

The current LineageOS implementation of LZMA compression seems to have some issues and might get discontinued. With some minor patches XZ compression will work fine. For a "reboot to recovery" however the process shown in the flowchart in post #1 won't work like before. XZ decompression is a bit more complex and ramdisk extraction is not as easy to implement as for LZMA or GZIP. Therefore I am looking for a more straight forward way to get rid of this extraction process from within the boot image.

For a cold boot to recovery this is not an issue anymore because for this usecase the newer S1 bootloader can interpret the power+volume down command correctly.

What's the idea?

The bootloader should be aware of the restart_reason and then decide which image to boot because of that. For our S1 bootloader, this does not work with the default reboot_reason 0x77665502, but thanks to the Sony Open Devices Project we know the specific restart_reason which is understood by S1: 0x6f656d46.

https://github.com/sonyxperiadev/ke....1.r1/drivers/power/reset/msm-poweroff.c#L366

OK but what's the problem then?

It still does not work. Here's an excerpt of the S1 bootloader activity (logged via serial console) depending on what the user is doing:

╔═══════════════════╦══════════════════════════════════════════════════════════════╦══════════════════════════════════════════════════════════════╦══════════════════════════════════════════════════════════════╦══════════════════════════════════════════════════════════════╗
║ User Action ║ Cold boot, no key pressed ║ Cold boot, volume down pressed ║ Select "Reboot to recovery" from within Android or ║ Select "Reboot to recovery" from within Android or ║
║ ║ ║ ║ from recovery ║ from recovery ║
║ ║ ║ ║ ║ ║
║ ║ ║ ║ (With unpatched kernel, using the default ║ (With patched kernel, using the S1 specific ║
║ ║ ║ ║ recovery_reason 0x77665502) ║ recovery_reason 0x6f656d46) ║
╠═══════════════════╬══════════════════════════════════════════════════════════════╬══════════════════════════════════════════════════════════════╬══════════════════════════════════════════════════════════════╬══════════════════════════════════════════════════════════════╣
║ Log excerpt ║ Warmboot reason: [COLDBOOT] ║ Warmboot reason: [COLDBOOT] ║ Warmboot reason: [UNKNOWN TO S1 BOOT (0x77665502)] ║ Warmboot reason: [FOTA] ║
║ ║ ... ║ ... ║ ... ║ ... ║
║ (serial console) ║ Service mode detected: [NONE] ║ Service mode detected: [RECOVERY] ║ Service mode detected: [NONE] ║ Service mode detected: [NONE] ║
║ ║ ... ║ ... ║ ... ║ ... ║
║ ║ [470] S1 decisions complete, image to boot is 0. ║ [470] S1 decisions complete, image to boot is 5. ║ [390] S1 decisions complete, image to boot is 0. ║ [400] S1 decisions complete, image to boot is 2. ║
║ ║ ... ║ ... ║ ... ║ ... ║
║ ║ [520] Loading boot image (7319552): start ║ [530] Loading boot image (13584384): start ║ [450] Loading boot image (7319552): start ║ [480] Loading boot image (7122944): start... ║
║ ║ ... ║ ... ║ ... ║ [1060] booting linux @ 0x8000, ramdisk @ 0x2000000 (1221292) ║
║ ║ [1530] booting linux @ 0x8000, ramdisk @ 0x2000000 (2128208) ║ [1450] booting linux @ 0x8000, ramdisk @ 0x2000000 (7691317) ║ [1450] booting linux @ 0x8000, ramdisk @ 0x2000000 (2128208) ║ ║
╠═══════════════════╬══════════════════════════════════════════════════════════════╬══════════════════════════════════════════════════════════════╬══════════════════════════════════════════════════════════════╬══════════════════════════════════════════════════════════════╣
║ What's happening? ║ Android is starting normally. ║ Recovery is starting as expected. ║ Boot image is starting, but then init_sony is detecting ║ I don't know exactly what's happening but after ║
║ ║ ║ ║ the intention to boot to recovery. It then tries to extract ║ a while Android is booting. There is still no direct ║
║ ║ ║ ║ the ramdisk and boot that [1]. ║ boot to recovery. ║
╚═══════════════════╩══════════════════════════════════════════════════════════════╩══════════════════════════════════════════════════════════════╩══════════════════════════════════════════════════════════════╩══════════════════════════════════════════════════════════════╝

[1] https://github.com/LineageOS/android_device_sony_common/blob/lineage-17.1/init/init_main.cpp#L167

The last column shows that the bootloader is understanding that we want to restart to recovery, but is doing something different than when when doing a cold boot to recovery (loading image "2" instead of image "5"). This does not work. So I am looking for some hints how to get a warm boot to recovery working properly.