diff --git a/README.md b/README.md index fc10cf9..94c4dcd 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,9 @@ sudo usermod -a -G dialout $USER sudo cp Setup/Linux/*.rules /etc/udev/rules.d sudo udevadm control -R ``` -Make sure to reboot after adding the user to dialout/plugdev. +Make sure to reboot after adding the user to dialout/plugdev. If the device +has a vendor interface 0xFF (like LG), make sure to add "blacklist qcaux" to +the "/etc/modprobe.d/blacklist.conf". --------------------------------------------------------------------------------------------------------------- diff --git a/mtkclient/Library/Port.py b/mtkclient/Library/Port.py index aa884f4..c003856 100755 --- a/mtkclient/Library/Port.py +++ b/mtkclient/Library/Port.py @@ -132,7 +132,7 @@ class Port(metaclass=LogBase): data = [data] for val in data: self.usbwrite(val) - tmp = self.usbread(len(val)) + tmp = self.usbread(len(val), maxtimeout=0) # print(hexlify(tmp)) if val != tmp: return False diff --git a/mtkclient/Library/kamakiri.py b/mtkclient/Library/kamakiri.py index a0ae728..2785db3 100755 --- a/mtkclient/Library/kamakiri.py +++ b/mtkclient/Library/kamakiri.py @@ -71,8 +71,11 @@ class Kamakiri(metaclass=LogBase): def kamakiri2(self, addr): self.udev = self.mtk.port.cdc.device - self.udev.ctrl_transfer(0x21, 0x20, 0, 0, self.linecode + array.array('B', pack(" 0: + msize = min(bytestoread,pagesize) + data = self.mtk.daloader.peek(addr=addr+pos, length=msize) + if wf is not None: + wf.write(data) else: - self.info( - f"Data read from {hex(addr)}, length: {hex(length)}:\n{hexlify(data).decode('utf-8')}\n") + retval.extend(data) + pg.show_progress("Dump:",bytesread//pagesize,length//pagesize) + pos+=len(data) + bytesread+=len(data) + bytestoread-=len(data) + if filename is not None: + wf.close() + self.info(f"Successfully wrote data from {hex(addr)}, length {hex(length)} to {filename}") + else: + self.info( + f"Data read from {hex(addr)}, length: {hex(length)}:\n{hexlify(retval).decode('utf-8')}\n") def da_poke(self, addr: int, data: str, filename: str): if filename is not None: diff --git a/mtkclient/Library/mtk_dalegacy.py b/mtkclient/Library/mtk_dalegacy.py index e405197..17a824e 100755 --- a/mtkclient/Library/mtk_dalegacy.py +++ b/mtkclient/Library/mtk_dalegacy.py @@ -865,7 +865,7 @@ class DALegacy(metaclass=LogBase): skipdl = 0 self.usbwrite(pack(">I", skipdl)) elif hwcode == 0x6582: - newcombo = 0 + newcombo = 1 self.usbwrite(pack(">I", newcombo)) time.sleep(0.350) buffer = self.usbread(toread) @@ -1049,14 +1049,16 @@ class DALegacy(metaclass=LogBase): self.daconfig.flashsize = self.sdc.m_sdmmc_ua_size elif self.daconfig.flashtype == "nor": self.daconfig.flashsize = self.nor.m_nor_flash_size - self.info("Reconnecting to preloader") - self.set_usb_cmd() - self.mtk.port.close(reset=False) - time.sleep(2) - while not self.mtk.port.cdc.connect(): - time.sleep(0.5) self.info("Connected to preloader") - self.check_usb_cmd() + speed = self.check_usb_cmd() + if speed[0] == 0: # 1 = USB High Speed, 2= USB Ultra high speed + self.info("Reconnecting to preloader") + self.set_usb_cmd() + self.mtk.port.close(reset=False) + time.sleep(2) + while not self.mtk.port.cdc.connect(): + time.sleep(0.5) + self.info("Connected to preloader") return True return False @@ -1112,14 +1114,13 @@ class DALegacy(metaclass=LogBase): if self.usbwrite(self.Cmd.USB_CHECK_STATUS): # 72 res = self.usbread(1) if res == self.Rsp.ACK: - res = self.usbread(1) - if len(res) > 0: - return True - return False + speed = self.usbread(1) + return speed + return None def set_usb_cmd(self): if self.usbwrite(self.Cmd.USB_SETUP_PORT): # 72 - if self.usbwrite(b"\x01"): + if self.usbwrite(b"\x01"): # USB_HIGH_SPEED res = self.usbread(1) if len(res) > 0: if res[0] is self.Rsp.ACK[0]: diff --git a/mtkclient/Library/mtk_preloader.py b/mtkclient/Library/mtk_preloader.py index 47614b3..722f6e0 100755 --- a/mtkclient/Library/mtk_preloader.py +++ b/mtkclient/Library/mtk_preloader.py @@ -9,6 +9,15 @@ from struct import unpack, pack from binascii import hexlify from mtkclient.Library.utils import LogBase, logsetup from mtkclient.Library.error import ErrorHandler +import time + +USBDL_BIT_EN = 0x00000001 # 1: download bit enabled +USBDL_BROM = 0x00000002 # 0: usbdl by brom; 1: usbdl by bootloader +USBDL_TIMEOUT_MASK = 0x0000FFFC # 14-bit timeout: 0x0000~0x3FFE: second; 0x3FFFF: no timeout +USBDL_TIMEOUT_MAX = (USBDL_TIMEOUT_MASK >> 2) # maximum timeout indicates no timeout +USBDL_MAGIC = 0x444C0000 # Brom will check this magic number +MISC_LOCK_KEY_MAGIC = 0xAD98 + def calc_xflash_checksum(data): checksum = 0 @@ -109,9 +118,9 @@ class Preloader(metaclass=LogBase): def __init__(self, mtk, loglevel=logging.INFO): self.mtk = mtk self.__logger = logsetup(self, self.__logger, loglevel, mtk.config.gui) - #self.info = self.__logger.info - #self.debug = self.__logger.debug - #self.error = self.__logger.error + # self.info = self.__logger.info + # self.debug = self.__logger.debug + # self.error = self.__logger.error self.eh = ErrorHandler() self.gcpu = None self.config = mtk.config @@ -130,7 +139,7 @@ class Preloader(metaclass=LogBase): os.remove(".state") except: pass - readsocid=self.config.readsocid + readsocid = self.config.readsocid skipwdt = self.config.skipwdt if not display: @@ -198,7 +207,7 @@ class Preloader(metaclass=LogBase): self.info("\tHW subcode:\t\t" + hex(self.config.hwsubcode)) self.info("\tHW Ver:\t\t\t" + hex(self.config.hwver)) self.info("\tSW Ver:\t\t\t" + hex(self.config.swver)) - meid=self.get_meid() + meid = self.get_meid() if meid is not None: self.config.set_meid(meid) if self.display: @@ -259,6 +268,33 @@ class Preloader(metaclass=LogBase): value += b"\x00" self.write32(addr + i, unpack("I", mode)) - self.mtk.port.echo(pack(">I", address)) - self.mtk.port.echo(pack(">I", length)) - status = self.mtk.port.usbread(2) - try: - status = unpack("I", mode)) + self.mtk.port.echo(pack(">I", address)) + self.mtk.port.echo(pack(">I", length)) status = self.mtk.port.usbread(2) try: status = unpack("HHHH", res) def get_meid(self): @@ -552,7 +588,7 @@ class Preloader(metaclass=LogBase): self.mtk.config.meid = self.usbread(length) status = unpack("