Skip to content

Commit

Permalink
Additional fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bkerler committed Jan 8, 2024
1 parent 9c7db52 commit a041a40
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
14 changes: 7 additions & 7 deletions mtkclient/Library/DA/daconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ def __init__(self, mtk, loader=None, preloader=None, loglevel=logging.INFO):
loaders.append(os.path.join(root, file))
loaders = sorted(loaders)[::-1]
for loader in loaders:
self.parse_da_loader(loader)
self.parse_da_loader(loader, self.dasetup)
else:
if not os.path.exists(loader):
self.warning("Couldn't open " + loader)
else:
self.info("Using custom loader: " + loader)
self.parse_da_loader(loader)
self.parse_da_loader(loader, self.dasetup)

def m_extract_emi(self, data):
idx = data.find(b"\x4D\x4D\x4D\x01\x38\x00\x00\x00")
Expand Down Expand Up @@ -211,7 +211,7 @@ def extract_emi(self, preloader=None) -> bytearray:
self.emiver = 0
self.emi = None

def parse_da_loader(self, loader):
def parse_da_loader(self, loader:str, dasetup:dict):
try:
with open(loader, 'rb') as bootldr:
# data = bootldr.read()
Expand All @@ -229,11 +229,11 @@ def parse_da_loader(self, loader):
da.v6 = v6
# if da.hw_code == 0x8127 and "5.1824" not in loader:
# continue
if da.hw_code not in self.dasetup:
if da.hw_code not in dasetup:
if da.hw_code != 0:
self.dasetup[da.hw_code] = [da]
dasetup[da.hw_code] = [da]
else:
for ldr in self.dasetup[da.hw_code]:
for ldr in dasetup[da.hw_code]:
found = False
if da.hw_version == ldr.hw_version:
if da.sw_version == ldr.sw_version:
Expand All @@ -242,7 +242,7 @@ def parse_da_loader(self, loader):
break
if not found:
if da.hw_code != 0:
self.dasetup[da.hw_code].append(da)
dasetup[da.hw_code].append(da)
return True
except Exception as e:
self.error("Couldn't open loader: " + loader + ". Reason: " + str(e))
Expand Down
2 changes: 1 addition & 1 deletion mtkclient/Library/DA/legacy/dalegacy_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ def readflash(self, addr: int, length: int, filename: str, parttype=None, displa
self.mtk.daloader.progress.show_progress("Read", length, length, display)
rq.put(None)
worker.join(60)
return b""
return True
else:
buffer = bytearray()
bytestoread = length
Expand Down
5 changes: 5 additions & 0 deletions mtkclient/Library/DA/xflash/extension/xflash.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def patch_da2(self, da2):
self.info("Patching da2 ...")
# open("da2.bin","wb").write(da2)
da2patched = bytearray(da2)
# Patch huawei security, rma state
pos = 0
huawei = find_binary(da2, b"\x01\x2B\x03\xD1\x01\x23", pos)
if huawei is not None:
da2patched[huawei:huawei + 4] = b"\x00\x00\x00\x00"
# Patch oppo security
oppo = 0
pos = 0
Expand Down
51 changes: 29 additions & 22 deletions mtkclient/Library/DA/xflash/xflash_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,15 @@ def formatflash(self, addr, length, storage=None,

def get_da_version(self):
data = self.send_devctrl(self.Cmd.GET_DA_VERSION)
status = self.status()
if status == 0:
self.info(f"DA-VERSION : {data.decode('utf-8')}")
return data
else:
self.error(f"Error on getting chip id: {self.eh.status(status)}")
return None
if data != b"":
status = self.status()
if status == 0:
self.info(f"DA-VERSION : {data.decode('utf-8')}")
return data
else:
self.error(f"Error on getting chip id: {self.eh.status(status)}")
return None
return None

def get_chip_id(self):
class Chipid:
Expand All @@ -437,19 +439,20 @@ class Chipid:

chipid = Chipid
data = self.send_devctrl(self.Cmd.GET_CHIP_ID)
chipid.hw_code, chipid.hw_sub_code, chipid.hw_version, chipid.sw_version, chipid.chip_evolution = unpack(
if data != b"":
chipid.hw_code, chipid.hw_sub_code, chipid.hw_version, chipid.sw_version, chipid.chip_evolution = unpack(
"<HHHHH",
data[:(5 * 2)])
status = self.status()
if status == 0:
self.info("HW-CODE : 0x%X" % chipid.hw_code)
self.info("HWSUB-CODE : 0x%X" % chipid.hw_sub_code)
self.info("HW-VERSION : 0x%X" % chipid.hw_version)
self.info("SW-VERSION : 0x%X" % chipid.sw_version)
self.info("CHIP-EVOLUTION : 0x%X" % chipid.chip_evolution)
return chipid
else:
self.error(f"Error on getting chip id: {self.eh.status(status)}")
status = self.status()
if status == 0:
self.info("HW-CODE : 0x%X" % chipid.hw_code)
self.info("HWSUB-CODE : 0x%X" % chipid.hw_sub_code)
self.info("HW-VERSION : 0x%X" % chipid.hw_version)
self.info("SW-VERSION : 0x%X" % chipid.sw_version)
self.info("CHIP-EVOLUTION : 0x%X" % chipid.chip_evolution)
return chipid
else:
self.error(f"Error on getting chip id: {self.eh.status(status)}")
return None

def get_ram_info(self):
Expand Down Expand Up @@ -783,8 +786,10 @@ def cmd_read_data(self, addr, size, storage=DaStorage.MTK_DA_STORAGE_EMMC,
def readflash(self, addr, length, filename, parttype=None, display=True) -> bytes:
global rq
partinfo = self.getstorage(parttype, length)
if not partinfo:
if not partinfo and not filename:
return b""
elif not partinfo:
return False
self.mtk.daloader.progress.clear()
storage, parttype, length = partinfo
self.get_packet_length()
Expand Down Expand Up @@ -823,10 +828,10 @@ def readflash(self, addr, length, filename, parttype=None, display=True) -> byte
self.mtk.daloader.progress.show_progress("Read", total, total, display)
rq.put(None)
worker.join(60)
return b""
return True
rq.put(None)
worker.join(60)
return b"ACK"
return True
else:
buffer = bytearray()
while length > 0:
Expand All @@ -841,7 +846,9 @@ def readflash(self, addr, length, filename, parttype=None, display=True) -> byte
if display:
self.mtk.daloader.progress.show_progress("Read", total, total, display)
return buffer
return b""
if not filename:
return b""
return False

class ShutDownModes:
NORMAL = 0
Expand Down

0 comments on commit a041a40

Please sign in to comment.