Skip to content

Commit 5c65953

Browse files
authored
Merge pull request #886 from luxonis/update_bootloader
Updated bootloader docs/examples
2 parents 08ab4e7 + 9fc936a commit 5c65953

File tree

6 files changed

+104
-20
lines changed

6 files changed

+104
-20
lines changed

docs/source/components/bootloader.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Bootloader
44
==========
55

66
DepthAI bootloader is a small program which handles the booting process, either by **booting the flashed application** (see :ref:`Standalone mode`),
7-
or by **initializing the OAK PoE camera** so DepthAI API can connect to it. OAK PoE cameras already come with bootloader flashed at the factory.
7+
or by **initializing the OAK PoE camera** so DepthAI API can connect to it. OAK PoE cameras already come with factory bootloader flashed at the factory.
88

9-
Bootloader is part of the ``depthai`` library, so to eg. flash the newest bootloader, you should use the newest ``depthai`` library.
9+
Bootloader is bundled inside with the ``depthai`` library, so to eg. flash the newest bootloader, you should use the newest ``depthai`` library.
1010

1111
Device Manager
1212
##############
@@ -81,6 +81,16 @@ Device Manager will try to flash the user bootloader first, if flashed (factory)
8181
* **Factory reset** will erase the whole flash content and re-flash it with only the USB or NETWORK bootloader. Flashed application (pipeline, assets) and bootloader configurations will be lost.
8282
* **Boot into USB recovery mode** will force eg. OAK PoE camera to be available through the USB connector, even if its boot pins are set to PoE booting. It is mostly used by our firmware developers.
8383

84+
Factory and User bootloader
85+
###########################
86+
87+
There are two types of bootloaders:
88+
89+
- **Factory bootloader**: bootloader that is flashed in the factory. We don't recommend re-flashing this bootloader, as it is not meant to be edited by end users.
90+
- **User bootloader**: bootloader that can be flashed by the user. If booting is unsuccessful (eg. gets corrupted when flashing), it will fallback to factory bootloader.
91+
92+
USB devices don't support user bootloader. If device has User bootloader, it will be used by default. If user bootloader is not flashed, it will fallback to Factory bootloader.
93+
8494
Boot switches
8595
#############
8696

docs/source/samples/bootloader/bootloader_version.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ Example script output
1616
.. code-block:: bash
1717
1818
~/depthai-python/examples$ python3 bootloader_version.py
19-
Found device with name: 14442C10D1789ACD00-ma2480
20-
Version: 0.0.15
19+
Found device with name: 1.1
20+
Version: 0.0.26
21+
USB Bootloader - supports only Flash memory
22+
Memory 'Memory.FLASH' size: 33554432, info: JEDEC ID: 01 02 19
2123
2224
Setup
2325
#####

docs/source/samples/bootloader/flash_bootloader.rst

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
Flash Bootloader
22
================
33

4-
This script will flash bootloader to the connected OAK camera. Bootloader can only be flashed to devices that
5-
have flash on-board.
6-
7-
Click on :ref:`Bootloader` for more information.
4+
This script will flash :ref:`factory bootloader <Factory and User bootloader>` to the connected OAK camera. It will
5+
also clear the :ref:`user bootloader <Factory and User bootloader>` (if it exists).
6+
:ref:`Bootloader` can only be flashed to devices that have on-board flash memory.
87

98
.. note::
109
We suggest using :ref:`Device Manager`, a GUI tool for interfacing with the bootloader and its configurations.
@@ -16,9 +15,20 @@ Example script output
1615

