Home > ROMs > Stock Firmware

How to Flash Stock Firmware via Fastboot Commands

In this tutorial, we will show you how to flash Stock Firmware via Fastboot Commands on any Android device. The everyday general users are more than contained when they receive an OTA on their Android device. They just hit the Install button, and if the device has an A/B partition, they continue with their work while the installation process is being carried out in the background in the inactive slot. Once that is done, they simply reboot their device to switch slots and enjoy the new update. Samsung device owners are a little bit less lucky and they have to wait for a few minutes until the installation is done.

But anyway, the only effort that the user has to exert in all of these is simply hitting the Install button in the initial phase and the Reboot button in the latter half. However, with the open-source nature of Android, things aren’t so plain and simple. Most of the users go ahead and try out tons of customizations and tweaks. These include the ability to flash custom ROMs, a custom recovery like TWRP, unlock their device bootloader, try out Build. Prop Tweaks, flashing mods from Magisk, and Frameworks of Xposed among others.

And while executing the above steps, there’s always a possibility of things going south. Just a slight miss-step and you will end up with a bootloop or a soft-bricked device. The worst-case scenario will lead to a hard-brick, in which case you will have to take up the EDL Mode route to repair your device. All in all, as and when you end up messing up your device, the first thing that comes to your mind is flashing the stock firmware to make it work back again.

But unfortunately, things in a bricked or boot-looped device works in a slightly different way. Since you cannot access the Android system, you cannot simply install the stock ROM in the “normal” way. Fortunately, there still exists a handy way of doing so. You could still flash the stock firmware of any Android device using fastboot commands. The process is applicable for near about every device running on any chipset (Exynos, Snapdragon, or MediaTek) and of any OEM. So without further ado, here are all the required instructions set.


Editor’s Choice


How to Flash Stock Firmware via Fastboot Commands

We are breaking down the entire instructions into simpler steps. Make sure to follow them in the same manner. Droidwin and its members wouldn’t be held responsible in case of a thermonuclear war, your alarm doesn’t wake you up, or if anything happens to your device and data by performing the below steps.

STEP 1: Download Android SDK Platform Tools

install adb platform tools windows

First and foremost, you will have to install the Android SDK Platform Tools on your PC. This is the official ADB and Fastboot binary provided by Google and is the only recommended one. So download it and then extract it to any convenient location on your PC. Doing so will give you the platform-tools folder, which will be used throughout this guide.

STEP 2: Boot your device to Fastboot Mode

Next up, you will have to boot your device to Fastboot, or as some OEMs like to call, the Bootloader menu. There are two ways of doing so- via hardware key combinations or using ADB Commands. If your device is in a perfectly working condition, then you could use either of the two methods (though we would recommend opting for the Fastboot Commands).

fastboot mode xiaomi device
Fastboot Mode in Xiaomi

On the other hand, if your device is stuck in the bootloop/softbrick state and you cannot access the OS, then you have no choice but to go with the hardware key combination method. So without any further ado, let’s check out both these methods (For detailed instructions, you should also refer to our guide on How to Boot any Android Device to Fastboot Mode).

Method 1: When the Device is working normally

If your device is working well and good, then it is advised that you opt for this ADB Command method to boot your device to Fastboot Mode. This is because it is the universal method that works across all Android devices.

  1. To begin with, enable USB Debugging on your device. Head over to Settings > About Phone > Tap on Build Number 7 times (MIUI Number in case of Xiaomi devices) > Go back to Settings > System > Advanced > Developer Options > Enable USB Debugging.
    flash stock firmware via fastboot commands
  2. Then head over to the platform-tools folder, type in CMD in the address bar, and hit Enter. This will launch the Command Prompt.
    command-prompt-inside-adb
  3. Type in the following command in the CMD window to boot your device to Fastboot Mode
    adb reboot bootloader

    flash stock firmware via fastboot commands

  4. To verify the Fastboot connection, type in the below command and you should get back the device ID.
    fastboot devices

    flash stock firmware via fastboot commands

Method 2: When Device is Stuck in Bootloop/Bricked

If you cannot access the OS, then you wouldn’t be able to enable USB Debugging. As a result, you wouldn’t be able to execute the adb reboot bootloader command and you would instead have to opt for the hardware key combinations. Now, there doesn’t exist any universal method to do so, but here are the generic instructions that work for most devices:

  1. To begin with, you will have to power off your device. For that, long-press the Power menu for around 5-6 seconds. This should force-shutdown the device.
  2. However, if that doesn’t happen, then you will have to wait for the battery to drain out. As soon as that happens, connect your device to the charger and move over to the next step.
  3. Once the device powers off, press and hold the Power and Volume Up Keys (or Power and Volume Down keys in some devices) and your device should be booted to Fastboot Mode.

STEP 3: Download and Extract Stock Firmware

The next step involves downloading the stock firmware. For that, you could refer to your device’s software download page. There might be other third-party sites as well, but they don’t usually have the updated software package. So the official one is the recommended one. Once you have downloaded it, extract it inside the folder where the Android SDK Platform Tools are installed.

extract stock boot.img oneplus 9 pro payload.bin root magisk

That is, extract it inside the platform-tools folder. However, nowadays, most OEMs pack their firmware under separate packages. For example, OnePlus and Asus use the payload.bin file, Realme and Oppo use OZIP, LG uses KDZ or DZ format, and so on. So please refer to our below-linked guide to extract the firmware corresponding to your device:

Once you have extracted the firmware and got hold of the Fastboot IMG files, proceed with the below manual steps or directly jump over to the list of device-specific Fastboot commands section: Fastboot Command Sheet For Various Android Devices.


Don’t Miss


STEP 4: Flash Stock Firmware via Fastboot

NOTE: This is a manual method to create the Fastboot Commands for your device. Carrying it out would require your precious time, in some cases, even up to 30 minutes. However, if you don’t have much time in hand, then I have also automated the process for most of the Android devices and have also created a sample Fastboot Commands sheet that covers most of the devices. So you could also refer to that as well if you don’t wish to manually carry out this task as of now. Here’s the direct link for both these guides:

  1. First of all, some OEMs (like Pixel and Xiaomi) make it pretty easy for the end-users and they add a flash-all.bat file (see below image). If the stock ROM that you have extracted has one as well, then simply double click on that file and wait for the process to finish.
  2. But the thing is not all OEMs are so generous, and if your smartphone falls into the latter category, then you will have to flash the stock firmware via Fastboot Commands.
    flash-all.bat file
  3. For that, extract all the contents of the stock firmware that you have downloaded inside the platform-tools folder.
  4. Then connect your device (that has been booted to fastboot mode) to the PC via USB cable. As mentioned before, if it has the flash-all.bat file, then simply execute that.
  5. If it doesn’t have one, then look out for the XML files. There should be something along the lines of servicefile.xml, flashfile.xml, or other similar names. The focus shouldn’t be on the names but rather the contents of that file (see next point).
    servicefile.xml stock firmware
  6. In this regard, the XML file holds the file name, type and more importantly the partitions of each of the file that is part of the stock firmware. We could then use this to manually create the fastboot commands and hence flash the stock firmware via it.
    xml file stock firmware fastboot commands
  7. Let’s understand it with the help of an example. Here are two lines from one of the device’s XML files (see below image):
    <step MD5="ff8711c8eb5c7fd7559bd79d74b1f4d8" partition="modem_a" operation="flash" filename="modem.bin"/>
    <step MD5="f31b2994072f47907504776a64bcd842" partition="vbmeta_a" operation="flash" filename="vbmeta.img"/>
  8. This is enough for us to understand that the modem.bin file has to be flashed in the modem_a partition whereas the vbmeta.img will be flashed in the vbmeta_a slot. This is an example of a dual-slot A/B Partition device, hence you are seeing the ‘a’ keyword in the partition name. Moving on, the flash command for the above two files will then be:
    fastboot flash modem_a modem.bin
    fastboot flash vbmeta_a vbmeta.img.
  9. Likewise, you could create the fastboot commands for all the stock firmware files using the below syntax:
    fastboot flash partition-name file-name-with-extension
  10. Once you have created the fastboot command list, head over to the platform-tools folder. Type in CMD in the address bar, and hit Enter. This will launch the Command Prompt.
  11. Now copy-paste all the fastboot commands one by one. It is highly recommended to execute the commands in the same order as mentioned in the XML file, otherwise, it might lead to brick issues.
  12. Once you have executed all the commands, enter the below code to boot your device to Android system:
    fastboot reboot

That is it. You have successfully flashed the stock firmware manually via the fastboot commands. A huge kudos to you as you have created the entire code-sheet yourself. With that said, we get it that not all OEMs are so developer-friendly, and as a result, you might face issues getting your hand with the XML file. If that is the case, then below we have attached a few sample fastboot commands to flash stock firmware files, that may come in handy.

