Skip to content

Commit

Permalink
Fix/update flash_bootloader example. Changes mirrored from C++ side:
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-luxonis committed Sep 18, 2021
1 parent ed2ca71 commit 6093aed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion depthai-core
29 changes: 17 additions & 12 deletions examples/flash_bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,42 @@
print("Specify either 'usb' or 'network' bootloader type")
exit()

print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.")
print("Do not unplug your device while the bootloader is flashing.")
print("Type 'y' and press enter to proceed, otherwise exits: ")
if input() != 'y':
print("Prompt declined, exiting...")
exit(-1)

(found, info) = dai.DeviceBootloader.getFirstAvailableDevice()
if not found:
print("No device found to flash. Exiting.")
exit(-1)

hasBootloader = (info.state == dai.XLinkDeviceState.X_LINK_BOOTLOADER)
if hasBootloader:
print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.")
print("Do not unplug your device while the bootloader is flashing.")
print("Type 'y' and press enter to proceed, otherwise exits: ")
if input() != 'y':
print("Prompt declined, exiting...")
exit(-1)

# Open DeviceBootloader and allow flashing bootloader
print(f"Booting latest bootloader first, will take a tad longer...")
with dai.DeviceBootloader(info, allowFlashingBootloader=True) as bl:
currentBlType = bl.getType()

# Check if bootloader type is the same
if blType != dai.DeviceBootloader.Type.AUTO and currentBlType != blType:
if blType == dai.DeviceBootloader.Type.AUTO:
blType = currentBlType

# Check if bootloader type is the same, if already booted by bootloader (not in USB recovery mode)
if currentBlType != blType and hasBootloader:
print(f"Are you sure you want to flash '{blType.name}' bootloader over current '{currentBlType.name}' bootloader?")
print(f"Type 'y' and press enter to proceed, otherwise exits: ")
if input() != 'y':
print("Prompt declined, exiting...")
exit(-1);
exit(-1)

# Create a progress callback lambda
progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')

print(f"Flashing {currentBlType.name} bootloader...")
print(f"Flashing {blType.name} bootloader...")
startTime = time.monotonic()
(res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, currentBlType, progress)
(res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress)
if res:
print("Flashing successful. Took", time.monotonic() - startTime, "seconds")
else:
Expand Down

0 comments on commit 6093aed

Please sign in to comment.