31#ifndef _SECOND_STAGE_BOOT_H
32#define _SECOND_STAGE_BOOT_H
35#include "boot_config.h"
37#include "core/crypto.h"
43#define BOOT_OFFSET 0x10000
47#ifndef BOOT_FALLBACK_SUPPORT
48#define BOOT_FALLBACK_SUPPORT DISABLED
49#elif ((BOOT_FALLBACK_SUPPORT != ENABLED) && (BOOT_FALLBACK_SUPPORT != DISABLED))
50#error BOOT_FALLBACK_SUPPORT parameter is not valid
51#elif ((BOOT_FALLBACK_SUPPORT == DISABLED) && \
52 (BOOT_FALLBACK_AUTO_MODE == ENABLED || BOOT_FALLBACK_MANUAL_MODE == ENABLED))
53#error BOOT_FALLBACK_SUPPORT is DISABLED while BOOT_FALLBACK_XXX_MODE is ENABLED
57#if (BOOT_FALLBACK_SUPPORT == ENABLED && EXTERNAL_MEMORY_SUPPORT == DISABLED && \
58 NB_MAX_MEMORY_SLOTS < 3)
59#error when BOOT_FALLBACK_SUPPORT is ENABLED on internal memory, NB_MAX_MEMORY_SLOTS must be >= 3
62#if (BOOT_FALLBACK_AUTO_MODE == ENABLED)
63#if (BOOT_FLAG_SUPPORT == DISABLED && BOOT_COUNTER_SUPPORT == DISABLED)
64#error when BOOT_FALLBACK_AUTO_MODE is ENABLED, also ENABLE BOOT_FLAG_SUPPORT and/or BOOT_COUNTER_SUPPORT
66#if (BOOT_COUNTER_SUPPORT == ENABLED && BOOT_COUNTER_MAX_ATTEMPTS <= 0)
67#error invalid counter value (should be > 0)
71#if (BOOT_FALLBACK_AUTO_MODE != ENABLED)
72#if (BOOT_COUNTER_SUPPORT == ENABLED || BOOT_FLAG_SUPPORT == ENABLED)
73#error BOOT_FALLBACK_AUTO_MODE is DISABLED while BOOT_XXX_SUPPORT is ENABLED
77#if (BOOT_FALLBACK_SUPPORT == ENABLED)
78#if (BOOT_FALLBACK_AUTO_MODE == DISABLED && BOOT_FALLBACK_MANUAL_MODE == DISABLED)
79#error BOOT_FALLBACK_SUPPORT is ENABLED BOOT_FALLBACK_XXX_MODE is DISABLED
84#ifndef BOOT_ANTI_ROLLBACK_SUPPORT
85#define BOOT_ANTI_ROLLBACK_SUPPORT DISABLED
86#elif ((BOOT_ANTI_ROLLBACK_SUPPORT != ENABLED) && (BOOT_ANTI_ROLLBACK_SUPPORT != DISABLED))
87#error BOOT_ANTI_ROLLBACK_SUPPORT parameter is not valid
91#ifndef BOOT_EXT_MEM_ENCRYPTION_SUPPORT
92#define BOOT_EXT_MEM_ENCRYPTION_SUPPORT DISABLED
93#elif ((BOOT_EXT_MEM_ENCRYPTION_SUPPORT != ENABLED) && \
94 (BOOT_EXT_MEM_ENCRYPTION_SUPPORT != DISABLED))
95#error BOOT_EXT_MEM_ENCRYPTION_SUPPORT parameter is not valid
103#ifndef BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT
104#define BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT DISABLED
109#ifndef BOOT_INTEGRITY_CHECK_ALGO
110#define BOOT_INTEGRITY_CHECK_ALGO CRC32_HASH_ALGO
116#define HASH_ALGO_CRC32 CRC32_HASH_ALGO
117#define HASH_ALGO_SHA1 SHA1_HASH_ALGO
118#define HASH_ALGO_SHA224 SHA224_HASH_ALGO
119#define HASH_ALGO_SHA256 SHA256_HASH_ALGO
120#define HASH_ALGO_SHA384 SHA384_HASH_ALGO
121#define HASH_ALGO_SHA512 SHA512_HASH_ALGO
126#if (BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT != ENABLED) && (BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT != DISABLED)
127#error "BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT must be ENABLED or DISABLED"
135#ifndef BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT
136#define BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT DISABLED
142#if (BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT == ENABLED)
143#if defined(BOOT_RUNTIME_SIGNATURE_ECDSA)
145#elif defined(BOOT_RUNTIME_SIGNATURE_RSA)
148 #error "Unknown signature algorithm macro enabled."
151#if ((BOOT_RUNTIME_SIGNATURE_ECDSA == ENABLED) && (BOOT_RUNTIME_SIGNATURE_RSA == ENABLED))
152#error "BOOT_RUNTIME_SIGNATURE_ECDSA and BOOT_RUNTIME_SIGNATURE_RSA cannot be enabled at the same time"
157#if (BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT != ENABLED) && (BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT != DISABLED)
158#error "BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT must be ENABLED or DISABLED"
161#if (BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT == ENABLED) && \
162 (BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT == ENABLED)
163#error "Enable at most one of BOOT_RUNTIME_INTEGRITY_CHECK_SUPPORT / BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT: an image carries a single embedded runtime field."
181 BOOT_STATE_UPDATE_APP,
182 BOOT_STATE_FALLBACK_APP,
192#if (BOOT_EXT_MEM_ENCRYPTION_SUPPORT == ENABLED)
197#if (BOOT_RUNTIME_SIGNATURE_CHECK_SUPPORT == ENABLED)
200 Memory memories[NB_MEMORIES];
210 Memory memories[NB_MEMORIES];
211#if (BOOT_EXT_MEM_ENCRYPTION_SUPPORT == ENABLED)
217#if (BOOT_FALLBACK_SUPPORT == ENABLED)
229#if ((defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined(__GNUC__) || \
230 defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) || defined(__TASKING__) || \
231 defined(__CWCC__) || defined(__TI_ARM__))
232void bootInitHook(
void);
233void bootIdleStateHook(
void);
234void bootNoValidUpdatesHook(
void);
236void bootFallbackPerformedHook(
void);
238void bootHandleFallbackError(
void);
239void bootHandleGenericError(
void);
240#elif ((defined(_MSC_VER) || defined(_WIN32) || defined(WIN32) || defined(WIN64) || \
242extern void bootInitHook(
void);
243extern void bootIdleStateHook(
void);
244extern void bootNoValidUpdatesHook(
void);
246extern void bootFallbackPerformedHook(
void);
248extern void bootHandleFallbackError(
void);
249extern void bootHandleGenericError(
void);
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
cboot_error_t bootUpdateApp(BootContext *context, Slot *slot)
Update current application. Basically it decrypt/copy an image from the external flash memory into th...
Definition boot_common.c:647
uint32_t mcuGetVtorOffset(void)
Return mcu vector table offset.
Definition sam_ed_5x_mcu_driver.c:51
void mcuJumpToApplication(uint32_t address)
Jump to the application at the given address.
Definition sam_ed_5x_mcu_driver.c:80
void mcuSystemReset(void)
Reset MCU system.
Definition sam_ed_5x_mcu_driver.c:59
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
BootState
Standalone bootloader states definition.
Definition boot.h:189
First-stage bootloader context.
Definition boot.h:136
bool_t fallbackAttempted
A fallback already failed during this boot.
Definition boot.h:218
size_t pskSize
Cipher PSK key size.
Definition boot.h:213
BootState state
Bootloader state.
Definition boot.h:208
BootSettings settings
Bootloader user settings.
Definition boot.h:209
First-stage bootloader user settings.
Definition boot.h:118
size_t pskSize
Secondary flash slot cipher key size.
Definition boot.h:195
VerifySettings verifySettings
Runtime verification of the resident image.
Definition boot.h:198
const char_t * psk
Secondary flash slot cipher key.
Definition boot.h:194
Memory Definition.
Definition memory.h:225
Slot Type definition.
Definition memory.h:181
Verification settings.
Definition verify.h:157
CycloneBOOT Image data verification module.