TWRP for Fairphone 4

Don’t boot, it just stays in the ‘powered by android’ image.
These debug flags only work, if the recovery is installed and not if you boot from fastboot boot ... as specified in the README.
You can try to compile it yourself and test it.

1 Like

Compile is done, I’ll try it soon :slight_smile:

Terminal output
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=127
TARGET_PRODUCT=twrp_FP4
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=kryo
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=cortex-a73
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.4.0-100-generic-x86_64-Ubuntu-20.04.4-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
[ 27% 4874/17836] //bionic/libc:libc.llndk versioner preprocess include
warning: attempted to generate guard with empty availability: obsoleted = 21
warning: attempted to generate guard with empty availability: obsoleted = 23
[ 27% 4886/17836] //bionic/libc:libc.llndk versioner preprocess include [arm]
warning: attempted to generate guard with empty availability: obsoleted = 21
warning: attempted to generate guard with empty availability: obsoleted = 23
[ 39% 6999/17836] Prebuilt:  (out/target/product/FP4/kernel)
calling depmod on prebuilt modules
depmod: WARNING: could not open modules.order at /home/oli/fp4-twrp2/out/target/product/FP4/recovery/root/vendor/lib/modules/1.1: No such file or directory
depmod: WARNING: could not open modules.builtin at /home/oli/fp4-twrp2/out/target/product/FP4/recovery/root/vendor/lib/modules/1.1: No such file or directory
[ 99% 17828/17836] Target vendor buildinfo: out/target/product/FP4/vendor/build.prop
Target vendor properties from: device/fairphone/FP4/vendor.prop
[ 99% 17834/17836] Install: out/target/product/FP4/root/system/bin/qcom_decrypt_fbe-timestamp
 
Running Service_Cleanup script for Qcom decryption...

OUT Folder set to: out/target/product/FP4

FBE Status: true

Blobs parsed:
android.hardware.keymaster@4.1-service-qti
android.hardware.gatekeeper@1.0-service-qti
 
Services in rc file:
android.hardware.keymaster@3.0-service
android.hardware.keymaster@3.0-service-qti
android.hardware.keymaster@4.0-service
android.hardware.keymaster@4.0-service-qti
android.hardware.keymaster@4.1-service
android.hardware.keymaster@4.1-service-qti
android.hardware.keymaster@4.1-service.citadel
android.hardware.gatekeeper@1.0-service
android.hardware.gatekeeper@1.0-service-qti
 
Services not included:
android.hardware.gatekeeper@1.0-service
android.hardware.keymaster@3.0-service
android.hardware.keymaster@3.0-service-qti
android.hardware.keymaster@4.0-service
android.hardware.keymaster@4.0-service-qti
android.hardware.keymaster@4.1-service
android.hardware.keymaster@4.1-service.citadel
 
Removing unneeded service: gatekeeper-1-0
Removing unneeded service: keymaster-3-0
Removing unneeded service: keymaster-3-0-qti
Removing unneeded service: keymaster-4-0
Removing unneeded service: keymaster-4-0-qti
Removing unneeded service: keymaster-4-1
Removing unneeded service: keymaster-4-1-citadel
 
Service_Cleanup script complete.

[100% 17836/17836] build out/target/product/FP4/recovery.img

#### build completed successfully (01:27:39 (hh:mm:ss)) ####

EDIT: ldcheck tells me that the dependency libandroidicu.so is missing for qseecomd!

ldcheck for qseecomd
/home/oli/fp4-twrp2/ldcheck/ldcheck -p system/lib64:vendor/lib64 -d system/bin/qseecomd
readelf: ERREUR: « libandroidicu.so »: pas de tel fichier
libs: ['system/bin/qseecomd', 'system/lib64/libcutils.so', 'system/lib64/libutils.so', 'system/lib64/liblog.so', 'vendor/lib64/libQSEEComAPI.so', 'vendor/lib64/libdrmfs.so', 'system/lib64/libc++.so', 'system/lib64/libc.so', 'system/lib64/libm.so', 'system/lib64/libdl.so', 'system/lib64/libbase.so', 'system/lib64/libprocessgroup.so', 'system/lib64/libvndksupport.so', 'system/lib64/libion.so', 'vendor/lib64/libdiag.so', 'system/lib64/libxml2.so', 'system/lib64/ld-android.so', 'system/lib64/libcgrouprc.so', 'system/lib64/libdl_android.so', 'libandroidicu.so']
nm: « libandroidicu.so »: pas de tel fichier
system/lib64/libxml2.so   UNRESOLVED #####          U ucnv_close_android
system/lib64/libxml2.so   UNRESOLVED #####          U ucnv_convertEx_android
system/lib64/libxml2.so   UNRESOLVED #####          U UCNV_FROM_U_CALLBACK_STOP_android
system/lib64/libxml2.so   UNRESOLVED #####          U ucnv_open_android
system/lib64/libxml2.so   UNRESOLVED #####          U ucnv_setFromUCallBack_android
system/lib64/libxml2.so   UNRESOLVED #####          U ucnv_setToUCallBack_android
system/lib64/libxml2.so   UNRESOLVED #####          U UCNV_TO_U_CALLBACK_STOP_android
nm: « libandroidicu.so »: pas de tel fichier
unused: {'system/lib64/libutils.so', 'system/lib64/libcgrouprc.so', 'system/lib64/libdl_android.so', 'system/lib64/libxml2.so', 'system/lib64/libvndksupport.so', 'libandroidicu.so', 'system/lib64/libprocessgroup.so', 'vendor/lib64/libdrmfs.so', 'vendor/lib64/libQSEEComAPI.so', 'system/lib64/libion.so', 'vendor/lib64/libdiag.so', 'system/lib64/libm.so'}

EDIT 2: gatekeeper and keymaster seems to have all dependencies satisfied :+1:

ldcheck for gatekeeper and keymaster
oli@CRMG5261:~/fp4-twrp2/out/target/product/FP4/recovery/root$ /home/oli/fp4-twrp2/ldcheck/ldcheck -p system/lib64:vendor/lib64 -d system/bin/android.hardware.gatekeeper@1.0-service-qti
libs: ['system/bin/android.hardware.gatekeeper@1.0-service-qti', 'system/lib64/android.hardware.gatekeeper@1.0.so', 'system/lib64/libhardware.so', 'system/lib64/libhidlbase.so', 'system/lib64/libutils.so', 'system/lib64/liblog.so', 'system/lib64/libc++.so', 'system/lib64/libc.so', 'system/lib64/libm.so', 'system/lib64/libdl.so', 'system/lib64/libcutils.so', 'system/lib64/libvndksupport.so', 'system/lib64/libbase.so', 'system/lib64/libprocessgroup.so', 'system/lib64/ld-android.so', 'system/lib64/libdl_android.so', 'system/lib64/libcgrouprc.so']
unused: {'system/lib64/libhardware.so'}
oli@CRMG5261:~/fp4-twrp2/out/target/product/FP4/recovery/root$ /home/oli/fp4-twrp2/ldcheck/ldcheck -p system/lib64:vendor/lib64 -d system/bin/android.hardware.keymaster@4.1-service-qti
libs: ['system/bin/android.hardware.keymaster@4.1-service-qti', 'system/lib64/liblog.so', 'system/lib64/libcutils.so', 'system/lib64/libbase.so', 'system/lib64/libutils.so', 'system/lib64/libhardware.so', 'system/lib64/libhidlbase.so', 'system/lib64/android.hardware.keymaster@4.0.so', 'system/lib64/android.hardware.keymaster@4.1.so', 'vendor/lib64/libqtikeymaster4.so', 'system/lib64/libcrypto.so', 'system/lib64/libc++.so', 'system/lib64/libc.so', 'system/lib64/libm.so', 'system/lib64/libdl.so', 'system/lib64/libprocessgroup.so', 'system/lib64/libvndksupport.so', 'system/lib64/android.hardware.keymaster@3.0.so', 'vendor/lib64/libkeymasterdeviceutils.so', 'vendor/lib64/libkeymasterutils.so', 'vendor/lib64/libqcbor.so', 'system/lib64/ld-android.so', 'system/lib64/libcgrouprc.so', 'system/lib64/libdl_android.so', 'system/lib64/libion.so', 'vendor/lib64/libQSEEComAPI.so']
unused: {'system/lib64/libcgrouprc.so', 'system/lib64/libm.so', 'system/lib64/libprocessgroup.so', 'system/lib64/libhardware.so', 'system/lib64/android.hardware.keymaster@3.0.so'}