If that doesn’t work out, the comments section is all yours. Drop-in your device name, the firmware version, and the region as well. If possible please download the entire firmware and send us the screenshot of the same (upload to Imgur, Google Photos, etc and share the link with us in the comments). We will try our best to create the fastboot commands for your device’s stock firmware and then share it with you, either on your email or right here in the comments section.

Unbrick Samsung Devices via Odin

how to unbrick samsung device via odin

If you have a Samsung device, then you wouldn’t be able to unbrick it via Fastboot Commands. Rather you would need the Odin Tool installed on your PC. After that, you need to download the firmware via Frija Tool or SamMobile site and load it to Odin.

Finally, you will have to boot your device to Download Mode and then flash the firmware via Odin. All this has been explained in our detailed guide, do refer to it: Unbrick Samsung | Flash Stock Firmware via Odin.

Fastboot Unbrick Commands Guides For Various Android Devices

Here is a sample fastboot command sheet. I tried to write down the commands for all frequently used files. The below commands are for A/B partition devices, if your device just has a single partition, you will have to ignore the ‘a’ or ‘b’ keywords. For example, fastboot flash dtb_a dtb.img will change to fastboot flash dtb dtb.img.

Fastboot Commands to Unbrick Pixel Devices

Fastboot Commands to Unbrick OnePlus Devices

Fastboot Commands to Unbrick Xiaomi/Redmi/Mi/Poco Devices

Unbrick Realme Devices via Fastboot Commands

Unbrick Oppo Devices via Fastboot Commands

Fastboot Commands to Unbrick Motorola Devices

If your device is not part of this list, then please let me know in the comments section below. In the meantime, you could also make use of the below command sheet. Just extract your device’s firmware inside the platform-tools and verify the files that it has. Then use the commands for those sets of files from here.

Fastboot Commands Sheet to Flash Stock Firmware

Here is a sample fastboot command sheet. I tried to write down the commands for all frequently used files. These commands are not for any particular device nor in any particular order. It could come in handy if you wish to flash a file but aren’t sure of that file’s associated fastboot command. Likewise, you could also just download the stock firmware, and rather than extracting and creating the fastboot commands from the XML File, you could refer to the fastboot commands from below and then flash the files using these commands.

Moreover, if you want to flash a file to both the partition, then make sure to specify the partition in the commands as well. For example, if you wish to flash the boot.img to Partition A and B, then the command will be fastboot flash boot_a boot.img and fastboot flash boot_b boot.img. Likewise, you may modify the rest of the commands accordingly, if required. Or ask me via the comments section below.

fastboot flash gpt PGPT
fastboot flash preloader preloader.bin
fastboot flash lk_a lk.img
fastboot flash tee_a tee.img
fastboot flash md1img_a md1img.img
fastboot erase nvdata
fastboot flash spmfw_a spmfw.img
fastboot flash scp_a scp.img
fastboot flash sspm_a sspm.img
fastboot flash cam_vpu1_a cam_vpu1.img
fastboot flash cam_vpu2_a cam_vpu2.img
fastboot flash cam_vpu3_a cam_vpu3.img
fastboot flash vbmeta_a vbmeta.img
fastboot flash oem_a oem.img
fastboot flash logo_a logo.bin
fastboot flash boot_a boot.img
fastboot flash dtb_a dtb.img
fastboot flash dtbo_a dtbo.img
fastboot flash system_a system.img_sparsechunk.0
fastboot flash system_a system.img_sparsechunk.1
fastboot flash system_a system.img_sparsechunk.2
fastboot flash system_a system.img_sparsechunk.3
fastboot flash system_a system.img_sparsechunk.4
fastboot flash system_a system.img_sparsechunk.5
fastboot flash system_a system.img_sparsechunk.6
fastboot flash system_a system.img_sparsechunk.7
fastboot flash system_a system.img_sparsechunk.8
fastboot flash system_a system.img_sparsechunk.9
fastboot flash system_b system_other.img_sparsechunk.0
fastboot flash system_b system_other.img_sparsechunk.1
fastboot flash vendor_a vendor.img_sparsechunk.0
fastboot flash vendor_a vendor.img_sparsechunk.1
fastboot flash abl abl.img
fastboot flash aop aop.img
fastboot flash bluetooth bluetooth.img
fastboot flash devcfg devcfg.img
fastboot flash dsp dsp.img
fastboot flash featenabler featenabler.img
fastboot flash hyp hyp.img
fastboot flash imagefv imagefv.img
fastboot flash keymaster keymaster.img
fastboot flash multiimgoem multiimgoem.img
fastboot flash qupfw qupfw.img
fastboot flash tz tz.img
fastboot flash uefisecapp uefisecapp.img
fastboot flash xbl xbl.img
fastboot flash xbl_config xbl_config.img
fastboot flash product product.img
fastboot flash system system.img
fastboot flash system_ext system_ext.img
fastboot flash vendor vendor.img
fastboot flash odm odm.img
fastboot flash boot boot.img
fastboot flash cpucp cpucp.img
fastboot flash dtbo dtbo.img
fastboot flash modem modem.img
fastboot flash oplusstanvbk oplusstanvbk.img
fastboot flash oplus_sec oplus_sec.img
fastboot flash qweslicstore qweslicstore.img
fastboot flash shrm shrm.img
fastboot flash splash splash.img
fastboot flash vbmeta vbmeta.img
fastboot flash vbmeta_vendor vbmeta_vendor.img
fastboot flash vbmeta_system vbmeta_system.img
fastboot flash vendor_boot vendor_boot.img
fastboot flash vm-bootsys vm-bootsys.img
fastboot flash xbl xbl.elf
fastboot flash xblbak xbl.elf
fastboot flash xbl_config xbl_config.elf
fastboot flash xbl_configbak xbl_config.elf

