From a2b09d6531e0eabf970669b83b6aa8cd67b72c84 Mon Sep 17 00:00:00 2001 From: James O'Shannessy <12959316+joshanne@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:23:10 +1100 Subject: [PATCH] scripts: Update uploader to read git hash from bootloader --- Tools/scripts/uploader.py | 56 ++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/Tools/scripts/uploader.py b/Tools/scripts/uploader.py index b926b26c232795..d67d6b1497a5f2 100755 --- a/Tools/scripts/uploader.py +++ b/Tools/scripts/uploader.py @@ -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 @@ -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) @@ -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):