libandroidicu.so are compiled from source: link

1 Like

Ok good :slight_smile:

And a (probably stupid) question: why, in this BoardConfig file, in the section:

  • TARGET_RECOVERY_DEVICE_MODULES there are 3 elements (libandroidicu libion libxml2)
  • RECOVERY_LIBRARY_SOURCE_FILES there are only the 2 last ones…

Looking randomly for those keywords on google I found a device.mk for the xiaomi vayu, and they wrote the path of libandroidicu.so in the section PRODUCT_COPY_FILES, so I assume they took it from the device instead of compiling it, even if it’s also in TARGET_RECOVERY_DEVICE_MODULES:thinking:

Just to try: I searched libandroidicu.so on my FP4 device (boot from a rooted boot.img) with lsof |grep icu.so and found it there:

/apex/com.android.art/lib64/libandroidicu.so

I pulled it with adb and put it in the device/fairphone/FP4/recovery/root/vendor/lib64/ directory (not sure if it’s the good path, as I read elsewere “/system/lib64”)
Then running again ldcheck it complained about two other missing libraries :wink: , libicuuc.so and libicui18n.so :

/apex/com.android.art/lib64/libicuuc.so
/apex/com.android.art/lib64/libicui18n.so

Pulled them to the same vendor/lib64 directory, and build it again, now ldcheck seems happy:

ldcheck output
~/fp4-twrp2/out/target/product/FP4/recovery/root$ /home/oli/fp4-twrp2/ldcheck/ldcheck -p system/lib64:vendor/lib64 -d system/bin/qseecomd 
libs: ['system/bin/qseecomd', 'system/lib64/libcutils.so', 'system/lib64/libutils.so', 'system/lib64/liblog.so', 'vendor/lib64/libQSEEComAPI.so', 'vendor/lib64/libdrmfs.so', 'system/lib64/libc++.so', 'system/lib64/libc.so', 'system/lib64/libm.so', 'system/lib64/libdl.so', 'system/lib64/libbase.so', 'system/lib64/libprocessgroup.so', 'system/lib64/libvndksupport.so', 'system/lib64/libion.so', 'vendor/lib64/libdiag.so', 'system/lib64/libxml2.so', 'system/lib64/ld-android.so', 'system/lib64/libcgrouprc.so', 'system/lib64/libdl_android.so', 'vendor/lib64/libandroidicu.so', 'vendor/lib64/libicuuc.so', 'vendor/lib64/libicui18n.so']
unused: {'vendor/lib64/libQSEEComAPI.so', 'vendor/lib64/libicuuc.so', 'vendor/lib64/libicui18n.so', 'vendor/lib64/libdrmfs.so', 'system/lib64/libprocessgroup.so', 'system/lib64/libdl_android.so', 'system/lib64/libutils.so', 'vendor/lib64/libandroidicu.so', 'system/lib64/libcgrouprc.so', 'system/lib64/libm.so', 'system/lib64/libion.so', 'system/lib64/libxml2.so', 'vendor/lib64/libdiag.so', 'system/lib64/libvndksupport.so'}