fastboot flash abl abl.elf
fastboot flash ablbak abl.elf
fastboot flash tz tz.mbn
fastboot flash tzbak tz.mbn

fastboot flash hyp hyp.mbn
fastboot flash hypbak hyp.mbn

fastboot flash devcfg devcfg.mbn
fastboot flash devcfgbak devcfg.mbn

fastboot flash storsec storsec.mbn
fastboot flash bluetooth BTFM.bin

fastboot flash cmnlib cmnlib.mbn
fastboot flash cmnlibbak cmnlib.mbn
fastboot flash cmnlib64 cmnlib64.mbn
fastboot flash cmnlib64bak cmnlib64.mbn

fastboot flash modem NON-HLOS.bin
fastboot flash dsp dspso.bin

fastboot erase metadata
fastboot flash metadata metadata.img

fastboot flash keymaster km41.mbn
fastboot flash keymasterbak km41.mbn
fastboot flash logo logo.img

fastboot flash misc misc.img
fastboot flash aop aop.mbn
fastboot flash aopbak aop.mbn

fastboot flash qupfw qupv3fw.elf
fastboot flash qupfwbak qupv3fw.elf
fastboot flash imagefv imagefv.elf

fastboot flash uefisecapp uefi_sec.mbn
fastboot flash uefisecappbak uefi_sec.mbn

fastboot flash multiimgoem multi_image.mbn
fastboot flash super super.img

fastboot flash vbmeta vbmeta.img
fastboot flash vbmeta_system vbmeta_system.img

fastboot flash dtbo dtbo.img
fastboot flash cache cache.img

fastboot flash userdata userdata.img
fastboot flash recovery recovery.img

fastboot erase secdata

fastboot flash cust cust.img
fastboot flash boot boot.img

So this is all from this guide on how to flash stock firmware via fastboot commands. Feel free to drop your queries in the comments section below!

FAQ: Other Methods to Flash Stock Firmware on Android

Apart from the Fastboot Commands method that we have just concluded, there do exist a couple of other methods through which you could flash the stock firmware on your Android device. These are the ADB Sideload and OEM-specific Tool methods. In the ADB Sideload method, you don’t even need to unlock the device’s bootloader and in most cases, it wouldn’t even wipe your data.

flash stock firmware via fastboot commands
ADB Sideload via Stock Recovery

However, this method is known to work mostly in the stock environment, such as when you are installing OTA updates on your stock device. Though you could still try out this method in bootloop or bricked device, the only prerequisite is that you should boot your device to Stock Recovery or TWRP Recovery. So if you are willing to try out this method, then you may check out our comprehensive tutorial on How to Use ADB Sideload in Android [Stock and TWRP Recovery].

flash stock firmware via fastboot commands
ADB Sideload via TWRP

The other method to flash firmware is via OEM-specific Flash Tool. These include the likes of Mi Flash Tool for Xiaomi devices or Android Flash Tool for Pixel devices. All the tools, irrespective of the device you own, would require your device’s bootloader to be unlocked. This is because these tools will be flashing the partition files to their slots via Fastboot Commands (something that we did manually in the Fastboot Commands method).

flash stock firmware via fastboot commands

And whenever there is flashing takes place, you need to have an unlocked bootloader. Moreover, these tools could also be used in custom development. So you could use these tools to fix bootloop or soft-bricked devices. To try it out, you could refer to our guides corresponding to your devices:

Share: