From 501a23a7faa07ea5aaaec1b5dc402c542905e6bd Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Sat, 19 Oct 2024 16:09:04 +0200 Subject: [PATCH] Add slot detection, minor v6 fixes --- examples/vbmeta.img.empty | Bin 4096 -> 0 bytes mtkclient/Library/DA/daconfig.py | 33 ++++-- mtkclient/Library/DA/legacy/dalegacy_lib.py | 6 ++ mtkclient/Library/DA/mtk_da_handler.py | 84 ++++++++++++---- .../Library/DA/xflash/extension/xflash.py | 4 +- mtkclient/Library/DA/xml/extension/v6.py | 24 +++-- mtkclient/Library/DA/xml/xml_lib.py | 21 ++-- mtkclient/Library/utils.py | 2 + mtkclient/config/brom_config.py | 95 +++++++++++++++--- 9 files changed, 210 insertions(+), 59 deletions(-) delete mode 100644 examples/vbmeta.img.empty diff --git a/examples/vbmeta.img.empty b/examples/vbmeta.img.empty deleted file mode 100644 index 63a1a0e750f6a0fcc0a4f30a73d40c5daa745726..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4096 zcmZ<^b24CHU|W2UT{RRaQ diff --git a/mtkclient/Library/DA/daconfig.py b/mtkclient/Library/DA/daconfig.py index f1c9deb..c2b071f 100755 --- a/mtkclient/Library/DA/daconfig.py +++ b/mtkclient/Library/DA/daconfig.py @@ -96,15 +96,29 @@ class EntryRegion: class DA: - def __init__(self, data): + v6=False + loader=None + magic=0 + hw_code=0 + hw_sub_code=0 + hw_version=0 + sw_version=0 + pagesize=512 + entry_region_index=1 + entry_region_count=0 + region = [] + + def __init__(self, data, old_ldr:bool=False, v6:bool=False): self.loader = None + self.v6 = v6 sh = Structhelper(data) self.magic = sh.short() self.hw_code = sh.short() self.hw_sub_code = sh.short() self.hw_version = sh.short() - self.sw_version = sh.short() - self.reserved1 = sh.short() + if not old_ldr: + self.sw_version = sh.short() + self.reserved1 = sh.short() self.pagesize = sh.short() self.reserved3 = sh.short() self.entry_region_index = sh.short() @@ -113,6 +127,7 @@ class DA: for _ in range(self.entry_region_count): entry_tmp = EntryRegion(sh.bytes(20)) self.region.append(entry_tmp) + self.old_ldr = old_ldr def setfilename(self, loaderfilename: str): self.loader = loaderfilename @@ -222,11 +237,17 @@ class DAconfig(metaclass=LogBase): hdr = bootldr.read(0x68) count_da = unpack("0: self.ack_value(0) resp = self.get_response() if "OK" not in resp: @@ -470,9 +471,10 @@ class DAXML(metaclass=LogBase): if "OK" not in resp: self.error(f"Error on writing stage2 at pos {hex(pos)}") return False - byteswritten += tmplen + pos += tmplen if display: - self.mtk.daloader.progress.show_progress("Written", byteswritten, length, display) + self.mtk.daloader.progress.show_progress("Written", pos, length, display) + bytestowrite-=packet_length if raw: self.ack() cmd, result = self.get_command_result() @@ -597,8 +599,8 @@ class DAXML(metaclass=LogBase): self.info("Stage 1 successfully loaded.") da2 = self.daconfig.da2 da2offset = self.daconfig.da_loader.region[2].m_start_addr - if not self.mtk.daloader.patch: - if self.carbonara is not None: + if not self.mtk.daloader.patch and not self.mtk.config.stock: + if self.carbonara is not None and self.mtk.config.target_config["sbc"]: loaded = self.boot_to(da2offset, da2) if loaded: self.patch = True @@ -798,8 +800,9 @@ class DAXML(metaclass=LogBase): return None def change_usb_speed(self): - return self.send_command(self.Cmd.cmd_can_higher_usb_speed()) - + resp = self.send_command(self.Cmd.cmd_can_higher_usb_speed()) + if not resp: + return False def read_partition_table(self) -> tuple: self.send_command(self.Cmd.cmd_read_partition_table(), noack=True) diff --git a/mtkclient/Library/utils.py b/mtkclient/Library/utils.py index 2f1612c..21de14e 100755 --- a/mtkclient/Library/utils.py +++ b/mtkclient/Library/utils.py @@ -275,6 +275,8 @@ class Structhelper: def bytes(self, rlen=1): dat = self.data[self.pos:self.pos + rlen] + if dat==b"": + return b"" self.pos += rlen if rlen == 1: return dat[0] diff --git a/mtkclient/config/brom_config.py b/mtkclient/config/brom_config.py index 38929e1..857e7c0 100755 --- a/mtkclient/config/brom_config.py +++ b/mtkclient/config/brom_config.py @@ -5,6 +5,10 @@ class DAmodes: class Efuse: + efuses = [] + internal_fuses = [] + external_fuses = [] + def __init__(self, base, hwcode): if hwcode in [0x6570, 0x6580, 0x321, 0x335]: self.efuses = [base + 0x20, base + 0x30, base + 0x38, base + 0x40, base + 0x44, @@ -222,13 +226,43 @@ class Efuse: class Chipconfig: + var1 = None + watchdog = None + uart = None + brom_payload_addr = None + da_payload_addr = None + pl_payload_addr = None + cqdma_base = None + ap_dma_mem = None + sej_base = None + dxcc_base = None + name = "" + description = "" + dacode = 0 + blacklist = None + blacklist_count = None + send_ptr = None + ctrl_buffer = None + cmd_handler = None + brom_register_access = None + meid_addr = None + socid_addr = None + prov_addr = None + gcpu_base = None + dacode = None + damode = None + loader = None + misc_lock = None + efuse_addr = None + has64bit = False + def __init__(self, var1=None, watchdog=None, uart=None, brom_payload_addr=None, da_payload_addr=None, pl_payload_addr=None, cqdma_base=None, sej_base=None, dxcc_base=None, gcpu_base=None, ap_dma_mem=None, name="", description="", dacode=None, meid_addr=None, socid_addr=None, blacklist=(), blacklist_count=None, send_ptr=None, ctrl_buffer=(), cmd_handler=None, brom_register_access=None, damode=DAmodes.LEGACY, loader=None, prov_addr=None, misc_lock=None, - efuse_addr=None): + efuse_addr=None, has64bit=False): self.var1 = var1 self.watchdog = watchdog self.uart = uart @@ -257,6 +291,7 @@ class Chipconfig: self.loader = loader self.misc_lock = misc_lock self.efuse_addr = efuse_addr + self.has64bit = has64bit # Credits to cyrozap and Chaosmaster for some values """ @@ -539,8 +574,8 @@ hwconfig = { ap_dma_mem=0xC100119C, # blacklist damode=DAmodes.LEGACY, - dacode=0x6572, - name="MT6575/77"), + dacode=0x6575, + name="MT6575/MT6577/MT8317"), 0x6577: Chipconfig( # var1 watchdog=0xC0000000, uart=0xC1009000, @@ -1412,10 +1447,12 @@ hwconfig = { # brom_register_access=(0xeba4, 0xec5c), meid_addr=0x1008EC, socid_addr=0x100934, + efuse_addr=0x11EE0000, # prov_addr=0x1066C0, damode=DAmodes.XML, dacode=0x907, name="MT6983", + has64bit=True, description="Dimensity 9000/9000+" # loader="mt6983_payload.bin" ), @@ -1468,6 +1505,7 @@ hwconfig = { # brom_register_access=(0xeba4, 0xec5c), meid_addr=0x1008EC, socid_addr=0x100934, + efuse_addr=0x11F10000, # prov_addr=0x1066C0, damode=DAmodes.XML, dacode=0x1172, @@ -1475,6 +1513,33 @@ hwconfig = { description="Dimensity 8200" # loader="mt6893_payload.bin" ), + 0x1203: Chipconfig( + var1=0xA, + watchdog=0x1c007000, + uart=0x11002000, + brom_payload_addr=0x100A00, + da_payload_addr=0x201000, + pl_payload_addr=0x40200000, + gcpu_base=0x1000D000, + dxcc_base=0x10403000, + sej_base=0x1040E000, + # cqdma_base=0x10212000, + # ap_dma_mem=0x11300800 + 0x1a0, + # blacklist=[(0x102848, 0x0), (0x00106B60, 0x0)], + # blacklist_count=0x0000000A, + # send_ptr=(0x102888, 0xE79C), + # ctrl_buffer=0x00102A9C, + # cmd_handler=0x0000F569, + # brom_register_access=(0xeba4, 0xec5c), + # meid_addr=0x1008EC, + socid_addr=0x20E7090, + # prov_addr=0x1066C0, + damode=DAmodes.XML, + dacode=0x1203, + name="MT6897", + description="Dimensity 8300 Ultra" + # loader="mt6897_payload.bin" + ), # MT6789 Oppo Realme 10 / Gigaset GX4 0x1208: Chipconfig( var1=0xA, @@ -1500,7 +1565,7 @@ hwconfig = { efuse_addr=0x11C10000, damode=DAmodes.XML, dacode=0x1208, - name="MT6789", + name="MT6789/MT8781V", description="MTK Helio G99" # loader="mt6789_payload.bin" ), @@ -1511,10 +1576,10 @@ hwconfig = { brom_payload_addr=0x100A00, da_payload_addr=0x2001000, pl_payload_addr=0x40200000, - # gcpu_base=0x10050000, - dxcc_base=0x10210000, - # sej_base=0x1000a000, - cqdma_base=0x10212000, + gcpu_base=0x1000D000, + dxcc_base=0x1C807000, + sej_base=0x1C009000, + # cqdma_base=0x10212000, # ap_dma_mem=0x11300800 + 0x1a0, # blacklist=[(0x102d5c, 0x0)], # blacklist_count=0x0000000A, @@ -1525,23 +1590,24 @@ hwconfig = { # meid_addr=0x1008EC, # socid_addr=0x100934, # prov_addr=0x1066C0, - # efuse_addr=0x11C10000, + efuse_addr=0x11E30000, damode=DAmodes.XML, dacode=0x1229, + has64bit=True, name="MT6886", description="Dimensity 7200 Ultra" # loader="mt7200_payload.bin" ), 0x1296: Chipconfig( var1=0xA, - watchdog=0x10007000, - uart=0x11002000, + watchdog=0x1C007000, + uart=0x1C011000, brom_payload_addr=0x100A00, da_payload_addr=0x201000, pl_payload_addr=0x40200000, # gcpu_base=0x10050000, - dxcc_base=0x10210000, - sej_base=0x1000a000, + dxcc_base=0x1C807000, + sej_base=0x1C009000, # cqdma_base=0x10212000, # ap_dma_mem=0x11300800 + 0x1a0, # blacklist=[(0x102d5c, 0x0)], @@ -1553,9 +1619,10 @@ hwconfig = { meid_addr=0x1008EC, socid_addr=0x100934, # prov_addr=0x1066C0, - # efuse_addr=0x11C10000, + efuse_addr=0x11E80000, damode=DAmodes.XML, dacode=0x1296, + has64bit=True, name="MT6985", description="Dimensity 9200/9200+" # loader="mt6985_payload.bin"