CycloneBOOT 2.6.6
Secure Bootloader for ARM Cortex-M MCU
Loading...
Searching...
No Matches
boot.h
Go to the documentation of this file.
1
31#ifndef _STANDALONE_BOOT_H
32#define _STANDALONE_BOOT_H
33
34// Dependencies
35#include "boot_config.h"
36#include "core/cboot_error.h"
37#include "core/verify.h"
39#include "os_port.h"
43#include "update/update.h"
44
45// Runtime signature check before boot
46#ifndef BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT
47#define BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT DISABLED
48#elif ((BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT != ENABLED) && \
49 (BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT != DISABLED))
50#error BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT parameter is not valid
51#endif
52
53#if (BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT == ENABLED)
54#if (BOOT_RUNTIME_SIGNATURE_ECDSA != ENABLED) && (BOOT_RUNTIME_SIGNATURE_RSA != ENABLED)
55#error BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT is ENABLED but no signature algorithm is selected
56#endif
57#endif
58
59// Runtime integrity check before boot
60#ifndef BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT
61#define BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT DISABLED
62#elif ((BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT != ENABLED) && \
63 (BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT != DISABLED))
64#error BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT parameter is not valid
65#endif
66
67#if (BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT == ENABLED) && \
68 (BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT == ENABLED)
69#error Enable at most one of BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT and BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT
70#endif
71
72// Update entry triggers
73#ifndef BOOT_TRIGGER_MAILBOX
74#define BOOT_TRIGGER_MAILBOX DISABLED
75#endif
76#ifndef BOOT_TRIGGER_WINDOW
77#define BOOT_TRIGGER_WINDOW DISABLED
78#endif
79#ifndef BOOT_TRIGGER_GPIO
80#define BOOT_TRIGGER_GPIO ENABLED
81#endif
82#ifndef BOOT_TRIGGER_NO_APP
83#define BOOT_TRIGGER_NO_APP DISABLED
84#endif
85#ifndef BOOT_TRIGGER_RESET_CAUSE
86#define BOOT_TRIGGER_RESET_CAUSE DISABLED
87#endif
88
89#if (BOOT_TRIGGER_MAILBOX == DISABLED) && (BOOT_TRIGGER_WINDOW == DISABLED) && \
90 (BOOT_TRIGGER_GPIO == DISABLED) && (BOOT_TRIGGER_NO_APP == DISABLED) && \
91 (BOOT_TRIGGER_RESET_CAUSE == DISABLED)
92#error at least one BOOT_TRIGGER_XXX must be ENABLED
93#endif
94
95#ifndef BOOT_TRIGGER_WINDOW_MS
96#define BOOT_TRIGGER_WINDOW_MS 10000
97#elif (BOOT_TRIGGER_WINDOW_MS <= 0)
98#error BOOT_TRIGGER_WINDOW_MS must be greater than 0
99#endif
100
101// Transport receive buffer size
102#ifndef BOOT_RECV_BUFFER_SIZE
103#define BOOT_RECV_BUFFER_SIZE 512
104#elif (BOOT_RECV_BUFFER_SIZE < 64)
105#error BOOT_RECV_BUFFER_SIZE must be at least 64
106#endif
107
108// Enable recovery support
109#ifndef BOOT_RECOVERY_SUPPORT
110#define BOOT_RECOVERY_SUPPORT DISABLED
111#elif ((BOOT_RECOVERY_SUPPORT != ENABLED) && (BOOT_RECOVERY_SUPPORT != DISABLED))
112#error BOOT_RECOVERY_SUPPORT parameter is not valid
113#endif
114
115#ifndef BOOT_RECOVERY_AUTO_MODE
116#define BOOT_RECOVERY_AUTO_MODE DISABLED
117#elif ((BOOT_RECOVERY_AUTO_MODE != ENABLED) && (BOOT_RECOVERY_AUTO_MODE != DISABLED))
118#error BOOT_RECOVERY_AUTO_MODE parameter is not valid
119#endif
120
121#ifndef BOOT_RECOVERY_MANUAL_MODE
122#define BOOT_RECOVERY_MANUAL_MODE DISABLED
123#elif ((BOOT_RECOVERY_MANUAL_MODE != ENABLED) && (BOOT_RECOVERY_MANUAL_MODE != DISABLED))
124#error BOOT_RECOVERY_MANUAL_MODE parameter is not valid
125#endif
126
127#if ((BOOT_RECOVERY_SUPPORT == DISABLED) && \
128 (BOOT_RECOVERY_AUTO_MODE == ENABLED || BOOT_RECOVERY_MANUAL_MODE == ENABLED))
129#error BOOT_RECOVERY_SUPPORT is DISABLED while BOOT_RECOVERY_XXX_MODE is ENABLED
130#endif
131
132#ifndef BOOT_COUNTER_SUPPORT
133#define BOOT_COUNTER_SUPPORT DISABLED
134#elif ((BOOT_COUNTER_SUPPORT != ENABLED) && (BOOT_COUNTER_SUPPORT != DISABLED))
135#error BOOT_COUNTER_SUPPORT parameter is not valid
136#endif
137
138#ifndef BOOT_COUNTER_MAX_ATTEMPTS
139#define BOOT_COUNTER_MAX_ATTEMPTS 3
140#elif (BOOT_COUNTER_MAX_ATTEMPTS <= 0)
141#error BOOT_COUNTER_MAX_ATTEMPTS must be greater than 0
142#endif
143
144#ifndef BOOT_FLAG_SUPPORT
145#define BOOT_FLAG_SUPPORT DISABLED
146#elif ((BOOT_FLAG_SUPPORT != ENABLED) && (BOOT_FLAG_SUPPORT != DISABLED))
147#error BOOT_FLAG_SUPPORT parameter is not valid
148#endif
149
150#if (BOOT_RECOVERY_AUTO_MODE == ENABLED)
151#if (BOOT_FLAG_SUPPORT == DISABLED && BOOT_COUNTER_SUPPORT == DISABLED)
152#error when BOOT_RECOVERY_AUTO_MODE is ENABLED, also ENABLE BOOT_FLAG_SUPPORT and/or BOOT_COUNTER_SUPPORT
153#endif
154#if (BOOT_COUNTER_SUPPORT == ENABLED && BOOT_COUNTER_MAX_ATTEMPTS <= 0)
155#error invalid counter value (should be > 0)
156#endif
157#endif
158
159#if (BOOT_RECOVERY_AUTO_MODE == DISABLED)
160#if (BOOT_COUNTER_SUPPORT == ENABLED || BOOT_FLAG_SUPPORT == ENABLED)
161#error BOOT_RECOVERY_AUTO_MODE is DISABLED while BOOT_XXX_SUPPORT is ENABLED
162#endif
163#endif
164
165#if (BOOT_RECOVERY_SUPPORT == ENABLED)
166#if (BOOT_RECOVERY_AUTO_MODE == DISABLED && BOOT_RECOVERY_MANUAL_MODE == DISABLED)
167#error BOOT_RECOVERY_SUPPORT is ENABLED while BOOT_RECOVERY_XXX_MODE is DISABLED
168#endif
169#endif
170
171#ifndef BOOT_FACTORY_SLOT_SUPPORT
172#define BOOT_FACTORY_SLOT_SUPPORT DISABLED
173#elif ((BOOT_FACTORY_SLOT_SUPPORT != ENABLED) && \
174 (BOOT_FACTORY_SLOT_SUPPORT != DISABLED))
175#error BOOT_FACTORY_SLOT_SUPPORT parameter is not valid
176#endif
177
178// C++ guard
179#ifdef __cplusplus
180extern "C"
181{
182#endif
183
188typedef enum
189{
190 BOOT_STATE_INIT = 0,
191 BOOT_STATE_TRIGGER,
192 BOOT_STATE_CHECK_RESIDENT,
193 BOOT_STATE_LISTEN,
194 BOOT_STATE_RECV,
195 BOOT_STATE_INSTALL,
196 BOOT_STATE_RECOVER,
197 BOOT_STATE_BOOT,
198 BOOT_STATE_RESET,
199 BOOT_STATE_ERROR
200} BootState;
201
206typedef struct
207{
209#if (BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT == ENABLED)
210 VerifySettings verifySettings;
211#endif
214
219typedef struct
220{
221 BootState state;
222 BootSettings settings;
223 bool_t busy;
224 UpdateContext updateContext;
226#if (BOOT_FACTORY_SLOT_SUPPORT == ENABLED)
228#endif
230 systime_t windowStart;
233
234// Bootloader related functions
238
240
241#if ((defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined(__GNUC__) || \
242 defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) || defined(__TASKING__) || \
243 defined(__CWCC__) || defined(__TI_ARM__))
246#elif ((defined(_MSC_VER) || defined(_WIN32) || defined(WIN32) || defined(WIN64) || \
247 defined(__unix__)))
248extern void bootApplicationUpdatedHook(void);
249extern void bootJumpingToApplicationHook(void);
250#endif
251
252// C++ guard
253#ifdef __cplusplus
254}
255#endif
256#endif //_STANDALONE_BOOT_H
CycloneBOOT standalone bootloader recovery.
RecoveryReason
Reason recovery was entered.
Definition boot_recovery.h:50
CycloneBOOT standalone bootloader update entry triggers.
Error codes description.
cboot_error_t
Error codes.
Definition cboot_error.h:57
cboot_error_t bootFsm(BootContext *context)
Bootloader Task routine.
Definition boot.c:233
cboot_error_t bootInit(BootContext *context, BootSettings *settings)
Initialize the first-stage bootloader context from user settings.
Definition boot.c:131
void bootGetDefaultSettings(BootSettings *settings)
Initialize first-stage bootloader settings with default values.
Definition boot.c:55
CycloneBOOT Memory Layer Abstraction.
BootState
Bootloader States definition.
Definition boot.h:178
__weak_func void bootJumpingToApplicationHook(void)
Pre-jump callback. It is declared weak and may be replaced in the user code space....
Definition boot.c:691
__weak_func void bootApplicationUpdatedHook(void)
Application updated callback. It is declared weak and may be replaced in the user code space....
Definition boot.c:676
cboot_error_t bootCheckResidentImage(const Slot *slot)
Checks the resident image before it is booted. This is a security gate, not a seam: it is deliberatel...
Definition boot.c:634
First-stage bootloader context.
Definition boot.h:136
RecoveryReason recoveryReason
Reason recovery was entered.
Definition boot.h:231
systime_t windowStart
Start of the listen window.
Definition boot.h:230
UpdateContext updateContext
Install path context.
Definition boot.h:224
UpdateEntryRequest entry
Arbitrated update entry request.
Definition boot.h:229
Slot * appSlot
Slot the application is booted from.
Definition boot.h:225
Slot * factorySlot
Slot holding the factory image.
Definition boot.h:227
First-stage bootloader user settings.
Definition boot.h:118
UpdateSettings update
Memory map and install path.
Definition boot.h:212
const UpdateTransport * transport
Protocol the bootloader receives an update over.
Definition boot.h:208
Slot Type definition.
Definition memory.h:181
Update entry request.
Definition boot_trigger.h:65
Update user settings.
Definition update.h:189
Update Transport definition.
Definition update_transport.h:85
Verification settings.
Definition verify.h:157
CycloneBOOT IAP User API.
Update transport interface.
CycloneBOOT Image data verification module.