diff --git a/include/depthai-bootloader-shared/Bootloader.hpp b/include/depthai-bootloader-shared/Bootloader.hpp index 9e99782..dd56737 100644 --- a/include/depthai-bootloader-shared/Bootloader.hpp +++ b/include/depthai-bootloader-shared/Bootloader.hpp @@ -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 { @@ -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 { @@ -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 { @@ -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"; }; @@ -73,8 +74,12 @@ 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) {} @@ -82,6 +87,9 @@ namespace request { // Data uint32_t totalSize; uint32_t numPackets; + + static constexpr const char* VERSION = "0.0.12"; + static constexpr const char* NAME = "BootMemory"; }; // UpdateFlashEx - Additional options @@ -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 @@ -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"; }; @@ -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"; + }; + } @@ -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 { @@ -144,6 +200,9 @@ 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 @@ -151,6 +210,9 @@ namespace response { // Data float progress; + + static constexpr const char* VERSION = "0.0.2"; + static constexpr const char* NAME = "FlashStatusUpdate"; }; struct BootloaderVersion : BaseResponse { // Common @@ -158,6 +220,9 @@ namespace response { // Data uint32_t major, minor, patch; + + static constexpr const char* VERSION = "0.0.2"; + static constexpr const char* NAME = "BootloaderVersion"; }; struct BootloaderType : BaseResponse { @@ -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 diff --git a/include/depthai-bootloader-shared/Config.hpp b/include/depthai-bootloader-shared/Config.hpp new file mode 100644 index 0000000..00a1571 --- /dev/null +++ b/include/depthai-bootloader-shared/Config.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include "Memory.hpp" + +// std +#include +#include +#include + +// 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 ipv6 = {}; + std::uint32_t ipv6Prefix = 0; + std::array ipv6Gateway = {}; + std::array ipv6Dns = {}; + std::array ipv6DnsAlt = {}; + bool staticIpv6 = false; + // MAC address - if not flashed, overwrites autogenerated one + std::array 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 + diff --git a/include/depthai-bootloader-shared/Memory.hpp b/include/depthai-bootloader-shared/Memory.hpp index 57e8990..bbe435a 100644 --- a/include/depthai-bootloader-shared/Memory.hpp +++ b/include/depthai-bootloader-shared/Memory.hpp @@ -9,7 +9,7 @@ namespace bootloader { enum class Memory : std::int32_t { - FLASH, EMMC + AUTO = -1, FLASH = 0, EMMC = 1, }; } // namespace bootloader diff --git a/include/depthai-bootloader-shared/NetworkBootloaderConfig.hpp b/include/depthai-bootloader-shared/NetworkBootloaderConfig.hpp deleted file mode 100644 index eccc99c..0000000 --- a/include/depthai-bootloader-shared/NetworkBootloaderConfig.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -// std -#include -#include - -// project -#include "Structure.hpp" - -namespace dai -{ -namespace bootloader -{ - -// Config -/* TODO(themarpe) -struct NetworkBootloaderConfig { - char ip[16]; - char subnetMask[16]; - char gateway[16]; -}; -*/ - - -// Structure -struct NetworkBootloaderStructure : Structure { - - constexpr static long HEADER_OFFSET = 0; - constexpr static long HEADER_SIZE = 512; - constexpr static long CONFIG_SIZE = 16 * 1024; - constexpr static long BOOTLOADER_OFFSET = HEADER_OFFSET + HEADER_SIZE; - constexpr static long BOOTLOADER_SIZE = 8 * 1024 * 1024 - CONFIG_SIZE; - constexpr static long CONFIG_OFFSET = BOOTLOADER_OFFSET + BOOTLOADER_SIZE; - constexpr static long APPLICATION_OFFSET = CONFIG_OFFSET + CONFIG_SIZE; - - NetworkBootloaderStructure() : Structure({ - {Section::HEADER, HEADER_OFFSET}, - {Section::BOOTLOADER_CONFIG, CONFIG_OFFSET}, - {Section::BOOTLOADER, BOOTLOADER_OFFSET}, - {Section::APPLICATION, APPLICATION_OFFSET}, - }, { - {Section::HEADER, HEADER_SIZE}, - {Section::BOOTLOADER_CONFIG, CONFIG_SIZE}, - {Section::BOOTLOADER, BOOTLOADER_SIZE}, - {Section::APPLICATION, 0}, - }) {} - -}; - -static const NetworkBootloaderStructure networkBootloaderStructure; - -} // namespace bootloader -} // namespace dai - - diff --git a/include/depthai-bootloader-shared/SBR.h b/include/depthai-bootloader-shared/SBR.h index ad51b10..7e90f17 100644 --- a/include/depthai-bootloader-shared/SBR.h +++ b/include/depthai-bootloader-shared/SBR.h @@ -12,9 +12,15 @@ extern "C" { #define SBR_SECTION_NAME_MAX_SIZE (16) #define SBR_IDENTIFIER_SIZE (2) -#define SBR_SECTION_FLAG_BOOTABLE (0x1) -#define SBR_SECTION_FLAG_IGNORE_CHECKSUM (0x2) - +#define SBR_SECTION_FLAG_BOOTABLE (1 << 0) +#define SBR_SECTION_FLAG_IGNORE_CHECKSUM (1 << 1) +#define SBR_SECTION_FLAG_COMPRESSION_MASK (0x7 << 2) +typedef enum { + SBR_NO_COMPRESSION = 0U << 2, + SBR_COMPRESSION_ZLIB = 1U << 2, + SBR_COMPRESSION_GZ = 2U << 2, + SBR_COMPRESSION_XZ = 3U << 2, +} SBR_COMPRESSION; static const uint8_t SBR_IDENTIFIER[SBR_IDENTIFIER_SIZE] = {'B', 'R'}; @@ -62,10 +68,12 @@ void sbr_section_set_checksum(SBR_SECTION* sbr_section, uint32_t checksum); void sbr_section_set_type(SBR_SECTION* sbr_section, uint8_t type); void sbr_section_set_bootable(SBR_SECTION* sbr_section, bool bootable); void sbr_section_set_ignore_checksum(SBR_SECTION* sbr_section, bool ignore_checksum); +void sbr_section_set_compression(SBR_SECTION* sbr_section, SBR_COMPRESSION compression); bool sbr_section_get_bootable(const SBR_SECTION* sbr_section); bool sbr_section_get_ignore_checksum(const SBR_SECTION* sbr_section); bool sbr_section_is_valid(const SBR_SECTION* sbr_section); +SBR_COMPRESSION sbr_section_get_compression(const SBR_SECTION* sbr_section); #ifdef __cplusplus } diff --git a/include/depthai-bootloader-shared/Section.hpp b/include/depthai-bootloader-shared/Section.hpp index 0292313..32fc7dd 100644 --- a/include/depthai-bootloader-shared/Section.hpp +++ b/include/depthai-bootloader-shared/Section.hpp @@ -9,7 +9,7 @@ namespace bootloader { enum class Section : std::int32_t { - HEADER, BOOTLOADER, BOOTLOADER_CONFIG, APPLICATION + AUTO = -1, HEADER = 0, BOOTLOADER = 1, BOOTLOADER_CONFIG = 2, APPLICATION = 3 }; } // namespace bootloader diff --git a/include/depthai-bootloader-shared/Structure.hpp b/include/depthai-bootloader-shared/Structure.hpp index d558b01..0b729bb 100644 --- a/include/depthai-bootloader-shared/Structure.hpp +++ b/include/depthai-bootloader-shared/Structure.hpp @@ -2,9 +2,11 @@ // std #include +#include // project #include "Section.hpp" +#include "Type.hpp" namespace dai { @@ -19,6 +21,66 @@ struct Structure { Structure(decltype(offset) a, decltype(size) b) : offset(a), size(b) {} }; +// Structure +struct NetworkBootloaderStructure : Structure { + + constexpr static long HEADER_OFFSET = 0; + constexpr static long HEADER_SIZE = 512; + constexpr static long CONFIG_SIZE = 16 * 1024; + constexpr static long BOOTLOADER_OFFSET = HEADER_OFFSET + HEADER_SIZE; + constexpr static long BOOTLOADER_SIZE = 8 * 1024 * 1024 - CONFIG_SIZE - HEADER_SIZE; + constexpr static long CONFIG_OFFSET = BOOTLOADER_OFFSET + BOOTLOADER_SIZE; + constexpr static long APPLICATION_OFFSET = CONFIG_OFFSET + CONFIG_SIZE; + + NetworkBootloaderStructure() : Structure({ + {Section::HEADER, HEADER_OFFSET}, + {Section::BOOTLOADER_CONFIG, CONFIG_OFFSET}, + {Section::BOOTLOADER, BOOTLOADER_OFFSET}, + {Section::APPLICATION, APPLICATION_OFFSET}, + }, { + {Section::HEADER, HEADER_SIZE}, + {Section::BOOTLOADER_CONFIG, CONFIG_SIZE}, + {Section::BOOTLOADER, BOOTLOADER_SIZE}, + {Section::APPLICATION, 0}, + }) {} + +}; + +// Structure +struct UsbBootloaderStructure : Structure { + + constexpr static long HEADER_OFFSET = 0; + constexpr static long HEADER_SIZE = 512; + constexpr static long CONFIG_SIZE = 16 * 1024; + constexpr static long BOOTLOADER_OFFSET = HEADER_OFFSET + HEADER_SIZE; + constexpr static long BOOTLOADER_SIZE = 1 * 1024 * 1024 - CONFIG_SIZE - HEADER_SIZE; + constexpr static long CONFIG_OFFSET = BOOTLOADER_OFFSET + BOOTLOADER_SIZE; + constexpr static long APPLICATION_OFFSET = CONFIG_OFFSET + CONFIG_SIZE; + + UsbBootloaderStructure() : Structure({ + {Section::HEADER, HEADER_OFFSET}, + {Section::BOOTLOADER_CONFIG, CONFIG_OFFSET}, + {Section::BOOTLOADER, BOOTLOADER_OFFSET}, + {Section::APPLICATION, APPLICATION_OFFSET}, + }, { + {Section::HEADER, HEADER_SIZE}, + {Section::BOOTLOADER_CONFIG, CONFIG_SIZE}, + {Section::BOOTLOADER, BOOTLOADER_SIZE}, + {Section::APPLICATION, 0}, + }) {} + +}; + +inline const Structure getStructure(Type type){ + switch(type){ + case Type::AUTO: throw std::invalid_argument("Invalid argument to getStructure function"); + case Type::USB: return UsbBootloaderStructure(); + case Type::NETWORK: return NetworkBootloaderStructure(); + } + // Default + return UsbBootloaderStructure(); +} + } // namespace bootloader } // namespace dai diff --git a/include/depthai-bootloader-shared/Type.hpp b/include/depthai-bootloader-shared/Type.hpp index a4d462c..adeead7 100644 --- a/include/depthai-bootloader-shared/Type.hpp +++ b/include/depthai-bootloader-shared/Type.hpp @@ -9,7 +9,7 @@ namespace bootloader { enum class Type : std::int32_t { - USB, NETWORK + AUTO = -1, USB = 0, NETWORK = 1 }; } // namespace bootloader diff --git a/include/depthai-bootloader-shared/UsbBootloaderConfig.hpp b/include/depthai-bootloader-shared/UsbBootloaderConfig.hpp deleted file mode 100644 index 193f68a..0000000 --- a/include/depthai-bootloader-shared/UsbBootloaderConfig.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -// std -#include -#include -#include - -// project -#include "Structure.hpp" - -namespace dai -{ -namespace bootloader -{ - -// Config -struct UsbBootloaderConfig { - /** - * If timeout < 0 - waits forever - * if timeout == 0 - no timeout - * if timeout > 0 - waits timeout milliseconds - */ - std::int32_t timeoutMs = -1; -}; - - -// Structure -struct UsbBootloaderStructure : Structure { - - constexpr static long HEADER_OFFSET = 0; - constexpr static long HEADER_SIZE = 512; - constexpr static long CONFIG_SIZE = 16 * 1024; - constexpr static long BOOTLOADER_OFFSET = HEADER_OFFSET + HEADER_SIZE; - constexpr static long BOOTLOADER_SIZE = 1 * 1024 * 1024 - CONFIG_SIZE; - constexpr static long CONFIG_OFFSET = BOOTLOADER_OFFSET + BOOTLOADER_SIZE; - constexpr static long APPLICATION_OFFSET = CONFIG_OFFSET + CONFIG_SIZE; - - UsbBootloaderStructure() : Structure({ - {Section::HEADER, HEADER_OFFSET}, - {Section::BOOTLOADER_CONFIG, CONFIG_OFFSET}, - {Section::BOOTLOADER, BOOTLOADER_OFFSET}, - {Section::APPLICATION, APPLICATION_OFFSET}, - }, { - {Section::HEADER, HEADER_SIZE}, - {Section::BOOTLOADER_CONFIG, CONFIG_SIZE}, - {Section::BOOTLOADER, BOOTLOADER_SIZE}, - {Section::APPLICATION, 0}, - }) {} - -}; - -} // namespace bootloader -} // namespace dai - - - diff --git a/src/Bootloader.cpp b/src/Bootloader.cpp new file mode 100644 index 0000000..16a399f --- /dev/null +++ b/src/Bootloader.cpp @@ -0,0 +1,49 @@ +#include "depthai-bootloader-shared/Bootloader.hpp" + +namespace dai { +namespace bootloader { + +// Bootloader.hpp definitions + +// Requests +decltype(request::UsbRomBoot::VERSION) constexpr request::UsbRomBoot::VERSION; +decltype(request::UsbRomBoot::NAME) constexpr request::UsbRomBoot::NAME; +decltype(request::BootApplication::VERSION) constexpr request::BootApplication::VERSION; +decltype(request::BootApplication::NAME) constexpr request::BootApplication::NAME; +decltype(request::UpdateFlash::VERSION) constexpr request::UpdateFlash::VERSION; +decltype(request::UpdateFlash::NAME) constexpr request::UpdateFlash::NAME; +decltype(request::GetBootloaderVersion::VERSION) constexpr request::GetBootloaderVersion::VERSION; +decltype(request::GetBootloaderVersion::NAME) constexpr request::GetBootloaderVersion::NAME; +decltype(request::BootMemory::VERSION) constexpr request::BootMemory::VERSION; +decltype(request::BootMemory::NAME) constexpr request::BootMemory::NAME; +decltype(request::UpdateFlashEx::VERSION) constexpr request::UpdateFlashEx::VERSION; +decltype(request::UpdateFlashEx::NAME) constexpr request::UpdateFlashEx::NAME; +decltype(request::UpdateFlashEx2::VERSION) constexpr request::UpdateFlashEx2::VERSION; +decltype(request::UpdateFlashEx2::NAME) constexpr request::UpdateFlashEx2::NAME; +decltype(request::GetBootloaderType::VERSION) constexpr request::GetBootloaderType::VERSION; +decltype(request::GetBootloaderType::NAME) constexpr request::GetBootloaderType::NAME; +decltype(request::SetBootloaderConfig::VERSION) constexpr request::SetBootloaderConfig::VERSION; +decltype(request::SetBootloaderConfig::NAME) constexpr request::SetBootloaderConfig::NAME; +decltype(request::GetBootloaderConfig::VERSION) constexpr request::GetBootloaderConfig::VERSION; +decltype(request::GetBootloaderConfig::NAME) constexpr request::GetBootloaderConfig::NAME; +decltype(request::BootloaderMemory::VERSION) constexpr request::BootloaderMemory::VERSION; +decltype(request::BootloaderMemory::NAME) constexpr request::BootloaderMemory::NAME; + +// Responses +decltype(response::FlashComplete::VERSION) constexpr response::FlashComplete::VERSION; +decltype(response::FlashComplete::NAME) constexpr response::FlashComplete::NAME; +decltype(response::FlashStatusUpdate::VERSION) constexpr response::FlashStatusUpdate::VERSION; +decltype(response::FlashStatusUpdate::NAME) constexpr response::FlashStatusUpdate::NAME; +decltype(response::BootloaderVersion::VERSION) constexpr response::BootloaderVersion::VERSION; +decltype(response::BootloaderVersion::NAME) constexpr response::BootloaderVersion::NAME; +decltype(response::BootloaderType::VERSION) constexpr response::BootloaderType::VERSION; +decltype(response::BootloaderType::NAME) constexpr response::BootloaderType::NAME; +decltype(response::GetBootloaderConfig::VERSION) constexpr response::GetBootloaderConfig::VERSION; +decltype(response::GetBootloaderConfig::NAME) constexpr response::GetBootloaderConfig::NAME; +decltype(response::BootloaderMemory::VERSION) constexpr response::BootloaderMemory::VERSION; +decltype(response::BootloaderMemory::NAME) constexpr response::BootloaderMemory::NAME; +decltype(response::BootApplication::VERSION) constexpr response::BootApplication::VERSION; +decltype(response::BootApplication::NAME) constexpr response::BootApplication::NAME; + +} // namespace bootloader +} // namespace dai \ No newline at end of file diff --git a/src/SBR.c b/src/SBR.c index c55e0ba..2602db6 100644 --- a/src/SBR.c +++ b/src/SBR.c @@ -137,6 +137,11 @@ bool sbr_section_get_ignore_checksum(const SBR_SECTION* sbr_section) { return false; } +SBR_COMPRESSION sbr_section_get_compression(const SBR_SECTION* sbr_section) { + if(sbr_section == NULL) return SBR_NO_COMPRESSION; + return sbr_section->flags & SBR_SECTION_FLAG_COMPRESSION_MASK; +} + bool sbr_section_is_valid(const SBR_SECTION* sbr_section) { // Valid SBR section must have a name set, as well as a non zero size if(sbr_section->name[0] == 0 || ((uint8_t)sbr_section->name[0]) == 0xFF) { @@ -206,3 +211,13 @@ void sbr_section_set_ignore_checksum(SBR_SECTION* sbr_section, bool ignore_check sbr_section->flags &= ~SBR_SECTION_FLAG_IGNORE_CHECKSUM; } } + +void sbr_section_set_compression(SBR_SECTION* sbr_section, SBR_COMPRESSION compression) { + assert(sbr_section != NULL); + + // Clear previous compression + sbr_section->flags &= ~SBR_SECTION_FLAG_COMPRESSION_MASK; + + // Set new compression + sbr_section->flags |= compression; +}