Flashing USB Recovery Boot Header
This script flashes a special USB "Recovery Header" to the device's on-board flash memory.Boot Header
Script allows the flashing of different boot headers. This example focuses only on the USB recovery header since other headers are not commonly used.
- Eliminate the bootloader’s extra power consumption in idle mode
- Revert to a simple USB-only setup, removing advanced bootloader features
Overwriting the bootloader means the device no longer supports advanced bootloader capabilities. Only do this if you understand the implications. This can be reversed by flashing the bootloader back.
Demo
An example script might produce output like:Command Line
1~/depthai-python/examples$ python3 flash_boot_header.py USB_RECOVERY
2Found device with name: 1.1
3Successfully flashed boot header!
Setup
Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the scriptCommand Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
Source code
Python
C++
Python
PythonGitHub
1import sys
2from typing import Callable, Tuple
3from enum import Enum
4import depthai
5
6FLASH = depthai.DeviceBootloader.Memory.FLASH
7
8def main():
9 if len(sys.argv) < 2:
10 print(f"Usage: {sys.argv[0]} [GPIO_MODE/USB_RECOVERY/NORMAL/FAST] [params]")
11 print("\tOptions:")
12 print(f"\t\t{sys.argv[0]} GPIO_MODE gpioModeNum")
13 print(f"\t\t{sys.argv[0]} USB_RECOVERY")
14 print(f"\t\t{sys.argv[0]} NORMAL [frequency] [location] [dummyCycles] [offset]")
15 print(f"\t\t{sys.argv[0]} FAST [frequency] [location] [dummyCycles] [offset]")
16 return 0
17
18 mode = sys.argv[1].lower()
19 flash_func = None
20
21 if mode == "gpio_mode":
22 # gpio mode header
23 if len(sys.argv) < 3:
24 print(f"Usage: {sys.argv[0]} GPIO_MODE gpioModeNum")
25 return 0
26
27 gpio_mode = int(sys.argv[2])
28 def flash_gpio(bl: 'depthai.DeviceBootloader') -> Tuple[bool, str]:
29 return bl.flashGpioModeBootHeader(FLASH, gpio_mode)
30 flash_func = flash_gpio
31
32 elif mode == "usb_recovery":
33 # usb recovery header
34 def flash_usb(bl: 'depthai.DeviceBootloader') -> Tuple[bool, str]:
35 return bl.flashUsbRecoveryBootHeader(FLASH)
36 flash_func = flash_usb
37
38 elif mode in ("normal", "fast"):
39 if len(sys.argv) != 2 and len(sys.argv) != 3 and len(sys.argv) <= 3:
40 print(f"Usage: {sys.argv[0]} NORMAL/FAST [frequency] [location] [dummyCycles] [offset]")
41 print(f"Usage: {sys.argv[0]} NORMAL/FAST [frequency]")
42 return 0
43
44 offset = -1
45 location = -1
46 dummy_cycles = -1
47 frequency = -1
48
49 if len(sys.argv) > 3:
50 if len(sys.argv) >= 3:
51 offset = int(sys.argv[2])
52 if len(sys.argv) >= 4:
53 location = int(sys.argv[3])
54 if len(sys.argv) >= 5:
55 dummy_cycles = int(sys.argv[4])
56 if len(sys.argv) >= 6:
57 frequency = int(sys.argv[5])
58 elif len(sys.argv) == 3:
59 frequency = int(sys.argv[2])
60
61 if mode == "normal":
62 def flash_normal(bl: 'depthai.DeviceBootloader') -> Tuple[bool, str]:
63 return bl.flashBootHeader(FLASH, frequency, location, dummy_cycles, offset)
64 flash_func = flash_normal
65 elif mode == "fast":
66 def flash_fast(bl: 'depthai.DeviceBootloader') -> Tuple[bool, str]:
67 return bl.flashFastBootHeader(FLASH, frequency, location, dummy_cycles, offset)
68 flash_func = flash_fast
69
70 # Find device and flash specified boot header
71 success, info = depthai.DeviceBootloader.getFirstAvailableDevice()
72
73 if success:
74 print(f"Found device with name: {info.name}")
75 bl = depthai.DeviceBootloader(info)
76
77 # Flash the specified boot header
78 if flash_func:
79 success, error_msg = flash_func(bl)
80 if success:
81 print("Successfully flashed boot header!")
82 else:
83 print(f"Couldn't flash boot header: {error_msg}")
84 else:
85 print("Invalid boot option header specified")
86 else:
87 print("No devices found")
88
89 return 0
90
91if __name__ == "__main__":
92 main()
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.