# Bootloader Version

This example shows basic bootloader interaction, retrieving the version of bootloader running on the device.

Click on [Bootloader](https://docs.luxonis.com/software/depthai/examples/flash_bootloader.md) for more information.

> We suggest using
> [Device Manager](https://docs.luxonis.com/software/depthai-components/bootloader.md)
> , a GUI tool for interfacing with the bootloader and its configurations.

## Demo

Example script output

```bash
~/depthai-python/examples$ python3 bootloader_version.py
    Found device with name: 1.1
    Version: 0.0.26
    USB Bootloader - supports only Flash memory
    Memory 'Memory.FLASH' size: 33554432, info: JEDEC ID: 01 02 19
```

## Setup

Please run the [install script](https://github.com/luxonis/depthai-python/blob/main/examples/install_requirements.py) to download
all required dependencies. Please note that this script must be ran from git context, so you have to download the
[depthai-python](https://github.com/luxonis/depthai-python) repository first and then run the script

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

For additional information, please follow the [installation guide](https://docs.luxonis.com/software/depthai/manual-install.md).

## Source code

#### Python

```python
#!/usr/bin/env python3

import depthai as dai

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

if res == True:
    print(f'Found device with name: {info.name}')
    bl = dai.DeviceBootloader(info)
    print(f'Version: {bl.getVersion()}')

    supportedMemTypes = [dai.DeviceBootloader.Memory.FLASH, dai.DeviceBootloader.Memory.EMMC]
    if bl.getType() == dai.DeviceBootloader.Type.USB:
        print("USB Bootloader - supports only Flash memory")
        supportedMemTypes = [dai.DeviceBootloader.Memory.FLASH];
    else:
        print(f"NETWORK Bootloader, is User Bootloader: {bl.isUserBootloader()}")

    try:
        for mem in supportedMemTypes:
            memInfo = bl.getMemoryInfo(mem)
            if memInfo.available:
                print(f"Memory '{mem}' size: {memInfo.size}, info: {memInfo.info}")
                appInfo = bl.readApplicationInfo(mem)
                if appInfo.hasApplication:
                    print(f"Application name: {appInfo.applicationName}, firmware version: {appInfo.firmwareVersion}")
            else:
                print(f"Memory '{mem.name}' not available...")
    except Exception as ex:
        print(f"Couldn't retrieve memory details: {ex}")
else:
    print('No devices found')
```

#### C++

```cpp
#include "depthai/depthai.hpp"

int main(int argc, char** argv) {
    bool res = false;
    dai::DeviceInfo info;
    std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice();

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

        std::list<dai::DeviceBootloader::Memory> supportedMemTypes = {dai::DeviceBootloader::Memory::FLASH, dai::DeviceBootloader::Memory::EMMC};
        if(bl.getType() == dai::DeviceBootloader::Type::USB) {
            std::cout << "USB Bootloader - supports only Flash memory" << std::endl;
            supportedMemTypes = {dai::DeviceBootloader::Memory::FLASH};
        } else {
            std::cout << "NETWORK Bootloader, is User Bootloader: " << bl.isUserBootloader() << std::endl;
        }

        try {
            for(const auto& mem : supportedMemTypes) {
                std::cout << std::endl;
                auto memoryInfo = bl.getMemoryInfo(mem);
                if(memoryInfo.available) {
                    std::cout << "Memory '" << mem << "' size: " << memoryInfo.size << ", info: " << memoryInfo.info << std::endl;

                    auto appInfo = bl.readApplicationInfo(mem);
                    std::cout << "Application, flashed: " << appInfo.hasApplication << " firmware version: " << appInfo.firmwareVersion
                              << " application name: " << appInfo.applicationName << std::endl;
                } else {
                    std::cout << "Memory '" << mem << "' not available..." << std::endl;
                }
            }
        } catch(const std::exception& ex) {
            std::cout << "Couldn't retrieve memory details: " << ex.what() << std::endl;
        }
    } else {
        std::cout << "No devices found" << std::endl;
    }

    return 0;
}
```

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