1716
.. code-block:: bash
1817
19-
~/depthai-python/examples$ python3 bootloader_version.py
20-
Found device with name: 14442C1031425FD700-ma2480
21-
Version: 0.0.15
18+
~/depthai-python/examples$ python3 flash_bootloader.py
19+
[0] 1844301041C83D0E00 [X_LINK_USB_VSC]
20+
Which DepthAI device to flash bootloader for [0..0]: 0
21+
Booting latest bootloader first, will take a tad longer...
22+
Bootloader version to flash: 0.0.26
23+
No config found, skipping erasing user bootloader
24+
Flashing USB bootloader...
25+
Flashing progress: 0.0%
26+
Flashing progress: 18.8%
27+
Flashing progress: 31.2%
28+
Flashing progress: 48.2%
29+
Flashing progress: 94.2%
30+
Flashing progress: 100.0%
31+
Flashing successful. Took 7.55600329185836 seconds
2232
2333
Setup
2434
#####
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Flash User Bootloader
2+
=====================
3+
4+
This script will flash :ref:`user bootloader <Factory and User bootloader>` to the connected OAK camera.
5+
:ref:`Bootloader` can only be flashed to devices that have on-board flash memory.
6+
7+
.. note::
8+
We suggest using :ref:`Device Manager`, a GUI tool for interfacing with the bootloader and its configurations.
9+
10+
Demo
11+
####
12+
13+
Example script output
14+
15+
.. code-block:: bash
16+
17+
~/depthai-python/examples/bootloader$ python3 flash_user_bootloader.py
18+
[0] 1844301041C83D0E00 [X_LINK_USB_VSC] current bootloader: 0.0.26
19+
Which DepthAI device to flash User Bootloader for (Note: Only NETWORK supported) [0..0]: 0
20+
User Bootloader version to flash: 0.0.26
21+
Flashing User Bootloader...
22+
Flashing progress: 0.0%
23+
Flashing progress: 18.8%
24+
Flashing progress: 31.2%
25+
Flashing progress: 48.2%
26+
Flashing progress: 94.2%
27+
Flashing progress: 100.0%
28+
Flashing successful. Took 7.55600329185836 seconds
29+
30+
Setup
31+
#####
32+
33+
.. include:: /includes/install_from_pypi.rst
34+
35+
Source code
36+
###########
37+
38+
.. tabs::
39+
40+
.. tab:: Python
41+
42+
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/bootloader/flash_user_bootloader.py>`__
43+
44+
.. literalinclude:: ../../../../examples/bootloader/flash_user_bootloader.py
45+
:language: python
46+
:linenos:
47+
48+
.. tab:: C++
49+
50+
Also `available on GitHub <https://github.com/luxonis/depthai-core/blob/main/examples/bootloader/flash_user_bootloader.cpp>`__
51+
52+
.. literalinclude:: ../../../../depthai-core/examples/bootloader/flash_user_bootloader.cpp
53+
:language: cpp
54+
:linenos:
55+
56+
.. include:: /includes/footer-short.rst

docs/source/tutorials/code_samples.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ are presented with code.
3535

3636
- :ref:`Bootloader Config` - Read/Flash/Clear bootloader on the device
3737
- :ref:`Bootloader Version` - Retrieves Version of Bootloader on the device
38-
- :ref:`Flash Bootloader` - Flash the bootloader to the device
38+
- :ref:`Flash Bootloader` - Flash factory bootloader to the device
39+
- :ref:`Flash User Bootloader` - Flash user bootloader to the device
3940
- :ref:`POE set IP` - Sets IP of the POE device
4041

4142
.. rubric:: Calibration

examples/bootloader/flash_bootloader.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
with dai.DeviceBootloader(di) as bl:
2626
print(f' current bootloader: {bl.getVersion()}', end='')
2727
print()
28-
selected = input(f'Which DepthAI device to flash bootloader for [0..{len(deviceInfos)-1}]: ')
28+
selected = input(f'Which OAK device to flash factory bootloader for [0..{len(deviceInfos)-1}]: ')
2929
info = deviceInfos[int(selected)]
3030

3131
hasBootloader = (info.state == dai.XLinkDeviceState.X_LINK_BOOTLOADER)
3232
if hasBootloader:
33-
print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.")
33+
print("Warning! Flashing factory bootloader can potentially soft brick your device and should be done with caution.")
3434
print("Do not unplug your device while the bootloader is flashing.")
3535
print("Type 'y' and press enter to proceed, otherwise exits: ")
3636
if input() != 'y':
@@ -54,15 +54,20 @@
5454
print("Prompt declined, exiting...")
5555
exit(-1)
5656

57+
try:
58+
# Clears out user bootloader
59+
configJson = bl.readConfigData()
60+
configJson["userBlSize"] = 0
61+
bl.flashConfigData(configJson)
62+
except:
63+
print('No config found, skipping erasing user bootloader')
64+
5765
# Create a progress callback lambda
5866
progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')
67+
68+
print(f"Flashing {blType.name} bootloader...")
5969
startTime = time.monotonic()
60-
is_user_bl = bl.isUserBootloaderSupported()
61-
print(f"Flashing {blType.name} {'USER' if is_user_bl else 'FACTORY'} bootloader...")
62-
if is_user_bl:
63-
(res, message) = bl.flashUserBootloader(progress)
64-
else: # Factory bootloader
65-
(res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress)
70+
(res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress)
6671
if res:
6772
print("Flashing successful. Took", time.monotonic() - startTime, "seconds")
6873
else:

0 commit comments

Comments
 (0)