[UNOFFICIAL][ENCRYPTION][wrappedkey] TWRP 3.3.1-6: proper system_as_root & decryption

mitomanu

Senior Member
Feb 4, 2014
266
374
0
CLUJ-Napoca
Hey, I am little bit confused about these above two FAQs. Earlier I used to flash custom ROM on my Redmi Note 3 by just downloading any ROM and just flash it in TWRP. But I guess from few things have changes related to system partitions which might soft brick phone (My new Redmi Note 7 Pro).

1. Can someone provide a source from which I can understand what have changed and what should I take care before flashing ROMs?
2. Is it same like before for installing ROM on my Note 7 Pro like I used to do in my Redmi Note 3? I think we have to now wipe data if I am moving from wrappedkey ROM to AOSP or vise versa.

Thanks in Advance.
Read The posts with custom roms. Some of those roms support wrappedkey some not. If you are on MIUI official and want to flash a custom rom you MUST format data partition. Just be aware if you have @PeterCxy's TWRP. When you boot in TWRP use the pin Code you used to unlock your device. Otherwise The data Will not be decrypted.

Hope is helpful.

---------- Post added at 05:52 PM ---------- Previous post was at 05:47 PM ----------

One big bug in this TWRP... Cannot restore data. Error 255. I tried to restore all except data, reboot, boot în TWRP, restore only data, failed. Again, now format data and restore all, failed then Again restore without data, reboot, and so on... Again, Error 255.
Any suggestion?
 
  • Like
Reactions: JZ™

JZ™

Senior Member
Jan 5, 2015
217
37
0
Read The posts with custom roms. Some of those roms support wrappedkey some not. If you are on MIUI official and want to flash a custom rom you MUST format data partition. Just be aware if you have @PeterCxy's TWRP. When you boot in TWRP use the pin Code you used to unlock your device. Otherwise The data Will not be decrypted.

Hope is helpful.

---------- Post added at 05:52 PM ---------- Previous post was at 05:47 PM ----------

One big bug in this TWRP... Cannot restore data. Error 255. I tried to restore all except data, reboot, boot în TWRP, restore only data, failed. Again, now format data and restore all, failed then Again restore without data, reboot, and so on... Again, Error 255.
Any suggestion?
https://forum.xda-developers.com/re...igrate-root-fixed-version-unofficial-t3944054
Check it out

---------- Post added at 04:31 AM ---------- Previous post was at 04:09 AM ----------

This is because of the fat32 limitation..if you can convert it to another file system technically it should work...

---------- Post added at 12:44 PM ---------- Previous post was at 12:43 PM ----------


Why do u even need to patch that? It works without flashing it, Peter's TWRP decrypts your device( using your phone screen password) so you don't need to flash anything else...
How to know the phone password? I hav set a pattern lock
 
  • Like
Reactions: mitomanu

Naveenthemi

Senior Member
Aug 8, 2016
439
126
0
Last edited:
  • Like
Reactions: JZ™

adriansticoid0312

Senior Member
Nov 2, 2012
176
59
48
San Pedro
One big bug in this TWRP... Cannot restore data. Error 255. I tried to restore all except data, reboot, boot în TWRP, restore only data, failed. Again, now format data and restore all, failed then Again restore without data, reboot, and so on... Again, Error 255.
Any suggestion?
Data restore works for me. But I encountered this bug too. What I did is I restored all other partitions except data, rebooted to system, rebooted back to TWRP to restore data and it worked.


Sent from my Redmi Note 7 Pro using XDA Labs
 
  • Like
Reactions: mitomanu

seong1

Senior Member
Feb 9, 2016
60
11
0
Code:
/*
 * I'm not responsible for bricked devices, dead SD cards, thermonuclear war, or you getting fired because the alarm app failed (like it did for me...). 
 * Please do some research if you have any concerns about features included in the products you find here before flashing it! 
 * YOU are choosing to make these modifications, and if you point the finger at me for messing up your device, I will laugh at you. 
 * Your warranty will be void if you tamper with any part of your device / software.
 * Same statement for XDA.
 */
Introduction

This is an unofficial build of TWRP for Redmi Note 7 Pro (violet). Differences with the official one include:

- Supports CAF-based wrappedkey encryption (decryption) properly (tested with MIUI 10.3.5.0)
- Supports decrypting devices that have screen lock set up after Android 9 May update, which introduced a new key derivation function.
- Mounts the system partition at /system_root as per AOSP standards. This makes the auto-backup scripts (e.g. GApps / Magisk survival script) work properly during updates, and you no longer need any 'patch' to flash GApps / Magisk properly. However, this may break some existing ROMs. See below FAQ section for details.
- Appended DTBO to the recovery image so it doesn't depend on the dtbo partition. No standalone DTBO image required.

Flashing instructions

- Download and extract the img file
- Reboot to fastboot mode
- fastboot flash recovery whatever_img_file_you_extracted.img
- Reboot and press Volume + to enter recovery
- DO NOT try to run 'fastboot boot recovery.img', it won't work.
- DO NOT flash the fcrypt disabler if you use my recovery. There is no need to do so, and it is possible to mess stuff up if you don't know what you are doing.
- You have to format the data partition if and ONLY IF:
1) You were not encrypted, now going to an encrypted state, or vice-versa OR
2) You were on a ROM other than MIUI that does not support "wrappedkey" (ROMs would often state it supports wrappedkey if it does), now going to a ROM that supports it

Limitations

DO NOT boot this recovery with empty system and vendor partitions. It will fail to decrypt any data partition with empty /system and /vendor. DO NOT wipe system and vendor partitions without installing a new one before rebooting. I am working to remove this limitation.

Now works even with empty system and vendor partitions after 3.3.1-5. No need to worry about formatting system and vendor breaking TWRP any more.

The restore zip created by the Migrate app is NOT compatible with this recovery. It's a problem of the Migrate app, not this recovery. Please DO NOT try to flash the restore zip created by Migrate.

FAQ

- Q: Do I need any specific DTBO image to make this recovery working?
- A: Nope. It is appended to the recovery image so it will work with any DTBO.

- Q: What is wrappedkey?
- A: It's a different mode of FBE implemented in CAF, the Qualcomm branch of AOSP.

- Q: This cannot install ROM X, why?
- A: Because it mounts the system partition at /system_root, which is AOSP standard behavior for A-only system_as_root devices, but is broken in some custom ROMs currently (MIUI should work though). To make any ROM work again, they will need to include this commit from LineageOS Gerrit https://review.lineageos.org/c/LineageOS/android_build/+/247066

- Q: Decryption doesn't work with ROM X, why?
- A: Decryption should work for most ROMs based on the CAF branch (not AOSP). CAF ROMs (including official MIUI) use a different scheme for key storage, which is why TWRP hasn't supported it till now. I have ported the CAF encryption changes (wrappedkey) to TWRP, but unfortunately this will break ROMs that do not support the CAF wrappedkey mode of encryption. Here is a list of patches non-CAF ROMs need to support CAF-encrypted /data partitions https://mokeedev.review/q/topic:%22fbe-wrapped-key%22+(status:eek:pen%20OR%20status:merged). If you confirm your ROM is CAF-based but the decryption still does not work, please open an issue on my GitHub repository which you could find below. (XDA threads are no good for issue tracking, sorry)

- Q: Why not contribute to the official TWRP?
- A: All the patches to the TWRP code base have been submitted to the official gerrit code review, though not merged yet, which you can see below.

Downloads

3.3.1-6: https://mega.nz/#!3QIRQYhK!Jq5QrGfJw5VCYZ8sq_BO1qNZecrFqlM9IB1IdSwogvI
changes: updated kernel to support pstore instead of /proc/last_kmsg. If you don't know what this is, it's probably not relevant to you.

Here you can find an unofficial LOS build with wrappedkey encryption and also proper system_as_root support for those survival scripts https://forum.xda-developers.com/redmi-note-7-pro/development/unofficial-lineageos-16-caf-encryption-t3933532. In addition, all official MIUI builds should flash just fine.

History versions:

3.3.1-5: https://mega.nz/#!nMowHKiL!zRvoTM0iIZKArmUDnZzaEFtXQv0_q7hIHUCmTHTOmOM
changes: 1) Now works even with empty /system and /vendor partition 2) Fixed brightness problem; 3) Enabled EDL Reboot
3.3.1-3: https://mega.nz/#!yAYXxAzZ!FNMYLzLphnSmJ-DbBx-OZUgxxYiftgn8e4Jn3kxiQik

Patches and sources

Patches for TWRP are available here:

https://gerrit.omnirom.org/#/c/34091/
https://gerrit.omnirom.org/#/c/34093/
https://gerrit.omnirom.org/#/c/34092/
https://gerrit.omnirom.org/#/c/android_bootable_recovery/+/34096/

Patches for ROMs to support wrapped key have been given in the above sections.

Source of the current device tree for TWRP: https://github.com/PeterCxy/android_device_xiaomi_violet-twrp
Kernel source: https://github.com/PeterCxy/android_kernel_xiaomi_sm6150, note that the device tree uses a prebuilt kernel image.

Contributors
PeterCxy, Dyneteve, merothh
Source Code: https://github.com/PeterCxy/android_device_xiaomi_violet-twrp
Hi Peter, i'm trying update persist.img for my device but your version didnt have, can you update at next version?
 

rameshshenoi3055

Senior Member
Apr 26, 2013
55
4
28
I have unlocked bootloader, but phone is not showing up in adb devices or fastboot devices to install this recovery. I have installed adb drivers but no success. Can some please help me with this? Thanks in advance.
 

Naveenthemi

Senior Member
Aug 8, 2016
439
126
0
I have unlocked bootloader, but phone is not showing up in adb devices or fastboot devices to install this recovery. I have installed adb drivers but no success. Can some please help me with this? Thanks in advance.
Download the Mi drivers too, use MiFlash tool and you will have the option to download drivers or just manually Google and get them online.
 
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone