92 lines
2.5 KiB
C
92 lines
2.5 KiB
C
#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 */
|