Bootloader Config

This example allows you to read/flash/clear bootloader on the device. You can specify the .json bootloader config file via cmd arguments, which will get flashed to the device.

Click on Bootloader for more information.

Demo

Example script output

~/depthai-python/examples$ python3 Bootloader/bootloader_config.py flash
Found device with name: 14442C10D1789ACD00-ma2480
Successfully flashed bootloader configuration

~/depthai-python/examples$ python3 Bootloader/bootloader_config.py read
Found device with name: 14442C10D1789ACD00-ma2480
Current flashed configuration
{'appMem': -1, 'network': {'ipv4': 0, 'ipv4Dns': 0, 'ipv4DnsAlt': 0, 'ipv4Gateway': 0, 'ipv4Mask': 0, 'ipv6': [0, 0, 0, 0], 'ipv6Dns': [0, 0, 0, 0], 'ipv6DnsAlt': [0, 0, 0, 0], 'ipv6Gateway': [0, 0, 0, 0], 'ipv6Prefix': 0, 'mac': [0, 0, 0, 0, 0, 0], 'staticIpv4': False, 'staticIpv6': False, 'timeoutMs': 30000}, 'usb': {'maxUsbSpeed': 3, 'pid': 63036, 'timeoutMs': 3000, 'vid': 999}}

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 script

git clone https://github.com/luxonis/depthai-python.git
cd depthai-python/examples
python3 install_requirements.py

For additional information, please follow installation guide

Source code

Also available on GitHub

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3

import depthai as dai
import sys
import json

usage = False
read = True
clear = False
path = ''
if len(sys.argv) >= 2:
    op = sys.argv[1]
    if op == 'read':
        read = True
    elif op == 'flash':
        read = False
        if len(sys.argv) >= 3:
            path = sys.argv[2]
    elif op == 'clear':
        clear = True
        read = False
    else:
        usage = True
else:
    usage = True

if usage:
    print(f'Usage: {sys.argv[0]} [read/flash/clear] [flash: path/to/config/json]')
    exit(-1)

(res, info) = dai.DeviceBootloader.getFirstAvailableDevice()

if res:
    print(f'Found device with name: {info.desc.name}');
    with dai.DeviceBootloader(info) as bl:
        if read:
            print('Current flashed configuration')
            print(json.dumps(bl.readConfigData()))
        else:
            success = None
            error = None
            if clear:
                (success, error) = bl.flashConfigClear()
            else:
                if path == '':
                    (success, error) = bl.flashConfig(dai.DeviceBootloader.Config())
                else:
                    (success, error) = bl.flashConfigFile(path)
            if success:
                print('Successfully flashed bootloader configuration')
            else:
                print(f'Error flashing bootloader configuration: {error}')
else:
    print('No devices found')

Also available on GitHub

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "depthai/depthai.hpp"

int main(int argc, char** argv) {
    // Options
    bool usage = false, read = true, clear = false;
    std::string path = "";
    if(argc >= 2) {
        std::string op = argv[1];
        if(op == "read") {
            read = true;
        } else if(op == "flash") {
            read = false;
            if(argc >= 3) {
                path = argv[2];
            }
        } else if(op == "clear") {
            clear = true;
            read = false;
        } else if(op == "clear") {
            clear = true;
            read = false;
        } else {
            usage = true;
        }
    } else {
        usage = true;
    }
    if(usage) {
        std::cout << "Usage: " << argv[0] << " [read/flash/clear] [flash: path/to/config/json]" << std::endl;
        return -1;
    }

    // DeviceBootloader configuration
    bool res = false;
    dai::DeviceInfo info;
    std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice();

    if(res) {
        std::cout << "Found device with name: " << info.desc.name << std::endl;
        dai::DeviceBootloader bl(info);

        if(read) {
            std::cout << "Current flashed configuration\n" << bl.readConfigData().dump(4) << std::endl;
        } else {
            std::cout << "Warning! Flashing bootloader config can potentially soft brick your device and should be done with caution." << std::endl;
            std::cout << "Do not unplug your device while the bootloader config is flashing." << std::endl;
            std::cout << "Type 'y' and press enter to proceed, otherwise exits: ";
            std::cin.ignore();
            if(std::cin.get() != 'y') {
                std::cout << "Prompt declined, exiting..." << std::endl;
                return -1;
            }

            bool success;
            std::string error;
            if(clear) {
                std::tie(success, error) = bl.flashConfigClear();
            } else {
                if(path.empty()) {
                    std::tie(success, error) = bl.flashConfig(dai::DeviceBootloader::Config{});
                } else {
                    std::tie(success, error) = bl.flashConfigFile(path);
                }
            }
            if(success) {
                std::cout << "Successfully flashed bootloader configuration\n";
            } else {
                std::cout << "Error flashing bootloader configuration: " << error;
            }
        }

    } else {
        std::cout << "No devices found" << std::endl;
    }

    return 0;
}

Got questions?

We’re always happy to help with code or other questions you might have.