Home > Unbrick

Create rawprogram0.xml and patch0.xml files | Unbrick Qualcomm Devices

In this guide, we will show you the steps to create rawprogram0.xml and patch0.xml files for Qualcomm devices that could be used for unbricking purposes. There literally exists a plentitude of tweaks that you could try out onto your smartphones. The likes of flashing custom ROMs, installing custom recoveries, or gaining administrative rights by rooting it via Magisk are just some of the noteworthy ones. However, there’s no denying the fact that flashing these binaries could bring in a few uninvited risks as well.

In most instances, it’s just a softbrick or bootloop which could easily be recited by flashing the stock firmware via Fastboot Commands. But sometimes, the issue might be much more concerning and your device could end up in a hard-brick state. Fortunately, if you own a device with the Qualcomm chipset, then there’s a handy way out. You could boot your device to the Emergency Download Mode and then flash the MBN firmware file via the Qualcomm Flash Image Loader (QFIL) Tool.

As soon as you do so, your device will end up in Fastboot Mode and from then onwards, you could flash the firmware via device-specific tools or using Fastboot Commands. However, the MBN file isn’t the only requirement for the QFIL Tool. It also requires you to have the rawprogam0 and patch0 XML files. But more often than not, you wouldn’t find these files inside the stock firmware. So what could be done? Well, let’s create both these files on our own! So without further ado, let’s check out the steps to create rawprogram0.xml and patch0.xml files and unbrick Qualcomm devices.

Create rawprogram0.xml and patch0.xml files and Unbrick Qualcomm Devices

Create rawprogram0.xml patch0.xml files unbrick qualcomm

The below instructions are listed under separate sections for ease of understanding. Make sure to follow in the exact same sequence as mentioned. 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 (well, it’s already bricked, but still) and data by performing the below steps.

STEP 1: Install Python

First and foremost, you will have to install Python on your PC. As for this guide, we require version 2.x. So download it from the official site [direct link] and proceed with on-screen instructions to install it. However, if you have the latest 3.x version installed, then do not uninstall it, rather install version 2.x in a separate directory.

Create rawprogram0.xml patch0.xml files unbrick qualcomm

We require a lower build of Python because the tool that we are about to use isn’t compatible with the latest version. However, if for some reason, you don’t want to install the older build of Python, then you could also make some changes to the tool and make it compatible with the latest Python. To do so, please check out the FAQ section at the end of this guide.

STEP 2: Download Qualcomm GPT Tool

Next up, download the Qualcomm GPT Tool [download link] and extract it inside the same folder where you have installed Python. So both the files of the GPT Tool (GPTAnalyzer and PTool) should be inside the Python folder itself.

Create rawprogram0.xml patch0.xml files unbrick qualcomm

STEP 3: Get GPT.Bin from Stock Firmware

Next up, download the stock firmware for your device and extract it to any convenient location. Then copy the GPT.bin file from the extracted firmware folder and transfer it to the Python folder. The GPT file might be named either primaryGPT.bin, gpt_backup0.bin, gpt_main0.bin, or gpt_both0.bin.

Create rawprogram0.xml patch0.xml files unbrick qualcomm

In some instances, the firmware might have the “backup0, main0, and both0” all these three GPT files. In that case, you should choose the ‘main’ file. Likewise, there could be numerous instances of the GPT main file. So you should choose the one that has 0 in its name. In simpler terms, it is recommended to choose the gpt_main0.bin file.

STEP 4: Create rawprogram0.xml and patch0.xml Files

  1. Head over to Python’s installation directory. Make sure that the gpt_main0.bin, GPTAnalyzer, and PTool files are present there as well.
    Create rawprogram0.xml patch0.xml files unbrick qualcomm
  2. Now go to this folder’s address bar, type in CMD, and hit Enter. This will launch the Command Prompt.
  3. Type in the below command in the CMD window to extract the partition.xml file from the gpt_main0.bin file.
    GPTAnalyzer.py gpt.bin > partition.xml

    Create rawprogram0.xml patch0.xml files unbrick qualcomm

  4. Finally, use the below command to create rawprogram0.xml and patch0.xml files using the partition XML file:
    ptool.py -x partition.xml

    Create rawprogram0.xml patch0.xml files unbrick qualcomm

  5. Both these files will be now created and placed in Python’s installation directory itself.Create rawprogram0.xml patch0.xml files unbrick qualcomm
  6. You may now use these files, along with the other firmware files, and flash them via the QFIL Tool to unbrick your device. [Read More: QFIL Unbrick Guide: How to Flash Firmware via QFIL Tool].
    Create rawprogram0.xml patch0.xml files unbrick qualcomm

So with this, we round off the guide on how you could create the rawprogram0.xml and patch0.xml files and then use them to unbrick your Qualcomm device. If you have any queries concerning the aforementioned steps, do let us know in the comments. We will get back to you with a solution at the earliest.

FAQ: Make Qualcomm GPT Tool Compatible with Python 3.x

To make the Qualcomm GPT Tool compatible with the latest Python, you will have to rectify the below-mentioned errors. So start off by downloading an advanced text editor (like Notepad++) and keeping both the tool files GPTAnalyzer and PTool files nearby.

Create rawprogram0.xml patch0.xml files unbrick qualcomm

Then select the GPTAnalyzer file, right-click on it and select Show More Options. After that, choose Open With > Notepad++. Likewise, do the same for PTool. Once both the files are opened in Notepad++, you may proceed with the below instructions.

Fix Invalid Hexadecimal Literal 0xFFFFFFFFL Error in Python 3.x

To rectify this issue, you will have to remove L from the end of 0xFFFFFFFFL. It would be in line 55 of the GPTAnalyzer.py file.

Create rawprogram0.xml patch0.xml files unbrick qualcomm

Fix Missing parentheses in call to print. Did you mean Print (….)? Error in Python 3.x

To fix this issue, enclose all the Print commands under parenthesis (). This will take a lot of time as the change has to be done across both the GPTAnalyzer and PTool files.

Create rawprogram0.xml patch0.xml files unbrick qualcomm

Fix: Multiple Exception Types must be Paranthesized Error in Python 3.x

To resolve this error, add the ‘except’ values under brackets, and instead of a comma, use the ‘as’ keyword. Taking an example from this GPTAnalyzer file, line 591 is:

except getopt.GetoptError, err:

So you will have to change it to:

except (getopt.GetoptError) as err:

Create rawprogram0.xml patch0.xml files unbrick qualcomm

Once you have made the changes and fixed all the aforementioned issues, use the Ctrl+S to save the changes. That’s it. The tool is now compatible with the latest Python build and you may use it without any issues.

Create rawprogram0.xml patch0.xml files unbrick qualcomm

So on that note, we round off the guide on how you could create the rawprogram0.xml and patch0.xml files and then use them to unbrick your Qualcomm device. Likewise, we also made you aware of the steps to make the tool compatible with the latest Python version. You may now drop in your queries regarding the tool conversion, QFIL usage, or the creation of raw program and XML files in the comments section below.

Share:
  • (ptool.py -x partition.xml), did not work.

  • good night

    in my case, in the last command

    (ptool.py -x partition.xml), did not work.

    it happens:

    C:\Python26>GPTAnalyzer.py gpt.bin > partition.xml

    C:\Python26>ptool.py -x partition.xml

    CWD: C:\Python26

    XMLFile= partition.xml
    OutputToCreate None
    PhysicalPartitionNumber 0
    verbose False

    Looking for partition.xml
    —————————————-
    Searching C:\Python26

    **Found partition.xml (40 bytes)
    Traceback (most recent call last):
    File “C:\Python26\ptool.py”, line 2197, in
    ParseXML(XMLFile) # parses XMLFile, discovers if GPT or MBR
    File “C:\Python26\ptool.py”, line 948, in ParseXML
    root = ET.parse( XMLFile )
    File “C:\Python26\lib\xml\etree\ElementTree.py”, line 862, in parse
    tree.parse(source, parser)
    File “C:\Python26\lib\xml\etree\ElementTree.py”, line 586, in parse
    parser.feed(date)
    File “C:\Python26\lib\xml\etree\ElementTree.py”, line 1245, in feed
    self._parser.Parse(date, 0)
    xml.parsers.expat.ExpatError: syntax error: line 1, column 0

    C:\Python26>

    and then the two files are not created

    What happened?

    need help

    thanks

  • I’m afraid it may not work anymore, the tool is not capable to parse the latest gpt_main0.bin from Xiaomi’s Mi 11 Lite (4G, courbet).

    Maybe the parser is capable of understanding a well formed XML file, but the analyzer produces bare one, malformed even (no closing tag).