Skip to content

Instantly share code, notes, and snippets.

@danielml3
Created August 26, 2023 11:00
Show Gist options
  • Save danielml3/2f670c75966869dd1b0be6d8d011053a to your computer and use it in GitHub Desktop.
Save danielml3/2f670c75966869dd1b0be6d8d011053a to your computer and use it in GitHub Desktop.
Python script for generating a flash_all.sh shell script from a decompressed OFP to flash all A/B & super partitions
import xml.etree.ElementTree as ET
import os
tree = ET.parse('ProFile.xml')
fastboot_cmds = ["fastboot set_active a"]
def AppendFastbootCmd(partition, image):
cmd = "fastboot flash %s %s" % (partition, image)
fastboot_cmds.append(cmd)
def GenerateProgramListCommands(programlist):
for program in programlist:
if program.tag == "program":
filename = program.attrib["filename"]
label = program.attrib["label"]
is_ab = label.endswith("_a") or label.endswith("_b")
if is_ab and filename != "":
AppendFastbootCmd(label, filename)
def GenerateSuperCommands(nvList):
nvidList = []
for child in nvList:
if child.tag == "nv":
nvidList.append(child.attrib["id"])
print("%s|%s" % (child.attrib["id"],child.attrib["text"]))
while True:
nvid = input("Write the nvid of your desired region: ")
if nvid in nvidList:
break
else:
print("Invalid nvid\n")
for child in nvList:
if child.tag == "nv" and child.attrib["id"] == nvid:
print("Using: %s|%s" % (child.attrib["id"],child.attrib["text"]))
selectedSuper = child
superIndex = 0
while "super%s" % superIndex in selectedSuper.attrib:
superN = selectedSuper.attrib["super%s" % superIndex]
if superN != "":
AppendFastbootCmd("super", superN)
superIndex = superIndex + 1
def GenerateShellScript():
script_file_path = "flash_all.sh"
if os.path.exists(script_file_path):
os.remove(script_file_path)
script_file = open(script_file_path, "a")
script_file.write("#!/bin/bash\n")
for step in fastboot_cmds:
script_file.write("%s\n" % step)
script_file.close()
print("Generated the script at %s" % script_file_path)
programList = None
nvList = None
for child in tree.getroot():
if child.tag == "ProgramList":
programList = child
elif child.tag == "NVList":
nvList = child
GenerateProgramListCommands(programList)
GenerateSuperCommands(nvList)
GenerateShellScript()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment