Skip to content

Commit

Permalink
Update bootloader CRC table
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Nov 5, 2023
1 parent 83b7c53 commit b7b203e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
7 changes: 4 additions & 3 deletions bk7231tools/serial/cmd_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
23 changes: 19 additions & 4 deletions bk7231tools/serial/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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),
}


Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b7b203e

Please sign in to comment.