CycloneBOOT 2.6.6
Secure Bootloader for ARM Cortex-M MCU
Loading...
Searching...
No Matches
update.h
Go to the documentation of this file.
1
31#ifndef _UPDATE_H
32#define _UPDATE_H
33
34// Dependencies
35#include "boot_config.h"
36#include "core/crc32.h"
37#include "core/crypto.h"
38#include "core/flash.h"
39#include "hash/hash_algorithms.h"
40#include "image/image.h"
41#include "memory/memory.h"
42
43#include <stdint.h>
44#if ((CIPHER_SUPPORT == ENABLED) && \
45 ((IMAGE_INPUT_ENCRYPTED == ENABLED) || (IMAGE_OUTPUT_ENCRYPTED == ENABLED)))
46#include "security/cipher.h"
47#endif
48#include "core/cboot_error.h"
49#include "error.h"
50#include "core/verify.h"
51
52// CycloneBOOT Version string
53#define CYCLONE_BOOT_UPDATE_VERSION_STRING "2.6.2"
54// CycloneBOOT Major version
55#define CYCLONE_BOOT_UPDATE_MAJOR_VERSION 2
56// CycloneBOOT Minor version
57#define CYCLONE_BOOT_UPDATE_MINOR_VERSION 6
58// CycloneBOOT Revision number
59#define CYCLONE_BOOT_UPDATE_REV_NUMBER 2
60
61#define IMAGE_MAX_CHECK_DATA_SIZE 512
62
63// Update single bank internal flash memory mode support
64#ifndef UPDATE_SINGLE_BANK_SUPPORT
65#define UPDATE_SINGLE_BANK_SUPPORT DISABLED
66#elif (UPDATE_SINGLE_BANK_SUPPORT != ENABLED && UPDATE_SINGLE_BANK_SUPPORT != DISABLED)
67#error UPDATE_SINGLE_BANK_SUPPORT parameter is not valid!
68#endif
69
70// Update dual bank internal flash memory mode support
71#ifndef UPDATE_DUAL_BANK_SUPPORT
72#define UPDATE_DUAL_BANK_SUPPORT ENABLED
73#elif (UPDATE_DUAL_BANK_SUPPORT != ENABLED && UPDATE_DUAL_BANK_SUPPORT != DISABLED)
74#error UPDATE_DUAL_BANK_SUPPORT parameter is not valid!
75#endif
76
77// Update fallback support
78#ifndef UPDATE_FALLBACK_SUPPORT
79#define UPDATE_FALLBACK_SUPPORT DISABLED
80#elif (UPDATE_FALLBACK_SUPPORT != ENABLED && UPDATE_FALLBACK_SUPPORT != DISABLED)
81#error UPDATE_FALLBACK_SUPPORT parameter is not valid!
82#endif
83
84// Update automatic backup support
85#ifndef UPDATE_AUTO_BACKUP_SUPPORT
86#define UPDATE_AUTO_BACKUP_SUPPORT DISABLED
87#elif (UPDATE_AUTO_BACKUP_SUPPORT != ENABLED && UPDATE_AUTO_BACKUP_SUPPORT != DISABLED)
88#error UPDATE_AUTO_BACKUP_SUPPORT parameter is not valid!
89#endif
90
91// Update anti-rollback support
92#ifndef UPDATE_ANTI_ROLLBACK_SUPPORT
93#define UPDATE_ANTI_ROLLBACK_SUPPORT DISABLED
94#elif (UPDATE_ANTI_ROLLBACK_SUPPORT != ENABLED && UPDATE_ANTI_ROLLBACK_SUPPORT != DISABLED)
95#error UPDATE_ANTI_ROLLBACK_SUPPORT parameter is not valid!
96#endif
97
98// Acceptable internal memory mode
99#if ((UPDATE_SINGLE_BANK_SUPPORT == ENABLED && UPDATE_DUAL_BANK_SUPPORT == ENABLED) || \
100 (UPDATE_SINGLE_BANK_SUPPORT == DISABLED && UPDATE_DUAL_BANK_SUPPORT == DISABLED))
101#error Exactly one of the following parameters MUST be enabled: \
102 UPDATE_SINGLE_BANK_SUPPORT - \
103 UPDATE_DUAL_BANK_SUPPORT
104#endif
105
106// Acceptable encryption of the output image activation
107#if (((CIPHER_SUPPORT == ENABLED) && (IMAGE_OUTPUT_ENCRYPTED == ENABLED)) && \
108 (UPDATE_SINGLE_BANK_SUPPORT == DISABLED))
109#error Encryption of the output image is available only in Singel Bank mode!
110#endif
111
112// Acceptable automatic backup activation
113#if ((UPDATE_AUTO_BACKUP_SUPPORT == ENABLED) && (UPDATE_SINGLE_BANK_SUPPORT == DISABLED))
114#error Automatic backup is available only in Single Bank mode!
115#endif
116
117// Add update encryption related dependencies
118#if ((CIPHER_SUPPORT == ENABLED) && \
119 ((IMAGE_INPUT_ENCRYPTED == ENABLED) || (IMAGE_OUTPUT_ENCRYPTED == ENABLED)))
120#include "security/cipher.h"
121#endif
122
123#if (UPDATE_SINGLE_BANK_SUPPORT == ENABLED)
124#if (VERIFY_INTEGRITY_SUPPORT == DISABLED)
125// Force activation of VERIFY_INTEGRITY_SUPPORT when UPDATE_SINGLE_BANK_SUPPORT
126// is activated.
127#error Integrity support (VERIFY_INTEGRITY_SUPPORT) MUST be enabled when using CycloneBOOT in Single Bank Mode!
128#endif
129#endif
130
131// C++ guard
132#ifdef __cplusplus
133extern "C"
134{
135#endif
136
137// Forward declaration of UpdateContext structure
138struct _UpdateContext;
139#define UpdateContext struct _UpdateContext
140
145typedef cboot_error_t (*IapRandCallback)(uint8_t *data, size_t length);
146
151typedef enum
152{
153 UPDATE_AUTH_NONE,
154 UPDATE_AUTH_HMAC
156
161typedef enum
162{
163 UPDATE_SIGN_NONE,
164 UPDATE_SIGN_RSA,
165 UPDATE_SIGN_ECDSA
167
172typedef struct
173{
174#if ((CIPHER_SUPPORT == ENABLED) && \
175 ((IMAGE_INPUT_ENCRYPTED == ENABLED) || (IMAGE_OUTPUT_ENCRYPTED == ENABLED)))
176 const CipherAlgo *cipherAlgo;
177 CipherMode cipherMode;
178 const uint8_t *cipherKey;
180#endif
183
188typedef struct
189{
190#if (UPDATE_ANTI_ROLLBACK_SUPPORT == ENABLED)
191 ImageVersion appVersion;
192#endif
195#if (UPDATE_SINGLE_BANK_SUPPORT == ENABLED)
198#if (IMAGE_OUTPUT_ENCRYPTED == ENABLED)
199 // const char_t *psk; ///<PSK key used to encrypt
200 // the output image
201 const uint8_t *psk;
202 uint32_t pskSize;
203#endif
204#endif
205 Memory memories[NB_MEMORIES];
207
212typedef enum
213{
214 UPDATE_STATE_IDLE,
215 UPDATE_STATE_RECV_APP_HEADER,
216 UPDATE_STATE_RECV_APP_DATA,
217 UPDATE_STATE_RECV_APP_CHECK,
218 UPDATE_STATE_VALIDATE_APP,
219 UPDATE_STATE_APP_REBOOT,
220 UPDATE_STATE_WRITE_APP_INIT,
221 UPDATE_STATE_WRITE_APP_HEADER,
222 UPDATE_STATE_WRITE_APP_DATA,
223 UPDATE_STATE_WRITE_APP_CHECK,
224 UPDATE_STATE_WRITE_APP_END
226
232{
234 Memory memories[NB_MEMORIES];
235 ImageProcessContext imageProcessCtx;
236};
237
238// CycloneBOOT Update application related functions
240char_t *updateGetVersion(void);
242
243cboot_error_t updateInit(UpdateContext *context, UpdateSettings *settings);
244cboot_error_t updateProcess(UpdateContext *context, const void *data, size_t length);
245cboot_error_t updateFinalize(UpdateContext *context);
246cboot_error_t updateCreateBackup(UpdateContext *context);
247cboot_error_t updateReboot(UpdateContext *context);
249
250// Update acceptance callback. Declared weak; an integrator may replace it to refuse an image the
251// library accepted. Only wired when UPDATE_ANTI_ROLLBACK_SUPPORT is ENABLED.
252bool_t updateAcceptUpdateImageCallback(ImageVersion currentAppVersion,
253 ImageVersion updateAppVersion);
254
255// Extern device MCU related function
256extern uint32_t mcuGetVtorOffset(void);
257extern void mcuSystemReset(void);
258extern void mcuJumpToApplication(uint32_t address);
259
260// Random data generation callback function
261extern IapRandCallback updateRandCallback;
262
263
264#if ((defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || defined(__GNUC__) || \
265 defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) || defined(__TASKING__) || \
266 defined(__CWCC__) || defined(__TI_ARM__))
267void updateResetMcuHook(void);
268#elif ((defined(_MSC_VER) || defined(_WIN32) || defined(WIN32) || defined(WIN64) || \
269 defined(__unix__)))
270void updateResetMcuHook(void);
271#endif
272
273
274// C++ guard
275#ifdef __cplusplus
276}
277#endif
278
279#endif // !_UPDATE_H
Error codes description.
cboot_error_t
Error codes.
Definition cboot_error.h:57
CycloneBOOT Encryption & Decryption handling.
CycloneBOOT CRC32 cryptographic integrity tag.
CycloneBOOT Flash layer.
CycloneBOOT Image management.
CycloneBOOT Memory Layer Abstraction.
Image Process context definition.
Definition image.h:199
Memory Definition.
Definition memory.h:225
Update Crypto settings.
Definition update.h:173
VerifySettings verifySettings
Various crypto settings for image verification.
Definition update.h:181
CipherMode cipherMode
Image cipher mode.
Definition update.h:177
size_t cipherKeyLen
Image cipher key size.
Definition update.h:179
const uint8_t * cipherKey
Image cipher key.
Definition update.h:178
const CipherAlgo * cipherAlgo
Image cipher algorithm.
Definition update.h:176
Update user settings.
Definition update.h:189
uint32_t pskSize
Size of the PSK key used to encrypt the output image.
Definition update.h:202
UpdateCryptoSettings imageOutCrypto
Definition update.h:196
UpdateCryptoSettings imageInCrypto
Cryptographic settings used to manage an update image.
Definition update.h:194
ImageVersion appVersion
Version of the current running application.
Definition update.h:191
const uint8_t * psk
PSK key used to encrypt the output image.
Definition update.h:201
Verification settings.
Definition verify.h:157
Update context.
Definition update.h:232
UpdateSettings settings
Update user settings.
Definition update.h:233
char_t * updateGetVersion(void)
This function returns the current version of CycloneBOOT IAP.
Definition update.c:74
UpdateState
Update states.
Definition update.h:213
cboot_error_t updateRegisterRandCallback(IapRandCallback callback)
Register RNG callback function.
Definition update.c:125
cboot_error_t updateConfirm(void)
Confirm firmware update. It performs :
Definition update.c:734
cboot_error_t updateInit(UpdateContext *context, UpdateSettings *settings)
Initialize IAP Application context.
Definition update.c:145
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
cboot_error_t updateReboot(UpdateContext *context)
Reboot the device by triggering a system reset. This reboot can only be performed if firmware validat...
Definition update.c:663
bool_t updateAcceptUpdateImageCallback(ImageVersion currentAppVersion, ImageVersion updateAppVersion)
This callback checks the version of firmware application inside the received update image....
Definition update.c:756
void mcuSystemReset(void)
Reset MCU system.
Definition sam_ed_5x_mcu_driver.c:59
void updateGetDefaultSettings(UpdateSettings *settings)
Initialize settings with default values.
Definition update.c:83
UpdateSignAlgo
Supported signature algorithms.
Definition update.h:162
cboot_error_t updateFinalize(UpdateContext *context)
Finalize firmware update. It performs :
Definition update.c:371
UpdateAuthAlgo
Supported authentication algorithms.
Definition update.h:152
cboot_error_t updateCreateBackup(UpdateContext *context)
Save a copy of the running application in the spare update slot. The copy is written in the update im...
Definition update.c:537
cboot_error_t updateProcess(UpdateContext *context, const void *data, size_t length)
Write receive firmware in the unused flash bank.
Definition update.c:289
cboot_error_t(* IapRandCallback)(uint8_t *data, size_t length)
Random data generation callback function.
Definition update.h:145
CycloneBOOT Image data verification module.