Files
templates/c/set-protocol/include/set_firmware.h

98 lines
2.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Кодирование метаданных и сообщений обновления SETProtocol v2. Размер образа, совместимость и
* параметры начала передачи передаются явно; сериализация команды сама по себе не выполняет
* запись Flash.
*/
#ifndef SET_FIRMWARE_H
#define SET_FIRMWARE_H
#include "set_protocol.h"
#ifdef __cplusplus
extern "C" {
#endif
#define SETP_SHA256_SIZE 32U
#define SETP_FW_BEGIN_FIXED_SIZE 58U
#define SETP_FW_DATA_HEADER_SIZE 12U
#define SETP_FW_END_SIZE 40U
#define SETP_FW_STATUS_SIZE 16U
#define SETP_FW_MANIFEST_SIZE 57U
#define SETP_FW_FLAG_RESUME 0x01U
#define SETP_FW_FLAG_SIGNED 0x02U
#define SETP_FW_FLAG_ERASE_SLOT 0x04U
#define SETP_FW_FLAG_ACTIVATE 0x08U
typedef enum {
SETP_FW_IDLE = 0,
SETP_FW_RECEIVING = 1,
SETP_FW_VERIFYING = 2,
SETP_FW_READY = 3,
SETP_FW_ACTIVE = 4,
SETP_FW_FAILED = 5
} setp_fw_state_t;
typedef struct {
uint32_t image_size;
uint32_t image_crc32;
uint32_t image_version;
uint32_t base_address;
uint8_t slot;
uint8_t flags;
uint16_t block_size;
uint8_t sha256[SETP_SHA256_SIZE];
uint32_t signing_key_id;
uint16_t signature_length;
const uint8_t *signature;
} setp_fw_begin_t;
typedef struct {
uint32_t offset;
uint16_t data_length;
uint16_t flags;
uint32_t data_crc32;
const uint8_t *data;
} setp_fw_data_t;
typedef struct {
uint32_t image_size;
uint32_t image_crc32;
uint8_t sha256[SETP_SHA256_SIZE];
} setp_fw_end_t;
typedef struct {
uint8_t state;
uint8_t active_slot;
uint16_t max_block_size;
uint32_t next_offset;
uint32_t image_size;
uint16_t last_error;
uint16_t flags;
} setp_fw_status_t;
size_t setp_fw_begin_encode(const setp_fw_begin_t *value, uint8_t *out, size_t capacity);
bool setp_fw_begin_decode(const uint8_t *payload, uint16_t length, setp_fw_begin_t *out);
size_t setp_fw_data_encode(uint32_t offset, uint16_t flags,
const uint8_t *data, uint16_t data_length,
uint8_t *out, size_t capacity);
bool setp_fw_data_decode(const uint8_t *payload, uint16_t length, setp_fw_data_t *out);
size_t setp_fw_end_encode(const setp_fw_end_t *value, uint8_t *out, size_t capacity);
bool setp_fw_end_decode(const uint8_t *payload, uint16_t length, setp_fw_end_t *out);
size_t setp_fw_status_encode(const setp_fw_status_t *value, uint8_t *out, size_t capacity);
bool setp_fw_status_decode(const uint8_t *payload, uint16_t length, setp_fw_status_t *out);
/** Canonical bytes verified by a firmware-signature backend. */
size_t setp_fw_manifest_encode(const setp_fw_begin_t *value,
uint8_t *out, size_t capacity);
#ifdef __cplusplus
}
#endif
#endif /* SET_FIRMWARE_H */