finally got a twrp build & workaround for the fastboot boot failure
It took quite a lot of time to figure this out with no help, but I finally got twrp to build using current versions of modpunk's sources. (Hint: Ignore the OP. The
source code link there is the wrong branch and contains incorrect instructions for TWRP.) Here's what worked for me:
These steps assume an ubuntu 18.04.4 system with openjdk-8 and all other necessary development packages already installed.
Warning: I am not covering build signing here; these instructions will use default (insecure) signing keys. (I'm also not sure a properly signed twrp image would be any better than an unsigned one, given that the bootloader must be unlocked to use it, but I figure it's worth mentioning.)
Start in an empty directory.
Prepare the vendor blobs, so the extract-files step will work:
- Retrieve and unpack the latest vendor firmware (47.2.A.11.228) using a tool like XperiFirm.
- Convert the system_*.sin and vendor_*.sin files to system_*.ext4 and vendor_*.ext4 using a tool like UnSIN.
- Create a new directory (I called mine "vendor-files") with two empty subdirectories named system and vendor.
- Mount the .ext4 files over those subdirectories, with commands like: mount -o loop system_*.ext4 system
- Remember the full path of the vendor-files directory.
Set up the project manifests, sync the code, and configure and run the build:
Code:
repo init -u git://github.com/minimal-manifest-twrp/platform_manifest_twrp_omni.git -b twrp-9.0
mkdir .repo/local_manifests
cat > .repo/local_manifests/twrp.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<!-- SONY -->
<project name="cryptomilk/android_kernel_sony_msm8998" path="kernel/sony/msm8998" remote="github" revision="lineage-17.1" />
<project name="cryptomilk/android_device_sony_common-treble" path="device/sony/common-treble" remote="github" revision="twrp-9.0" />
<project name="cryptomilk/android_device_sony_yoshino" path="device/sony/yoshino" remote="github" revision="twrp-9.0" />
<project name="cryptomilk/android_device_sony_lilac" path="device/sony/lilac" remote="github" revision="twrp-9.0" />
<project name="cryptomilk/android_vendor_sony_lilac" path="vendor/sony/lilac" remote="github" revision="lineage-16.0" />
<!-- QCOM -->
<project name="android_device_qcom_caf-sepolicy" path="device/qcom/sepolicy" remote="omnirom" revision="android-9.0" />
<project name="android_vendor_qcom_opensource_commonsys" path="vendor/qcom/opensource/commonsys" remote="omnirom" revision="android-9.0" />
<!-- TWRP -->
<remove-project name="android_bootable_recovery" />
<project name="TeamWin/android_bootable_recovery" path="bootable/recovery" remote="github" revision="android-9.0" />
</manifest>
EOF
repo sync # this will take a long time
cd device/sony/lilac
./extract-files.sh /path/to/vendor-files
cd -
export WITH_TWRP=true
export ALLOW_MISSING_DEPENDENCIES=true # required by minimal-manifest-twrp
. build/envsetup.sh
lunch omni_lilac-eng
mka -j5 recoveryimage # 5 is the number of parallel tasks to run. CPU cores + 1 is a good choice.
When the build finishes, the twrp image will be out/target/product/lilac/recovery.img
A few notes about the repositories used here:
- I used the minimal-manifest-twrp (twrp-9.0 branch) base manifests, because both the full omnirom manifests and the LineageOS manifests currently seem to be incompatible with modpunk's lilac repos. I tried around twenty repo combinations hoping to get those to work, and they all failed to build.
- I used the lineage-17.1 branch of android_kernel_sony_msm8998, because the lineage-16.0 branch referenced by OP failed on illegal/unsupported C code. (Probably due to differences between clang and other compiler front-ends.)
- I used the twrp-9.0 branches of android_device_sony_*, rather than the lineage-16.0 branch referenced by OP.
- I added the android_device_qcom_caf-sepolicy and android_vendor_qcom_opensource_commonsys projects, neither of which is mentioned in OP or its linked repo, because I found them buried in the comments of another thread.
- I used the TeamWin/android_bootable_recovery project, rather than omnirom/android_bootable_recovery as suggested by the official twrp build instructions, because the latter contains a build-breaking bug. A twrp developer recommended ignoring the instructions and using the TeamWin one instead. Apparently all their instructions and links to them are out of date.
- I did not name my local manifest roomservice.xml as suggested by the readme at OP's link, because that file will be overwritten by the build system if it detects a conflict with omni.dependencies. Anything you put in roomservice.xml is at risk of being lost when you run lunch. Instead, I named my local manifest twrp.xml.
Regarding fastboot:
I wanted to test my twrp build before flashing it to a phone, so I put the phone in bootloader mode (blue LED) and ran fastboot boot recovery.img. That brought up the black Sony logo on a white background, but the phone remained stuck on that logo screen. I don't know why. There were no logs to examine and nothing responding to adb over usb, so I'm in the dark on this one.
There's a workaround, though: Put the phone in bootloader (fastboot) mode, and then run fastboot reboot-bootloader, to make it enter bootloader mode a second time. Then run fastboot boot recovery.img. I have no idea why this works. If someone else knows what's going on here, please share the details.
Once I was satisfied that this twrp build worked, I flashed it with fastboot flash recovery recovery.img . Rebooting to recovery mode worked on the first try.