The Custom Droid

Android Tutorials, Tips and Tricks

How to Create Fastboot-flashable Factory Image for Any OnePlus Phone

How to Create a Fastboot-flashable Factory Image for Any OnePlus Phone

Factory images (or Fastboot ROMs) can be used to unbrick and to restore stock OxygenOS software on OnePlus devices.


In this tutorial, I will show you how to create a fastboot-flashable factory image for any OnePlus phone and how to flash it. This will work for all OnePlus phones including the latest OnePlus 8T, OnePlus Nord, OnePlus 8/8 Pro, OnePlus 7T/7T Pro, OnePlus 7/7 Pro, and OnePlus 6/6T.


OnePlus phones are considered among the most flexible Android devices when it comes to software modding and development, due to the fact the bootloader is easily unlockable. So you can easily install a custom recovery, flash custom ROMs, and root your OnePlus phone using Magisk.

Well, that’s easy and fun, but it also means that these phones (like any other Android device) are susceptible to software failures if you accidentally flash a wrong ROM/mod, use a wrong command, or just be too much liberal with root permissions.

A majority of these things can often land your OnePlus phone into a bootloop or a bricked state. Moreover, even faulty OTA updates can sometimes be a cause.

So, what do you do then to recover your phone from such an ordeal?

OnePlus Provides OTA Packages of OxygenOS ROM

OnePlus does provide OTA ZIP packages of the latest OxygenOS updates for all its phones. And you can find these on the official support page.

OnePlus provided Recovery-flashable ROMs for its Phones

However, these could only be flashed via the in-built update engine (Local Upgrade option) or through a custom recovery such as TWRP. Further, the OEM also pulled the plug by removing the option to manually sideload OTA updates from the stock OxygenOS recovery, specifically on more recent phones.

So, there’s no way to recover your phone and restore the stock OxygenOS software in case you can’t access the Local Upgrade option and moreover, do not have a custom recovery installed.

The Need for Factory Images

Google already publishes factory images for all Pixel phones to give users the liberty to flash their phones and fix such issues. Something similar is also done by Xiaomi and was done by Essential too in the past.

Google publishes factory images for its Pixel devices

Sadly, OnePlus doesn’t offer any other form of firmware files or a flash tool that users could use in such situations. I am sure users would admire OnePlus if they facilitate the users with an official way to restore stock OxygenOS software on OnePlus phones, allowing them to fix such issues on their own.

A factory image not only aids in software restoration, but is also very useful when you’re dealing with things like Magisk root, TWRP, and other software modifications. Users could also cherry-pick and use the device partition images from a factory image to restore individual partitions. For example:

  • You can extract and flash the stock boot image (boot.img) if you’ve flashed a wrong boot image, and also if you wish to unroot your phone.
  • You can extract and flash the system image (system.img) if you accidentally bricked your phone by modifying the /system partition directly.

As it happens, I was able to find a way that could allow you to fix issues like boot loops and even help you unbrick the phone as long as you can boot it into Fastboot Mode. The said way is to create a factory image for your OnePlus phone and flash it through fastboot. And that’s what is tutorial is all about. So let’s begin!

How to Create Fastboot Flashable Factory Image for Any OnePlus Phone

So, how can you create a factory image for my OnePlus phone? Do you need to be a developer and compile it from the source code? – No, not at all.

The process of generating a factory image is quite easy and does not require any expertise. The idea is to download the OxygenOS OTA package for your OnePlus phone, extract the payload.bin file from within it to get the individual partition images, and finally flash these partition images to your phone using fastboot commands.

I will take you through the complete process in a step-by-step manner and all you’ll require is:

  • Your OnePlus phone
  • A compatible USB-C cable
  • A Windows, macOS, or Linux computer
  • And, some of your time

So without any further delay, follow the instructions below to create a factory image for your OnePlus phone.

Step 1: Download the OxygenOS OTA Package

The first step is to download the OxygenOS OTA package (.zip file) for your OnePlus phone. To do this, visit the official database on your computer and select your OnePlus phone from the list. Then click the ‘Download’ button to download the OTA package to your computer.

Download the OxygenOS OTA for your OnePlus Phone