However when I fastboot boot the new recovery.img, I get stuck at a blinking TWRP welcome screen:

Picture

Pulling /tmp/recovery.log doesn’t gives many hints on what is happening…

recovery.log

Starting TWRP 3.6.0_11-0-2c53845c on Sat Mar 5 17:05:31 2022
(pid 1298)
I:Lun file ‘/sys/class/android_usb/android0/f_mass_storage/lun0/file’ does not exist, USB storage mode disabled
PRODUCT_USE_DYNAMIC_PARTITIONS := true
TW_INCLUDE_CRYPTO := true
I:TW_BRIGHTNESS_PATH := /sys/class/backlight/panel0-backlight/brightness
I:Found brightness file at ‘/sys/class/backlight/panel0-backlight/brightness’
I:TWFunc::Set_Brightness: Setting brightness control to 127
I:TW_EXCLUDE_ENCRYPTED_BACKUPS := true
I:LANG: en
I:AB_OTA_UPDATER := true
Starting the UI…
setting DRM_FORMAT_BGRA8888 and GGL_PIXEL_FORMAT_BGRA_8888
setting DRM_FORMAT_ARGB8888 and GGL_PIXEL_FORMAT_RGBA_8888
setting DRM_FORMAT_ARGB8888 and GGL_PIXEL_FORMAT_RGBA_8888

It’s actually exactly the same first lines as the working TWRP from @z3ntu, then it stops before the line Using drm graphics.

2 Likes

Maybe they can help you here. I opened a topic for Fairphone 4 inside suport-device stream, time ago.
I can’t dedicate hours to this right now.

I’ve just released twrp-3.6.2_FP4-UNOFFICIAL-20220602 which fixes MTP and is rebuilt from latest TWRP sources.

The initial post is updated with the new download link.

6 Likes

Is it ready to go official? Do we have any blockers?

1 Like

@TeamB58 Encrypted userdata and haptics would be nice (latter is obviously less important). Unfortunately I didn’t have any luck getting encrypted userdata to work in the past, and other people that tried also seemed to have had the same problems as me.

So, it’s our device side issue and not an issue with TWRP it self?

Yes on other devices with android-11 branch both work.
For encryption: GitHub - TeamWin/android_device_qcom_twrp-common: TWRP standard device files for Qualcomm SoCs

Haptic is the driver for the vibrator, correct? Looking up for “aw8695_haptic” I found your description here when you added it to the linux kernel :wink: :

Indeed looking at the dmesg (and logcat) some errors are correlated to this:

[    6.368098] aw8695_ram_work_routine enter
[    6.368195] aw8695_haptic 2-005a: Falling back to syfs fallback for: aw8695_haptic.bin
[    6.371161] aw8695_ram_loaded enter
[    6.371167] aw8695_ram_loaded: failed to read aw8695_haptic.bin
[    6.371172] aw8695_ram_loaded:start hrtimer:load_cont1
[    7.366073] init: starting service 'adbd'...
[    7.366551] init: Created socket '/dev/socket/adbd', mode 660, user 1000, group 1000
[    7.368607] init: starting service 'recovery'...
[    7.368953] init: Created socket '/dev/socket/recovery', mode 422, user 1000, group 1000
[    7.390804] read descriptors
[    7.390876] read strings
[    7.391470] init: processing action (sys.usb.config=adb && sys.usb.configfs=1 && sys.usb.ffs.ready=1) from (/system/etc/init/hw/init.rc:199)
[    7.392070] aw8695_ram_work_routine enter
[    7.392124] aw8695_haptic 2-005a: Falling back to syfs fallback for: aw8695_haptic.bin
[    7.394792] ueventd: firmware: loading 'aw8695_haptic.bin' for '/devices/platform/soc/990000.i2c/i2c-2/2-005a/firmware/aw8695_haptic.bin'
[    7.395047] ueventd: firmware: could not find firmware for aw8695_haptic.bin
[    7.395061] ueventd: firmware: attempted /etc/firmware/aw8695_haptic.bin, open failed: No such file or directory
[    7.395073] ueventd: firmware: attempted /odm/firmware/aw8695_haptic.bin, open failed: No such file or directory
[    7.395084] ueventd: firmware: attempted /vendor/firmware/aw8695_haptic.bin, open failed: No such file or directory
[    7.395095] ueventd: firmware: attempted /firmware/image/aw8695_haptic.bin, open failed: No such file or directory
[    7.395164] ueventd: loading /devices/platform/soc/990000.i2c/i2c-2/2-005a/firmware/aw8695_haptic.bin took 0ms
[    7.395213] aw8695_ram_loaded enter
[    7.395218] aw8695_ram_loaded: failed to read aw8695_haptic.bin
[    7.395223] aw8695_ram_loaded:start hrtimer:load_cont2

Is this blob have to be manually extracted and added somewhere inside TWRP build folder?

Looking inside the /vendor/firmware/ directory on my FP4 phone, those two files are present:

aw8695_haptic.bin
aw8695_osc_rtp_24K_5s.bin

The kernel driver (probably) works in TWRP but it exposes a non-standard sysfs interface so the HAL from Android needs to be used that works with that one.

Trying to add vendor.qti.hardware.vibrator.service my notes say “Locks up the UI, no adb available”, so sounds relatively similar to the behavior with the userdata decryption libraries present. If someone wants to try further this is what I had last time: [WIP] FP4 vibrator · z3ntu/android_device_fairphone_FP4@091badc · GitHub

edit: once the HAL is working, the aw8695 “firmware” (it’s defining the waveform used for haptics so it’s more data than firmware) is very likely needed,

Is this non-standard syfs interface for aw8695_haptic related to the hardware, or specific to FP4?
In other words, if I take another device using AW8695 (just as an example Motorola Nio ), is the TWRP port for this device likely suffering from the same issue? :thinking:

Looking for “syfs fallback” in the dmesg I found two other similar lines to the aw8695_haptic one:

[    2.411813] msm-dsi-display soc:qcom,dsi-display-primary: Falling back to syfs fallback for: iris6.fw
[...]
[    3.712157] himax_tp 1-0048: Falling back to syfs fallback for: Himax_firmware.bin

Are those two firmware to be fixed as well?

@oli.sax I believe the modifications to the HAL is only for the aw8695 driver, so specific to that, not to FP4. What might be different to the Motorola device that the HAL is now AIDL and not HIDL, which changed with recent Android versions, but it might be possible that the Motorola HAL also works on FP4.

I haven’t looked too much into Himax_firmware.bin and iris6.fw but I’m quite certain they’re not needed for normal operation.

1 Like

Do you have a clear idea of where/which decryption library is failing?

Looking up for “decrypt” in dmesg/logcat I see nothing, and in recovery.log there is this part:

