Skip to content

Commit

Permalink
Fix protocol type detection on non-BootROM chips
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Mar 30, 2024
1 parent c0fa9e1 commit 171c753
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bk7231tools/serial/cmd_ll_flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def flash_read_id(self, cmd: int = 0x9F) -> dict:

def flash_detect_size(self) -> int:
self.info("Flash size - detecting...")
sizes = [0.5, 1, 2, 4, 8, 16] # MiB
sizes = [2, 4, 8, 16] # MiB
# disable bootloader protection bypass
self.boot_protection_bypass = False
safe_offset = 0x11000
Expand Down
30 changes: 25 additions & 5 deletions bk7231tools/serial/linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def connect(self):
pass
if not self.flash_size and self.flash_params:
self.flash_size = self.flash_params["size"]
if not self.flash_size and self.bootloader_type.value.flash_size:
if not self.flash_size and self.bootloader_type:
self.flash_size = self.bootloader_type.value.flash_size
if not self.flash_size:
self.flash_size = self.flash_detect_size()
Expand Down Expand Up @@ -88,11 +88,28 @@ def detect_chip(self) -> None:
else:
# if bootloader is not known, try to guess the protocol type
self.chip_type = None
data = self.flash_read_bytes(start=0, length=256 + 1, crc_check=False)
if crc == crc32(data[0:257]):
self.bootloader = None
self.warn(
f"Unknown bootloader CRC - 0x{crc:08X}"
f" - please report this on GitHub issues!"
)
# check CRC of app data, which is readable on all protocols
check_offset = 0x11000
check_length = 256
crc = self.read_flash_range_crc(
start=check_offset,
end=check_offset + check_length,
)
data = self.flash_read_bytes(
start=check_offset,
length=check_length + 1,
crc_check=False,
)
# guess the protocol type
if crc == crc32(data[0 : check_length + 1]):
# BK72xx BootROM protocol - CRC range end-inclusive
self.protocol_type = BkProtocolType.FULL
elif crc == crc32(data[0:256]):
elif crc == crc32(data[0 : check_length + 0]):
# BK72xx Bootloader protocol - assume minimal command support
self.protocol_type = BkProtocolType.BASIC_BEKEN
else:
Expand All @@ -106,7 +123,10 @@ def detect_chip(self) -> None:
if any(c.value == self.bk_chip_id for c in BkChipType):
self.chip_type = BkChipType(self.bk_chip_id)
else:
self.warn(f"Unknown SCTRL_CHIP_ID - {hex(self.bk_chip_id)}")
self.warn(
f"Unknown SCTRL_CHIP_ID - {hex(self.bk_chip_id)}"
f" - please report this on GitHub issues!"
)

if self.check_protocol(BkBootVersionCmnd):
# read BK7231T boot version
Expand Down

0 comments on commit 171c753

Please sign in to comment.