Development [RECOVERY][3.7.0-12.1][UNOFFICIAL][UNIFIED] TWRP with A12/A13 encryption support

Search This thread

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
15,308
34,656
Halifax
GT-i9250
Google Nexus 4
Last edited:

der_akinator

Senior Member
Mar 27, 2015
168
259
Berlin
OnePlus 3T
OnePlus 9 Pro
😍

What was breaking losetup?!

I was about to try it with my busybox builds today to see if it worked any better.

Official TWRP status wen? 🙌
I disabled internal TWRP APEX handling. I think TWRP might have blocked the loop devices but I'm not sure why magisk installer couldn't create a new loop device. Maybe loop-control was constantly blocked by TWRP.

I will do a bit of code cleanup and ask in zulip to make it official.
 

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
15,308
34,656
Halifax
GT-i9250
Google Nexus 4
I disabled internal TWRP APEX handling. I think TWRP might have blocked the loop devices but I'm not sure why magisk installer couldn't create a new loop device. Maybe loop-control was constantly blocked by TWRP.

I will do a bit of code cleanup and ask in zulip to make it official.
A bit of further digging today, just for my own curiosity:

It's both loop0 and loop1 which are blocked, any losetup action on them from busybox or toybox (TWRP's ramdisk losetup is toybox) will cause a hang. All loops higher than 1 behave normally.

`busybox losetup /dev/block/loop0` just silently hangs.
`toybox losetup /dev/block/loop0` displays "losetup: /dev/block/loop0: Value too large for defined data type" then hangs.

Interestingly AK3 was unaffected, though I'm not entirely sure why yet, since it still falls back to using losetup.

TWRP's never blocked the loop devices previously; not sure if it's something specific to lemonadep, lineage-20 or twrp-12.

I believe Lineage switched to .capex with lineage-20. Could it just be that TWRP's internal apex handling just doesn't know how to support .capex yet? 🤔


Edit: Aha! AK3 unmounts all existing /apex first, so it basically reset loop0 and loop1, so no hang with AK3. Well there's one part of the mystery solved anyway. :cool:
 
Last edited:
  • Like
Reactions: der_akinator

der_akinator

Senior Member
Mar 27, 2015
168
259
Berlin
OnePlus 3T
OnePlus 9 Pro
A bit of further digging today, just for my own curiosity:

It's both loop0 and loop1 which are blocked, any losetup action on them from busybox or toybox (TWRP's ramdisk losetup is toybox) will cause a hang. All loops higher than 1 behave normally.

`busybox losetup /dev/block/loop0` just silently hangs.
`toybox losetup /dev/block/loop0` displays "losetup: /dev/block/loop0: Value too large for defined data type" then hangs.

Interestingly AK3 was unaffected, though I'm not entirely sure why yet, since it still falls back to using losetup.

TWRP's never blocked the loop devices previously; not sure if it's something specific to lemonadep, lineage-20 or twrp-12.

I believe Lineage switched to .capex with lineage-20. Could it just be that TWRP's internal apex handling just doesn't know how to support .capex yet? 🤔


Edit: Aha! AK3 unmounts all existing /apex first, so it basically reset loop0 and loop1, so no hang with AK3. Well there's one part of the mystery solved anyway. :cool:
I also noticed that TWRP keeps /dev/loop-control open as RW for its whole lifetime but that doesn't seem to be a problem because magisk installation still hangs after I patched this. Only loop0 and 1 are a problem because TWRP only loads two apex files in its current configuration.
Maybe we should create a PR for magisk to include the unmount/losetup parts from AK3. This might be helpful for devices that have apex included in TWRP. For now I just keep building it without apex support.
 
  • Like
Reactions: osm0sis

osm0sis

Senior Recognized Developer / Contributor
Mar 14, 2012
15,308
34,656
Halifax
GT-i9250
Google Nexus 4
I also noticed that TWRP keeps /dev/loop-control open as RW for its whole lifetime but that doesn't seem to be a problem because magisk installation still hangs after I patched this. Only loop0 and 1 are a problem because TWRP only loads two apex files in its current configuration.
Maybe we should create a PR for magisk to include the unmount/losetup parts from AK3. This might be helpful for devices that have apex included in TWRP. For now I just keep building it without apex support.
Nah, it's definitely more an issue on TWRP's side, since it didn't used to hold the loops the way it currently is which causes the hangs. My guess is still that TWRP is lacking .capex support.

Magisk not unmounting them is technically better than what I currently do in AK3 since after install everything goes back to how it was, since the installer mounts a tmpfs over /apex to not touch anything there from TWRP.
 

javi2246

Member
Jul 22, 2022
33
6
Restore doesn't work on LOS 19.1. Force checked twice...

I made the backup without pattern/pin, now when it comes to restoring I try to do a factory reset first, I restart I enter the OS, I go back to TWRP and I do the restore, I restart and the lineageos logo stays loading, it restarts only a couple of times, I enter TWRP to get the logs (it doesn't ask for a pin) but I'm going to mount the files and it's empty, it seems that everything has been deleted, in the "mount" option there is a button that says decrypt data, but it asks for a password (text)....
 

der_akinator

Senior Member
Mar 27, 2015
168
259
Berlin
OnePlus 3T
OnePlus 9 Pro
Restore doesn't work on LOS 19.1. Force checked twice...

I made the backup without pattern/pin, now when it comes to restoring I try to do a factory reset first, I restart I enter the OS, I go back to TWRP and I do the restore, I restart and the lineageos logo stays loading, it restarts only a couple of times, I enter TWRP to get the logs (it doesn't ask for a pin) but I'm going to mount the files and it's empty, it seems that everything has been deleted, in the "mount" option there is a button that says decrypt data, but it asks for a password (text)....
I could reproduce your issue when restoring backup with pattern set. It looks like super and data shouldn't be restored at the same time.
May solution:
1. Factory reset but NOT format data in TWRP
2. Flash previously installed OTA zip.
3. Reboot to system
4. Don't set any pin/password
5. Reboot to TWRP
6. Backup should show up again and restore only data
7. Reboot to system
8. If that doesn't help reboot to TWRP and restore only super

Edit: It doesn't matter if backup is made with or without pin/pattern. It is important that pin/pattern is not present when restoring it.
 
Last edited:

javi2246

Member
Jul 22, 2022
33
6
I could reproduce your issue when restoring backup with pattern set. It looks like super and data shouldn't be restored at the same time.
May solution:
1. Factory reset but NOT format data in TWRP
2. Flash previously installed OTA zip.
3. Reboot to system
4. Don't set any pin/password
5. Reboot to TWRP
6. Backup should show up again and restore only data
7. Reboot to system
8. If that doesn't help reboot to TWRP and restore only super

Edit: It doesn't matter if backup is made with or without pin/pattern. It is important that pin/pattern is not present when restoring it.
super? I'm talking from memory (I've updated to LO20 and haven't installed TWRP yet), but I didn't seem to see any partition named super, just data, efs, modem and internal storage (SD).
The rest of the steps coincide with yours, I tried several combinations without success.
 

rav3ns

Member
Jul 2, 2010
24
2
Hello @der_akinator ,

I'm trying to install following the universal option, but I have a screen with artifacts, similar to:

Wn4Us.jpg



In the computer I can see the device and navigate under folders, but I can't do anything obviusly.
0a4155c4cc8d0d9e99e13420241a7eb7 md5sum of boot.img , maybe is incorrect?

Also I try with the boot.img of folder 30/12 and this only returns to the fastboot mode.

Any sugestion?
 

der_akinator

Senior Member
Mar 27, 2015
168
259
Berlin
OnePlus 3T
OnePlus 9 Pro
super? I'm talking from memory (I've updated to LO20 and haven't installed TWRP yet), but I didn't seem to see any partition named super, just data, efs, modem and internal storage (SD).
The rest of the steps coincide with yours, I tried several combinations without success.
Super is the partition that contains more logical partitions like system, vendor, etc. It's basically like an OTA zip.
 

Attachments

  • Screenshot_2023-01-10-07-43-40.png
    Screenshot_2023-01-10-07-43-40.png
    129.7 KB · Views: 41
  • Like
Reactions: javi2246 and Aqq123

der_akinator

Senior Member
Mar 27, 2015
168
259
Berlin
OnePlus 3T
OnePlus 9 Pro
Hello @der_akinator ,

I'm trying to install following the universal option, but I have a screen with artifacts, similar to:

Wn4Us.jpg



In the computer I can see the device and navigate under folders, but I can't do anything obviusly.
0a4155c4cc8d0d9e99e13420241a7eb7 md5sum of boot.img , maybe is incorrect?

Also I try with the boot.img of folder 30/12 and this only returns to the fastboot mode.

Any sugestion?
Do you use OP9 or pro and what OS are you running? Was your screen changed at one point? I think is has something to do with the arguments of the msm_drm kernel module which is responsible for the screen. I give it some standard arguments that work at least on the pro with custom roms.

Edit: If you have root you can send me the contents of /sys/module/msm_drm/parameters/dsi_display0 and I can include this in the next build to support other screens too.
 
Last edited:
  • Like
Reactions: Aqq123

rav3ns

Member
Jul 2, 2010
24
2
Do you use OP9 or pro and what OS are you running? Was your screen changed at one point? I think is has something to do with the arguments of the msm_drm kernel module which is responsible for the screen. I give it some standard arguments that work at least on the pro with custom roms.

Edit: If you have root you can send me the contents of /sys/module/msm_drm/parameters/dsi_display0 and I can include this in the next build to support other screens too.
OP9 not Pro version.
Stock rom full updated to the last version. ( I can't remember what version was)

Finally I got a brick and I unbricked with MSM and with stock rom.


At this point I'm on Oxygen OS 11.2.10.10 LE25AA on OP9 model LE2113.
with fastboot boot twrp.img was not working.
I installed official "twrp-3.7.0_11-0-lemonadep.img" and then install with adb sideload twrp-installer-3.7.0-12.1-2-lemonadep.zip


Recovery is loaded correctly but i'm not able to use (touch isn't working) also I tryed OTB mouse & keyboard but not working.
 

rav3ns

Member
Jul 2, 2010
24
2
Do you use OP9 or pro and what OS are you running? Was your screen changed at one point? I think is has something to do with the arguments of the msm_drm kernel module which is responsible for the screen. I give it some standard arguments that work at least on the pro with custom roms.

Edit: If you have root you can send me the contents of /sys/module/msm_drm/parameters/dsi_display0 and I can include this in the next build to support other screens too.
Attached the file /sys/module/msm_drm/parameters/dsi_display0 extracted with terminal in twrp.

Thank you a lot.
 

Attachments

  • dsi_display0.zip
    197 bytes · Views: 6

der_akinator

Senior Member
Mar 27, 2015
168
259
Berlin
OnePlus 3T
OnePlus 9 Pro
OP9 not Pro version.
Stock rom full updated to the last version. ( I can't remember what version was)

Finally I got a brick and I unbricked with MSM and with stock rom.


At this point I'm on Oxygen OS 11.2.10.10 LE25AA on OP9 model LE2113.
with fastboot boot twrp.img was not working.
I installed official "twrp-3.7.0_11-0-lemonadep.img" and then install with adb sideload twrp-installer-3.7.0-12.1-2-lemonadep.zip


Recovery is loaded correctly but i'm not able to use (touch isn't working) also I tryed OTB mouse & keyboard but not working.
I might have found a fix but for testing I depend on you because I haven't an OP9. If you want to stay on OOS11 you should probably use the official TWRP 3.7.0-11.0 version due to differences in encryption.

 

rav3ns

Member
Jul 2, 2010
24
2
I might have found a fix but for testing I depend on you because I haven't an OP9. If you want to stay on OOS11 you should probably use the official TWRP 3.7.0-11.0 version due to differences in encryption.


I want to flash a rom with Android 12 / 13.
I go to test this recovery, thanks!
EDIT: installed with adb sideload and now is working! Thanks a lot!
 
Last edited:
  • Like
Reactions: der_akinator

Top Liked Posts

  • 1
    Maybe someone can answer a question for me: If I wanna replace this TWRP with LineageOS recovery, can I still follow the instructions for installing LOS 20, or do I need to take any extra steps? I remember reading that there is no dedicated recovery partition anymore, so it says to flash it to boot, but just wanted to confirm that that'll replace TWRP with LineageOS revovery.

    Thanks!
    Flash the required boot.img will replace TWRP.
  • 10
    Good new for OOS users. One of the TWRP devs found a workaround for data restore on OOS. Just delete "/data/system/users/0/package-restrictions.xml", after data is restored. I will exclude this file by default in a future build, but for existing backups, the file must always be removed manually.

    Edit:
    This is also useful for custom ROMs, because it makes first boot faster and eliminates the need to reboot again.
    6
    Seems to take a lot longer to boot and show the decryption prompt than -5. 🤔
    Uploaded a new build that reverts some of the fstab changes. Works fine on my device and hopefully on yours too.

    5
    Update
    • Fix backups and logs not accessible from system
    If you already have backups that aren't accessible from system, flash change_backup_selinux_context.zip which is available in the latest download folder. All backups made with TWRP builds starting from 14-01-23 (aka 3.7.0-12.1-4) are affected.

    4
    Hi der_akinator,
    thanks for your reply.

    Why only boot.img can be flashed at the moment ?

    I do not understand the difference between TWRP flashnig methid and Fastboot / ADB sideload and the other stuff.....

    I ask only for better understand as I have anyway understood that the correct procedure is by using Fastboot / ADB sideload and so on.....
    I uploaded a new build with which you can flash vendor_boot and dtbo. It also adds backup support for additional firmware partitions.

  • 46
    This is an unofficial build of TWRP, based on the Android 12.1 branch, that supports encryption used by Android 12 and 13 ROMs. This build is tested on OP9pro but it was confirmed to work on OP9 with OOS 12 firmware installed. Other configurations have to be tested.

    As always I'm not responsible for any bricked device or data loss resulting from the use of this TWRP builds. You use this at your own risk.

    For ROMs using FBEv1 encryption aka A11 encryption, please use the official builds by
    @Nebrassy from:

    Download:


    Installation:

    Permanent installation is not possible with TMO stock ROM installed.


    To temporarily boot TWRP, use the first three steps of Option 3.
    For permanent installation, you have three options depending on your current system.

    1. Option for rooted devices:
    1. Download the twrp-installer zip
    2. Flash it with Magisk manager or some other kernel flash utility
    3. Reflash your custom kernel and Magisk if previously installed
    2. Option for users with other custom recoveries but without root:
    1. Download the twrp-installer zip
    2. Flash it with "adb sideload twrp-installer*.zip"
    3. Reboot to recovery
    4. Reflash your custom kernel and Magisk if previously installed
    3. Option is universal:
    1. OOS13 (firmware) users please download boot-oos13.img. All other users please use boot.img
    2. Reboot to bootloader
    3. Run "fastboot boot boot*.img" with the boot image
    4. Go to Advanced > Flash Current TWRP
    5. Reflash your custom kernel and Magisk if previously installed

    Uninstall:

    Just flash the boot partition with your current ROMs boot image with the following steps:
    1. Reboot to bootloader
    2. Run "fastboot flash boot_a YOUR ROM BOOTIMAGE"
    3. Run "fastboot flash boot_b YOUR ROM BOOTIMAGE"
    Alternatively you can flash your currently installed OTA zip, which overwrites boot on the unused slot, but not on the currently used one.

    TWRP Updates:
    1. Download and flash the twrp-installer zip
    2. After that reflash your custom kernel and Magisk if previously installed

    ROM Updates:

    Please follow the official update instructions for your ROM!


    If they give an option to update via recovery you have to substitute adb sideload commands with zip installations. And use the "Automatically reflash TWRP after flashing a ROM" option if you are going to install a ROM zip to preserve TWRP.

    In case your ROM does not provide a recovery update instruction you can try to update via recovery but you are on the safe side if you follow the official instructions. They always have a reason for their particular update instructions!

    Instructions that work for me (on LOS based ROMs):
    1. Flash ROM zip with "Automatically reflash TWRP after flashing a ROM" checked
    2. Flash your previously installed zips (custom kernel, Gapps, Magisk, etc)
    3. Reboot to system
    4. If Gapps packages keep crashing:
      1. Reboot to TWRP
      2. Flash Gapps again
      3. Reboot to system
    For OOS updates you can follow these steps (I haven't tested them):

    About backups/restore:

    Restore data only WITHOUT pin/pattern set.


    Backups can be made with or without pin/pattern set. It is always good practice to copy your backups to your PC or an USB drive. Also after you restored your data partition you have to reboot to system and do a second reboot to get a working system.
    To make first boot faster and eliminate the need to reboot again, additionally use the step mandatory for OOS users.

    If you want to copy your backup to PC, but it doesn't show up, flash change_backup_selinux_context.zip, which is available in download folder.

    For OOS users:
    When data is restored, you have to delete "/data/system/users/0/package-restrictions.xml" before rebooting to system.

    In case you restore a backup with pin/pattern set or have some other issues I have a guide that works for me:

    Source Code:
    Bugs:
    • Permanent installation besides TMO stock isn't possible
    • In case you notice anything else please let me know.

    Thanks to:
    • @Nebrassy for the original device tree
    • @osm0sis for the zip installer
    • TWRP team
    • LineageOS
    13
    Update
    • /data/fonts/* is excluded from backups (has to be verified by someone with backup errors)
    • screen turns completely off now
    • updated firmware files from LE2125_11.C.63 (maybe this helps with OOS13 problems)
    • initial installation is now possible without flashing vendor_boot (I tested a few combinations of installation methods and initial system configurations. So hopefully nothing is broken this time.)
    Have a happy New Year tomorrow!

    10
    Update
    • improve vibration support
    • fix kernel modules loading in fastbootd mode for custom roms (might result in an error message regarding vendor_dlkm for OOS users, but it's just cosmetic)
    Tested on LOS 19.1 (OOS 12 firmware) and crdroid 13 (OOS 13 firmware).

    10
    Update
    • add vendor_boot and dtbo to backup targets
    • add CPU temperature output
    • fix vibration (still doesn't work in fastbootd mode)
    I tested this build on LOS 19.1 (OOS 12 firmware) and crdroid 13 (OOS 13 firmware). Also keep in mind that you have to use the boot image according to your installed firmware, if you want to install/test via fastboot.

    10
    Good new for OOS users. One of the TWRP devs found a workaround for data restore on OOS. Just delete "/data/system/users/0/package-restrictions.xml", after data is restored. I will exclude this file by default in a future build, but for existing backups, the file must always be removed manually.

    Edit:
    This is also useful for custom ROMs, because it makes first boot faster and eliminates the need to reboot again.