Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 120 additions & 14 deletions include/depthai-bootloader-shared/Bootloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@
#include "Type.hpp"
#include "Section.hpp"
#include "Memory.hpp"
#include "UsbBootloaderConfig.hpp"
#include "NetworkBootloaderConfig.hpp"

namespace dai
{
namespace bootloader
{

inline const Structure getStructure(Type type){
switch(type){
case Type::USB: return UsbBootloaderStructure();
case Type::NETWORK: return NetworkBootloaderStructure();
}
// Default
return UsbBootloaderStructure();
}

namespace request {

enum Command : uint32_t {
Expand All @@ -37,6 +26,9 @@ namespace request {
UPDATE_FLASH_EX_2,
NO_OP,
GET_BOOTLOADER_TYPE,
SET_BOOTLOADER_CONFIG,
GET_BOOTLOADER_CONFIG,
BOOTLOADER_MEMORY,
};

struct BaseRequest {
Expand All @@ -48,12 +40,18 @@ namespace request {
struct UsbRomBoot : BaseRequest {
// Common
UsbRomBoot() : BaseRequest(USB_ROM_BOOT) {}

static constexpr auto VERSION = "0.0.2";
static constexpr const char* NAME = "UsbRomBoot";
};
struct BootApplication : BaseRequest {
// Common
BootApplication() : BaseRequest(BOOT_APPLICATION) {}

// Data

static constexpr const char* VERSION = "0.0.2";
static constexpr const char* NAME = "BootApplication";
};

struct UpdateFlash : BaseRequest {
Expand All @@ -65,6 +63,9 @@ namespace request {
Storage storage;
uint32_t totalSize;
uint32_t numPackets;

static constexpr const char* VERSION = "0.0.2";
static constexpr const char* NAME = "UpdateFlash";
};


Expand All @@ -73,15 +74,22 @@ namespace request {
GetBootloaderVersion() : BaseRequest(GET_BOOTLOADER_VERSION) {}

// Data

static constexpr const char* VERSION = "0.0.2";
static constexpr const char* NAME = "GetBootloaderVersion";
};

// 0.0.12 or higher
struct BootMemory : BaseRequest {
// Common
BootMemory() : BaseRequest(BOOT_MEMORY) {}

// Data
uint32_t totalSize;
uint32_t numPackets;

static constexpr const char* VERSION = "0.0.12";
static constexpr const char* NAME = "BootMemory";
};

// UpdateFlashEx - Additional options
Expand All @@ -94,6 +102,9 @@ namespace request {
Section section;
uint32_t totalSize;
uint32_t numPackets;

static constexpr const char* VERSION = "0.0.12";
static constexpr const char* NAME = "UpdateFlashEx";
};

// UpdateFlashEx2 - Additional options
Expand All @@ -106,6 +117,9 @@ namespace request {
uint32_t offset;
uint32_t totalSize;
uint32_t numPackets;

static constexpr const char* VERSION = "0.0.12";
static constexpr const char* NAME = "UpdateFlashEx2";
};


Expand All @@ -114,11 +128,50 @@ namespace request {
GetBootloaderType() : BaseRequest(GET_BOOTLOADER_TYPE) {}

// Data
uint32_t totalSize;
uint32_t numPackets;

static constexpr const char* VERSION = "0.0.12";
static constexpr const char* NAME = "GetBootloaderType";
};


// 0.0.14 or higher
struct SetBootloaderConfig : BaseRequest {
// Common
SetBootloaderConfig() : BaseRequest(SET_BOOTLOADER_CONFIG) {}

// Data
Memory memory = Memory::AUTO;
int64_t offset = -1;
uint32_t clearConfig = 0;
uint32_t totalSize = 0;
uint32_t numPackets = 0;

static constexpr const char* VERSION = "0.0.14";
static constexpr const char* NAME = "SetBootloaderConfig";
};

struct GetBootloaderConfig : BaseRequest {
// Common
GetBootloaderConfig() : BaseRequest(GET_BOOTLOADER_CONFIG) {}

// Data
Memory memory = Memory::AUTO;
int64_t offset = -1;
uint32_t maxSize = 0;

static constexpr const char* VERSION = "0.0.14";
static constexpr const char* NAME = "GetBootloaderConfig";
};
struct BootloaderMemory : BaseRequest {
// Common
BootloaderMemory() : BaseRequest(BOOTLOADER_MEMORY) {}

// Data

static constexpr const char* VERSION = "0.0.14";
static constexpr const char* NAME = "BootloaderMemory";
};

}


Expand All @@ -128,7 +181,10 @@ namespace response {
FLASH_COMPLETE = 0,
FLASH_STATUS_UPDATE,
BOOTLOADER_VERSION,
BOOTLOADER_TYPE
BOOTLOADER_TYPE,
GET_BOOTLOADER_CONFIG,
BOOTLOADER_MEMORY,
BOOT_APPLICATION,
};

struct BaseResponse {
Expand All @@ -144,20 +200,29 @@ namespace response {
// Data
uint32_t success;
char errorMsg[64];

static constexpr const char* VERSION = "0.0.2";
static constexpr const char* NAME = "FlashComplete";
};
struct FlashStatusUpdate : BaseResponse {
// Common
FlashStatusUpdate() : BaseResponse(FLASH_STATUS_UPDATE) {}

// Data
float progress;

static constexpr const char* VERSION = "0.0.2";
static constexpr const char* NAME = "FlashStatusUpdate";
};
struct BootloaderVersion : BaseResponse {
// Common
BootloaderVersion() : BaseResponse(BOOTLOADER_VERSION) {}

// Data
uint32_t major, minor, patch;

static constexpr const char* VERSION = "0.0.2";
static constexpr const char* NAME = "BootloaderVersion";
};

struct BootloaderType : BaseResponse {
Expand All @@ -166,8 +231,49 @@ namespace response {

// Data
Type type;

static constexpr const char* VERSION = "0.0.12";
static constexpr const char* NAME = "BootloaderType";
};


// 0.0.14
struct GetBootloaderConfig : BaseResponse {
// Common
GetBootloaderConfig() : BaseResponse(GET_BOOTLOADER_CONFIG) {}

// Data
uint32_t success;
char errorMsg[64];
uint32_t totalSize;
uint32_t numPackets;

static constexpr const char* VERSION = "0.0.14";
static constexpr const char* NAME = "GetBootloaderConfig";
};

struct BootloaderMemory : BaseResponse {
// Common
BootloaderMemory() : BaseResponse(BOOTLOADER_MEMORY) {}

// Data
Memory memory;

static constexpr const char* VERSION = "0.0.14";
static constexpr const char* NAME = "BootloaderMemory";
};

struct BootApplication : BaseResponse {
// Common
BootApplication() : BaseResponse(BOOT_APPLICATION) {}

// Data
uint32_t success;
char errorMsg[64];

static constexpr const char* VERSION = "0.0.14";
static constexpr const char* NAME = "BootApplication";
};
}

} // namespace bootloader
Expand Down
82 changes: 82 additions & 0 deletions include/depthai-bootloader-shared/Config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#pragma once

#include "Memory.hpp"

// std
#include <array>
#include <chrono>
#include <cstdint>

// libraries
#include "nlohmann/json.hpp"

#define DEPTHAI_BOOTLOADER_NLOHMANN_JSON_OPTIONAL_TO(v1) nlohmann::to_json(nlohmann_json_j[#v1], nlohmann_json_t.v1);
#define DEPTHAI_BOOTLOADER_NLOHMANN_JSON_OPTIONAL_FROM(v1) if(nlohmann_json_j.contains(#v1)) nlohmann_json_j[#v1].get_to(nlohmann_json_t.v1);

#define DEPTHAI_BOOTLOADER_NLOHMANN_DEFINE_TYPE_OPTIONAL_NON_INTRUSIVE(Type, ...) \
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DEPTHAI_BOOTLOADER_NLOHMANN_JSON_OPTIONAL_TO, __VA_ARGS__)) } \
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DEPTHAI_BOOTLOADER_NLOHMANN_JSON_OPTIONAL_FROM, __VA_ARGS__)) }

