Last active
August 7, 2017 13:26
-
-
Save thurask/0d441964eae65a9714e0dfcdcc0894f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import os | |
import platform | |
import subprocess | |
import sys | |
import time | |
def disclaimer(dirty=False): | |
if dirty: | |
print("THIS IS A DIRTY FLASH BUT BACK UP ANYWAY") | |
else: | |
print("THIS IS AN AUTOLOADER AND WILL WIPE YOUR STUFF") | |
print("YOU HAVE BEEN WARNED") | |
goforit = input("Would you like to continue? Y/N: ") | |
if goforit.lower() != "y": | |
print("Exiting, goodbye.") | |
raise SystemExit | |
else: | |
print("Please reboot into fastboot by holding power and volume down for 30s") | |
print("Waiting 5 seconds...") | |
time.sleep(5) | |
def fbexe(): | |
return os.path.join(os.getcwd(), "host", platform.system().lower(), "bin", "fastboot") | |
def fbrun(args, check=False): | |
spargs = [fbexe()] + args | |
if check: | |
return subprocess.check_output(spargs, stderr=subprocess.STDOUT, universal_newlines=True) | |
else: | |
subprocess.call(spargs) | |
def fbparse(getvar): | |
return getvar.split("\n")[0].split(":")[1].strip() | |
def fuse(img): | |
return os.path.join(os.getcwd(), "img", img) | |
def fastboot_read(): | |
device = fbparse(fbrun(["getvar", "device"], True)) # bbb100 | |
variant = fbparse(fbrun(["getvar", "variant"], True)) # usa | |
hlossigtag = fbparse(fbrun(["getvar", "hlos-sig-tag"], True)) # sprint | |
return device, variant, hlossigtag | |
def prep_filenames(device, variant, subvariant): | |
fnames = collections.OrderedDict() | |
if device == "bbb100": | |
devcfg = "devcfg_cn.mbn" if subvariant == "china" else "devcfg.mbn" | |
modem = "NON-HLOS-china.bin" if variant in ("dscn", "cn") else "NON-HLOS-{0}.bin".format(variant) | |
oem = "oem_common.img" if subvariant == "" else "oem_{0}.img".format(subvariant) | |
fnames["tz"] = fuse("tz.mbn") | |
fnames["devcfg"] = fuse(devcfg) | |
fnames["rpm"] = fuse("rpm.mbn") | |
fnames["sbl1"] = fuse("sbl1_signed.mbn") | |
fnames["aboot"] = fuse("emmc_appsboot.mbn") | |
fnames["bootsig"] = fuse("boot.img.sig") | |
fnames["recoverysig"] = fuse("recovery.img.sig") | |
fnames["boot"] = fuse("boot.img") | |
fnames["recovery"] = fuse("recovery.img") | |
fnames["cache"] = fuse("cache.img") | |
fnames["userdata"] = fuse("userdata.img") | |
fnames["modem"] = fuse(modem) | |
fnames["dsp"] = fuse("adspso.bin") | |
fnames["system"] = fuse("system.img") | |
fnames["oem"] = fuse(oem) | |
return fnames | |
def run_fastboot(fnames, dirty=False): | |
if not dirty: | |
print("FASTBOOT OEM SECUREWIPE") | |
fbrun(["oem", "securewipe"]) | |
time.sleep(5) | |
if dirty: | |
del fnames["userdata"] | |
for key, value in fnames.items(): | |
print("FASTBOOT FLASH {0}".format(key.upper())) | |
fbrun(["flash", key, value]) | |
print("REBOOTING") | |
fbrun(["reboot"]) | |
def goodbye(): | |
smeg = input("Press Enter to exit") | |
if smeg or not smeg: | |
raise SystemExit | |
def main(): | |
dirty = False | |
if len(sys.argv) > 1 and sys.argv[1].lower() == "dirty": | |
dirty = True | |
disclaimer(dirty) | |
device, variant, subvariant = fastboot_read() | |
fnames = prep_filenames(device, variant, subvariant) | |
run_fastboot(fnames, dirty) | |
goodbye() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment