mirror of
https://github.com/bkerler/mtkclient.git
synced 2024-11-14 19:25:05 -05:00
Fix reinit and rpmb issues
This commit is contained in:
parent
aa425b56db
commit
f338168cab
8 changed files with 29 additions and 16 deletions
|
@ -10,6 +10,7 @@ from mtkclient.Library.error import ErrorHandler
|
||||||
from mtkclient.Library.utils import Progress
|
from mtkclient.Library.utils import Progress
|
||||||
from mtkclient.config.brom_config import Efuse, DAmodes
|
from mtkclient.config.brom_config import Efuse, DAmodes
|
||||||
from mtkclient.Library.Filesystem.mtkdafs import MtkDaFS
|
from mtkclient.Library.Filesystem.mtkdafs import MtkDaFS
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from fuse import FUSE
|
from fuse import FUSE
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
|
@ -145,6 +145,7 @@ class DAloader(metaclass=LogBase):
|
||||||
self.config.meid = bytes.fromhex(config["meid"])
|
self.config.meid = bytes.fromhex(config["meid"])
|
||||||
if "socid" in config:
|
if "socid" in config:
|
||||||
self.config.socid = bytes.fromhex(config["socid"])
|
self.config.socid = bytes.fromhex(config["socid"])
|
||||||
|
self.config.hwparam = HwParam(self.mtk.config, self.config.meid.hex(), self.mtk.config.hwparam_path)
|
||||||
if config["flashmode"] == "LEGACY":
|
if config["flashmode"] == "LEGACY":
|
||||||
self.mtk.config.chipconfig.damode = DAmodes.LEGACY
|
self.mtk.config.chipconfig.damode = DAmodes.LEGACY
|
||||||
self.flashmode = DAmodes.LEGACY
|
self.flashmode = DAmodes.LEGACY
|
||||||
|
@ -155,8 +156,6 @@ class DAloader(metaclass=LogBase):
|
||||||
self.mtk.config.chipconfig.damode = DAmodes.XML
|
self.mtk.config.chipconfig.damode = DAmodes.XML
|
||||||
self.flashmode = DAmodes.XML
|
self.flashmode = DAmodes.XML
|
||||||
self.config.init_hwcode(self.config.hwcode)
|
self.config.init_hwcode(self.config.hwcode)
|
||||||
if self.config.meid is not None:
|
|
||||||
self.config.hwparam = HwParam(self.mtk.config, self.config.meid.hex(), self.mtk.config.hwparam_path)
|
|
||||||
if self.flashmode == DAmodes.XML:
|
if self.flashmode == DAmodes.XML:
|
||||||
self.da = DAXML(self.mtk, self.daconfig, self.loglevel)
|
self.da = DAXML(self.mtk, self.daconfig, self.loglevel)
|
||||||
self.daconfig.flashtype = config["flashtype"]
|
self.daconfig.flashtype = config["flashtype"]
|
||||||
|
|
|
@ -127,6 +127,7 @@ class XFlashExt(metaclass=LogBase):
|
||||||
ufshcd_queuecommand_ptr = daextdata.find(b"\x55\x55\x55\x55")
|
ufshcd_queuecommand_ptr = daextdata.find(b"\x55\x55\x55\x55")
|
||||||
ufshcd_get_free_tag_ptr = daextdata.find(b"\x66\x66\x66\x66")
|
ufshcd_get_free_tag_ptr = daextdata.find(b"\x66\x66\x66\x66")
|
||||||
ptr_g_ufs_hba_ptr = daextdata.find(b"\x77\x77\x77\x77")
|
ptr_g_ufs_hba_ptr = daextdata.find(b"\x77\x77\x77\x77")
|
||||||
|
efuse_addr_ptr = daextdata.find(b"\x88\x88\x88\x88")
|
||||||
|
|
||||||
if register_ptr != -1 and mmc_get_card_ptr != -1:
|
if register_ptr != -1 and mmc_get_card_ptr != -1:
|
||||||
if register_devctrl:
|
if register_devctrl:
|
||||||
|
@ -159,6 +160,8 @@ class XFlashExt(metaclass=LogBase):
|
||||||
if g_ufs_hba is None:
|
if g_ufs_hba is None:
|
||||||
g_ufs_hba = 0
|
g_ufs_hba = 0
|
||||||
|
|
||||||
|
efuse_addr = self.config.chipconfig.efuse_addr
|
||||||
|
|
||||||
# Patch the addr
|
# Patch the addr
|
||||||
daextdata[register_ptr:register_ptr + 4] = pack("<I", register_devctrl)
|
daextdata[register_ptr:register_ptr + 4] = pack("<I", register_devctrl)
|
||||||
daextdata[mmc_get_card_ptr:mmc_get_card_ptr + 4] = pack("<I", mmc_get_card)
|
daextdata[mmc_get_card_ptr:mmc_get_card_ptr + 4] = pack("<I", mmc_get_card)
|
||||||
|
@ -167,6 +170,7 @@ class XFlashExt(metaclass=LogBase):
|
||||||
daextdata[ufshcd_get_free_tag_ptr:ufshcd_get_free_tag_ptr + 4] = pack("<I", ufshcd_get_free_tag)
|
daextdata[ufshcd_get_free_tag_ptr:ufshcd_get_free_tag_ptr + 4] = pack("<I", ufshcd_get_free_tag)
|
||||||
daextdata[ufshcd_queuecommand_ptr:ufshcd_queuecommand_ptr + 4] = pack("<I", ufshcd_queuecommand)
|
daextdata[ufshcd_queuecommand_ptr:ufshcd_queuecommand_ptr + 4] = pack("<I", ufshcd_queuecommand)
|
||||||
daextdata[ptr_g_ufs_hba_ptr:ptr_g_ufs_hba_ptr + 4] = pack("<I", g_ufs_hba)
|
daextdata[ptr_g_ufs_hba_ptr:ptr_g_ufs_hba_ptr + 4] = pack("<I", g_ufs_hba)
|
||||||
|
daextdata[efuse_addr_ptr:efuse_addr_ptr+4]=pack("<I", efuse_addr)
|
||||||
|
|
||||||
# print(hexlify(daextdata).decode('utf-8'))
|
# print(hexlify(daextdata).decode('utf-8'))
|
||||||
# open("daext.bin","wb").write(daextdata)
|
# open("daext.bin","wb").write(daextdata)
|
||||||
|
@ -315,10 +319,10 @@ class XFlashExt(metaclass=LogBase):
|
||||||
def custom_read(self, addr, length):
|
def custom_read(self, addr, length):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
pos = 0
|
pos = 0
|
||||||
while pos<length:
|
while pos < length:
|
||||||
if self.cmd(XCmd.CUSTOM_READ):
|
if self.cmd(XCmd.CUSTOM_READ):
|
||||||
self.xsend(data=addr+pos, is64bit=True)
|
self.xsend(data=addr + pos, is64bit=True)
|
||||||
sz = min(length,0x10000)
|
sz = min(length, 0x10000)
|
||||||
self.xsend(sz)
|
self.xsend(sz)
|
||||||
tmp = self.xread()
|
tmp = self.xread()
|
||||||
data.extend(tmp)
|
data.extend(tmp)
|
||||||
|
@ -443,7 +447,8 @@ class XFlashExt(metaclass=LogBase):
|
||||||
if meid != b"\x00" * 16:
|
if meid != b"\x00" * 16:
|
||||||
# self.config.set_meid(meid)
|
# self.config.set_meid(meid)
|
||||||
self.info("Generating sej rpmbkey...")
|
self.info("Generating sej rpmbkey...")
|
||||||
rpmbkey = hwc.aes_hwcrypt(mode="rpmb", data=meid, btype="sej", otp=otp)
|
#rpmbkey = hwc.aes_hwcrypt(mode="rpmb", data=meid, btype="sej", otp=otp)
|
||||||
|
rpmbkey = hwc.aes_hwcrypt(btype="dxcc", mode="rpmb")
|
||||||
if rpmbkey is not None:
|
if rpmbkey is not None:
|
||||||
if self.cmd(XCmd.CUSTOM_SET_RPMB_KEY):
|
if self.cmd(XCmd.CUSTOM_SET_RPMB_KEY):
|
||||||
self.xsend(rpmbkey)
|
self.xsend(rpmbkey)
|
||||||
|
@ -461,6 +466,8 @@ class XFlashExt(metaclass=LogBase):
|
||||||
cmd = XCmd.CUSTOM_INIT_UFS_RPMB
|
cmd = XCmd.CUSTOM_INIT_UFS_RPMB
|
||||||
if self.cmd(cmd):
|
if self.cmd(cmd):
|
||||||
derivedrpmb = self.xread()
|
derivedrpmb = self.xread()
|
||||||
|
# rpmb_frame = self.xread()
|
||||||
|
# hash = self.xread()
|
||||||
if int.from_bytes(derivedrpmb[:4], 'little') != 0xff:
|
if int.from_bytes(derivedrpmb[:4], 'little') != 0xff:
|
||||||
status = self.status()
|
status = self.status()
|
||||||
if status == 0:
|
if status == 0:
|
||||||
|
|
|
@ -1245,9 +1245,6 @@ class DAXFlash(metaclass=LogBase):
|
||||||
if status == 0x0 and unpack("<I", ret)[0] == 0xA1A2A3A4:
|
if status == 0x0 and unpack("<I", ret)[0] == 0xA1A2A3A4:
|
||||||
self.info("DA Extensions successfully added")
|
self.info("DA Extensions successfully added")
|
||||||
self.daext = True
|
self.daext = True
|
||||||
self.config.hwparam = HwParam(self.mtk.config, self.mtk.config.meid,
|
|
||||||
self.mtk.config.hwparam_path)
|
|
||||||
self.config.hwparam.writesetting("hwcode", hex(self.config.hwcode))
|
|
||||||
if not self.daext:
|
if not self.daext:
|
||||||
self.warning("DA Extensions failed to enable")
|
self.warning("DA Extensions failed to enable")
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -135,6 +136,7 @@ class XmlFlashExt(metaclass=LogBase):
|
||||||
ufshcd_queuecommand_ptr = daextdata.find(b"\x55\x55\x55\x55")
|
ufshcd_queuecommand_ptr = daextdata.find(b"\x55\x55\x55\x55")
|
||||||
ufshcd_get_free_tag_ptr = daextdata.find(b"\x66\x66\x66\x66")
|
ufshcd_get_free_tag_ptr = daextdata.find(b"\x66\x66\x66\x66")
|
||||||
ptr_g_ufs_hba_ptr = daextdata.find(b"\x77\x77\x77\x77")
|
ptr_g_ufs_hba_ptr = daextdata.find(b"\x77\x77\x77\x77")
|
||||||
|
efuse_addr_ptr = daextdata.find(b"\x88\x88\x88\x88")
|
||||||
|
|
||||||
# register_xml_cmd("CMD:GET-SYS-PROPERTY", & a1, cmd_get_sys_property);
|
# register_xml_cmd("CMD:GET-SYS-PROPERTY", & a1, cmd_get_sys_property);
|
||||||
|
|
||||||
|
@ -181,6 +183,7 @@ class XmlFlashExt(metaclass=LogBase):
|
||||||
if mmc_rpmb_send_command is None:
|
if mmc_rpmb_send_command is None:
|
||||||
mmc_rpmb_send_command = 0
|
mmc_rpmb_send_command = 0
|
||||||
|
|
||||||
|
efuse_addr = self.config.chipconfig.efuse_addr
|
||||||
#########################################
|
#########################################
|
||||||
if register_ptr != -1:
|
if register_ptr != -1:
|
||||||
if register_xml_cmd:
|
if register_xml_cmd:
|
||||||
|
@ -196,6 +199,7 @@ class XmlFlashExt(metaclass=LogBase):
|
||||||
daextdata[ufshcd_get_free_tag_ptr:ufshcd_get_free_tag_ptr + 4] = pack("<I", ufshcd_get_free_tag)
|
daextdata[ufshcd_get_free_tag_ptr:ufshcd_get_free_tag_ptr + 4] = pack("<I", ufshcd_get_free_tag)
|
||||||
daextdata[ufshcd_queuecommand_ptr:ufshcd_queuecommand_ptr + 4] = pack("<I", ufshcd_queuecommand)
|
daextdata[ufshcd_queuecommand_ptr:ufshcd_queuecommand_ptr + 4] = pack("<I", ufshcd_queuecommand)
|
||||||
daextdata[ptr_g_ufs_hba_ptr:ptr_g_ufs_hba_ptr + 4] = pack("<I", g_ufs_hba)
|
daextdata[ptr_g_ufs_hba_ptr:ptr_g_ufs_hba_ptr + 4] = pack("<I", g_ufs_hba)
|
||||||
|
daextdata[efuse_addr_ptr:efuse_addr_ptr + 4] = pack("<I", efuse_addr)
|
||||||
|
|
||||||
# print(hexlify(daextdata).decode('utf-8'))
|
# print(hexlify(daextdata).decode('utf-8'))
|
||||||
# open("daext.bin","wb").write(daextdata)
|
# open("daext.bin","wb").write(daextdata)
|
||||||
|
@ -358,7 +362,8 @@ class XmlFlashExt(metaclass=LogBase):
|
||||||
if meid != b"\x00" * 16:
|
if meid != b"\x00" * 16:
|
||||||
# self.config.set_meid(meid)
|
# self.config.set_meid(meid)
|
||||||
self.info("Generating sej rpmbkey...")
|
self.info("Generating sej rpmbkey...")
|
||||||
rpmbkey = hwc.aes_hwcrypt(mode="rpmb", data=meid, btype="sej", otp=otp)
|
rpmbkey = hwc.aes_hwcrypt(btype="dxcc", mode="rpmb")
|
||||||
|
#rpmbkey = hwc.aes_hwcrypt(mode="rpmb", data=meid, btype="sej", otp=otp)
|
||||||
if rpmbkey is not None:
|
if rpmbkey is not None:
|
||||||
xmlcmd = self.xflash.Cmd.create_cmd("CUSTOMRPMBKEY")
|
xmlcmd = self.xflash.Cmd.create_cmd("CUSTOMRPMBKEY")
|
||||||
if self.xsend(xmlcmd):
|
if self.xsend(xmlcmd):
|
||||||
|
@ -375,9 +380,7 @@ class XmlFlashExt(metaclass=LogBase):
|
||||||
if rpmbkey == read_key:
|
if rpmbkey == read_key:
|
||||||
self.info("Setting rpmbkey: ok")
|
self.info("Setting rpmbkey: ok")
|
||||||
ufs = False
|
ufs = False
|
||||||
if self.xflash.emmc.rpmb_size != 0:
|
if self.xflash.emmc is None:
|
||||||
ufs = False
|
|
||||||
elif self.xflash.ufs.block_size != 0:
|
|
||||||
ufs = True
|
ufs = True
|
||||||
xmlcmd = self.xflash.Cmd.create_cmd("CUSTOMMMCINIT")
|
xmlcmd = self.xflash.Cmd.create_cmd("CUSTOMMMCINIT")
|
||||||
if ufs:
|
if ufs:
|
||||||
|
|
|
@ -11,6 +11,7 @@ from binascii import hexlify
|
||||||
from Cryptodome.Util.number import size
|
from Cryptodome.Util.number import size
|
||||||
from mtkclient.Library.Auth.sla_keys import brom_sla_keys
|
from mtkclient.Library.Auth.sla_keys import brom_sla_keys
|
||||||
from mtkclient.Library.Auth.sla import generate_brom_sla_challenge
|
from mtkclient.Library.Auth.sla import generate_brom_sla_challenge
|
||||||
|
from mtkclient.Library.settings import HwParam
|
||||||
from mtkclient.Library.utils import LogBase, logsetup
|
from mtkclient.Library.utils import LogBase, logsetup
|
||||||
from mtkclient.Library.error import ErrorHandler
|
from mtkclient.Library.error import ErrorHandler
|
||||||
from mtkclient.config.brom_config import DAmodes
|
from mtkclient.config.brom_config import DAmodes
|
||||||
|
@ -224,6 +225,8 @@ class Preloader(metaclass=LogBase):
|
||||||
self.info("\tSW Ver:\t\t\t" + hex(self.config.swver))
|
self.info("\tSW Ver:\t\t\t" + hex(self.config.swver))
|
||||||
meid = self.get_meid()
|
meid = self.get_meid()
|
||||||
if meid is not None:
|
if meid is not None:
|
||||||
|
self.config.hwparam = HwParam(self.mtk.config, self.config.meid.hex(), self.mtk.config.hwparam_path)
|
||||||
|
self.config.hwparam.writesetting("hwcode", hex(self.config.hwcode))
|
||||||
self.config.set_meid(meid)
|
self.config.set_meid(meid)
|
||||||
if self.display:
|
if self.display:
|
||||||
self.info("ME_ID:\t\t\t" + hexlify(meid).decode('utf-8').upper())
|
self.info("ME_ID:\t\t\t" + hexlify(meid).decode('utf-8').upper())
|
||||||
|
@ -234,6 +237,8 @@ class Preloader(metaclass=LogBase):
|
||||||
if self.display:
|
if self.display:
|
||||||
if socid != b"":
|
if socid != b"":
|
||||||
self.info("SOC_ID:\t\t\t" + hexlify(socid).decode('utf-8').upper())
|
self.info("SOC_ID:\t\t\t" + hexlify(socid).decode('utf-8').upper())
|
||||||
|
self.config.hwparam.writesetting("socid", hexlify(socid).decode('utf-8'))
|
||||||
|
|
||||||
if self.config.auth is not None and self.config.is_brom and self.config.target_config["daa"]:
|
if self.config.auth is not None and self.config.is_brom and self.config.target_config["daa"]:
|
||||||
if os.path.exists(self.config.auth):
|
if os.path.exists(self.config.auth):
|
||||||
authdata = open(self.config.auth, "rb").read()
|
authdata = open(self.config.auth, "rb").read()
|
||||||
|
|
|
@ -26,7 +26,9 @@ class HwParam:
|
||||||
self.paramsetting = {}
|
self.paramsetting = {}
|
||||||
if os.path.exists(os.path.join(path, self.paramfile)):
|
if os.path.exists(os.path.join(path, self.paramfile)):
|
||||||
try:
|
try:
|
||||||
self.paramsetting = json.loads(open(os.path.join(path, self.paramfile), "r").read())
|
tmp = json.loads(open(os.path.join(path, self.paramfile), "r").read())
|
||||||
|
if tmp["meid"] == meid:
|
||||||
|
self.paramsetting = tmp
|
||||||
except Exception:
|
except Exception:
|
||||||
# json file invalid, load nothing.
|
# json file invalid, load nothing.
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -112,7 +112,6 @@ class MtkConfig(metaclass=LogBase):
|
||||||
self.hwparam.writesetting("hwcode", hex(hwcode))
|
self.hwparam.writesetting("hwcode", hex(hwcode))
|
||||||
|
|
||||||
def set_meid(self, meid):
|
def set_meid(self, meid):
|
||||||
self.hwparam = HwParam(self, meid, self.hwparam_path)
|
|
||||||
self.meid = meid
|
self.meid = meid
|
||||||
self.hwparam.writesetting("meid", hexlify(meid).decode('utf-8'))
|
self.hwparam.writesetting("meid", hexlify(meid).decode('utf-8'))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue