[guide] Update MIUI 12 (android 11) rom - MI 9 SE (possibly others)


fatjoez

Members
Aug 8, 2011
108
30
I post this because the MIUI 12 rom for MI 9 SE can result in boot loop to Recovery / Fastboot

# How to flash rom in recovery while data encrypted
1. Put ROM on a USB stick & connect to phone with USB OTG
2. "mount" "System" partitions + select storage USB OTG
3. Flash the rom (system partition is not encrypted even if data is inaccessible so roms can be flashed)
4. Reboot

Troubleshooting

# bootloop - stuck in fastboot

1. reflash a recovery image

# bootloop - stuck in recovery (see below) OR
# bootloop - stuck in MI logo (initial boot screen)

(24/6/21 FOLLOW THE STEPS IN SEQUENCE ORDER: #1(required), #2(try but skip if error "cannot access /data"), #3(required)

0. Connect phone to your computer by usb & boot phone to fastboot
1. disable verity using command (you need to download the vbmeta file for your phone):
fastboot --disable-verity --disable-verification flash vbmeta vbmeta.img
disconnect, reboot

IF STILL bootloop to recovery
2. flash zip MAGISK uninstaller (this may fail with error "cannot access /data" but it's OK)
3. flash zip MAGISK installer (21.0 works) (latest correct version, check betas & user feedback)

Reboot & phone will boot OK. Repeat the above steps if it doesn't work first time.
 

wojtek858

Members
Aug 6, 2016
13
15
Hello, unfortunately this didn't help me. At first I couldn't even install new system, because nweset TWRP is bugged. I installed some modified and was able to proceed. I was on xiaomi.eu MIUI 12.0.1 stable and I updated to xiaomi.eu 12.5 stable. I think I also installed Magisk 23 in same run. Then I had bootloader loop. I flashed different TWRP 3.5.* mod, installed system again and now I have recovery loop. I reinstalled system almost a dozen times from different recoveries. I also insalled Magisk with file name changed to "uninstall.zip", then I installed same Magisk, it's v. 23. Still in recovery loop. After that I flashed that vbeta.img file found here [RECOVERY][grus] KudProject's Unofficial TWRP 3.5.2_9-1 [16-05-2021] | XDA Forums (xda-developers.com) , restarted and it did nothing.

Does anyone have any other ideas? Help!
 
Last edited:

Poney70

Donator
Oct 3, 2019
5,471
337
Hello, unfortunately this didn't help me. At first I couldn't even install new system, because nweset TWRP is bugged. I installed some modified and was able to proceed. I was on xiaomi.eu MIUI 12.1 stable and I updated to xiaomi.eu 12.5 stable. I think I also installed Magisk 23 in same run. Then I had bootloader loop. I flashed different TWRP mod, installed system again and now I have recovery loop. I reinstalled system almost a dozen times from different recoveries. I also insalled Magisk with file name changed to "uninstall.zip", then I installed same Magisk, it's v. 23. Still in recovery loop.

Does anyone have any other ideas? Help!
You already got an answer => https://xiaomi.eu/community/threads/upgrade-to-miui-12-5.62844/post-625615

And stop saying "MIUI 12.1 Stable", This version doesn't exist for your device..., I guess you mean MIUI 12.0.1(.0) Stable. ;)
 

wojtek858

Members
Aug 6, 2016
13
15
You already got an answer => https://xiaomi.eu/community/threads/upgrade-to-miui-12-5.62844/post-625615

And stop saying "MIUI 12.1 Stable", This version doesn't exist for your device..., I guess you mean MIUI 12.0.1(.0) Stable. ;)
Yes, it had to be 12.0.1 then. But all you suggested there was nuking the phone memory. We don't even know what's the issue exactly and why it happened. I ran "adb logcat", but this doesn't tell me much and I couldn't find anything useful:
Code:
08-29 16:32:03.585   539   539 W libc    : Unable to set property "ro.crypto.state" to "encrypted": error code: 0xb
08-29 16:32:03.585   539   539 W libc    : Unable to set property "ro.crypto.type" to "file": error code: 0xb
08-29 16:32:03.588   539   539 E cutils-trace: Error opening trace file: No such file or directory (2)
08-29 16:32:03.611   534   534 W hwservicemanager: getTransport: Cannot find entry android.hidl.manager@1.0::IServiceManager/default in either framework or device manifest.
08-29 16:32:03.612   534   534 E SELinux : avc:  denied  { find } for interface=android.hardware.keymaster::IKeymasterDevice sid=u:r:recovery:s0 pid=539 scontext=u:r:recovery:s0 tcontext=u:object_r:hal_keymaster_hwservice:s0 tclass=hwservice_manager permissive=1
08-29 16:32:03.613   534   534 W hwservicemanager: getTransport: Cannot find entry android.hardware.keymaster@3.0::IKeymasterDevice/default in either framework or device manifest.
08-29 16:32:03.614   539   539 I /sbin/recovery: List of Keymaster HALs found:
08-29 16:32:03.614   539   539 I /sbin/recovery: Keymaster HAL #1: Keymaster HAL: 4 from QTI SecurityLevel: TRUSTED_ENVIRONMENT HAL: android.hardware.keymaster@4.0::IKeymasterDevice/default
08-29 16:32:03.622   576   576 E KeyMasterHalDevice: Begin send cmd failed
08-29 16:32:03.622   576   576 E KeyMasterHalDevice: ret: 0
08-29 16:32:03.622   576   576 E KeyMasterHalDevice: resp->status: -62
08-29 16:32:03.762   534   534 W hwservicemanager: getTransport: Cannot find entry android.hidl.manager@1.0::IServiceManager/default in either framework or device manifest.
08-29 16:32:03.764   534   534 W hwservicemanager: getTransport: Cannot find entry android.hardware.keymaster@3.0::IKeymasterDevice/default in either framework or device manifest.
08-29 16:32:03.765   539   539 I /sbin/recovery: List of Keymaster HALs found:
08-29 16:32:03.765   539   539 I /sbin/recovery: Keymaster HAL #1: Keymaster HAL: 4 from QTI SecurityLevel: TRUSTED_ENVIRONMENT HAL: android.hardware.keymaster@4.0::IKeymasterDevice/default
08-29 16:32:03.770   576   576 E KeyMasterHalDevice: Begin send cmd failed
08-29 16:32:03.770   576   576 E KeyMasterHalDevice: ret: 0
08-29 16:32:03.770   576   576 E KeyMasterHalDevice: resp->status: -62
08-29 16:32:03.794   534   534 W hwservicemanager: getTransport: Cannot find entry android.hidl.manager@1.0::IServiceManager/default in either framework or device manifest.
08-29 16:32:03.797   534   534 W hwservicemanager: getTransport: Cannot find entry android.hardware.keymaster@3.0::IKeymasterDevice/default in either framework or device manifest.
08-29 16:32:03.797   539   539 I /sbin/recovery: List of Keymaster HALs found:
08-29 16:32:03.797   539   539 I /sbin/recovery: Keymaster HAL #1: Keymaster HAL: 4 from QTI SecurityLevel: TRUSTED_ENVIRONMENT HAL: android.hardware.keymaster@4.0::IKeymasterDevice/default
08-29 16:32:03.804   576   576 E KeyMasterHalDevice: Begin send cmd failed
08-29 16:32:03.804   576   576 E KeyMasterHalDevice: ret: 0
08-29 16:32:03.804   576   576 E KeyMasterHalDevice: resp->status: -62
08-29 16:32:03.829   534   534 W hwservicemanager: getTransport: Cannot find entry android.hidl.manager@1.0::IServiceManager/default in either framework or device manifest.
08-29 16:32:03.832   534   534 W hwservicemanager: getTransport: Cannot find entry android.hardware.keymaster@3.0::IKeymasterDevice/default in either framework or device manifest.
08-29 16:32:03.832   539   539 I /sbin/recovery: List of Keymaster HALs found:
08-29 16:32:03.833   539   539 I /sbin/recovery: Keymaster HAL #1: Keymaster HAL: 4 from QTI SecurityLevel: TRUSTED_ENVIRONMENT HAL: android.hardware.keymaster@4.0::IKeymasterDevice/default
08-29 16:32:03.840   576   576 E KeyMasterHalDevice: Begin send cmd failed
08-29 16:32:03.840   576   576 E KeyMasterHalDevice: ret: 0
08-29 16:32:03.840   576   576 E KeyMasterHalDevice: resp->status: -62
08-29 16:32:03.858   539   539 W libc    : Unable to set property "ro.crypto.state" to "encrypted": error code: 0xb
08-29 16:32:07.821   617   618 I adbd    : initializing functionfs
08-29 16:32:07.821   617   618 I adbd    : opening control endpoint /dev/usb-ffs/adb/ep0
08-29 16:32:07.824   617   618 I adbd    : functionfs successfully initialized
08-29 16:32:07.824   617   618 I adbd    : registering usb transport
08-29 16:32:07.825   617   619 E cutils-trace: Error opening trace file: No such file or directory (2)
08-29 16:32:27.597   539   539 I ArmToArm64Assembler: generated scanline__00000077:03545401_00000A08_00000000 [ 69 ipp] (116 ins) at [0x6fc7900960:0x6fc7900b30] in 51042 ns
08-29 16:32:28.258   539   539 I ArmToArm64Assembler: generated scanline__00000077:03545401_00000000_00000000 [ 65 ipp] (94 ins) at [0x6fc7900b40:0x6fc7900cb8] in 56302 ns
08-29 16:32:28.264   539   539 I ArmToArm64Assembler: generated scanline__00000077:03545401_00000A05_00000000 [ 69 ipp] (113 ins) at [0x6fc7900cc0:0x6fc7900e84] in 49532 ns
08-29 16:34:03.288   631   631 E cutils-trace: Error opening trace file: No such file or directory (2)
08-29 16:34:03.289   534   534 W hwservicemanager: getTransport: Cannot find entry android.hidl.manager@1.1::IServiceManager/default in either framework or device manifest.
08-29 16:34:03.290   631   631 I keystore: found android.hardware.keymaster@4.0::IKeymasterDevice with interface name default and seclevel TRUSTED_ENVIRONMENT
08-29 16:34:03.291   578   578 E SELinux : avc:  denied  { add } for service=android.security.keystore pid=631 uid=0 scontext=u:r:recovery:s0 tcontext=u:object_r:keystore_service:s0 tclass=service_manager permissive=1
08-29 16:34:03.292   534   534 E SELinux : avc:  denied  { add } for interface=android.system.wifi.keystore::IKeystore sid=u:r:recovery:s0 pid=631 scontext=u:r:recovery:s0 tcontext=u:object_r:system_wifi_keystore_hwservice:s0 tclass=hwservice_manager permissive=1
08-29 16:34:03.331   578   578 E SELinux : avc:  denied  { find } for service=android.security.keystore pid=539 uid=0 scontext=u:r:recovery:s0 tcontext=u:object_r:keystore_service:s0 tclass=service_manager permissive=1
08-29 16:34:03.396   631   631 E SELinux : avc:  denied  { add_auth } for pid=633 uid=1000 scontext=u:r:recovery:s0 tcontext=u:r:recovery:s0 tclass=keystore_key permissive=1
08-29 16:34:03.397   631   631 D keystore: AddAuthenticationToken: timestamp = 125848, time_received = 123
08-29 16:34:03.397   633   633 D         : successfully added auth token to keystore
08-29 16:34:03.451   576   576 E KeyMasterHalDevice: get_key_characteristics
08-29 16:34:03.452   576   576 E KeyMasterHalDevice: ret: 0
08-29 16:34:03.452   576   576 E KeyMasterHalDevice: resp->status: -62
08-29 16:34:03.452   631   631 I keystore: upgradeKeyBlob USRPKEY_synthetic_password_a2293fde93d9a192 0
08-29 16:34:03.480   631   631 W keystore: key found but type doesn't match: 6 vs 5
08-29 16:34:03.480   631   631 D keystore: Unable to read cached characteristics for key
08-29 16:34:03.487   631   631 I keystore: 1 0
08-29 16:34:04.396   631   631 I ServiceManager: Waiting for service dropbox...
08-29 16:34:07.409   631   631 I chatty  : uid=0(root) /sbin/keystore identical 3 lines
08-29 16:34:08.515   631   631 W ServiceManager: Service dropbox didn't start. Returning NULL
08-29 16:34:08.532   578   578 I ServiceManager: service 'android.security.keystore' died
08-29 16:34:08.600   534   534 W hwservicemanager: getTransport: Cannot find entry android.hidl.manager@1.0::IServiceManager/default in either framework or device manifest.
08-29 16:34:08.605   534   534 W hwservicemanager: getTransport: Cannot find entry android.hardware.keymaster@3.0::IKeymasterDevice/default in either framework or device manifest.
08-29 16:34:08.607   539   628 I /sbin/recovery: List of Keymaster HALs found:
08-29 16:34:08.608   539   628 I /sbin/recovery: Keymaster HAL #1: Keymaster HAL: 4 from QTI SecurityLevel: TRUSTED_ENVIRONMENT HAL: android.hardware.keymaster@4.0::IKeymasterDevice/default
08-29 16:34:08.615   576   576 E KeyMasterHalDevice: Begin send cmd failed
08-29 16:34:08.615   576   576 E KeyMasterHalDevice: ret: 0
08-29 16:34:08.615   576   576 E KeyMasterHalDevice: resp->status: -62
08-29 16:34:08.707   577   577 E GatekeeperHalDevice: verify
08-29 16:34:08.707   577   577 E GatekeeperHalDevice: ret: 0
08-29 16:34:08.707   577   577 E GatekeeperHalDevice: resp->status: 30000
08-29 16:34:08.720   534   534 W hwservicemanager: getTransport: Cannot find entry android.hidl.manager@1.0::IServiceManager/default in either framework or device manifest.
08-29 16:34:08.723   534   534 W hwservicemanager: getTransport: Cannot find entry android.hardware.keymaster@3.0::IKeymasterDevice/default in either framework or device manifest.
08-29 16:34:08.724   539   628 I /sbin/recovery: List of Keymaster HALs found:
08-29 16:34:08.724   539   628 I /sbin/recovery: Keymaster HAL #1: Keymaster HAL: 4 from QTI SecurityLevel: TRUSTED_ENVIRONMENT HAL: android.hardware.keymaster@4.0::IKeymasterDevice/default
08-29 16:34:30.460   671   672 I adbd    : initializing functionfs
08-29 16:34:30.460   671   672 I adbd    : opening control endpoint /dev/usb-ffs/adb/ep0
08-29 16:34:30.464   671   672 I adbd    : functionfs successfully initialized
08-29 16:34:30.464   671   672 I adbd    : registering usb transport
08-29 16:34:30.465   671   673 E cutils-trace: Error opening trace file: No such file or directory (2)
08-29 17:45:31.568   539   729 I /sbin/recovery: read key e=3 hash=20
08-29 17:45:31.582   539   729 I /sbin/recovery: comment is 1738 bytes; signature is 1720 bytes from end
08-29 17:45:37.228   539   729 I /sbin/recovery: signature (offset: b4532f0c, length: 6b2): 308206ae06092a864886f70d010702a082069f3082069b020101310b300906052b0e03021a0500300b06092a864886f70d010701a08204ac308204a830820390a003020102020900936eacbe07f201df300d06092a864886f70d0101050500308194310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e20566965773110300e060355040a1307416e64726f69643110300e060355040b1307416e64726f69643110300e06035504031307416e64726f69643122302006092a864886f70d0109011613616e64726f696440616e64726f69642e636f6d301e170d3038303232393031333334365a170d3335303731373031333334365a308194310b3009060355040613025553311330110603550408130a43616c69666f726e6961311630140603550407130d4d6f756e7461696e20566965773110300e060355040a1307416e64726f69643110300e060355040b1307416e64726f69643110300e06035504031307416e64726f69643122302006092a864886f70d0109011613616e64726f686440616e64726f69642e636f6d30820120300d06092a864886f70d01010105000382010d00308201080282010100d6931904dec60b24b1edc762e0d9d8253e3ecd6ceb1de2ff068ca8e8
08-29 17:45:37.228   539   729 I /sbin/recovery: whole-file signature verified against RSA key 0
 

wojtek858

Members
Aug 6, 2016
13
15
In the end I had to format data partition, because I needed the phone by Monday. Yes it helped, but now I need to waste a lot of time to restore everything. And we still don't know what was wrong.

EDIT:
If I flashed that vbmeta.img, did it stay after formatting /data? It sounds dangerous, from what I've read. How to revert it?
 
Last edited:

Poney70

Donator
Oct 3, 2019
5,471
337
If I flashed that vbmeta.img, did it stay after formatting /data? It sounds dangerous, from what I've read. How to revert it?
Yes it stays after formatting /data, vbmeta is a special partition. ;)

Xiaomi.eu ROMs already include a patched vbmeta.img, reinstall the ROM in TWRP if you want but I don't think it's a problem if your phone is currently working fine. :)
 
  • Like
Reactions: wojtek858