part of recovery.log when TW_INCLUDE_CRYPTO := true
I:Unable to mount '/data'
I:Actual block device: '/dev/block/sda11', current file system: 'f2fs'
I:Backup folder set to '/data/media/TWRP/BACKUPS/ef69ff96'
I:Settings storage is '/data/media'
DEBUG:prepdecrypt::Running prepdecrypt script for TWRP...
I:prepdecrypt::File Based Encryption (FBE) is present.
DEBUG:prepdecrypt::SDK version: 30
DEBUG:prepdecrypt::DEFAULTPROP variable set to prop.default.
DEBUG:prepdecrypt::A/B device detected! Finding current boot slot...
DEBUG:prepdecrypt::Current boot slot: _b
DEBUG:prepdecrypt::SETPATCH Override flag found.
DEBUG:prepdecrypt::Device has recovery partition!
DEBUG:prepdecrypt::Resetprop binary not found. Falling back to setprop.
DEBUG:prepdecrypt::Recovery/Fastbootd mode boot detected.
DEBUG:prepdecrypt::SETPATCH Override flag found.
I:prepdecrypt::SETPATCH=true
DEBUG:prepdecrypt::Build tree is Oreo or above. Proceed with setting props...
DEBUG:prepdecrypt::Temporary vendor folder created at /v.
DEBUG:prepdecrypt::vendor mounted at /v.
DEBUG:prepdecrypt::prepdecrypt.vendor_mounted=1
DEBUG:prepdecrypt::Vendor Build.prop exists! Reading vendor properties from build.prop...
DEBUG:prepdecrypt::Current vendor Android SDK version: 30
DEBUG:prepdecrypt::Current vendor is Oreo or above. Proceed with setting vendor security patch level...
DEBUG:prepdecrypt::Current Vendor Security Patch Level: 2127-12-31
E:prepdecrypt::setprop failed. Vendor Security Patch Level unchanged.
DEBUG:prepdecrypt::prop.default update successful! ro.vendor.build.security_patch=2021-12-05
DEBUG:prepdecrypt::System-as-Root device detected! Updating build.prop path variable...
DEBUG:prepdecrypt::Build.prop location set to system/build.prop.
DEBUG:prepdecrypt::Temporary system folder created at /s.
DEBUG:prepdecrypt::system mounted at /s.
DEBUG:prepdecrypt::prepdecrypt.system_mounted=1
DEBUG:prepdecrypt::Build.prop exists! Reading system properties from build.prop...
DEBUG:prepdecrypt::Current system Android SDK version: 30
DEBUG:prepdecrypt::Current system is Oreo or above. Proceed with setting OS Version & Security Patch Level...
DEBUG:prepdecrypt::Current OS Version: 11
DEBUG:prepdecrypt::setprop successful! New OS Version: 11
DEBUG:prepdecrypt::prop.default update successful! ro.build.version.release=11
DEBUG:prepdecrypt::Current Security Patch Level: 2127-12-31
E:prepdecrypt::setprop failed. Security Patch Level unchanged.
DEBUG:prepdecrypt::prop.default update successful! ro.build.version.security_patch=2021-12-05
I:prepdecrypt::crypto.ready=1
I:prepdecrypt::Script complete. Device ready for decryption.
Starting TWRP 3.6.0_11-0-bee26852 on Sat Feb 19 19:58:49 2022
 (pid 638)
I:Lun file '/sys/class/android_usb/android0/f_mass_storage/lun0/file' does not exist, USB storage mode disabled
PRODUCT_USE_DYNAMIC_PARTITIONS := true
TW_INCLUDE_CRYPTO := true

The only error I see here is linked to the patch level (I guess?)

DEBUG:prepdecrypt::Resetprop binary not found. Falling back to setprop.
E:prepdecrypt::setprop failed. Vendor Security Patch Level unchanged.
E:prepdecrypt::setprop failed. Security Patch Level unchanged.

Then the prepdecrypt says it succeeded, but just after the device automatically reboot - and continue rebooting every 10 seconds. So strange :wink:

I:prepdecrypt::crypto.ready=1
I:prepdecrypt::Script complete. Device ready for decryption.
Starting TWRP 3.6.0_11-0-bee26852 on Sat Feb 19 19:58:49 2022
 (pid 638)

Booting the twrp image in the description causes me the phone stuck at the logo in boot up. FP4 Iode os. Any idea? Thanks

Strange, for me it works correctly (on stock OS)

Are you doing fastboot boot twrp.img or fastboot flash recovery twrp.img ? (I do the first one)

The first one too. fastboot boot twrp.img

Kurze Frage mal meinerseits

Um ein Backup der system PArtiotion zu machen, nützt mir TWRP nun nichts, da diese mit in der super PArtion abliegt und diese super verschlüsselt ist. Richtig?

Heißt für Backups auf dem FP4 ist TWRP ungeeignet.
Da muss ich anders ran.