Skip to content

Commit

Permalink
Update flash.py
Browse files Browse the repository at this point in the history
Now it informs you if the flash was unsuccessful because of a damaged usb port or cables.
  • Loading branch information
italorecife committed Feb 10, 2022
1 parent 1963f99 commit 2301469
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
os.system("")
cpcount = 0
invalidsuper = False

fatalerror = ""
def byebye():
wait = input("Press Enter to continue...")
exit(0)
Expand Down Expand Up @@ -230,20 +230,23 @@ def checkhashfile(path, wfilename, checksums):
os.remove(os.path.join(path, wfilename))

def flashpartition(partition, file):
global fatalerror
print(f"FLASHING: {partition}")
try:
flashreturn = str(subprocess.check_output(["fastboot", "flash", partition, file], stderr=subprocess.STDOUT))
except subprocess.CalledProcessError as e:
flashreturn = str(e.output)
if "FAILED (remote: Flashing is not allowed for Critical Partitions" in flashreturn:
print("FLASH FAIL: Changing this partition is not allowed for security reasons")
print("FLASH FAIL: Changing this partition is not allowed for security reasons (Critical Partition)")
elif "unknown partition" in flashreturn:
print("FLASH FAIL: Unknown partition")
elif "FAILED" in flashreturn:
print("FLASH FAILED!")
else:
print("FLASH SUCCESS!")

if "read failed (Too many links)" in flashreturn:
fatalerror = "Use another USB port or another cable, and try flash again!"

def decryptitem(item, pagesize):
sha256sum=""
md5sum=""
Expand Down Expand Up @@ -272,7 +275,7 @@ def decryptitem(item, pagesize):
return wfilename, start, length, rlength,[sha256sum,md5sum],decryptsize

def main():
global cpcount, invalidsuper
global cpcount, invalidsuper, fatalerror
print("Oppo/Realme Flash .OFP File on Bootloader | 1.0 (c) 2022 | Italo Almeida (@SirCDA) - GPL-3.0 License\n")
print("Usage: Put the .ofp file in the same folder as the program,\nthen put your device in mode fastboot to start flash.")
print("\nNote: if your device was not recognized in fastboot\nmode by the computer, try to install the adb drivers.")
Expand Down Expand Up @@ -501,7 +504,10 @@ def main():
except subprocess.CalledProcessError as e:
print("EXTRACT ERROR: Error on super's. OFP super partiton might be broken!")
shutil.rmtree(path)
print("\nDone. ofp file flashed with success!")
if fatalerror == "":
print("\nDone. ofp file flashed with success!")
else:
print(f"\nFATALERROR: {fatalerror}")
byebye()


Expand Down

0 comments on commit 2301469

Please sign in to comment.