36#include "boot_config.h"
43#define BOOT_MBX_VERSION (uint32_t) 0x00010001
46#define BOOT_MBX_SIGNATURE 0x1b241671
51 UPDATE_REQUESTED = 1 << 0,
52 UPDATE_PERFORMED = 1 << 1,
53 UPDATE_CONFIRMED = 1 << 2,
54 FALLBACK_REQUESTED = 1 << 3,
55 FALLBACK_PERFORMED = 1 << 4,
56 FALLBACK_AVAILABLE = 1 << 5,
57 REPAIR_PERFORMED = 1 << 6
61#define BOOT_MBX_NVM_MAGIC 0xBEEF
62#define BOOT_MBX_NVM_FLAG_UPDATE_REQUESTED 0xF00D
63#define BOOT_MBX_NVM_FLAG_UPDATE_PERFORMED 0xC0DE
64#define BOOT_MBX_NVM_FLAG_UPDATE_CONFIRMED 0xFEED
65#define BOOT_MBX_NVM_FLAG_FALLBACK_REQUESTED 0xB105
66#define BOOT_MBX_NVM_FLAG_FALLBACK_PERFORMED 0xDEAD
67#define BOOT_MBX_NVM_FLAG_FALLBACK_AVAILABLE 0x0BAC
68#define BOOT_MBX_NVM_FLAG_REPAIR_PERFORMED 0xB007
71#define BOOT_MBX_PSK_MAX_SIZE 32
75 #define BOOT_MBX_PACK_BEGIN __pragma(pack(push, 1))
76 #define BOOT_MBX_PACK_END __pragma(pack(pop))
77 #define BOOT_MBX_PACK_ATTR
78#elif defined(__GNUC__) || defined(__clang__) || defined(__ARMCC_VERSION) || \
79 defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) || defined(__TASKING__)
80 #define BOOT_MBX_PACK_BEGIN
81 #define BOOT_MBX_PACK_END
82 #define BOOT_MBX_PACK_ATTR __attribute__((packed))
84 #define BOOT_MBX_PACK_BEGIN
85 #define BOOT_MBX_PACK_END
86 #define BOOT_MBX_PACK_ATTR
98 uint8_t psk[BOOT_MBX_PSK_MAX_SIZE];
103 uint8_t reserved[64];
109#if defined(__cplusplus) && (__cplusplus >= 201103L)
110 #define BOOT_MBX_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
111#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
112 #define BOOT_MBX_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
114 #define BOOT_MBX_STATIC_ASSERT_CAT_(a, b) a ## b
115 #define BOOT_MBX_STATIC_ASSERT_CAT(a, b) BOOT_MBX_STATIC_ASSERT_CAT_(a, b)
116 #define BOOT_MBX_STATIC_ASSERT(cond, msg) \
117 typedef char BOOT_MBX_STATIC_ASSERT_CAT(boot_mbx_static_assert_, __LINE__)[(cond) ? 1 : -1]
121BOOT_MBX_STATIC_ASSERT(
sizeof(BootMailBox) == 132,
"BootMailBox RAM layout changed (must stay 132 bytes)");
122BOOT_MBX_STATIC_ASSERT(offsetof(BootMailBox, version) == 0,
"BootMailBox.version offset changed");
123BOOT_MBX_STATIC_ASSERT(offsetof(BootMailBox, signature) == 4,
"BootMailBox.signature offset changed");
124BOOT_MBX_STATIC_ASSERT(offsetof(BootMailBox, pskSize) == 8,
"BootMailBox.pskSize offset changed");
125BOOT_MBX_STATIC_ASSERT(offsetof(BootMailBox, psk) == 12,
"BootMailBox.psk offset changed");
126BOOT_MBX_STATIC_ASSERT(offsetof(BootMailBox, flags) == 44,
"BootMailBox.flags offset changed");
127BOOT_MBX_STATIC_ASSERT(offsetof(BootMailBox, boot_counter) == 48,
"BootMailBox.boot_counter offset changed");
128BOOT_MBX_STATIC_ASSERT(offsetof(BootMailBox, fsbVersion) == 52,
"BootMailBox.fsbVersion offset changed");
129BOOT_MBX_STATIC_ASSERT(offsetof(BootMailBox, ssbVersion) == 60,
"BootMailBox.ssbVersion offset changed");
130BOOT_MBX_STATIC_ASSERT(offsetof(BootMailBox, reserved) == 68,
"BootMailBox.reserved offset changed");
175#if ((defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined(__GNUC__) || \
176 defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) || defined(__TASKING__) || \
177 defined(__CWCC__) || defined(__TI_ARM__))
180bool_t mbx_get_nvm_flag(uint32_t flag);
181#elif ((defined(_MSC_VER) || defined(_WIN32) || defined(WIN32) || defined(WIN64) || \
184extern cboot_error_t mbx_set_nvm_flag(uint32_t flag, bool_t value);
185extern bool_t mbx_get_nvm_flag(uint32_t flag);
cboot_error_t
Error codes.
Definition cboot_error.h:57
bool_t mailBoxIsUpdatePerformed(void)
Checks whether UPDATE_PERFORMED message is present in the mailbox.
Definition mailbox.c:194
bool_t mailBoxIsUpdateConfirmed(void)
Checks whether UPDATE_CONFIRMED message is present in the mailbox.
Definition mailbox.c:210
void mailBoxSetFallbackAvailable(bool_t state)
Posts FALLBACK_AVAILABLE message to the mailbox.
Definition mailbox.c:268
void mailBoxSetFallbackPerformed(bool_t state)
Posts FALLBACK_PERFORMED message to the mailbox.
Definition mailbox.c:250
bool_t mailBoxIsUpdateRequested(void)
Checks whether UPDATE_REQUESTED message is present in the mailbox.
Definition mailbox.c:178
void mailBoxSetFallbackRequested(bool_t state)
Posts FALLBACK_REQUESTED message to the mailbox.
Definition mailbox.c:234
void mailBoxSetFirstStageVersion(const ImageVersion *version)
Publish the first-stage version for later stages (HDP/HDPL-safe).
Definition mailbox.c:292
void mailBoxClearBootCounter(void)
Clears the current value of the boot counter in the mailbox.
Definition mailbox.c:343
void mailBoxSetPsk(const uint8_t *psk, size_t pskSize)
Set Pre-Shared Key value of the mailbox.
Definition mailbox.c:352
bool_t mailBoxIsFallbackPerformed(void)
Checks whether FALLBACK_PERFORMED message is present in the mailbox.
Definition mailbox.c:242
void mailBoxSetSecondStageVersion(const ImageVersion *version)
Publish the second-stage version for the application to read.
Definition mailbox.c:310
bool_t mailBoxIsRepairPerformed(void)
Tells whether the bootloader already reinstalled a candidate to repair the application.
Definition mailbox.c:276
const ImageVersion * mailBoxGetFirstStageVersion(void)
Get the first-stage version published in the mailbox.
Definition mailbox.c:302
void mailBoxSetRepairPerformed(bool_t state)
Posts REPAIR_PERFORMED message to the mailbox.
Definition mailbox.c:284
cboot_error_t mailBoxInit(void)
Initializes the shared bootloader mailbox if signature is not valid. The NVM flag storage is initiali...
Definition mailbox.c:151
void mailBoxSetUpdatePerformed(bool_t state)
Posts UPDATE_PERFORMED message to the mailbox.
Definition mailbox.c:202
void mailBoxClearPsk(void)
Clear the Pre-Shared Key from the mailbox.
Definition mailbox.c:389
void mailBoxGetPsk(uint8_t *psk, size_t *pskSize)
Returns a copy of Pre-Shared Key value of the mailbox.
Definition mailbox.c:373
bool_t mailBoxIsFallbackAvailable(void)
Checks whether a fall back to a previous firmware is possible.
Definition mailbox.c:260
void mailBoxSetUpdateRequested(bool_t state)
Posts UPDATE_REQUESTED message to the mailbox.
Definition mailbox.c:186
bool_t mailBoxIsFallbackRequested(void)
Checks whether FALLBACK_REQUESTED message is present in the mailbox.
Definition mailbox.c:226
void mailBoxIncrementBootCounter(void)
Increments the boot counter in the mailbox.
Definition mailbox.c:329
uint32_t mailBoxGetBootCounter(void)
Returns the current value of the boot counter in the mailbox.
Definition mailbox.c:336
const ImageVersion * mailBoxGetSecondStageVersion(void)
Get the second-stage version published in the mailbox.
Definition mailbox.c:320
void mailBoxSetUpdateConfirmed(bool_t state)
Posts UPDATE_REQUESTED message to the mailbox.
Definition mailbox.c:218
Bootloader shared RAM mailbox structure.
Definition mailbox.h:94
uint32_t version
Bootloader Mailbox version.
Definition mailbox.h:95
ImageVersion fsbVersion
First-stage version, published forward by the 1st stage.
Definition mailbox.h:101
uint32_t signature
Bootloader Mailbox signature.
Definition mailbox.h:96
ImageVersion ssbVersion
Second-stage version, published forward by the 2nd stage.
Definition mailbox.h:102
uint32_t boot_counter
Bootloader Mailbox boot counter.
Definition mailbox.h:100
uint32_t pskSize
Bootloader Mailbox PSK size.
Definition mailbox.h:97
uint32_t flags
Bootloader Mailbox event flags.
Definition mailbox.h:99