How to flash Xiaomi Mi5: official and custom firmware

Xiaomi Mi5

Snapdragon 820

In this article, you will find step-by-step instructions for all methods of firmware: through Fastboot, Recovery (TWRP) and the official Mi Flash Tool. We will learn how to unlock the bootloader, where to download verified firmware files (including Global Stable, China Stable and custom builds based on LineageOS or Pixel Experience), as well as solve typical errors like anti-rollback or EDL mode. If you have never flashed a smartphone, do not worry: the instructions are adapted for beginners, with explanations of each step.

⚠️ Important: Xiaomi firmware Mi5 (codename gemini requires you to unlock the bootloader through the official Mi Unlock Tool. Without this, you can not install either the official or custom firmware. The unlock process takes up to 720 hours (30 days) of waiting for the account to be linked - consider this in advance.

πŸ“Š Why do you want to use Xiaomi? Mi5?
Install a new version of Android
Fix mistakes and lags
Install custom firmware (LineageOS, Pixel Experience)
Return the official MIUI after a failed firmware
Other

1. Firmware Preparation: What to Do Before Starting

Before you start firmware, make sure that all the preliminary steps are followed, and ignoring them can lead to a device β€œbrick” (completely inoperable) or data loss.

Mandatory conditions:

  • πŸ”‹ Battery charge at least 60% (optimally β€” 80-100%). The firmware may take up to 30 minutes, and the discharge during the process will cause a failure.
  • πŸ–₯️ Computer on Windows 7/10/11 (for the Mi Flash Tool or Linux/macOS (For fastboot via terminal, you will need to install Android Platform Tools on your Mac.
  • πŸ“± Unlocked bootloader (if not unlocked – see section 2). You can check status by command fastboot oem device-info (see Device unlocked: true).
  • πŸ”Œ Original. USB-The cable (better the one that came with it) is cheap, and it doesn't have to be fastboot.

Also prepare:

  • πŸ“ Backup data. Firmware erases internal memory! Use Mi Cloud, Google Photos or adb backup to save contacts, photos and apps.
  • πŸ› οΈ Firmware files for your model. download only from official sources: Official website MIUI (Choose the version for Gemini). XDA Developers (for custom firmware).

⚠️ Note: Unofficial builds (e.g. LineageOS) require custom recovery installation (TWRP). You can install official firmware via Mi Flash Tool or fastboot without TWRP.

β˜‘οΈ Checklist before firmware

Done: 0 / 5

2 Unlocking the Xiaomi Mi5 bootloader

Xiaomi blocks the bootloader on all devices, including the Mi5. Without unlocking, you can not flash the phone with either official or custom firmware. The process consists of two stages: linking the Mi Account to the device and actually unlocking through the Mi Unlock Tool.

Step 1. Account binding (up to 30 days):

  1. Turn on your phone and go to Settings β†’ About Phone β†’ MIUI version. Click 7 times on the line with the version to activate Developer Mode.
  2. Back to Settings β†’ Additionally. β†’ For developers and include: πŸ”“ Unlocking OEM (OEM Unlocking). πŸ”Œ Debugging by USB (USB Debugging).

Mi

Settings β†’ Xiaomi account

Settings β†’ Xiaomi Account β†’ Mi Cloud

Synchronization

Find the device.

This device has been added to your Mi Account.

Step 2: Unlocking through the Mi Unlock Tool:

  1. Download Mi Unlock Tool (Windows version)
  2. Install the program and run on behalf of the administrator.
  3. Log in to the same Mi Account as on your phone.
  4. Turn off the Mi5, press Volume Down + Power to log into the Fastboot.
  5. Connect your phone to your PC. In Mi Unlock Tool, press Unlock.

Step 2: Preparing the phone

  1. Turn off the Mi5.
  2. Press Volume Down + Power to enter Fastboot (a hare in a hat-eared hat will appear on the screen).
  3. Connect the phone to the PC.

Step 3: Firmware via Mi Flash Tool

  1. Run the Mi Flash Tool on behalf of the administrator.
  2. Press Select and select the folder with the unpacked firmware (it should contain files with the.bat,.img, etc. extension).
  3. At the bottom, select firmware mode: Clean all – complete cleaning (recommended when changing the version of MIUI); Clean all and lock – cleaning + lock the bootloader (use if you want to return the phone to the factory state); Save user data – data storage (does not always work correctly!).

Refresh

COM-port

Flash

⚠️ Note: If the process is suspended on "Waiting for device":

  • Check if drivers are installed (Android Bootloader Interface should be displayed in Device Manager).
  • Try another one. USB-port.
  • Reinstall the Mi Flash Tool to a folder without Cyrillic characters (e.g., C:\MiFlash).

πŸ’‘

If you've got your phone stuck on the MI logo after you've run it, don't panic! Wait 10-15 minutes (it can be a long first run). If it doesn't work, repeat the firmware with the Clean all option.

5. Firmware through Fastboot (manual method)

This method provides more control than the Mi Flash Tool, and is suitable for installing both official and custom firmware in.tgz or.img format.

Step 1: Preparing files

  • Download the firmware for gemini (for example, with XDA).
  • Unpack the archive in a folder. C:\mi5_fastboot (pathless!).
  • Download Android Platform Tools and unpack it into the same folder.

Step 2. Commands for firmware

  1. Open Command Prompt in the firmware folder (click Shift + PCM β†’ Open the PowerShell window here).
  2. Check the phone connection: fastboot devices should appear a line with the serial number of the device.
  3. Unlock critical sections (if you are flashing through the cast): fastboot oem unlock-go ⚠️ This team will dump all the data!
  4. Switch the firmware alternately (example for the official one) MIUI): fastboot flash boot boot.img fastboot flash recovery recovery.img fastboot flash system system.img fastboot flash modem NON-HLOS.bin fastboot flash fsb fsb.img fastboot flash splash splash.img fastboot flash cust cust.img fastboot flash devcfg devcfg.img fastboot flash keymaster keymaster.img fastboot flash aboot emmc_appsboot.mbn fastboot flash rpm rpm.mbn fastboot flash tz tz.mbn fastboot flash hyp hyp.mbn fastboot flash cmnlib cmnlib.mbn fastboot flash cmnlib64 cmnlib64.mbn fastboot flash bluetooth BTFM.bin fastboot flash dsp adspso.bin fastboot flash logo logo.bin fastboot flash sec sec.dat fastboot flash userdata userdata.img fastboot flash cache cache.img
  5. Clear the cache: fastboot erase cache fastboot erase userdata
  6. Reboot the phone: fastboot reboot

⚠️ Note: If you are flashing custom firmware (such as LineageOS), install it first. TWRP Recovery:

fastboot flash recovery twrp-3.7.0_gemini.img


fastboot boot twrp-3.7.0_gemini.img

Then move to the TWRP and sew ZIP-firmware.

6. Firmware through TWRP Recovery (Castom firmware)

TWRP (Team Win Recovery Project is a custom recovery project that allows you to install ZIP-Firmware files, backups and repairs, and this is a method that you need to install LineageOS, Pixel Experience, or other unofficial builds.

Step 1: Installation of TWRP

  • πŸ“₯ Download the latest version TWRP for Gemini from the official website.
  • πŸ–₯️ Connect your phone to fastboot and run recovery: fastboot flash recovery twrp-3.7.0_gemini.img fastboot boot twrp-3.7.0_gemini.img

Step 2: Custom OS firmware

  1. Download. ZIP-Firmware file (e.g. LineageOS 18.1) and Open GApps if necessary (select option) arm64 β†’ nano).
  2. Move files to your phone or flash drive (if you have a TWRP You can’t see your internal memory, use it. OTG-cable).
  3. V TWRP Do it: Press the Wipe. β†’ Advanced Wipe and mark: 🧹 Dalvik / ART Cache 🧹 System 🧹 Data 🧹 Cache
  4. Return to the main menu and click Install, select ZIP-firmware.
  5. After installation, run GApps (if you need Google services).
  6. Press Reboot System.

⚠️ Note: When installing LineageOS or Pixel Experience, you can not flash firmware for other models (for example, capricorn for the device). Mi5s). This will result in a hard brick (not being able to turn your phone on even in a fastboot).

How to return the official MIUI after custom firmware?
1. Download the official Fastboot firmware for gemini. 2. Sweep it through the Mi Flash Tool with the Clean all. 3 option. If the phone doesn't turn on, try logging in. EDL-Mode (close the Volume up) + Loudness down + Power on the phone turned off and swipe through the Mi Flash Tool with the checkmark Clean all and lock.

7. Solving Mistakes When Firmware Xiaomi Mi5

Even with the correct instructions, errors can occur, and here are the most common ways to correct them:

Mistake.Reason.Decision
anti-rollbackTrying to flash an older version of MIUI than the one installedSweat through a newer version or the same one that's worth it now. Use the Anti-Rollback Checker.
This device is lockedThe bootloader is not unlockedUnlock the bootloader through the Mi Unlock Tool (see section 2).
Waiting for device in fastbootDrivers are not installed or the cable is faultyInstall drivers manually through Device Manager (look for Android Bootloader Interface).
The phone does not turn on after firmware (black screen)Incompatible firmware or failure when recordingTry to log in to fastboot (Loudness down). + Food, and then you can re-sweethe. If it doesn't work, use it. EDL (You need an authorized Xiaomi account).
E: Unknown command [log] in TWRPA damaged firmware file or an incompatible version of TWRPDownload the firmware again and check the checksum (MD5). Update the TWRP to the latest version.

If your phone has turned into a brick (no button response, no PC detection), try the following steps:

  1. Connect your phone to charge for 30 minutes – sometimes it helps with battery drain.
  2. Try to get in. EDL (Emergency mode: 1. Turn off the phone. 2. Press Volume up + Loud down and plug in. USB-cable to PC. 3. Qualcomm should appear in Device Manager HS-USB QDLoader 9008.

The first run after firmware can take up to 15 minutes – don’t turn off your phone!