[Xiaomi Mi A1 Guides, News, & Discussion] CosmicDan:
Here I will share all the info you need to know about using Treble on the Mi A1. Everyone is more than welcome to ask questions and clarification here, I am happy to answer and will update this thread over time. Thanks!

Contents

0. Key Terms

1. Restoring to Stock

-- 1.1. Requirements

-- 1.2. Full-device backup

-- 1.3. Stock restore process

2. "Treblize" (repartition) the device

3. Your first Treble ROM install

4. Installing AIO's, GSI's, Vendors and More

-- 4.1. Install a Treble AIO

-- 4.2. Install a Treble GSI

-- 4.3. Install/update a Vendor Pack

-- 4.4. Install a non-Treble ROM

-- 4.5. Restore a TWRP backup

5. Mods and Extras [Gapps, Magisk, custom kernels, etc.]

6. FAQ and Troubleshooting

----------------------------------------------

0. Key Terms

Throughout your Treble adventures, you may see lots of new terms. Here I will explain them all. This is essential reading!

Treble

Treble is the broad term of a new Android architecture model of splitting the system into two partitions:

System: where the Android OS goes, i.e. Oreo or later operating system;

Vendor, where the device-specific files go, such as drivers.

Before Treble, both the Android OS and device-specific files would live together on system. See below for a more detailed description of Vendor.

"Treblizing"

May also be called Treble-enable, Treble-conversion or some variation of that. This is the process of converting a non-Treble device to a Treble-capable one, unofficially, by changing the partition map of the device. This involves shrinking an existing partition - such as userdata or system in the case of the Mi A1 - in order to create a new vendor partition - or two vendor partition in the case for our Mi A1, one for each slot. Treblizing is just the preparation stage - you still need an AIO installation (see AIO below) before you are actually able to use a Treble ROM.

Vendor

Also known as Vendor Pack or Vendor Image. In the context of Treble, this is a standalone vendor image (either as a ZIP or usually as an IMG) that can be flashed to your Treble-enabled device for it to be compatible with a Treble system/ROM. These are similar to a kernel in the way that they are flashed to their own partition on your device and are compatible with many Treble ROM's. They are also similar to a kernel in that they are made specifically for one device to provide the low-level functionality of the system. It mostly includes drivers, but can also include apps and overlays that are automatically added at runtime to the Android OS that's living on System.

Treble developers for the Mi A1 may release standalone "vendor.img" for use on other ROM's - usually GSI's (see description of GSI below) but they are also part of an AIO (see description of AIO below).

GSI

Stands for "Generic System Image". This concept, introduced and developed by @phhusson is the creation of a System image that is device-agnostic - that is, it is a ROM that is designed to work with an existing Treble device, as long as the device has a GSI-compatible Vendor and kernel installation. For devices with official Treble support, phhusson makes the effort to try and adapt his GSI system for compatibility - but for unofficial Treble device like the Mi A1, it's our (tissot developers) responsibility to make a Vendor/Kernel that is as GSI-compatible as possible.

AIO

Stands for "All In One". This is a Treble firmware that includes a Kernel, System and Vendor image in the one ROM ZIP. This provides an all-in-one Treble experience through a device-specific Treble ROM. AIO's are designed to work well with their own ROM but should also strive to be compatible with a GSI.

An explanatory chart of Key Terms

Click here for full size image.

Ignore this spoiler (coded link to thumbnail because XDA thread edit breaks the IMG link)

https://img.xda-cdn.com/ic22y2zu5yi9EClrY11FS8FU5C0=/https%3A%2F%2Fimg.xda-cdn.com%2FU8u8IdA66PAFHOM4PsKNQbFHwSA%3D%2Fhttps%253A%252F%252Fimg.xda-cdn.com%252Fo1fMEJDyu5x7pv2B9KB323i8_IA%253D%252Fhttps%25253A%25252F%25252Fthumbs2.imgbox.com%25252Fd7%25252Fc2%25252FDxa93pOz_t.png

----------------------------------------------

1. Restoring to Stock