namespace dai
{
namespace bootloader
{


// Config
struct NetworkConfig {
/**
* If timeout < 0 - waits forever
* if timeout == 0 - no timeout
* if timeout > 0 - waits timeout milliseconds
*/
int timeoutMs = 30000;
// Network configuration options
// IPv4
std::uint32_t ipv4 = 0;
std::uint32_t ipv4Mask = 0;
std::uint32_t ipv4Gateway = 0;
std::uint32_t ipv4Dns = 0;
std::uint32_t ipv4DnsAlt = 0;
bool staticIpv4 = false;
// TODO(themarpe) - IPv6
std::array<uint32_t, 4> ipv6 = {};
std::uint32_t ipv6Prefix = 0;
std::array<uint32_t, 4> ipv6Gateway = {};
std::array<uint32_t, 4> ipv6Dns = {};
std::array<uint32_t, 4> ipv6DnsAlt = {};
bool staticIpv6 = false;
// MAC address - if not flashed, overwrites autogenerated one
std::array<uint8_t, 6> mac = {};
};
DEPTHAI_BOOTLOADER_NLOHMANN_DEFINE_TYPE_OPTIONAL_NON_INTRUSIVE(NetworkConfig, timeoutMs, ipv4, ipv4Mask, ipv4Gateway, ipv4Dns, ipv4DnsAlt, staticIpv4, ipv6, ipv6Prefix, ipv6Gateway, ipv6Dns, ipv6DnsAlt, staticIpv6, mac);

// Config
struct UsbConfig {
/**
* If timeout < 0 - waits forever
* if timeout == 0 - no timeout
* if timeout > 0 - waits timeout milliseconds
*/
int timeoutMs = 3000;

/**
* UNKNOWN = 0, LOW, FULL, HIGH, SUPER, SUPER_PLUS
*/
int maxUsbSpeed = 3;

/// VID/PID pair used by bootloader
uint16_t vid = 0x03E7, pid = 0xF63C;
};
DEPTHAI_BOOTLOADER_NLOHMANN_DEFINE_TYPE_OPTIONAL_NON_INTRUSIVE(UsbConfig, timeoutMs, maxUsbSpeed, vid, pid);

struct Config {
Memory appMem = Memory::AUTO;
UsbConfig usb;
NetworkConfig network;
};
DEPTHAI_BOOTLOADER_NLOHMANN_DEFINE_TYPE_OPTIONAL_NON_INTRUSIVE(Config, appMem, usb, network);

} // namespace bootloader
} // namespace dai

2 changes: 1 addition & 1 deletion include/depthai-bootloader-shared/Memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace bootloader
{

enum class Memory : std::int32_t {
FLASH, EMMC
AUTO = -1, FLASH = 0, EMMC = 1,
};

} // namespace bootloader
Expand Down
55 changes: 0 additions & 55 deletions include/depthai-bootloader-shared/NetworkBootloaderConfig.hpp

This file was deleted.

Loading