1

After writing a bash code that automatically installs LineageOS on the Fair Phone 2 (FP2), I am also implementing the "reverse" OS installation, from LineageOS to Fairphone Open OS. From Fairphone Open OS to LineageOS works flawlessly, however the other way round does not yield the expected behaviour.

Expected behaviour

I would expect the FP2 to successfully boot up into a new instance of Fairphone Open OS after executing:

sudo adb shell twrp sideload
sudo adb sideload 19.11.2-sibon-24df0be9-ota.zip
# terminate/end the sideloading modus
sudo adb sideload /dev/null
adb reboot

Observed behaviour

That does not work, as the phone gets stuck in an infinite boot until the usb connection with the host is disconnected. In that case,

  • the phone starts the new Fairphone Open OS installation for about half a second,
  • then displays the "power off" message,
  • and reboots into the Android Recovery menu whilst displaying:
**Android Recovery**
Fairphone/FP2/FP2
9/21.03.0-rel.2-sibon-3cb25d6c
userdebug/release-keys
Use volume up/down and power.

Can't load Android system. Your data may be corrupt. If you continue to get this message you may need to perform a factory data reset and erase all data stored on this device.

**Try Again**
**Factory data reset**

If the option Try Again is selected, the phone reboots, and then repeats itself coming back at this menu. However, if Factory data reset is selected, the factory data reset is executed successfully and the phone successfully boots into Fairphone Open OS.

Error Mitigation Strategy I

Since the factory reset "solves the problem", I tried to automate this. However, I am experiencing some difficulties doing so. The main issue is that I do not have control over the phone anymore as soon as I reboot it after sideloading the Fairphone Open OS in TWRP. This is because throughout the booting (up to failure/reboot into Android Recovery mode), the adb is unauthorized:

List of devices attached
somedeviceid    unauthorized

So I tried to erase the data after sideloading in TWRP, but before rebooting, using:

adb shell twrp wipe data
adb shell twrp wipe cache
adb shell twrp wipe dalvik

However, that also leads to the observed behaviour as described above.

Error Mitigation Strategy II

Since erasing the data from the TWRP system did not equal a factory reset in/of the Fairphone Open OS, I thought I might reboot into fastboot and do a factory reset from there, as is explained here, using the code:

adb reboot bootloader
fastboot erase userdata
fastboot erase cache
fastboot reboot

However, that soft-bricked the device. I think this soft-bricked it because, Fairphone Open OS replaces the TWRP recovery system with its own Android Recovery system, which corrupts the TWRP recovery system, and then the Fairphone Open OS tried to fail into its recovery mode, but that still was set to the TWRP because it was not removed due to the use of fastboot in between, yet the TWRP was corrupted. However, after some of trial and error and some improperly documented actions, I did manage to unbrick the TWRP somehow, which brings me back to trying to the observed behaviour.

Error mitigation strategy III

I tried the reset functionality as described here, from twrp after sideloading, before rebooting:

adb shell
recovery --wipe_data

Which outputted:

I:Lun file '/sys/class/android_usb/android0/f_mass_storage/lun0/file' does not exist, USB storage mode disabled
TW_INCLUDE_CRYPTO := true
I:Found brightness file at '/sys/class/leds/lcd-backlight/brightness'
I:Got max brightness 255 from '/sys/class/leds/lcd-backlight/max_brightness'
I:TWFunc::Set_Brightness: Setting brightness control to 255
I:LANG: en
I:TW_NO_LEGACY_PROPS := true

However, it resulted in the same described observed behaviour, needing a manual factory reset before Fairphone Open OS would boot successfully.

Question

What could I do to successfully sideload and boot into the Fairphone Open OS coming from a LineageOS system without the user having to perform a manually factory reset?

1
  • 1
    fastboot erase does delete the entire file system from partition. twrp wipe data does only delete files from file system. but switching between different (encrypted) ROMs requires fresh formatted partition with (unencrypted) file system (ext4/f2fs) that's why one should format data instead (aka factory reset)
    – alecxs
    Commented May 10, 2021 at 9:00

1 Answer 1

1

Road to answer

Because I did not clearly understand the difference between selecting, Wipe>Advanced Wipe>Data>yes, and Wipe>format data>yes I did not thoroughly/consistently test the latter option as I thought it was the same as the Wipe>Advanced Wipe>Data>yes option.

Since I experimentally determined that a factory reset did fix the issue, I focused on automating that option in the given constraints. Doing so in this question, I was reminded of the Wipe>format data>yes option again and provided with the adb command in a comment. Since I did not yet find a factory reset method I tried the sudo adb shell twrp format data command manually, and it worked. Then I tried it again in the automated setting with: format_data=$(adb shell twrp format data) and it still worked. This answer has been made possible thanks to the comments of alecxs.

Answer

I was able to automate the installation and booting of Fairphone Open OS using the following set of commands:

sudo adb shell twrp sideload
sudo adb sideload 19.11.2-sibon-24df0be9-ota.zip
sudo adb shell twrp format data
adb reboot

That made the phone successfully boot into the new instance of Fairphone Open OS.

Note

The termination of the sideload modus was not needed anymore, hence the following lines were ommitted:

# terminate/end the sideloading modus
sudo adb sideload /dev/null

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .