Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tools/px_uploader: exit if unsuitable board is connected #14690

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Tools/px_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
else:
runningPython3 = True

class FirmwareNotSuitableException(Exception):
def __init__(self, message):
super(FirmwareNotSuitableException, self).__init__(message)

class firmware(object):
'''Loads a firmware file'''
Expand Down Expand Up @@ -567,13 +570,13 @@ def upload(self, fw, force=False, boot_delay=None):
# Make sure we are doing the right thing
start = time.time()
if self.board_type != fw.property('board_id'):
msg = "Firmware not suitable for this board (board_type=%u board_id=%u)" % (
msg = "Firmware not suitable for this board (Firmware board_type=%u board_id=%u)" % (
self.board_type, fw.property('board_id'))
print("WARNING: %s" % msg)
if force:
print("FORCED WRITE, FLASHING ANYWAY!")
else:
raise IOError(msg)
raise FirmwareNotSuitableException(msg)

# Prevent uploads where the image would overflow the flash
if self.fw_maxsize < fw.property('image_size'):
Expand Down Expand Up @@ -798,6 +801,7 @@ def main():
baud_flightstack = [int(x) for x in args.baud_flightstack.split(',')]

successful = False
unsuitable_board = False
for port in portlist:

# print("Trying %s" % port)
Expand Down Expand Up @@ -828,7 +832,7 @@ def main():
continue

found_bootloader = False
while (True):
while True:
up.open()

# port is open, try talking to it
Expand Down Expand Up @@ -869,6 +873,11 @@ def main():
# print the error
print("\nERROR: %s" % ex.args)

except FirmwareNotSuitableException:
unsuitable_board = True
up.close()
continue

except IOError:
up.close()
continue
Expand All @@ -883,6 +892,12 @@ def main():
else:
sys.exit(1)

if unsuitable_board:
# If we land here, we went through all ports, did not flash any
# board and found at least one unsuitable board.
# Exit with 2, so a caller can distinguish from other errors
sys.exit(2)

# Delay retries to < 20 Hz to prevent spin-lock from hogging the CPU
time.sleep(0.05)

Expand Down