It is worth noting that the official database isn’t updated that often. In that case, or if you’re looking for a particular OxygenOS version, you could go through the unofficial OTA repository for your device by clicking the link below.

Step 2: Extract the OTA to Get the Payload.bin File

The second step is to extract the contents of the OTA ZIP package on your computer to get the payload.bin file. To do this, you will need an archive utility like 7-Zip installed on your computer.

Once you have that, open the folder where the OTA package was downloaded, right-click it on it, select “7-Zip”, and then “Extract here”.

Extract the OTA package to get the payload.bin file

The extracted files should include the Payload BIN file (See the figure below for reference) that you’ll be needing in the steps that follow.

Payload.bin file extracted from the OTA package

Step 3: Install and Set Up Python on Your Computer

Since Payload Dumper is a Python-based program, you’d first need to install and set up Python on your Windows, macOS, or Linux computer. To do this:

  • On Windows: Download the latest Python executable installer from this page and launch the installer by double-clicking the executable (.exe) file. Select the ‘Add Python to the PATH’ option and click ‘Install Now’.
    Install Python on your Windows computer
  • On macOS: Download the macOS 64-bit installer from here and launch the downloaded package (.pkg) file. Follow the on-screen instructions shown in the installer window.
  • On Linux: You could install Python on your Linux machine by compiling it from the source. I suggest you take a look at the instructions in this guide published by

Once you have installed Python, restart your computer to ensure that Python is added to the PATH variable.

Step 4: Download the Payload Dumper Tool

Now that you have Python installed, the next step is to download the Payload Dumper tool by developer vm03. Unlike some alternatives, this tool works across multiple platforms including Windows, macOS, Linux, and even Android itself.

You can click the direct link below to download the latest Payloader Dumper tool and save it on your computer.

After downloading, extract the ZIP file to get the ‘payload_dumper-master’ folder. This folder should contain the tool’s Python scripts, a readme file, a requirements TXT file, and the output folder where the Payload.bin file is extracted to.

Download the Payload Dumper Tool on the computer

I suggest you rename the ‘payload_dumper-master’ folder to just ‘payload_dumper’. Also, move the folder to the root of the C:\ drive on your Windows computer, or to the ‘Documents’ directory on your macOS/Linux computer for easier access.

Step 5: Open the Command-line inside the ‘payload_dumper’ Folder

With the Payload Dumper tool set up on your computer, you have to launch the command-line inside the working directory (i.e. the ‘payload_dumper’ folder).

  • If you’re operating on a Windows computer, open the ‘payload_dumper’ folder. Hold the SHIFT key and right-click on an empty spot inside the folder, then select the ‘Open PowerShell window here’ option.
    Launch PowerShell inside 'payload_dumper' folder
  • If you’re using a macOS/Linux PC, launch the Terminal and change its directory to the ‘payload_dumper’ folder using the ‘cd’ command. For example: If the ‘payload_dumper’ folder is located in the ‘Documents’ directory, then the command should look like: cd Documents/payload_dumper

Step 6: Extract the Payload.bin File

To begin, enter the following command in the PowerShell/Terminal to ensure that requirements for the Payload Dumper tool are met:

python -m pip install -r requirements.txt

The tool utilizes protobuf, six, and bsdiff4 dependencies to work properly. The above command will automatically install these required modules on your computer if they are not already installed.

Install Payload Dumper Dependencies


  • Windows users will need to precede the commands with a dot and a backslash “.\” when using PowerShell. On the other hand, Linux/macOS users will need to precede these commands with a dot and a forward slash “./“in the Terminal.
  • Additionally, macOS users may also need to use “python3” instead of “python” in the syntax.

With the dependencies out of the way, it’s time to create the factory image by extracting the individual device partitions from the Payload.bin file. So, copy the payload.bin file you extracted during step #2 and paste it inside the ‘payload_dumper’ folder.

Copy the payload.bin file inside 'payload_dumper' folder

Now use the following command to extract the Payload BIN file:

python payload.bin

Since full OTA packages are quite large in size, often 2-3 GB, it could take some time for the extraction to finish. The progress for the same will be shown in the PowerShell/Terminal.

Payload Dumper extracting the device partition images from payload.bin

After the extraction finishes, you will find the individual device partition images inside the “output” folder.

Payload.bin extracted successfully

This is essentially what a factory image looks like, except that the ones officially provided by OEMs also include some sort of flashing script. However, since that isn’t the case here, you’d need to manually flash the firmware image files to the respective partitions of your OnePlus phone. Let’s see how.

Step 7: Boot your OnePlus Phone into Fastboot Mode

Flashing your device’s partitions is done via Fastboot commands. The Fastboot tool can only interact with the phone while it’s in “Fastboot Mode”, or also sometimes referred to as the “Bootloader Mode”.

So, you must boot your OnePlus phone into Fastboot Mode first. To do this, first power off your phone completely. Then hold the Volume Up, Volume Down, and Power keys together until your phone enters Fastboot Mode.

  • Note: On previous OnePlus phones, you’d need to press the Volume Down and Power keys to get into Fastboot Mode

Boot your OnePlus phone into Fastboot Mode

Once your phone is in Fastboot Mode, connect it to your computer using a compatible USB-C cable.

Step 8: Flash the Factory Image using Fastboot Commands

Now, it’s finally time to flash the factory image you just created to your OnePlus phone. You’ll need to have the Android SDK platform-tools (and more specifically ‘Fastboot’) to be installed on your computer to do this. If you haven’t done it yet, you could follow our tutorial.

Next, open the command-line inside the ‘platform-tools’ folder, where Fastboot, ADB, and other tool binaries are present. This is very similar to what we did in the case of the ‘payload_dumper’ folder in step #5 above.

Now verify that your computer can recognize and communicate with your OnePlus phone over the bootloader interface. This could be done by using the following command:

fastboot devices

The command should return your phone’s unique identifier string. In case it doesn’t and you’re working on a Windows PC, you may need to install the OnePlus USB drivers.

Use the 'fastboot devices' command to verify the connection

Here are a few key things to keep in mind before you start flashing:

  • Some partitions may exist on newer OnePlus phones, but not on the older ones, or vice-versa. For example, OnePlus re-introduced the /recovery partition on the OnePlus 7T, OnePlus 8, and newer phones. This partition does not exist on the older OnePlus 7 and the OnePlus 6 series.
  • You would only need to use the commands for the partitions that apply to your particular model. To make this easier, I would suggest you observe the list of partition images extracted from the OTA file of your phone. If the image file exists, then the corresponding partition also exists on your phone.

Here’s the complete list of commands you’ll need to manually flash the factory image (partition images) on your OnePlus phone:

fastboot flash boot boot.img
fastboot flash dtbo dtbo.img
fastboot flash modem modem.img
fastboot flash recovery recovery.img
fastboot --disable-verity flash vbmeta vbmeta.img
fastboot --disable-verity flash vbmeta_system vbmeta_system.img
fastboot reboot fastboot
fastboot flash abl abl.img
fastboot flash aop aop.img
fastboot flash bluetooth bluetooth.img
fastboot flash cmnlib cmnlib.img
fastboot flash cmnlib64 cmnlib64.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 logo logo.img
fastboot flash mdm_oem_stanvbk mdm_oem_stanvbk.img
fastboot flash multiimgoem multiimgoem.img
fastboot flash odm odm.img
fastboot flash opproduct opproduct.img
fastboot flash qupfw qupfw.img
fastboot flash spunvm spunvm.img
fastboot flash storsec storsec.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 system system.img
fastboot flash vendor vendor.img
fastboot flash product product.img

Although not required, you might also want to format the /data partition, which is nothing but a factory data reset in essence. For this, use:

fastboot -w

Once you have flashed the factory image, reboot your phone into the OS by using the following command.

fastboot reboot

Wrapping Up

So by now, you know how significant a factory image is when it comes to unbricking and restoring the stock firmware on OnePlus phones, or any other Android OEM device for that matter. You have also learned how to create a factory image for any OnePlus device, as well as how to manually flash it via fastboot commands.

Yes, I know that it may all seem a bit extensive at first. But once you get a hold of the process, and have everything already set up on your computer, it will take a lot less time when you perform this again.

Tip: You can also extract the Payload BIN file on your Android device itself.

An Alternative Way

XDA developer mauronofrio, who is well-known for his work on TWRP recovery for a variety of OEM Android devices, also provides self-created fastboot ROMs for devices like OnePlus 8, OnePlus 8 Pro, OnePlus Nord, and more. I appreciate his effort and generosity for helping fellow users of the community.

If you feel that creating a factory image for your OnePlus phone is a daunting task, you might want to use the ones provided by him. As a bonus, they also include a flashing script that will further automate the whole flashing process.

It took a lot of time and effort to come up with this tutorial. I believe it would prove useful for users who’d like to do things on their own and learn something new in the process. If you have any feedback or questions, feel free to let me know.

About the Author

Founder and Editor-in-Chief

Dhananjay has more than 11 years of experience in Android software customization and development, and has spent the past 10 years writing about it. He spends most of his prime time reading, learning and writing about Android and other open-source projects. He is also a community-taught web developer. Apart from that, he loves mountain biking and playing video games on his PlayStation.

Comments 11 Comments

  1. After the command “python -m pip install -r requirements.txt” it installed protobuf version 4.21.x, which would not work with the next command (python payload.bin), to extract the partitions and folders. I searched the internet and found I had to downgrade protobuf again to 3.20.x, using the command “pip install protobuf==3.20.*”. Then the payload dumper worked nicely 🙂

    1. Thank you for the information! It will be very useful for other users.

      I also suggest using Payload Dumper Go now instead of the original Python-based script. It’s way fast and also extremely easy to use.

  2. I’m getting this error on OP6: FAILED (remote: Flashing is not allowed in Lock State)
    finished. total time: 1.628s

    Any suggestions, been over 10 days now trying to re-boot phone so i can attempt to recover photos/videos etc.

    1. Rob, flashing any device partitions requires an unlocked bootloader. The error you’re seeing reflects the same.

      Did you OnePlus 6 land into a bootloop? If so, then how?

  3. “fastboot flash abl abl.img” after flashing this it showing me “FAILED (remote: Flashing is not allowed for Critical Partitions)”. no other files after that is succesfully flashed.

    1. Milind, those are the critical partitions. Back in the day, if I remember correctly, with the Pixel 2/XL, the critical partitions needed to be unlocked along with the bootloader.

      While this doesn’t apply for newer Pixel devices anymore, I am not sure if OnePlus has their own implementation for the same, thus blocking the critical partitions to be flashed.

      I do have a few things that might help debug this:
      1) Have you extracted the partition image files from an OxygenOS version that’s either equal or newer than the one that was installed on your device?
      2) While in Fastboot Mode, try issuing the fastboot flashing unlock_critical command and see if it allows you to manually unlock the critical partitions.

  4. Followed your tutorial on the Flashed all the image files that were extracted a few were missing from your list.

    Vendor.img and system.img had this message “Invalid sparse file format at header magic”.

    Also xbl_lp5 and xbl_config_lp5 “FAILED (remote: ‘No such file or directory’)”. With these errors it seems a full wipe has not occurred as i cannot relock the boot loader without the “your device is corrupt” message.

    Started phone up seems to be working normally though. I will continue to investigate but if you have any other pointers that would be great.

    1. Justin, the “Invalid sparse file format at header magic” message is completely normal and can be safely ignored.

      The commands that I listed in this article are rather more generic across different OnePlus smartphones. Some devices/models may include even more partitions, while others may include less.

      You might want to check the flash script included in OnePlus 8/8 Pro fastboot ROMs. These ROMs were precompiled by a renowned developer over at XDA. That should give you some hint on which partitions to flash, and which not.

      Another quick alternative to ensure that everything returns to factory state is to flash decrypted OxygenOS firmware on OnePlus 8T via MSM Tool. While this tool’s main usage is for unbricking bricked devices, it can be used for restoring the stock firmware as well. I have done it a few times myself on the OnePlus 8.

  5. Hands down the most helpful and easily followed guide I’ve ever had the pleasure of reading!! Thank you so much

    1. Glad you found it to be helpful. Thank you for your appreciation.

Leave a Reply

Comments are moderated, and published only if they are relevant to the topic and add value in a constructive way. If you disagree with something, please be polite and respectful. We suggest you read our comment policy before commenting.