How to Flash Stock Firmware Using a Fastboot Script (flash-all.bat)

Many Android manufacturers, including Google (for its Pixel devices), Motorola, and BQ, distribute their official factory firmware in a package that includes a flashing script. This script, typically named flash-all.bat for Windows or flash-all.sh for macOS/Linux, automates the process of flashing all the necessary partition images (like boot, system, recovery, etc.) to your device via fastboot.

This method is one of the most reliable ways to restore a device to its factory state, unbrick a soft-bricked phone, or revert from a custom ROM to the official software. This guide will walk you through the entire process, from setting up your computer to running the script and successfully restoring your device.

Prerequisites and Critical Warnings

Data Deletion: This process requires unlocking the bootloader, which will perform a mandatory factory reset and completely erase all data on your device. Back up everything important before you start.

Compatibility: Only use the official firmware package that is specifically designed for your exact device model. Using the wrong firmware will likely brick your device.

Battery Level: Ensure your phone is charged to at least 60% to prevent it from shutting down during the flashing process.

Required Downloads and Tools

Before you begin, you need to prepare your computer and download the necessary files.

  • Android SDK Platform-Tools: This is Google’s official package containing ADB and Fastboot. Download the latest version for your operating system from the official Android developer website.
  • Device-Specific USB Drivers: Your computer needs the correct drivers to communicate with your phone in fastboot mode.
  • The Correct Firmware Package: Download the official firmware for your device model from a trusted source. This should be a .zip file containing multiple .img files and the flash-all script.

Step-by-Step Flashing Instructions

Follow these steps in order. Do not skip any part of the process.

Step 1: Set Up ADB and Fastboot on Your PC

  1. Extract the Platform-Tools zip file to a simple location, like C:\platform-tools.
  2. For ease of use, you should add this folder to your system’s PATH environment variable. This allows you to run adb and fastboot commands from any command prompt window.

Step 2: Enable USB Debugging and OEM Unlocking on Your Phone

  1. Go to Settings > About phone.
  2. Scroll down and tap on the “Build number” seven times until you see a message that says, “You are now a developer!”
  3. Go back to the main Settings menu, and you will find a new “Developer options” menu.
  4. Inside Developer options, find and enable “OEM unlocking” and “USB debugging”. A confirmation pop-up will appear for each; accept them.

Step 3: Unlock the Bootloader

  1. Turn off your phone completely.
  2. Boot your phone into Fastboot/Bootloader mode. The key combination is usually Volume Down + Power Button held together.
  3. Connect your phone to your computer with a high-quality USB cable.
  4. Open a Command Prompt (or Terminal on Mac/Linux) and type fastboot devices. You should see your device’s serial number, which confirms the connection.
  5. To unlock the bootloader, type one of the following commands (the exact command varies by manufacturer):
    • For most modern devices (Pixel, newer Motorola): fastboot flashing unlock
    • For older devices (Nexus, some BQ): fastboot oem unlock or fastboot oem unlock-go
  6. A confirmation screen will appear on your phone. Use the volume keys to select “Yes” or “Unlock the bootloader” and press the power button. This will wipe your device. Your phone will reboot after this.

Step 4: Flash the Firmware Using the Script

  1. After the bootloader is unlocked, power off your phone and boot it back into Fastboot mode using the same key combination (e.g., Volume Down + Power).
  2. Connect the phone to your PC again.
  3. Extract the firmware .zip file you downloaded into a simple folder path (e.g., C:\firmware\my_device).
  4. Open the extracted firmware folder. You will see a list of .img files and the script.
  5. For Windows: Simply double-click the flash-all.bat file.
  6. For macOS/Linux: Open a terminal inside the firmware folder and run the command ./flash-all.sh.
  7. A command window will open and you will see the script executing a series of fastboot flash... commands. Do not close the window or disconnect the device.
  8. Once the process is complete, the script will often automatically reboot your phone.

Troubleshooting Common Problems

“fastboot is not recognized as an internal or external command”
This means you haven’t set up the Platform-Tools PATH correctly, or your command prompt is not open in the platform-tools folder. Open your command prompt directly inside the folder where `fastboot.exe` is located.
Fastboot is stuck on “waiting for device”
This is the most common issue and is almost always driver-related. Your PC is not recognizing the phone in fastboot mode.

  • Ensure you have installed the correct USB drivers for your brand.
  • Try a different USB cable and port (use a USB 2.0 port on the back of your computer if possible).
  • Open Device Manager on Windows and check for any devices with a yellow exclamation mark. If you see one, manually update the driver by pointing it to the driver files you downloaded.
The script fails with an error like “FAILED (remote: partition is locked)”
This means your bootloader is not unlocked. You must successfully complete Step 3 before attempting to run the flash script.

Conclusion

Using the official fastboot script is a safe and thorough way to restore your Android device to its factory software. While it seems complex at first, following the steps carefully—installing drivers, unlocking the bootloader, and running the script—will ensure a successful flash. This method is perfect for fixing persistent software bugs, resolving bootloops, and getting a clean start on your device.

Daniel
Daniel

With more than 7 years of experience in the Mobile software field (though not consistent), I hope I can be of great service to you in providing you with the firmware files that works, flashing guides that won't brick your phone and a new mobile experience.

Articles: 7625

Leave a Reply

Your email address will not be published. Required fields are marked *