How to install firmware on Xiaomi through TWRP Recovery

The modified TWRP (Team Win Recovery Project) is the de facto standard for advanced Xiaomi smartphone users, allowing full access to the device’s file system. Unlike stock Recovery, which is limited to basic reset and update functions, the custom environment allows you to install third-party operating systems, make full backups and clean system partitions. It is the presence of root rights and unlocked bootloader that often become a prerequisite for full customization of the gadget.

The process of replacing software through this tool requires care, because an error at any stage can lead to the failure of the device. You have to work with the memory partitions directly, so understanding the structure of the Android file system will be a good advantage.

It should be noted that this procedure is only relevant for devices with unlocked Bootloader. If your smartphone is on warranty or you are afraid of losing data, it is better to refrain from experimenting. However, if the goal is worth it, then following the instructions minimizes the risks and will allow you to get the desired result in the shortest possible time.

Preparation of the device and necessary files

Before any manipulations are started, it is critical to assemble all the necessary components and prepare the working environment, USB-A cable with good data transfer and a computer running Windows or Linux, without a high-quality cable, the connection can be interrupted at the most inopportune moment, which can lead to errors in recording.

You need to download the current firmware image in.zip format, designed specifically for your device model. The use of archives from other models is strictly prohibited, as this will lead to a conflict of drivers and the inability to boot the system. You will also need a file installer of the recovery twrp.img, which corresponds to the version of the processor of your device.

Make sure to back up all your important data, as it will be permanently deleted during the installation process. Sync contacts, photos and documents with cloud services or copy them to an external medium. Full Wipe reset is a must-have step when switching between regional firmware versions (e.g. China to Global).

⚠️ Warning: Make sure the battery is at least 60-70%. Interrupting the firmware process due to battery discharge can cause serious damage to the software part of the device, known as β€œbrick".

To work with files on your computer, it is recommended to use the original ADB and Fastboot drivers. These can be found in the SDK Platform-Tools platform from Google, installing these components provides stable communication between the PC and the smartphone in bootloader mode.

πŸ“Š What kind of firmware you have right now?
Official Global
Chinese (China)
Castomic (LineageOS/etc)
Europe (EEA)
other

Unlock the bootloader and log into Fastboot mode

The fundamental condition for installing TWRP is an unlocked bootloader (Bootloader). On Xiaomi devices, this procedure requires official permission from the manufacturer through the Mi Unlock Tool utility. The process can take from a few days to a week of waiting, as the company artificially limits the time for the user to think.

To put the smartphone into Fastboot mode, you need to turn the device off completely, then press the combination of power buttons and volume down. The screen will show an image of a rabbit repairing an android, indicating a successful transition to low-level mode, in which you interact with the computer to flash the partitions.

If the bootloader is already unlocked, you can immediately proceed to the next step. Otherwise, connect the phone to the PC and run a command to check the status:

fastboot oem device-info

In the system's response, look for Device unlocked: true. If it says false, you'll need to go through the unlock procedure through your Mi Account. Without this step, any attempts to write to the system partition will be blocked hardwarely.

What if the Mi Unlock Tool is 99% locked?
Often the problem is an unstable Internet connection or an antivirus lock. Try using mobile Internet instead of Wi-Fi, disabling the firewall or running the utility on behalf of the administrator. USB-Port 2.0 on the back of the PC.

Install TWRP image via Fastboot

Once you successfully unlock and log in to Fastboot mode, the recavator itself is installed. The twrp.img image file you downloaded earlier should be in the same folder where the ADB and Fastboot terminal are running, making it easier to navigate and enter commands.

To upload an image to the device’s RAM without permanently writing it (which is safe for the test) or to direct firmware, the appropriate command is used. We will consider the option of direct writing to the recovery section so that the menu is saved after the reboot.

fastboot flash recovery twrp.img

After successfully executing a command that takes a few seconds, you need to immediately put the device into recovery mode. On many Xiaomi smartphones with the new partition system (A/B partitions), the standard reboot can again replace the TWRP with stock recapvery.

fastboot boot twrp.img

This command will download TWRP once, and if you plan to install firmware and Magisk right after you log in, that's enough. If you want to fix the Recovery permanently, you need to do it from inside the TWRP menu or using custom installer scripts, because a simple reboot can wipe the changes.

β˜‘οΈ Pre-firmware check

Done: 0 / 5

TWRP Configurement and Clean Partitions

Once you're in the TWRP menu, you'll see an interface that's adapted for touch control. The first thing you need to do is solve the encryption problem, and if the system asks for a password, and you don't remember the pattern lock or pin code from the old system, you'll have to format the data, which will delete all the files.

To install a new firmware cleanly, you need to do the Wipe (clean up) procedure, which is a step you need to take to keep the new operating system running smoothly without conflicting old files. From the Wipe menu, select Advanced Wipe and select the following sections:

  • πŸ“‚ Dalvik / ART Cache – the application compilation cache that you need to reset.
  • πŸ“‚ System – the partition where the operating system itself is located.
  • πŸ“‚ Vendor – partition with drivers and specific hardware settings.
  • πŸ“‚ Data – User data, applications and settings.

It is important not to mark the Internal Storage section if the firmware file is located there. Shifting the Swipe to Wipe slider will start the cleaning process, which will take a few seconds. Once completed, the screen will return to the main menu.

⚠️ Note: When switching from Chinese to global firmware, you sometimes need to format the Data partition through the Format Data menu (typing the word "yes"). This will delete everything, including internal memory, so the firmware file in this case should be re-tossed after formatting through the Format Data partition. MTP.

Now the device is fully ready to accept the new software. Make sure the firmware file (.zip archive) is readable. If you format memory, connect your phone to your PC, copy the firmware archive into internal memory, and turn off the cable.

The process of installing firmware and patches

The main step is to install the distribution itself. In the main TWRP menu, click Install. The file manager will open, where you want to find the previously downloaded firmware archive.

A confirmation slider will appear at the bottom of the screen, and you can press Add More Zips before activating it if you plan to install additional patches, such as GApps or Magisk for root rights, in one session, saving time because the device will only reboot once.

The table below shows a typical sequence of installation of components:

Order.ComponentDescriptionI'll be sure.
1ROM (Firmware)Main file of the system (MIUI, Pixel Experience, etc.)Yes.
2FirmwareModem and Bluetooth drivers (if not built into ROM)Depends on ROM.
3GAppsGoogle Play Services (for AOSP builds)No (for Custom ROM only)
4MagiskPackage for obtaining superuser rightsNo (optional)

Once you have selected all the files you need, swipe through the Swipe to confirm Flash slider, the installation process will begin, the progress of which will be displayed in the log, the green lines of Done indicate success, the red lines indicate an error, do not interrupt the process and do not touch the device.

πŸ’‘

If you install custom firmware based on Android 12/13, be sure to install a compatible version of GApps (such as NikGapps or OpenGApps), otherwise the settings menu may not work properly or crash.

First start and eliminate possible errors

When you complete the installation, you will see an Install from adb complete message in the log, or just a success notification. Press the Wipe Cache/Dalvik button to clear the installer cache, and then select Reboot System. The first run can last up to 5-10 minutes, as the system optimizes applications.

If the Xiaomi or Android logo is followed by an endless bootloop, it means that the firmware is incompatible or partition cleaning error, in which case you need to go back to TWRP (pressing the power and volume buttons), rerun Wipe Data and try to reflash again.

If the device does not respond to buttons at all and only the indicator or black screen is on, you may need to enter EDL (Emergency Download Mode) mode to recover through the service software Mi Flash Pro. However, with strict adherence to the instructions, such situations rarely occur.

A successful desktop boot marks the end of the process. Now your Xiaomi is running a new version of the software with advanced features. Be sure to check the basic functions: calls, Wi-Fi, camera and fingerprint sensor.

⚠️ Warning: After the first download, do not install all applications from the backup. 15-20 minutes to work in the background to complete indexation, otherwise overheating and fast battery discharge are possible.

πŸ’‘

Successful installation is not just about installation ZIP-File, but also correct preparation (Wipe) and subsequent calibration of the system in the first minutes of operation.

Frequently Asked Questions (FAQ)

Can I update my firmware through TWRP and save all the data?
In theory, if you install an update on top of the same Dirty Flash version without changing the region, the data can be saved by selecting only Dalvik and Cache from the Wipe menu. However, practice shows that for stable operation, Xiaomi is always better to do a complete cleanup (Clean Install) to avoid errors and bugs in the future.
What if TWRP asks for a password when you sign in?
This is encryption. If you remember the unlock password, enter it. If you forgot or want to install the system, press Cancel, go to Wipe -> Format Data, type yes and confirm. This will delete all the data and decrypt the encryption.
Is it safe to use TWRP for banking applications?
TWRP itself does not interfere with the operation of banks, but the presence of modified receivers and especially Root (Magisk) rights can block their launch due to the security check of Google Play Protect.
How to return stock Recovery if you need to surrender the phone under warranty?
This requires unlocking the bootloader again (if it was blocked after the firmware was installed) or using the fastboot command to flash the original recovery image. However, the presence of an unlocked bootloader in the logs of the Xiaomi server can be fixed, which theoretically affects warranty obligations in some regions.