Hardware & Firmwareadvanced · 14 min read

How to Flash Stock ROMs on Xiaomi, Redmi and POCO Without Mi Flash

Restore official MIUI or HyperOS fastboot firmware on Linux or macOS using global or portable Fastboot, with a guide to choosing the correct Xiaomi flash script.

Mi Flash is not required to reinstall stock MIUI or HyperOS on many Xiaomi, Redmi and POCO phones. The official fastboot firmware archives commonly include the same kinds of flashing scripts that a graphical flashing utility runs. On Linux and macOS, Android SDK Platform-Tools and a terminal can be enough to restore compatible firmware on a phone whose bootloader permits the operation.

The worked example is the Global MIUI 14 fastboot package for the light device family, build V14.0.3.0.TLSMIXM. The walkthrough is based on inspection of its original scripts; it is not a device-tested flashing result. Other releases may use different partitions, commands and filenames. For third-party Android builds, see the custom ROM installation guide.

Before starting: Back up your photos, documents, messages, authenticator recovery codes and other important data outside the phone. Use a device you own or are authorized to service. Flashing can permanently erase data and incompatible firmware can render a phone unbootable. Do not treat this as a way to recover files from a damaged phone.

Understand what you are downloading

Xiaomi distributes different firmware package types. A recovery ROM normally comes as a ZIP intended for the supported system updater or recovery workflow. A fastboot ROM usually comes as a .tgz or .tar.gz archive containing partition images and platform-specific scripts. They are not interchangeable.

Choose the official fastboot package for the exact phone model, codename, original sales region and supported firmware version. Check the Xiaomi Community ROM download guidance and use a trusted manufacturer download source. Do not download a similarly named ROM just because the phone's retail name looks familiar. Do not use repacked firmware or modified bootloader images.

If you are updating a working stock phone and the official updater accepts the intended release, that may be the safer option. For an unlocked phone requiring a clean reinstall, fastboot scripts can be useful. Locked phones generally cannot be restored through unrestricted fastboot partition writes; use Xiaomi's supported recovery or authorized service process instead.

Bootloader unlocking is separate from flashing

Mi Flash installs firmware; Mi Unlock handles Xiaomi's bootloader authorization. Installing Fastboot does not bypass the bootloader lock, Xiaomi account binding, regional eligibility or any required waiting period. A device may have different requirements under MIUI and HyperOS. Refer to Xiaomi's official bootloader FAQ for the current supported procedure. The official PC unlocking workflow may require Windows, even if subsequent flashing is done on Linux or macOS.

Unlocking normally factory resets the device. Do not use generic fastboot flashing unlock commands as a substitute for Xiaomi authorization. Do not bypass account locks, anti-rollback protection, verified boot or authorization checks. If the phone is already unlocked, you do not need to unlock it again for this guide.

Install Fastboot globally on Linux or macOS

Kali, Debian and Ubuntu

sudo apt update
sudo apt install adb fastboot android-sdk-platform-tools-common

Check the installation:

command -v adb
command -v fastboot
adb version
fastboot --version

Distribution packages can lag Google's releases. If a package is unavailable or too old for your firmware, use Google's current Platform-Tools instead. Linux may require Android USB udev rules and appropriate group permissions; follow the Android hardware-device setup documentation. Reconnect the phone after installing the rules and sign out and back in if group membership changes. Do not routinely run firmware scripts as root.

macOS using Homebrew

brew install --cask android-platform-tools
fastboot --version
adb version

Homebrew puts the tools on its configured PATH. If the shell cannot find them, check that Homebrew's shell environment is initialized. No Xiaomi Windows driver or Mi Flash UI is needed for the native Fastboot client.

Download Platform-Tools without installing them globally

Download the Linux or macOS archive from Google's official SDK Platform-Tools page. Extract it into a folder you control. Use the binary for your host operating system, not the Windows .exe on a Unix system.

For example, assuming the downloaded archive is in Downloads:

mkdir -p "$HOME/android-tools"
# Linux; use the actual downloaded filename
unzip "$HOME/Downloads/platform-tools-latest-linux.zip" -d "$HOME/android-tools"

