[Xiaomi Mi A2 Lite Guides, News, & Discussion] a1291762:
History...

I originally wrote this guide to upgrade from 10.0.4.0 to 10.0.7.0.

I have also used this same guide to install every OTA from 10.0.7.0 to 11.0.11.0.

This guide assumes you have both Magisk and TWRP, that Magisk cannot "uninstall" (because of TWRP installation) and that you want to keep both Magisk and TWRP after installation. Parts of this guide may still be useful if you aren't in this exact situation.

If you only have Magisk, you should be able to follow these much simpler instructions: https://xdaforums.com/mi-a2-lite/how-to/guide-install-magisk-proper-support-ota-t3836952

Things to have on hand:

- vanilla_boot.img (for the version you currently have)

- patched_boot.img (your current boot image with Magisk)

- TWRP img and zip (see version info below)

I think that TWRP also causes the vendor partition to be modified. It may also touch system but I have a modified bootanimation.zip which modifies system, so I can't be sure. In any case, I also have a backup of system.img and vendor.img.

Because Magisk is installed after TWRP, Magisk's "backup" of the "stock boot image" is not vanilla. This means that in order to take the OTA, I have to flash the vanilla boot image.

0 - Update your patched_boot.img

If you don't have a patched_boot.img for your current Magisk (eg. my patched_boot.img was old, since I had installed several Magisk updates), you should build a new patched_boot.img so that when you boot it, the system will continue to work.

Push the vanilla image to the phone.

adb push vanilla_boot.img /sdcard

Then get Magisk to install using the "Select and Patch a File" method, select the file you uploaded. Then pull down the patched image.

adb pull /sdcard/Download/magisk_patched.img patched_boot.img

1 - Prepare to OTA

For some reason, my carrier does not like the OTA process so I always turn on Airplane mode + Wifi.

Get to fastboot and check the current slot.

adb reboot bootloader
fastboot getvar current-slot

My current slot was b

Flash the system and vendor partitions (if necessary).

fastboot flash system_b vanilla_system.img
fastboot flash vendor_b vanilla_vendor.img

Flash vanilla and boot the patched image (so that Magisk is active and the OTA can be applied).

fastboot flash boot_b vanilla_boot.img
fastboot boot patched_boot.img

2 - Do the OTA

Install OTA (DO NOT REBOOT)

If the OTA fails

If the OTA fails, you can find out which partitions it doesn't like from the logcat. If you have a fastboot image, you can reflash the affected partitions. As previously mentioned, I've had to flash all of boot, vendor and system for each OTA.

adb logcat | grep update_engine
...
07-01 06:52:38.470 E/update_engine(935): [0701/065238.470683:ERROR:delta_performer.cc(990)] The hash of the source data on disk for this operation doesn't match the expected value. This could mean that the delta update payload was targeted for another version, or that the source partition was modified after it was installed, for example, by mounting a filesystem.
07-01 06:52:38.470 E/update_engine(935): [0701/065238.470931:ERROR:delta_performer.cc(995)] Expected: sha256|hex = A4AD686D7BF628486668446221D0089BF5915DBC1158C83D30A06222FE7D2ACB
07-01 06:52:38.471 E/update_engine(935): [0701/065238.471002:ERROR:delta_performer.cc(998)] Calculated: sha256|hex = 4CADBE88EC1C019913A0B416EB9031840D4BA6B2287A3FC814A2B8B7F9871F7D
07-01 06:52:38.473 E/update_engine(935): [0701/065238.471072:ERROR:delta_performer.cc(1009)] Operation source (offset:size) in blocks: 0:5221,5461:405,5869:1,5873:343,6221:589
07-01 06:52:38.473 E/update_engine(935): [0701/065238.473233:ERROR:delta_performer.cc(1191)] ValidateSourceHash(source_hash, operation, source_fd_, error) failed.
07-01 06:52:38.473 E/update_engine(935): [0701/065238.473340:ERROR:delta_performer.cc(298)] Failed to perform BROTLI_BSDIFF operation 187, which is the operation 0 in partition "boot"
07-01 06:52:38.473 E/update_engine(935): [0701/065238.473411:ERROR:download_action.cc(337)] Error ErrorCode::kDownloadStateInitializationError (20) in DeltaPerformer's Write method when processing the received payload -- Terminating processing
07-01 06:52:38.739 E/SystemUpdate(15410): [Execution,NonStreamingAbApplyAction] Installation failed with error code: 20.

3 - Backup the vanilla boot image

Note that you need to pull from the other slot (in my case, a).

adb shell
su
dd if=/dev/block/by-name/boot_a of=/sdcard/vanilla_boot.img bs=1024k

Backup system.img and vendor.img too (if required).

dd if=/dev/block/by-name/system_a of=/sdcard/vanilla_system.img bs=1024k
dd if=/dev/block/by-name/vendor_a of=/sdcard/vanilla_vendor.img bs=1024k

4 - Magisk patch the other slot

Use Magisk to "Install to Inactive Slot (After OTA)" (DO NOT REBOOT)

5 - Backup the patched boot image

Note that you need to pull from the other slot (in my case, a).

dd if=/dev/block/by-name/boot_a of=/sdcard/patched_boot.img bs=1024k
exit
exit

# back on your computer
adb pull /sdcard/vanilla_boot.img
adb pull /sdcard/patched_boot.img

Pull down system and vendor images too (if required).

adb pull /sdcard/vanilla_system.img
adb pull /sdcard/vanilla_vendor.img

Now you can let Magisk reboot. This is the moment of truth...

At this point you should have an upgraded, Magisk-enabled system and backups of the vanilla and patched boot images. Congratulations on completing the OTA!

If the system fails to boot

There's a few things to try before giving up if the system fails to boot...

1) Boot without Magisk (fastboot boot vanilla_boot.img). Probably indicates that a Magisk module you have is no longer compatible.

2) Boot TWRP (fastboot boot twrp.img) and poke at things. As an example, I used the /sdcard/mm program (part of Magisk Manager for recovery) to disable EdXposed when the OTA to Android 10 failed to boot.

6 - Restore TWRP

It is possible to boot TWRP from fastboot so you don't strictly need to install TWRP. I like to have it available anyway.

Old version info...

I had been using the official TWRP 3.2.3, which worked great up until 10.0.9.0. With 10.0.9.0, I couldn't get to TWRP, I just got the system destroyed screen. I could fastboot boot it, but it couldn't mount /data (a problem it has always had).

I figured out that TWRP 3.3.1-dees_troy (from the official TWRP site) works with 10.0.9.0 and up. What's more, it works (can decrypt /data) if you fastboot boot it, not just after install. So you could in theory simply not install TWRP and fastboot boot if in the event that you actually need it.

I know that people have their own favourite versions, with the offain version being popular (didn't work for me). There's OrangeFox too (also didn't work for me).

In summary, I recommend Official TWRP 3.3.1-dees_troy but if you have a favourite alternative, feel free to use it instead.

TWRP thread: https://xdaforums.com/mi-a2-lite/development/official-twrp-daisy-t3855396

Download link: https://dl.twrp.me/daisy/

Restoring TWRP is the same as installing it the first time. This is the process that I use.

Flash vanilla boot, then install TWRP to it.

adb reboot bootloader
fastboot boot twrp-3.3.1-dees_troy-daisy.img

Install TWRP

adb push twrp-installer-3.3.1-dees_troy-daisy.zip /sdcard

Use TWRP to install twrp-installer-3.3.1-dees_troy-daisy.zip

I install my modified bootanimation.zip at this time.

Mount System from TWRP (it is normally already mounted for me).

From a shell:

adb shell
cd /sdcard
cp bootanimation.zip /system/system/media/bootanimation.zip

Umount System

You must re-install Magisk after installing TWRP.

adb reboot bootloader
fastboot boot patched_boot.img

Use Magisk to "Direct Install (Recommended)"

Reboot

For some reason, my carrier does not like the OTA process so at this point I normally power off the phone rather than just rebooting. When the phone boots, I can turn off airplane mode and check that a mobile data connection can be made.

7 - Confirm that everything works

Make sure the system comes up and Magisk Manager says that Magisk is installed.

Make sure you can get to TWRP. Boot while holding VOL+ or

adb reboot recovery

Make sure TWRP can see your files.

Congratulations! You have installed an OTA while keeping Magisk and TWRP!

8 - Backup boot.img with TWRP + Magisk (optional)

If you want a copy of the boot.img with both Magisk and TWRP. This pulls from the now-current slot (in my case, a). I'm not totally sure of the value of this, since I can't get fastboot to boot this image. It may come in handy if you upgrade TWRP and that breaks (since you can flash this back rather than having to install the old TWRP again).

adb shell
su
cd /sdcard
dd if=/dev/block/by-name/boot_a of=twrp_boot.img bs=1024k
exit
exit

# back on the computer
adb pull /sdcard/twrp_boot.img