Install firmware on Xiaomi via a computer with TWRP: a complete guide for beginners

Reflashing Xiaomi’s smartphone via TWRP using a computer is a process that requires careful and understanding of each step. Many users resort to custom firmware to get advanced features, current updates for outdated models or get rid of preinstalled MIUI software. However, the wrong actions can turn the device into a β€œbrick”, so it is important to follow proven algorithms.

This guide will take a look at all the steps from tool preparation to the final system setup, and not only the standard scenario, but also the typical errors that users encounter when working with fastboot, ADB and TWRP itself. We will pay special attention to the nuances of unlocking the bootloader, a key step without which custom firmware installation is impossible.

If you’ve never done firmware before, we recommend you study each section carefully. For experienced users, the firmware and Xiaomi model compatibility tables, as well as ways to solve rare bugs that are not covered in the standard guides, will be useful.

πŸ“Š What kind of firmware do you plan to install?
LineageOS
Pixel Experience
MIUI (official)
Another custom
I haven't decided yet.

1. Firmware Preparation: What to Do Before Starting

Before you start installing TWRP and new firmware, you need to follow a few critical steps, and ignoring them can lead to data loss, device lockdown, or even physical smartphone failure.

The first is to back up all your data. TWRP firmware is full-wipe, so contacts, photos, messages and apps will be deleted. Use Mi Cloud, Google Drive or local copying on your PC. Pay special attention to the DCIM (photo/video) and WhatsApp/Databases (if you use the messenger).

Second, check your Xiaomi model and its encoding, for example, the Redmi Note 10 Pro may have versions of sweet (global) and sweetin (Indian), a mismatch in the firmware model will lead to an error Error 7 in TWRP.

  • πŸ“± In Settings menu β†’ About Phone β†’ Version MIUI (click multiple times on "Kerole")
  • πŸ’» Using the adb shell command getprop ro.product.device (by connecting the phone to the PC)
  • πŸ” On the Xiaomi Firmware website at IMEI

Third, get your computer ready. Install the latest versions.

  • πŸ–₯️ Android SDK Platform-Tools (includes fastboot and adb)
  • πŸ”Œ Xiaomi Drivers (download from official website)
  • πŸ“ Firmware and TWRP for your model (from verified sources only!)

⚠️ Warning: Never download firmware from torrent trackers or obscure forums. Viruses in custom firmware can steal bank card details or passwords. Use only XDA Developers or official project repositories (like LineageOS).

2. Unlocking the Xiaomi bootloader: bypassing the limitations of MIUI

Xiaomi blocks the bootloader on all its devices to prevent unofficial software from being installed. Unlocking is a mandatory step before firmware is installed via TWRP. The process takes between 3 and 360 hours (depending on Xiaomi policy).

To unlock, follow the following steps:

  1. Link your Mi Account to your phone in Settings β†’ Xiaomi Account.
  2. Activate USB debugging: Settings β†’ About Phone β†’ MIUI version (click 7 times), then Settings β†’ Additional β†’ For Developers β†’ Debugging over USB.
  3. Connect the phone to the PC and confirm the debugging permission.
  4. Download Mi Unlock Tool and log in to the program.
  5. Turn the phone into fastboot mode (turn it off, then press Volume Down + Power).
  6. In Mi Unlock Tool, press Unlock and wait until it is completed (it may take several attempts).

Once successfully unlocked, the phone will display Unlocked in fastboot mode, and you can now start installing TWRP.

⚠️ Warning: If the Mi Unlock Tool is giving a Couldn't unlock error, check: πŸ”— Mi Account is linked to the phone and confirmed by SMS/email. πŸ•’ At least 168 hours (7 days) have passed since the account was linked. πŸ“‘ The phone is connected to the Internet via a SIM- card (Wi-Fi may not work). If the error persists, try using alternative tools (at your own risk!).

πŸ’‘

If unlocking is delayed, try connecting the phone to another USB- port (preferably USB 2.0 on the back of the PC) or using the original Xiaomi cable.Some users solve the problem by disabling the antivirus on the PC.

3. Install TWRP on Xiaomi via fastboot

TWRP (Team Win Recovery Project) is a custom recovery that allows you to install firmware, create backups and manage memory partitions.

Installation instructions:

  1. Download the current version of TWRP for your model from the official website (file with the extension.img).
  2. Place the file in the folder with the platform-tools (where fastboot.exe and adb.exe are located).
  3. Open the command prompt in this folder (click Shift + PCM β†’ Open the PowerShell window here).
  4. Connect your phone in fastboot mode and execute the command: fastboot flash recovery twrp-3.7.0_12-0-sweet.img (replace twrp-3.7.0_12-0-sweet.img with your file name).
  5. After a successful recording, run: fastboot boot twrp-3.7.0_12-0-sweet.img This will temporarily boot TWRP without overwriting stock recovery.

If TWRP is replaced with stock recovery after the reboot, then your device is active anti-rollback protection.

  • πŸ”„ Re-scan TWRP and immediately after installation (without turning off the phone!) run to TWRP: Wipe β†’ Format Data β†’ type "yes" This will remove encryption and prevent the recovery of the stock recovery.
  • πŸ“¦ Install firmware with disable_forceencrypt support (e.g. OrangeFox or modified TWRP).

Uploaded the correct.img file for your model | Phone in fastboot mode | ADB/Fastboot drivers installed on PC | Secure Boot disabled in BIOS (for some PCs) |Data backup made-->

4. Selection and download of firmware for Xiaomi

The firmware choice is the key to the stability of the phone, bugs and hardware compatibility. There are several types of firmware for Xiaomi:

Type of firmwareFeaturesWho's right for?Recommended projects
Official MIUIStock firmware from Xiaomi, stable, but with BlaatwareFor beginners who want a warranty and OTA- updatesOfficial website
Castomic (AOSP)Pure Android without MIUI shell, more settingsAdvanced users, fans of β€œvanilla” AndroidLineageOS, Pixel Experience
MIUI customModified MIUI with remote bloatware and additional featuresThose who love MIUI but want to optimizeXiaomi.EU, RevengeOS
GSI (Generic System Image)Universal firmware, works on most devices with Project TrebleFor experiments or unofficially supported modelsXDA GSI

When choosing a firmware, pay attention to:

  • πŸ“… Build Date – The latest versions contain fewer bugs and up-to-date security patches.
  • πŸ”§ Installation type – some firmware requires a vendor to be installed.
  • πŸ”‹ Camera support – Custom firmware may not support all camera modules (check on forums).

Critical: Firmware for MediaTek devices (such as the Redmi Note 11) often requires additional patching boot.img via Magisk for sensors and mobile network to work properly.

5. The firmware process through TWRP: step-by-step instruction

Now that the TWRP is installed and the firmware is downloaded, you can start installing it, and it takes 15 to 40 minutes, depending on the speed of your PC and phone.

Algorithm of action:

  1. Copy the firmware file (.zip) and, if necessary, Magisk (for root) into the phone's memory.
  2. Boot to TWRP (Put Volume Up + Power on).
  3. Run Wipe: Wipe β†’ Advanced Wipe β†’ Mark Dalvik, Cache, Data, System β†’ Swipe to Wipe ⚠️ Warning: If you install firmware on top of an existing one (such as an update), just clear Dalvik and Cache. Full wipe wipes all data!
  4. Install β†’ Select.zip β†’ Swipe to Confirm Flash
  5. If required, file Magisk (for root rights) or Disable Force Encrypt (for disabling encryption).
  6. Reboot your phone: Reboot β†’ System.

The first download can take up to 10 minutes, which is normal, and if the phone has been stuck on the logo for longer than 15 minutes, it means there's been an error.

  • πŸ”„ Return to TWRP and re-install.
  • πŸ“‘ Check if the firmware is suitable for your model (Error 7 indicates incompatibility).
  • πŸ”§ Try another version of TWRP (e.g. OrangeFox).
What if TWRP doesn’t see internal memory?
If TWRP does not display files in internal memory, encryption is most likely enabled. Solutions: Connect the phone to the PC via adb and copy the firmware command: adb push rom.zip /sdcard/ Use OTG- cable and flash drive with firmware. Install TWRP with support for disable_forceencrypt and execute Format Data.

Typical errors and their solutions

Even with strict adherence to the instructions, errors can occur, and let's consider the most common ways to eliminate them:

Mistake.Reason.Decision
Error 7 in TWRPThe firmware is not suitable for your model or MIUI version.Download the correct firmware version or edit updater-script in the archive
Fastboot mode starts but no device detectedProblems with drivers or cableReinstall the drivers, try another one. USB-port
The phone does not turn on after firmware (black screen)Incompatible firmware or interrupted processRepeat the firmware via fastboot with the official MIUI
Invalid sparse file format at headerA damaged firmware file or an incorrect TWRPDownload the firmware, check the checksum (MD5)
No network after firmwareThere is no vendor module or incorrect firmwareInstall the appropriate firmware for your firmware

If the camera, Wi-Fi or Bluetooth stopped working after the firmware, the problem is most likely the lack of proprietary drivers.

  • πŸ“Έ For Camera: Set up the ANX Camera or GCam with the settings for your model.
  • πŸ“Ά For Wi-Fi/Bluetooth: Fold firmware from stock MIUI through TWRP.

πŸ’‘

If the phone doesn’t detect the SIM- card after firmware is installed, check if your firmware supports your region. Some custom builds (e.g., Redmi Note 9 Pro) require manual modem selection in settings.

7.Setup of the system after firmware

After successful firmware installation, several steps must be taken to ensure the system works correctly:

Initial setting:

- Go through the Initial Configuration wizard (select language, connect to Wi-Fi, log in to Google account).

If the firmware is based on AOSP, you may need to manually install Google services (Open GAPPS).

Verification of functionality:

Test in turn: calls, mobile Internet, Wi-Fi, Bluetooth, camera, sensors.

If something doesn’t work, go back to TWRP and install the missing components (e.g., vendor or firmware).

Optimization:

Disable unnecessary background processes in Settings β†’ Applications.

For firmware on AOSP, install Magisk for root rights and modules (e.g. ViPER4Android for sound).

The new system's backup:

- V TWRP Create a full backup (Backup) β†’ Select sections β†’ Swipe to Backup).

Save a copy on a PC, it will save you in future experiments.

  1. Charge the phone to 100%.
  2. In TWRP, clear Battery Stats (Wipe β†’ Battery Stats).
  3. Discharge the phone before automatically turning off, then charge back to 100% without interruptions.

-->

8 How to Get Back the MIUI Stock Firmware

If custom firmware does not suit you or critical errors occur, you can return the official MIUI.

  • πŸ“₯ Download the official firmware for your model (select the Fastboot version).
  • πŸ–₯️ Install Mi Flash Tool on PC.
  • πŸ”§ Unlock the bootloader (if it was blocked after firmware).

Recovery process:

  1. Unpack the downloaded firmware in a folder without spaces in the title.
  2. Download the phone to fastboot mode.
  3. In the Mi Flash Tool, specify the path to the firmware folder and press Refresh (the phone must be determined).
  4. Select Clean All mode and press Flash.

Once complete, the phone will reboot to stock MIUI. All data will be erased, so pre-backup!

⚠️ Warning: If you want to log in to Mi Account after you return to your firmware, and you don't remember it, you'll have to go to Xiaomi's service center to unlock it, which is called FRP (Factory Reset Protection) and it works if you've linked your account to your device.

FAQ: Answers to Frequent Questions

❓ Can I flash Xiaomi without unlocking the bootloader?
No, installing custom firmware or TWRP without unlocking the bootloader is impossible. The only exception is the official updates via About Phone β†’ System Update, but they do not provide advanced features.
❓ Why does TWRP ask for a password when downloading?
This means that the data partition is encrypted. Solutions: Enter a password from your previous account (if you remember). Run Format Data in TWRP (all data will be deleted!). Use TWRP with the disable_forceencrypt patch.
❓ How to update the firmware through TWRP without losing data?
To upgrade without losing data: Download the new firmware version (required for your current version!) In TWRP clean only Dalvik and Cache. Install the firmware on top of the old (Install β†’ Select ZIP β†’ Swipe). Reboot. ⚠️ Not all firmware supports a dirty update. For example, LineageOS requires a full wipe when changing the Android version.
❓ What to do if there is no IMEI after the firmware?
The loss of IMEI is due to damage to the modem partition. Solutions: Restore IMEI via Engineer Mode (enter ##3646633## and go to Connectivity β†’ CDS Information β†’ Radio Information β†’ Phone 1/2). Run the stock firmware for your model through TWRP. Use the SN Write Tool utility (requireses NV-data backup). ⚠️ Recover IMEI Illegally check for local legislation.
❓ What firmware supports Google Pay after the root?
Most custom firmware breaks Google Pay because of SafetyNet Solutions: Install Magisk and activate Universal SafetyNet Fix + MagiskHide Props Config modules. Use Google-certified firmware (e.g. Pixel Experience). Set up MagiskHide for Google Pay. Check SafetyNet status in the Magisk app or via the command: adb shell su -c "snet check"