On macOS, the equivalent archive is normally named platform-tools-latest-darwin.zip:

mkdir -p "$HOME/android-tools"
unzip "$HOME/Downloads/platform-tools-latest-darwin.zip" -d "$HOME/android-tools"

Run the downloaded executables directly:

cd "$HOME/android-tools/platform-tools"
./fastboot --version
./adb version
./fastboot devices

The ./ prefix means execute the file in the current directory. A bare fastboot command instead searches PATH. Keep any supporting libraries supplied in the archive alongside the tools; do not substitute unknown binaries.

Extract and inspect the fastboot ROM

Keep the downloaded archive intact as a backup. On both Linux and macOS, tar can unpack a normal .tgz:

mkdir -p "$HOME/roms"
tar -tzf "$HOME/Downloads/YOUR_EXACT_ROM.tgz" | less
tar -xzf "$HOME/Downloads/YOUR_EXACT_ROM.tgz" -C "$HOME/roms"

Use a trusted archive; review the complete listing before extracting (press q to exit less). Avoid archives containing absolute paths, parent-directory traversal or unexpected executable files. Extract as an ordinary user. If the ROM was packaged in two layers, extract the inner tar as well. Enter the directory that actually contains the flash scripts and images/, not its parent.

A complete extracted fastboot package should have a layout similar to this. The image filenames shown are referenced by the example scripts:

rom-root/
├── flash_all.sh
├── flash_all_lock.sh
├── flash_all_except_data_storage.sh
├── flash_all.bat
├── flash_all_lock.bat
├── flash_all_except_data_storage.bat
├── misc.txt
└── images/
    ├── preloader_light.bin
    ├── boot.img
    ├── super.img
    ├── userdata.img
    └── ...

Check the actual directory before proceeding. The shell scripts in this example use unquoted path expansions, so avoid spaces, shell metacharacters and unusual characters in the ROM directory path.

cd "$HOME/roms/YOUR_EXTRACTED_ROM_DIRECTORY"
ls -l flash_all*.sh
ls -ld images
cat misc.txt

Verify the archive against a trusted published checksum when available. On Linux use sha256sum, and on macOS use shasum -a 256. A checksum calculated locally is not proof of authenticity unless it matches a trusted reference.

What the three scripts actually do

Many Xiaomi fastboot packages contain three variants, though names and behavior can vary between models and releases. The supplied example contains the following:

Unix script Windows counterpart User data Bootloader
flash_all.sh flash_all.bat Wipes No explicit relock in this example
flash_all_except_data_storage.sh flash_all_except_data_storage.bat Attempts to retain No explicit relock in this example
flash_all_lock.sh flash_all_lock.bat Wipes Attempts to relock

Clean all: flash_all.sh

The script checks the product codename and anti-rollback version, erases boot and writes the package's firmware partitions. Among its data-related operations are:

fastboot $* flash userdata `dirname $0`/images/userdata.img
fastboot $* erase misc
fastboot $* erase metadata

These are excerpts for explanation, not commands to run individually. The userdata image and metadata erase are destructive to existing user data. The script ends with a reboot and contains no explicit bootloader-lock command. This is generally the appropriate mode for an intentional clean restore from a custom ROM, after confirming compatibility and backing up everything.

Save user data: flash_all_except_data_storage.sh

In the supplied shell script, the userdata operation is commented out:

#fastboot $* flash userdata `dirname $0`/images/userdata.img

The metadata erase is also absent. The script still replaces system and firmware partitions, erases boot at the beginning and erases misc later. This does not guarantee that existing encrypted data will remain readable after a version change. Use this mode only for a supported compatible stock-to-stock update, and only after making a backup. Do not assume it will preserve data when switching from a custom ROM, changing regions or downgrading Android.

Clean all and lock: flash_all_lock.sh

This is not a normal clean installation. It includes userdata flashing, metadata erasure, additional CRC-list operations, and bootloader-locking logic. In the example, its final logic queries oem lks and may invoke oem lock before exiting with status 1. Therefore, a nonzero exit code does not necessarily mean that the device stayed unlocked.

Relocking while the phone contains incompatible, modified, wrong-region or incomplete firmware can prevent it from booting. Relocking can also reset the phone. Only consider it if Xiaomi's official instructions explicitly support the exact device, region and fully official firmware. Confirm that a normal clean stock install boots successfully before evaluating whether relocking is appropriate. This guide does not instruct readers to run the lock script. See the Android verified boot device-state documentation for why a locked bootloader enforces software trust.

Read the actual package checks

The supplied misc.txt identifies device=light and build_number=V14.0.3.0.TLSMIXM. Public firmware listings associate this Global MIUI 14 / Android 13 build with the light family, including supported Redmi 10 5G, Redmi 11 Prime 5G and POCO M4 5G variants. The retail model and original region still need independent verification.

All three supplied shell scripts start with a product check accepting light or thunder:

fastboot $* getvar product 2>&1 | grep -E "^product: *light$|^product: *thunder$"
if [ $? -ne 0 ] ; then echo "error : Missmatching image and device"; exit 1; fi

The example also declares CURRENT_ANTI_VER=1 and aborts if the device reports a higher anti-rollback value. Its query uses fastboot getvar anti without the $* selection arguments and treats missing output as zero. That is an implementation detail, not a reliable safety guarantee: missing or ambiguous anti-rollback information must not be interpreted as proof that downgrading is safe. Confirm the supported firmware upgrade path before flashing; if the version cannot be verified, stop. Never remove the checks or force a lower anti-rollback version.

The package references critical firmware such as preloader_a, verified boot metadata, modem firmware and super.img. These are specific to the package and must not be copied into a universal flashing command list. The package checks are necessary but are not a substitute for confirming official provenance, original region and firmware compatibility.

Connect the phone and perform preflight checks

If Android is running, enable USB debugging on your own device, authorize the computer and use:

adb devices
adb reboot bootloader

If Android cannot start, many Xiaomi phones enter Fastboot mode by holding Volume Down and Power with the phone powered off. Check the device's instructions. Use a reliable data cable, direct USB port and sufficient battery charge; keep the computer connected to power and prevent sleep during flashing.

fastboot devices
fastboot getvar product
fastboot getvar anti

Some devices expose bootloader status through fastboot getvar unlocked, while others use vendor-specific status queries. Unsupported variables are not evidence of an unlocked device. Verify the state independently using the device's documented procedure. If you have downloaded tools without adding them to PATH, use the full path or ./fastboot from their directory for these checks.

Disconnect all other phones. This matters even when a script accepts -s SERIAL, because the supplied anti-rollback query ignores the forwarded device selector. Do not proceed with more than one Fastboot device, a mismatched product, an unknown unlock state or uncertain rollback compatibility.

Before running any of the following methods, confirm that:

  • Exactly one phone is connected in Fastboot mode and its bootloader permits flashing.
  • The ROM matches the device codename, variant, original region and supported rollback requirements.
  • Your backup is complete, the archive is verified and the selected script has been reviewed.
  • You understand whether the selected mode wipes data or attempts to preserve it.

Choose one of the following methods. They are alternative ways of running the same vendor script, not consecutive installation steps.

Method A: global Fastboot — no script modification

When command -v fastboot resolves to the intended installed binary, the stock scripts' bare fastboot invocations already work. There is no need to change every command or install Mi Flash.

Review the entire selected script, not just its filename:

command -v fastboot
fastboot --version
bash -n flash_all.sh
less flash_all.sh

bash -n checks shell syntax only. It cannot establish device compatibility or validate firmware. Search for data operations and lock commands during review:

grep -nE 'userdata|metadata|oem[[:space:]]+lock|flashing[[:space:]]+lock|CURRENT_ANTI_VER|getvar' flash_all.sh

If all preflight checks passed and you explicitly intend a clean installation that wipes user data, run the appropriate vendor script from the ROM root:

bash ./flash_all.sh

For a verified supported data-preserving stock-to-stock installation, the alternative is bash ./flash_all_except_data_storage.sh. Do not run both scripts. The clean script is the normal choice for an intentional reset; neither option is risk-free.

Method B: portable Fastboot — no script modification

This method is useful when you do not want to install tools globally. Point PATH at Google's extracted tools for this invocation only:

TOOLS="$HOME/android-tools/platform-tools"
PATH="$TOOLS:$PATH" fastboot --version
PATH="$TOOLS:$PATH" fastboot devices

From the ROM root, after the same preflight and script review, a clean install is:

PATH="$TOOLS:$PATH" bash ./flash_all.sh

This keeps the vendor script unchanged, works with both Linux and macOS, and avoids accidentally using an older global Fastboot binary. Confirm the selected executable exists and is the intended version before running the script. PATH should reference a trusted tools directory rather than adding the current directory globally.

Method C: put Fastboot in the ROM root and use ./fastboot

Another useful approach is to place the downloaded fastboot binary in the same folder as the extracted ROM's scripts. Keep any required supporting libraries nearby. From the ROM root:

cp "$HOME/android-tools/platform-tools/fastboot" ./fastboot
chmod u+x ./fastboot
./fastboot --version
./fastboot devices

The vendor scripts call fastboot, not ./fastboot, so simply copying the file is not enough. Make a copy of only the intended script in the same directory (the original uses its own location to locate images/):

cp flash_all.sh flash_all_local.sh

Open flash_all_local.sh in a text editor and change the executable name in every actual Fastboot invocation, including device and rollback queries inside backticks or command substitutions. For example:

# Original
fastboot $* getvar product 2>&1 | grep -E "^product: *light$|^product: *thunder$"
version=`fastboot getvar anti 2>&1 | grep "anti:" | awk -F ": " '{print $2}'`

# Local binary version
./fastboot $* getvar product 2>&1 | grep -E "^product: *light$|^product: *thunder$"
version=`./fastboot getvar anti 2>&1 | grep "anti:" | awk -F ": " '{print $2}'`

Do the same for the remaining Fastboot commands, such as image writes and reboot. Do not change partition names, firmware paths, checks or arguments. Avoid a blind replace of every occurrence of the string fastboot in arbitrary scripts. Do not modify the lock script for this workflow.

diff -u flash_all.sh flash_all_local.sh
bash -n flash_all_local.sh

The diff should show only the executable path change. Run the reviewed copy from the ROM root, not a different working directory, only after the device and firmware preflight is complete and you accept the full data wipe:

bash ./flash_all_local.sh

If you prefer the data-preserving mode, review and copy that script instead, using the same method. Do not run the clean script and data-preserving script successively. The temporary PATH approach in Method B is simpler and less prone to editing mistakes.

Observe the flash and verify the result

Fastboot prints progress for each transfer and partition operation. Keep the phone connected and do not close the terminal, suspend the computer or interrupt a write. The example scripts check most individual return codes; not all vendor scripts are equally robust. If an operation fails, stop and record the complete error. Do not skip a failed partition, immediately retry a different script or relock the device to clear a warning.

After a successful reboot, the first boot may take longer than usual. Verify the expected build number, original region, network and SIM functions, Wi-Fi, Bluetooth, camera, touch and charging. If preserving data was intended, verify that files and apps are usable. Retain your backup until the restored system is stable.

Troubleshooting

Symptom What to check
fastboot: command not found Install globally, set the temporary PATH or use the reviewed local-script method.
Permission denied or no device on Linux USB data cable, udev rules, permissions and the active Fastboot mode.
waiting for any device Device mode, USB connection and host drivers; disconnect other phones.
Missmatching image and device Stop. Verify exact model, codename and official ROM.
Anti-rollback error Stop. Select a supported firmware release, not a modified check.
Flashing is not allowed Verify bootloader state and official authorization.
Missing image or partition error Check archive integrity and model-specific instructions; do not improvise a partition map.
Device fails to boot Preserve logs and seek the official recovery or service procedure for that model; do not relock.

References

← Back to the journal