Skip to content

Commit

Permalink
uploader.py: Update to support reading bootloader software version
Browse files Browse the repository at this point in the history
Supports both ArduPilot and PX4 implementation of reading bootloader software version.
  • Loading branch information
joshanne committed Jan 8, 2025
1 parent 27deea4 commit 1d1e8e6
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions Tools/scripts/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class uploader(object):
GET_CHIP = b'\x2c' # rev5+ , get chip version
SET_BOOT_DELAY = b'\x2d' # rev5+ , set boot delay
GET_CHIP_DES = b'\x2e' # rev5+ , get chip description in ASCII
GET_SOFTWARE = b'\x2f'
MAX_DES_LENGTH = 20

REBOOT = b'\x30'
Expand Down Expand Up @@ -262,7 +263,8 @@ def __init__(self,
source_system=None,
source_component=None,
no_extf=False,
force_erase=False):
force_erase=False,
identify_only=False):
self.MAVLINK_REBOOT_ID1 = bytearray(b'\xfe\x21\x72\xff\x00\x4c\x00\x00\x40\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\x00\x01\x00\x00\x53\x6b') # NOQA
self.MAVLINK_REBOOT_ID0 = bytearray(b'\xfe\x21\x45\xff\x00\x4c\x00\x00\x40\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\x00\x00\x00\x00\xcc\x37') # NOQA
if target_component is None:
Expand All @@ -273,6 +275,7 @@ def __init__(self,
source_component = 1
self.no_extf = no_extf
self.force_erase = force_erase
self.identify_only = identify_only

# open the port, keep the default timeout short so we can poll quickly
self.port = serial.Serial(portname, baudrate_bootloader, timeout=2.0, write_timeout=2.0)
Expand Down Expand Up @@ -437,6 +440,17 @@ def __getCHIPDes(self):
peices = value.split(",")
return peices

# send the GET_SOFTWARE command
def __getBootloaderSoftware(self):
self.__send(uploader.GET_SOFTWARE + uploader.EOC)
length = self.__recv_int()
print(f"RX Len: {length}")
value = self.__recv(length)
if runningPython3:
value = value.decode('ascii')
self.__getSync()
return value

def __drawProgressBar(self, label, progress, maxVal):
if maxVal < progress:
progress = maxVal
Expand Down Expand Up @@ -737,6 +751,13 @@ def identify(self):
self.board_rev = self.__getInfo(uploader.INFO_BOARD_REV)
self.fw_maxsize = self.__getInfo(uploader.INFO_FLASH_SIZE)

if self.identify_only:
# Only run if we are trying to identify the board
try:
self.git_hash_bl = self.__getBootloaderSoftware()
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 +860,9 @@ 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:
print(" git hash (Bootloader): %s" % self.git_hash_bl)

print("Identification complete")

def board_name_for_board_id(self, board_id):
Expand Down Expand Up @@ -1162,7 +1186,8 @@ def main():
args.source_system,
args.source_component,
args.no_extf,
args.force_erase)
args.force_erase,
args.identify)

except Exception as e:
if not is_WSL and not is_WSL2 and "win32" not in _platform:
Expand Down

0 comments on commit 1d1e8e6

Please sign in to comment.