✏ Porting TWRP recovery

You better read this. If you experiment without knowledge you will end with an unusable phone.

Q1:yes, every phone has a recovery, but not TWRP …
Q2: from Ouinouin, oi
Q3: yes

If you want the newest TWRP (3.0.2-0, based on the android-7.0 branch) version with fixed adb (so you can use it without mounting /system), you can download it here: download here :slight_smile: I didn’t test it extensively but afaik everything should work as expected.

I will also send the patch I used for fixing adb so hopefully it can get fixed by the Fairphone devs in the next release :thumbsup:

6 Likes

Really great, thanks a lot!

ADB is working indeed.
Though, an encrypted /data partition cannot be mounted. Too bad, was hoping to be able to use TWRP for backups.

Anyhow, great work, thanks a lot!

It looks like twrp v3 still isn’t able to decrypt out of the box… I surfed a bit on their forum and it looks like it still need tweaking per every device… Too bad, as long as Fairphone won’t attack this problem…

2 Likes

Just to let you know:
I tried to make an OS update (Fairphone Open OS) through the FP Updater app, which usually performs the update in the recovery (automatically, after an reboot). However, with this recovery version after the reboot the update process is not started (instead it looks like a normal start of TWRP, asking if you want to use it read only).

Not sure if the updater script of the update file needs modification, or if this is related to the recovery itself. Just wanted to share the experience that I needed to reinstall again the default TWRP from Open OS for the update.

See https://github.com/z3ntu/FairphoneUpdater/commit/01cb543cc212d7c0c8a8a761ef226583edc298af “Point 3”

I hope they’ll integrate those changes into the updater.

(also you can press the most right on-screen button in the recovery to see the error log)

2 Likes

One workaround is to let the updater dowload the update, then when it shows “reboot” button, don’t push it. Instead, manually reboot to recovery. From TWRP, you will be able to apply the update zip which you will find in /cache/recovery. This will also be the occasion to flash the rooted boot or other additions at the same time.

From the link you provided, i also think that it would be possible to edit the /cache/recovery/command to remove wipe_cache which is causing the issue. I’ll try this on next update.

1 Like

I noticed that TWRP log shows a cache wipe, but I suspected it to be a TWRP behaviour more than an updater one.

I don’t understand, if the script instructs a wipe_cache, why is the “standard” recovery NOT wiping the cache as well ? Or does it smartly keep /cache/recovery while wiping ?

To be honest I have no idea why it works in the FP Open TWRP version and in the standard recovery because it’s completely illogical to me.

And it can’t keep /cache/recovery/ because it’s located on the cache partition mounted on /cache

Did you keep a copy of the /cache/recovery/command ?
Or i will check it on next update.

According to https://android.googlesource.com/platform/bootable/recovery/+/ics-mr1/recovery.c, and if I understood correctly (which is not granted :slight_smile: ) :

When there is a firmware update (ie radio), the firmware binary is rawly written to the cache partition and flashed by bootloader. That’s why the cache has to be wiped before, then reformatted afterwards. But the recovery should handle it by itself, it doesnt need to be instructed from updater.

It’s something like the following (I know I pulled that file once but I can’t find it anymore)

--wipe-cache
--update_package=/cache/fp_update.zip

Would be interesting to see a standard recovery update log, to see what happens about the cache wipe.

1 Like

Dumb question: has someone tried the TW_INCLUDE_CRYPTO build var?

Edit: Surprisingly, TWRP is pretty undocumented (just a build guide on XDA), but I found this useful chart you may want to take a look at:

http://forum.xda-developers.com/android/software/twrp-flags-boardconfig-mk-t3333970

I could now use Updater to upgrade to 1.9.3b without issue.

Firstly, I flashed the recovery from FPOpenOS, instead of the one from this thread. (visible change is the different splash screen)

While the updater was waiting for me to push ‘reboot’, I replaced the boot.img in /cache/fp_update.zip in order to keep root.

I didn’t have time to have a look at cache/recovery/command, as it is only written AFTER you push this reboot button. And cache gets wiped after the update.
But the update went smooth.

I’m quite happy, it’s first time I manage to install an update with root on bare phone, without using a computer.

I received a brand new phone from support and can’t get OuinOuin’s TWRP recovery image installed. :frowning:
I’m really keen about getting TWRP to work, as I’d like to restore the nandroid-backup I made before sending my old FP2 to Fairphone’s support.

Questions:

  • Any experiences with the “new” FP2 (manufactury date Dec.2016)? (I assumed there would not be any differences, partition-wise.)
  • Could it be possible, that the new phone needs different TWRP recovery image?
  • What am I doing wrong otherwise?

The new FP2 came with FPOS 1.8.1 preinstalled.
I tried the commands below with the same result (TWRP not installed).
I then used “Updater” to get the update to 1.10.1.
Using “Hiccup”, the board identifies as being manufactured on 2016-12-09, it definitely is a new phone out of the most current production batch. (My previous FP2 was one of the first 17000, board manufactury date about a year ago.)

I used the very same recovery.img that worked in the past with my old FP2, md5: 8A634C3BE94136D6C4ABB859057599C7.

Here’s what I did:

C:\Programme\Android\sdk\platform-tools>adb reboot bootloader

...>fastboot devices
fb1bf6a2        fastboot

...>fastboot flash recovery c:\recovery.img
target reported max download size of 536870912 bytes
sending 'recovery' (15046 KB)...
OKAY [  0.485s]
writing 'recovery'...
OKAY [  0.170s]
finished. total time: 0.656s

...>fastboot reboot
rebooting...
finished. total time: 0.001s

...>adb devices
List of devices attached
fb1bf6a2        device

...>adb reboot recovery

Unfortunately, FP2 then boots inte the default recovery:

Android system recovery <3e>
r4275.1_FP2_gms70_1.10.1

Volume up/down to move highlight:
enter button to select.

reboot system now
apply update from ADB
...
apply update from sdcard

Any ideas? :neutral_face:

You are not alone.
See the post here and following.

I also got this problem from time to time. On xda I read about giving twrp the right to change boot at first start to be persistent.

You could try booting it without flashing (see here).

I had that problem once with another smartphone. The reason is: if you reboot into the system, then the system replaces the recovery with the stock one. (With my FP2 I had not this effect). The solution: after flashing TWRP type

fastboot reboot - but do not hit ENTER!

Fetch your phone and hold the Volume up and with the other Hand hit ENTER on your computer. This way the phone is forced to boot into recovery. Here should be a option to protect the recovery.

(Updated because I wrote the wrong key! Thanks @amers)

Thank you all - TWRP is just now restoring the backup. :slight_smile:

  • @sky, the described booting into the recovery directly after flashing TWRP solved the problem for me too. (Obviously, I had missed the post in the thread that you pointed me to.)
  • @Spielmops, nice and easy way to reboot into fastboot or recovery. (“Volume -” takes me into fastboot again, “Volume +” while executing the command takes me into recovery then.)
  • @retsifp also thanks for the link - yet, the permanent installation worked now (and I always use it for OS updates, rooting, backups).

Feels good to have my FP2 back again! :relaxed:

( Edit: just updated the initial wiki post to include this information. )

1 Like

I have a new build of TWRP (compiled with omnirom 6.0 sources) - version 3.0.3+ (git hash cc19c6f) available! Download link: https://private.z3ntu.xyz/fairphone/TWRP_3.0.3-0/ (look at the readme.txt file for info what is what).

If there are any problems you notice, please report them to me!

EDIT: Updated the build to include crypto support. This should hopefully enable you to decrypt /data if you have it encrypted.

EDIT 2: Apparently flashing images doesn’t work right now because the product is set to fp2 instead of FP2 and the Fairphone zips check that… Will try to fix that next.

EDIT 3: Fixed that :slight_smile: If you have encrypted /data please report back if it works for you :thumbsup:

EDIT 4: Encrypted /data doesn’t work but I was working most of my Sunday to get this to work (still doesn’t unfortunately).

3 Likes