Skip to content

Commit

Permalink
less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
bongbui321 committed Apr 19, 2024
1 parent 754f134 commit 0886608
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 41 deletions.
9 changes: 7 additions & 2 deletions edl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ class main(metaclass=LogBase):
version = 2
else:
version = conninfo["data"].version

# For less verbose option when using multiple commands
verbose = True
if mode == "sahara":
cmd = conninfo["cmd"]
if cmd == cmd_t.SAHARA_HELLO_REQ:
Expand Down Expand Up @@ -343,6 +346,8 @@ class main(metaclass=LogBase):
print("Error on sahara handshake, resetting.")
self.sahara.cmd_reset()
sys.exit(1)
else:
verbose = False
if mode == "error":
print("Connection detected, quiting.")
sys.exit(1)
Expand Down Expand Up @@ -378,8 +383,8 @@ class main(metaclass=LogBase):
options = parse_option(args)
if cmd != "":
self.info("Trying to connect to firehose loader ...")
if fh.connect(sahara):
fh.handle_firehose(cmd, options)
if fh.connect(sahara, verbose=verbose):
fh.handle_firehose(cmd, options, verbose)


if __name__ == '__main__':
Expand Down
64 changes: 33 additions & 31 deletions edlclient/Library/firehose.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def getluns(self, argument):
luns = [0]
return luns

def configure(self, lvl):
def configure(self, lvl, verbose=True):
if self.cfg.SECTOR_SIZE_IN_BYTES == 0:
if self.cfg.MemoryName.lower() == "emmc":
self.cfg.SECTOR_SIZE_IN_BYTES = 512
Expand Down Expand Up @@ -894,7 +894,7 @@ def configure(self, lvl):
self.cfg.MemoryName = rsp.data["MemoryName"]
except TypeError:
self.warning("!DEBUG! rsp.data: '%s'" % (rsp.data,))
return self.configure(lvl + 1)
return self.configure(lvl + 1, verbose)
if "MaxPayloadSizeFromTargetInBytes" in rsp.data:
self.cfg.MaxPayloadSizeFromTargetInBytes = int(rsp.data["MaxPayloadSizeFromTargetInBytes"])
if "MaxPayloadSizeToTargetInBytes" in rsp.data:
Expand All @@ -904,12 +904,12 @@ def configure(self, lvl):
rsp.data["MaxPayloadSizeToTargetInBytesSupported"])
if "TargetName" in rsp.data:
self.cfg.TargetName = rsp.data["TargetName"]
return self.configure(lvl + 1)
return self.configure(lvl + 1, verbose)
for line in rsp.error:
if "Not support configure MemoryName eMMC" in line:
self.info("eMMC is not supported by the firehose loader. Trying UFS instead.")
self.cfg.MemoryName = "UFS"
return self.configure(lvl + 1)
return self.configure(lvl + 1, verbose)
elif "Only nop and sig tag can be" in line:
self.info("Xiaomi EDL Auth detected.")
try:
Expand Down Expand Up @@ -950,7 +950,7 @@ def configure(self, lvl):
else:
self.cfg.Version = "Unknown"
if lvl == 0:
return self.configure(lvl + 1)
return self.configure(lvl + 1, verbose)
else:
self.error(f"Error:{rsp}")
sys.exit()
Expand All @@ -971,13 +971,13 @@ def configure(self, lvl):
field["MemoryName"] = "eMMC"
if "MaxXMLSizeInBytes" not in field:
field["MaxXMLSizeInBytes"] = "4096"
self.warning("Couldn't detect MaxPayloadSizeFromTargetinBytes")
verbose and self.warning("Couldn't detect MaxPayloadSizeFromTargetinBytes")
if "MaxPayloadSizeToTargetInBytes" not in field:
field["MaxPayloadSizeToTargetInBytes"] = "1038576"
if "MaxPayloadSizeToTargetInBytesSupported" not in field:
field["MaxPayloadSizeToTargetInBytesSupported"] = "1038576"
if field["MemoryName"].lower() != self.cfg.MemoryName.lower():
self.warning("Memory type was set as " + self.cfg.MemoryName + " but device reported it is " +
verbose and self.warning("Memory type was set as " + self.cfg.MemoryName + " but device reported it is " +
field["MemoryName"] + " instead.")
self.cfg.MemoryName = field["MemoryName"]
if "MaxPayloadSizeToTargetInBytes" in field:
Expand All @@ -997,51 +997,51 @@ def configure(self, lvl):
self.cfg.MaxPayloadSizeFromTargetInBytes = int(field["MaxPayloadSizeFromTargetInBytes"])
else:
self.cfg.MaxPayloadSizeFromTargetInBytes = self.cfg.MaxXMLSizeInBytes
self.warning("Couldn't detect MaxPayloadSizeFromTargetinBytes")
verbose and self.warning("Couldn't detect MaxPayloadSizeFromTargetinBytes")
if "TargetName" in field:
self.cfg.TargetName = field["TargetName"]
if "MSM" not in self.cfg.TargetName:
self.cfg.TargetName = "MSM" + self.cfg.TargetName
else:
self.cfg.TargetName = "Unknown"
self.warning("Couldn't detect TargetName")
verbose and self.warning("Couldn't detect TargetName")
if "Version" in field:
self.cfg.Version = field["Version"]
else:
self.cfg.Version = 0
self.warning("Couldn't detect Version")
self.info(f"TargetName={self.cfg.TargetName}")
self.info(f"MemoryName={self.cfg.MemoryName}")
self.info(f"Version={self.cfg.Version}")
self.info("Trying to read first storage sector...")
verbose and self.warning("Couldn't detect Version")
verbose and self.info(f"TargetName={self.cfg.TargetName}")
verbose and self.info(f"MemoryName={self.cfg.MemoryName}")
verbose and self.info(f"Version={self.cfg.Version}")
verbose and self.info("Trying to read first storage sector...")
rsp = self.cmd_read_buffer(0, 1, 1, False)
self.info("Running configure...")
if not rsp.resp and self.args["--memory"] is None:
for line in rsp.error:
if "Failed to set the IO options" in line:
self.warning(
verbose and self.warning(
"Memory type eMMC doesn't seem to match (Failed to init). Trying to use NAND instead.")
self.cfg.MemoryName = "nand"
return self.configure(0)
return self.configure(0, verbose)
elif "Failed to open the SDCC Device" in line:
self.warning(
verbose and self.warning(
"Memory type eMMC doesn't seem to match (Failed to init). Trying to use UFS instead.")
self.cfg.MemoryName = "UFS"
return self.configure(0)
return self.configure(0, verbose)
elif "Failed to initialize (open whole lun) UFS Device slot" in line:
self.warning(
verbose and self.warning(
"Memory type UFS doesn't seem to match (Failed to init). Trying to use eMMC instead.")
self.cfg.MemoryName = "eMMC"
return self.configure(0)
return self.configure(0, verbose)
elif "Attribute \'SECTOR_SIZE_IN_BYTES\'=4096 must be equal to disk sector size 512" in line \
or "different from device sector size (512)" in line:
self.cfg.SECTOR_SIZE_IN_BYTES = 512
return self.configure(0)
return self.configure(0, verbose)
elif "Attribute \'SECTOR_SIZE_IN_BYTES\'=512 must be equal to disk sector size 4096" in line \
or "different from device sector size (4096)" in line:
self.cfg.SECTOR_SIZE_IN_BYTES = 4096
return self.configure(0)
self.parse_storage()
return self.configure(0, verbose)
self.parse_storage(verbose)
for function in self.supported_functions:
if function == "checkntfeature":
if type(self.devicemodel)==list:
Expand Down Expand Up @@ -1113,7 +1113,7 @@ def get_supported_functions(self):
'ufs', 'emmc', 'power', 'benchmark', 'read', 'getstorageinfo',
'getcrc16digest', 'getsha256digest', 'erase', 'peek', 'poke', 'nop', 'xml']

def connect(self):
def connect(self, verbose=False):
v = b'-1'
if platform.system() == 'Windows':
self.cdc.timeout = 50
Expand Down Expand Up @@ -1143,7 +1143,7 @@ def connect(self):
if len(info) > 0:
supfunc = False
for line in info:
self.info(line)
verbose and self.info(line)
if "chip serial num" in line.lower():
try:
serial = line.split("0x")[1][:-1]
Expand Down Expand Up @@ -1217,8 +1217,8 @@ def connect(self):

return self.supported_functions

def parse_storage(self):
storageinfo = self.cmd_getstorageinfo()
def parse_storage(self, verbose=True):
storageinfo = self.cmd_getstorageinfo(verbose)
if storageinfo is None or storageinfo.resp and len(storageinfo.data) == 0:
return False
info = storageinfo.data
Expand Down Expand Up @@ -1255,7 +1255,7 @@ def cmd_writeimei(self, imei):
self.error("writeIMEI failed.")
return False

def cmd_getstorageinfo(self):
def cmd_getstorageinfo(self, verbose=True):
data = "<?xml version=\"1.0\" ?><data><getstorageinfo physical_partition_number=\"0\"/></data>"
val = self.xmlsend(data)
if val.data == '' and val.log == '' and val.resp:
Expand All @@ -1278,9 +1278,9 @@ def cmd_getstorageinfo(self):
except Exception as err: # pylint: disable=broad-except
self.debug(str(err))
continue
self.info("Storage report:")
verbose and self.info("Storage report:")
for sii in si:
self.info(f"{sii}:{si[sii]}")
verbose and self.info(f"{sii}:{si[sii]}")
if "total_blocks" in si:
self.cfg.total_blocks = si["total_blocks"]
if "num_physical" in si:
Expand Down Expand Up @@ -1311,6 +1311,8 @@ def cmd_getstorageinfo(self):
return None

def cmd_setactiveslot(self, slot: str):
self.info(f"Setting slot {slot} to active...")

# flags: 0x3a for inactive and 0x6f for active boot partition
def set_flags(flags, active, is_boot):
new_flags = flags
Expand Down Expand Up @@ -1361,7 +1363,7 @@ def cmd_patch_multiple(lun, start_sector, byte_offset, patch_data):
write_size = len(patch_data)
for i in range(0, write_size, size_each_patch):
pdata_subset = int(unpack(unpack_fmt, patch_data[offset:offset+size_each_patch])[0])
self.cmd_patch( lun, start_sector, byte_offset + offset, pdata_subset, size_each_patch, True)
self.cmd_patch( lun, start_sector, byte_offset + offset, pdata_subset, size_each_patch, False)
offset += size_each_patch
return True

Expand Down
16 changes: 8 additions & 8 deletions edlclient/Library/firehose_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def __init__(self, arguments, cdc, sahara, loglevel, printer):
luns=self.getluns(arguments), args=arguments)
self.connected = False

def connect(self, sahara):
self.firehose.connect()
def connect(self, sahara, verbose=True):
self.firehose.connect(verbose=verbose)
if "hwid" in dir(sahara):
if sahara.hwid is not None:
hwid = (sahara.hwid >> 32) & 0xFFFFFF
Expand All @@ -94,29 +94,29 @@ def connect(self, sahara):
self.cfg.MemoryName = "eMMC"
elif type == memory_type.ufs:
self.cfg.MemoryName = "UFS"
self.warning("Based on the chipset, we assume " +
verbose and self.warning("Based on the chipset, we assume " +
self.cfg.MemoryName + " as default memory type..., if it fails, try using " +
"--memory\" with \"UFS\",\"NAND\" or \"spinor\" instead !")
elif socid in sochw:
self.target_name = sochw[socid].split(",")[0]
# We assume ufs is fine (hopefully), set it as default
if self.cfg.MemoryName == "":
if "ufs" in self.firehose.supported_functions:
self.warning(
verbose and self.warning(
"No --memory option set, we assume \"UFS\" as default ..., if it fails, try using \"--memory\" " +
"with \"UFS\",\"NAND\" or \"spinor\" instead !")
self.cfg.MemoryName = "UFS"
else:
self.warning(
verbose and self.warning(
"No --memory option set, we assume \"eMMC\" as default ..., if it fails, try using \"--memory\" " +
"with \"UFS\",\"NAND\" or \"spinor\" instead !")
self.cfg.MemoryName = "eMMC"
if self.firehose.configure(0):
if self.firehose.configure(0, verbose):
funcs = "Supported functions:\n-----------------\n"
for function in self.firehose.supported_functions:
funcs += function + ","
funcs = funcs[:-1]
self.info(funcs)
verbose and self.info(funcs)
self.target_name = self.firehose.cfg.TargetName
self.connected = True
try:
Expand Down Expand Up @@ -190,7 +190,7 @@ def get_storage_info(self):
return info
return False

def handle_firehose(self, cmd, options):
def handle_firehose(self, cmd, options, verbose=True):
if cmd == "gpt":
luns = self.getluns(options)
directory = options["<directory>"]
Expand Down

0 comments on commit 0886608

Please sign in to comment.