For the sake of consistency, I highly recommend everybody revert to a clean stock state. This ensures that as many of us are coming from the same place to eliminate inconsistency with reported bugs. If you're impatient or experienced though, feel free to skip this - but if you have issues, be sure to try again from here before asking for help.

Note that this will also restore you to the stock partition map, i.e. before "Treblizing".

1.1. Requirements

Unlocked bootloader and EDL access/drivers. See FAQ at bottom of this post for details on EDL.

Modern fastboot binary - it needs the "--set-active" option. Check with fastboot --help to see if it's listed in the usage.

Latest/recent official firmware package. Recommended "V.9.5.10.0.ODHMIFA" only because it's what I used, if you're not sure - but anything newer should be fine too.

Recent MiFlash version. I used 7.4.25 which can be downloaded from here.

1.2. Full-device backup

HIGHLY RECOMMENDED. While all this is relatively safe (as safe as device modding can be), I cannot be held responsible for any data loss or bricks. You can make a Low-Level backup with my tool here. You can use the "skip-systems-and-userdata" partition list to save time, since those can be backed up in TWRP anyway. This is here mostly as a failsafe.

Also backup your internal storage files. The Treblizing process may wipe your internal storage.

1.3. Stock restore process

Flash latest firmware (V.9.5.10.0.ODHMIFA at time of writing) in EDL mode with MiFlash. This will wipe your device (including Internal Storage) and restore stock partition map. This could take a while.

Optional: If Wifi is broken (you can check by booting ROM), flash the "tissot_images_V.9.5.10.0.ODHMIFA___persist-only" in MiFlash under EDL, attached. Just extract the ZIP and browse to the folder in MiFlash. You can replace the persist.img from official V.9.5.10.0.ODHMIFA or another ROM if you want to be sure it's genuine. Credits to @AlexAiS for discovering this.

Remember - you backed up your original persist.img in step 1 anyway, so this is not risky.

I am not sure how this works exactly. It seems MiFlash in EDL is able to re-build a MAC address while flashing the persist. I don't know where this MAC comes from though.

----------------------------------------------

2. "Treblize" (repartition) the device

If you looked at the chart, you'll know that this is just the first step. You will need to actually install an AIO ROM after this part. This is a ONE TIME PROCESS for getting Treble capability on your device.

Repartitioning is relatively painless ever since I created TWRP with Treble Manager. Read on for a walkthrough.

Fastboot boot to TWRP with mohancm's recovery img (i.e. recovery-3.2.1-1) if you don't already have TWRP installed. Do not get the installer - we're using the one with Treble Manager instead.

Install the latest TWRP with Treble Manager (v1.2 at time of writing, but of course latest version is best) then Reboot Recovery to actually load it. Be sure to read about TWRP with Treble Manager in that thread to understand how it works. If you have any questions specifically about the TWRP and Treble Manager, please ask in that thread.

Format Data in Wipe menu (to remove Stock encryption), then Reboot Recovery again (maybe not necessary but it can't hurt).

In TWRP, go to Advanced > Treble Manager and repartition the device by following the wizard. Userdata shrink is recommended, as per the in-menu description explaining this. Just try the Treble Manager and see yourself - it will ask you one last time before repartitioning so don't worry about it wiping without warning. Alternatively, you can just check the screenshots.

After finished it will reboot TWRP. You are now ready for installing a Treble AIO (and then a GSI, if desired), but be sure to still read on, especially the next section below (there is a known issue that you need to work around - otherwise a bootloop will occur).

----------------------------------------------

3. Your first Treble ROM install

THERE IS AN IMPORTANT STEP THAT MUST BE FOLLOWED HERE WHEN INSTALLING YOUR FIRST TREBLE ROM. FAILURE TO FOLLOW THESE INSTRUCTIONS WILL RESULT IN A BOOTLOOP.

Make a note of the current slot (in Reboot menu). If you followed this guide from Section 1, you should be in Slot A. If you're not, just swap any mention of Slot A and B in these steps.

Download a Treble AIO ROM (such as RR Treble Experimental) and flash in TWRP. This is required even if you want to use a GSI, since it has the required Vendor Pack and Kernel.

Immediately install TWRP with Treble Manager again, as you usually do, to re-inject TWRP into the new ROM boot image.

Reboot Recovery, NOT SYSTEM.

Confirm in Reboot menu that the device has successfully switched to Slot B. If it is still stuck in Slot A, this is a one-time bug that must be solved now - if you do not fix this then you will just bootloop.

If it is still stuck in Slot A, you must reboot to fastboot (make sure you have a current version, as explained in Section 1.1. "Requirements") and manually run the command:

fastboot --set-active=b

...after doing this once, slot switching should work fine in TWRP again. You should never have to do this again (unless you go back to stock then re-Treblize again).

In case you didn't know, all ROMs for our Seamless device actually install into the *other* slot that isn't currently active - that's why you always need to Reboot Recovery first before installing Magisk or Gapps and such.

I advise users from now on to keep an eye on their Slot switching whenever you install an AIO ROM to make sure it worked. If it happens again after these steps, please report it to me with as much details as possible (we're still trying to figure out this bug).

After following these steps, you should be able to flash Treble ROM's just as you would a normal ROM from now on. Your Treble transformation is complete. But read on for more help and walkthroughs if you need it.

----------------------------------------------

4. Installing AIO's, GSI's, Vendors and More

Assuming you followed Section 3 above, you are now ready to install anything as usual. But some users have expressed confusion about what they can and can't do from this point, so I will give you some example choices here.

4.1. Install a Treble AIO

At the time of writing this guide, currently the only Treble AIO is the RR Experimental build. If or when others come along, you can just install them like normal ROMs. We already did this in Section 3 above, but here is a simplified summary of that process:

Flash the AIO ROM in TWRP with Treble Manager 1.2+ - do NOT reboot

Immediately reflash TWRP with Treble Manager 1.2+ so you get the Treble-compatible TWRP back

Factory Reset if it's a different ROM, as you usually would in this case.

Make a note of which slot you are on right now

Reboot recovery

Make sure your device has now swapped to the other slot by checking the reboot menu. If it has not, you will need to repeat the fastboot --set=active step as explained in Section 3. (I don't know if this is necessary again - but I just want to warn users to be aware of this known bug)

Now that the slot has changed, you can install Gapps, Magisk and/or whatever other compatible additional mods you want.

4.2. Install a Treble GSI

You may remember from earlier that the Treble GSI's are just System images that use your existing Vendor and Kernel. We already have a Treble kernel and Vendor from an AIO (Section 3 or Section 4.1. above), so this is quite simple:

Download any GSI/Phh-Treble ROM's from the Treble-Enabled Device Development section and copy the IMG to device

Make sure your current slot is a Treble ROM slot (i.e. existing AIO or GSI working). Unlike AIO/ROM ZIP flashing, image flashing installs it to the CURRENT slot.

Flash the IMG to "System Image" in TWRP with Treble Manager 1.2+

Factory Reset if you're changing ROM's

Install any other mods (Gapps, GSI-compatible Magisk [i.e. 16.4 beta or later], etc.). You may need to boot the ROM once before installing any mods - this varies per GSI. Some existing mods may also be outright incompatible with the GSI.

Reboot

Note that since this is only a System image, there is no need to reinstall TWRP or Reboot Recovery.

4.3. Install/update a Vendor Pack

While you're on a current and working AIO or GSI slot, you can flash a vendor.img to update the driver/device level stuff for that ROM. This could be done to e.g. fix the Camera. This is useful if you're running a GSI.

Download a vendor.img from your AIO or Vendor Pack provider (e.g. RR AIO Experimental) and copy the IMG to device

Make sure your current slot is a Treble ROM slot (i.e. existing AIO or GSI working). Unlike AIO/ROM ZIP flashing, image flashing installs it to the CURRENT slot.

Optionally make a TWRP backup of Vendor (or more) if you want to be careful and it's your daily (I always do).

Flash the IMG to "Vendor Image" in TWRP with Treble Manager 1.2+

Reboot

Note that since this is only a System image, there is no need to reinstall TWRP, Reboot Recovery or install any Mods (Gapps, Magisk, etc) UNLESS it's a Vendor mod (as of time of writing, no Vendor mods exist yet).

4.4. Install a non-Treble ROM

This is simple, same as you're used to before Treblizing. But do note that this is only possible if you chose to resize Userdata when repartitiong with Treble Manager.

Download the ROM to your device

Optional - make sure the active slot is one with a Treble AIO/GSI ROM already - remember that ROM ZIPs install to the OTHER slot, not the currently active one; so this way you can easily switch back to the Treble ROM just by doing a Factory Reset (or TWRP restore of Data) and slot switch.

Factory reset

Install the ROM as per usual procedure (Install ZIP, reflash TWRP with Treble Manager 1.2+, reboot recovery to allow slot switch, install Gapps + Magisk + Mods, etc., reboot).

4.5. Restore a TWRP backup

There is nothing special about restoring a backup. Even if your backup was from a non-Treble ROM, you can restore that backup on a Treblized device. Obviously, though, any Treble ROM backup can only be restored on a Treblized device.

----------------------------------------------

5. Mods and Extras [Gapps, Magisk, custom kernels, etc.]

After you have confirmed that TWRP is booting in to the correct slot (see Section 3), you're ready to install other ROMs (see Section 4) followed by mods. I did briefly go over mods in Section 4, but I'll go into more detailed info about compatibility here.

Any usual Gapps should work fine, just as long as you flash after the slot is correctly set. Note that RR Camera (GCam) requires Gapps to be installed. I used Nano, they worked fine.

Also note that some GSI's will require you to boot the system first before installing Gapps.

Custom kernels must be marked Treble compatible for our device. Specifically (info for kernel developers) this means adding slotselect flag to vendor entry in DTB, and disabling dm-verity (so we can inject vendor changes to system).

It is reported that standard Magisk will work in RR Treble ROM, but it does NOT work on GSI. You need Magisk 16.4 beta or later for GSI's. Also see the FAQ section at the end for more info on the Magisk situation.

Some other ZIP's might need updating for Treble, really unsure. Experimentation is welcome. Just be sure you make TWRP backups before testing anything, of course!

--------------------------------

6. FAQ and Troubleshooting

Q) I get "cannot receive hello packet" in MiFlash

A) Just reboot EDL mode and try again. Usually only happens if you try to flash in EDL twice in a row. See the Low-level Backup/Restore/Unbrick toolkit thread for more info about EDL.

Q) How to Magisk with Treble? What is the TWRP and Magisk interaction?

A) Best to use Magisk 16.4 beta or later, it's reported as working on GSI's. Also note that Magisk is installed to the boot ramdisk (the same place as where TWRP goes) and this has the following implications:

Whenever you flash the TWRP installer, you will need to reinstall Magisk *after* you Reboot Recovery

TWRP installer will flash to BOTH slots, but Magisk will only flash to the CURRENT slot. So if you flash TWRP installer, it may erase any Magisk install on the inactive slot.

TWRP survival (in my recent TWRP builds) backs-up and restores the whole ramdisk. This will include Magisk, if it was already on the boot slot that it backs up.

Q) EDL mode? Eh?

A) EDL mode, or "Emergency DownLoad" mode, is a low-level mode for flashing devices. It is entered by the command:

fastboot oem edl

EDL mode is used to read/write to the eMMC more directly. It is used by this tool, as well as flashing with MiFlash.

Other important notes:

You will need good QDLoader drivers. These drivers gave me the best results.

You can exit EDL mode by holding Power button for ~10 seconds. Hold with VolDn to reboot into fastboot again, as one might expect.

Make sure you use a good USB-C cable.

Sometimes the flashing process can freeze. It will always report success when done. If it freezes, you need to reboot EDL mode. Try a different USB port or cable if you keep experiencing freezes.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~