From b7b203e2f184f7128349e110f51455ac4c9e17b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sun, 5 Nov 2023 18:35:36 +0100 Subject: [PATCH] Update bootloader CRC table --- bk7231tools/serial/cmd_chip.py | 7 ++++--- bk7231tools/serial/protocol.py | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/bk7231tools/serial/cmd_chip.py b/bk7231tools/serial/cmd_chip.py index f705fbd..6b3ec55 100644 --- a/bk7231tools/serial/cmd_chip.py +++ b/bk7231tools/serial/cmd_chip.py @@ -69,16 +69,17 @@ def read_chip_info(self) -> str: # all known protocols support this command crc = self.read_flash_range_crc(0, 256) ^ 0xFFFFFFFF if crc in CHIP_BY_CRC: - self.chip_info = CHIP_BY_CRC[crc] - default = ProtocolType.BASIC_DEFAULT + self.chip_info, _ = CHIP_BY_CRC[crc] # read the protocol here already - it might not support BootVersion - self.protocol_type = PROTOCOLS.get(self.chip_info, default) + self.protocol_type = PROTOCOLS.get(self.chip_info, ProtocolType.UNKNOWN) # try BK7231S chip info command command = BkBootVersionCmnd() response: BkBootVersionResp = self.command(command, support_optional=True) if not response: # BootVersion not supported (got no error response as well) + default = ProtocolType.BASIC_DEFAULT + self.protocol_type = PROTOCOLS.get(self.chip_info, default) return self.chip_info if response.version == b"\x07": diff --git a/bk7231tools/serial/protocol.py b/bk7231tools/serial/protocol.py index 75c3fbd..e647a65 100644 --- a/bk7231tools/serial/protocol.py +++ b/bk7231tools/serial/protocol.py @@ -79,7 +79,7 @@ class ProtocolType(Enum): # bl_bk7231s_1.0.6_625D.bin "BK7231S_1.0.6": ProtocolType.BASIC_TUYA, # bl_bk7231q_6AFA.bin - "BK7231QN40": ProtocolType.BASIC_BEKEN, + "BK7231Q": ProtocolType.BASIC_BEKEN, # bl_bk7252_0.1.3_F4D3.bin "BK7252": ProtocolType.BASIC_BEKEN, } @@ -88,10 +88,24 @@ class ProtocolType(Enum): # for chips that don't respond to BootVersion at all # NOTE: the values here are RAW, as received from the chip. They need to be XOR'ed to represent the real CRC. CHIP_BY_CRC = { + # bl_bk7231n_1.0.1_34B7.bin + 0xBF9C2D66: ("BK7231N", "1.0.1"), # bl_bk7231q_6AFA.bin - 0x0FDCE109: "BK7231QN40", + 0x0FDCE109: ("BK7231Q", None), + # bl_bk7231q_tysdk_03ED.bin + 0x00A5C153: ("BK7231Q", None), + # bl_bk7231s_1.0.1_79A6.bin + 0x3E13578E: ("BK7231T", "1.0.1"), + # bl_bk7231s_1.0.3_DAAE.bin + 0xB4CE1BB2: ("BK7231T", "1.0.3"), + # bl_bk7231s_1.0.5_4FF7.bin + 0x45AB3E47: ("BK7231T", "1.0.5"), + # bl_bk7231s_1.0.6_625D.bin + 0x1A3436AC: ("BK7231T", "1.0.6"), # bl_bk7252_0.1.3_F4D3.bin - 0xC6064AF3: "BK7252", + 0xC6064AF3: ("BK7252", "0.1.3"), + # bootloader_7252_2M_uart1_log_20190828.bin + 0x1C5D83D9: ("BK7252", None), } @@ -136,12 +150,13 @@ def require_protocol(self, code: int, is_long: bool): f"Not implemented in protocol {self.protocol_type.name}: code={code}, is_long={is_long}" ) - def check_protocol(self, code: int, is_long: bool) -> bool: + def check_protocol(self, code: int, is_long: bool = False) -> bool: if self.protocol_type == ProtocolType.UNKNOWN: return True pair = (code, is_long) if pair not in self.protocol_type.value: return False + return True @staticmethod def encode(packet: Packet) -> bytes: