[Huawei P20 Guides, News, & Discussion] sorinbotirla:
Hello,

I am currently building a python script to generate codes for Huawei P20 (EML-L29) bootloader.

So far, I have to deal with these things in order to make it work:

- the code is a 16 digit number

- the last tried code is stored in a txt file to resume if anything crashes and it goes up incrementally.

- the code usually starts with 15XXXXXXXXXXXXXX

- at 5 failed attempts, the phone will reboot to normal mode. To prevent this, at every 4th failed attempt, It runs "fastboot reboot-bootloader" command to reset the counter.

- each attempt takes 4.5 seconds to complete. No other command will be taken while waiting for response from the phone.

- It tries about 10000 codes per day (which is too slow).

Is there any method to prevent the wait time for every attempt in order to make it run faster?

Here is the code I have used:

import os, sys, time

start = 1500000000000000
bootloaderGeneratedCode = "bootloaderGeneratedCode.txt"
bootloaderFoundCode = "bootloaderFoundCode.txt"
currentCode = start
lastCode = currentCode
tries = 1

def checkTxtFiles():
if not os.path.isfile(bootloaderGeneratedCode):
with open(bootloaderGeneratedCode, "w+") as bgc:
bgc.seek(0)
bgc.write(str(start))
if not os.path.isfile(bootloaderFoundCode):
with open(bootloaderFoundCode, "w+") as bgc:
bgc.seek(0)
bgc.write(str(""))

def checkFastbootDevices():
res = str(os.popen("fastboot devices").read()).replace("List of devices attached", "").replace("fastboot", "").replace("device", "").replace(" ", "").replace("\n", "").replace("\r", "").replace("\t", "")
# print(res)
if "" == res:
return False
else:
if "not found" in str(res) or "error" in str(res):
return False
else:
return True
def checkAdbDevices():
res = str(os.popen("adb devices").read()).replace("List of devices attached", "").replace("fastboot", "").replace("device", "").replace(" ", "").replace("\n", "").replace("\r", "").replace("\t", "")# print(str(res))
if "" == res:
return False
else:
if "not found" in str(res) or "error" in str(res):
return False
else:
return True

def rebootBootloader():
if checkFastbootDevices():
res = os.popen("fastboot reboot-bootloader").read()
else:
res = os.popen("adb reboot-bootloader").read()
print(str(res))

def tryCode(code):
global bootloaderFoundCode
global tries
res = os.popen("fastboot oem unlock "+str(code)).read()
if "too many links" in str(res):
tries = 1
if "FAILED" in str(res):
#code failed
pass
elif "OKAY" in str(res) or "SUCCESS" in str(res):
#code succeeded
with open(bootloaderFoundCode, "w+") as bgc:
bgc.seek(0)
bgc.write(str(code))
print("FOUND BOOTLOADER CODE: "+str(code))
sys.exit(0)
#print(str(res))

def getLastCode():
with open(bootloaderGeneratedCode, "r") as f:
f.seek(0)
return f.read()

checkTxtFiles()

with open(bootloaderFoundCode, "r") as bgc:
bgc.seek(0)
code = bgc.read()
if 0 < len(code):
print("FOUND BOOTLOADER CODE: "+str(code))
sys.exit(0)
else:
while True:
while checkFastbootDevices():
#has fastboot devices
print("Found fastboot device")
if tries <= 4:
#can try oem unlock
currentCode = int(getLastCode())
print("Trying "+str(tries)+" of 4 with code "+str(currentCode))
tryCode(currentCode)
currentCode += 1
with open(bootloaderGeneratedCode, "w") as f:
f.seek(0)
f.write(str(currentCode))
tries += 1
else:
#need to reboot-bootloader
tries = 1
rebootBootloader()

if not checkFastbootDevices():
#no fastboot device detected
print("Waiting for device..")
while not checkFastbootDevices():
if checkAdbDevices():
print("ADB Device found. Will reboot to bootloader");
rebootBootloader()
tries = 1
else:
time.sleep(1)
tries = 1