Skip to content

Commit

Permalink
scripts: Update uploader to read git hash from bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
joshanne committed Nov 6, 2024
1 parent 6df8acd commit a2b09d6
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions Tools/scripts/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,16 @@ class uploader(object):

CHIP_FULL_ERASE = b'\x40' # full erase of flash

INFO_BL_REV = b'\x01' # bootloader protocol revision
BL_REV_MIN = 2 # minimum supported bootloader protocol
BL_REV_MAX = 5 # maximum supported bootloader protocol
INFO_BOARD_ID = b'\x02' # board type
INFO_BOARD_REV = b'\x03' # board revision
INFO_FLASH_SIZE = b'\x04' # max firmware size in bytes
INFO_EXTF_SIZE = b'\x06' # available external flash size
INFO_BL_REV = b'\x01' # bootloader protocol revision
BL_REV_MIN = 2 # minimum supported bootloader protocol
BL_REV_MAX = 5 # maximum supported bootloader protocol
INFO_BOARD_ID = b'\x02' # board type
INFO_BOARD_REV = b'\x03' # board revision
INFO_FLASH_SIZE = b'\x04' # max firmware size in bytes
INFO_EXTF_SIZE = b'\x06' # available external flash size
INFO_SW_BL_BUILD = b'\x07' # information about bootloader software build version
INFO_SW_BL_OPTS = b'\x08' # information about bootloader build options
INFO_SW_APP_BUILD = b'\x09' # information about application software build version

PROG_MULTI_MAX = 252 # protocol max is 255, must be multiple of 4
READ_MULTI_MAX = 252 # protocol max is 255
Expand Down Expand Up @@ -737,6 +740,21 @@ def identify(self):
self.board_rev = self.__getInfo(uploader.INFO_BOARD_REV)
self.fw_maxsize = self.__getInfo(uploader.INFO_FLASH_SIZE)

try:
self.bootloader_options = self.__getInfo(uploader.INFO_SW_BL_OPTS)
except Exception:
self.__sync()

try:
self.git_hash_bl = self.__getInfo(uploader.INFO_SW_BL_BUILD)
except Exception:
self.__sync()

try:
self.git_hash_app = self.__getInfo(uploader.INFO_SW_APP_BUILD)
except Exception:
self.__sync()

def dump_board_info(self):
# OTP added in v4:
print("Bootloader Protocol: %u" % self.bl_rev)
Expand Down Expand Up @@ -839,6 +857,30 @@ def dump_board_info(self):
print(" board_type: %u" % self.board_type)
print(" board_rev: %u" % self.board_rev)

if hasattr(self, "git_hash_bl") and self.git_hash_bl is not None:
git_hash_bl = "%x" % (self.git_hash_bl)
print(" git hash (Bootloader): %s" % git_hash_bl)

if hasattr(self, "bootloader_options") and self.bootloader_options is not None:
def decode_bootloader_options(bootloader_options):
'''decode the bootloader options bits'''
print(f" bootloader options: {bootloader_options:032b}")
option_bits = {
0: "UnsignedFirmware", # CheckFirmware Enabled, Unsigned Firmware
1: "SignedFirmware", # CheckFirmware Enabled, Signed Firmware
2: "FlashFromSDCard", # Flash From SD Card Supported
3: "OptionCheckFWOk", # CheckFirmware Enabled, firmware check is good
}
for i in range(32):
if (bootloader_options & (1 << i)) == (1 << i):
print(f" - {option_bits.get(i, 'Unknown Option')}")

decode_bootloader_options(self.bootloader_options)

if hasattr(self, "git_hash_app") and self.git_hash_app is not None:
git_hash_app = "%x" % (self.git_hash_app)
print(" git hash (Application): %s" % git_hash_app)

print("Identification complete")

def board_name_for_board_id(self, board_id):
Expand Down

0 comments on commit a2b09d6

Please sign in to comment.