35#include "boot_config.h"
36#include "compiler_port.h"
39#include "core/crypto.h"
65#ifndef GPL_LICENSE_TERMS_ACCEPTED
66 #error Before compiling CycloneBOOT Open, you must accept the terms of the GPL license
70#ifndef IMAGE_INPUT_ENCRYPTED
71#define IMAGE_INPUT_ENCRYPTED DISABLED
72#elif (IMAGE_INPUT_ENCRYPTED != ENABLED && IMAGE_INPUT_ENCRYPTED != DISABLED)
73#error IMAGE_INPUT_ENCRYPTED parameter is not valid!
77#ifndef IMAGE_OUTPUT_ENCRYPTED
78#define IMAGE_OUTPUT_ENCRYPTED DISABLED
79#elif (IMAGE_OUTPUT_ENCRYPTED != ENABLED && IMAGE_OUTPUT_ENCRYPTED != DISABLED)
80#error IMAGE_OUTPUT_ENCRYPTED parameter is not valid!
84#if (((IMAGE_OUTPUT_ENCRYPTED == ENABLED) || (IMAGE_INPUT_ENCRYPTED == ENABLED)) && \
85 (CIPHER_SUPPORT == DISABLED))
86#error CIPHER_SUPPORT MUST be ENABLED if IMAGE_INPUT_ENCRYPTED or IMAGE_OUTPUT_ENCRYPTED is enabled!
90#if (CIPHER_SUPPORT == ENABLED) && \
91 ((IMAGE_INPUT_ENCRYPTED == ENABLED) || (IMAGE_OUTPUT_ENCRYPTED == ENABLED))
96#define IMAGE_MAX_CHECK_DATA_SIZE 512
105 IMAGE_STATE_RECV_APP_HEADER,
106 IMAGE_STATE_RECV_APP_DATA,
107 IMAGE_STATE_RECV_APP_CHECK,
108 IMAGE_STATE_VALIDATE_APP,
109 IMAGE_STATE_APP_REBOOT,
110 IMAGE_STATE_WRITE_APP_INIT,
111 IMAGE_STATE_WRITE_APP_HEADER,
112 IMAGE_STATE_WRITE_APP_DATA,
113 IMAGE_STATE_WRITE_APP_CHECK,
114 IMAGE_STATE_WRITE_APP_END
124 IMAGE_VERSION_SUPERIOR,
125 IMAGE_VERSION_INFERIOR
129#define IMAGE_HEADER_VERSION_MAJOR 1
131#define IMAGE_HEADER_VERSION_MINOR 3
133#define IMAGE_HEADER_VERSION_PATCH 0
137#define IMAGE_HEADER_VERSION \
138 (uint32_t)(((IMAGE_HEADER_VERSION_MAJOR & 0xFF) << 16) | \
139 ((IMAGE_HEADER_VERSION_MINOR & 0xFF) << 8) | (IMAGE_HEADER_VERSION_PATCH & 0xFF))
142#define IMAGE_HEADER_VERSION_GET_MAJOR(version) (((version) >> 16) & 0xFF)
143#define IMAGE_HEADER_VERSION_GET_MINOR(version) (((version) >> 8) & 0xFF)
144#define IMAGE_HEADER_VERSION_GET_PATCH(version) ((version) & 0xFF)
170#if ((CIPHER_SUPPORT == ENABLED) && \
171 ((IMAGE_INPUT_ENCRYPTED == ENABLED) || (IMAGE_OUTPUT_ENCRYPTED == ENABLED)))
174 uint32_t magicNumberCrc;
175 bool_t magicNumberCrcRetrieved;
180 uint8_t checkData[IMAGE_MAX_CHECK_DATA_SIZE];
192 ImageVersion updateAppVersion);
218bool_t
imageFitsSlot(
const ImageHeader *header,
size_t slotSize);
cboot_error_t
Error codes.
Definition cboot_error.h:57
CycloneBOOT Encryption & Decryption handling.
cboot_error_t imageGetHeader(uint8_t *buffer, size_t bufferLen, ImageHeader **header)
Get image header from data buffer.
Definition image.c:173
bool_t(* ImageAntiRollbackCallback)(ImageVersion currentAppVersion, ImageVersion updateAppVersion)
Image Anti-Rollback callback definition.
Definition image.h:191
bool_t imageSafeAdd32(uint32_t a, uint32_t b, uint32_t *sum)
Overflow-safe addition of two 32-bit image geometry values.
Definition image.c:72
ImageState
Image states.
Definition image.h:103
cboot_error_t imageCheckIntegrity(Image *image)
Verifies the complete image integrity.
Definition image.c:232
cboot_error_t imageCheckHeader(ImageHeader *header)
Check Internal Image header validity.
Definition image.c:130
bool_t imageIsBootImage(const ImageHeader *header)
Check whether an image holds a bootloader.
Definition image.c:112
ImageVersionComparisonFlag
Image version comparison flags definition.
Definition image.h:122
bool_t imageFitsSlot(const ImageHeader *header, size_t slotSize)
Check that an image (header, data and CRC32 tag) fits in a slot.
Definition image.c:92
cboot_error_t imageComputeHeaderCrc(ImageHeader *header)
Compute image header crc and store it in the image header crc field. The given input header will also...
Definition image.c:208
CycloneBOOT Memory Layer Abstraction.
Cipher engine structure definition.
Definition cipher.h:64
Image Process context definition.
Definition image.h:199
ImageVersion currentAppVersion
Current Application version.
Definition image.h:203
ImageVersion currentBootVersion
Current Bootloader version.
Definition image.h:204
Memory * memories
Memories list.
Definition image.h:207
Image inputImage
Input Image context.
Definition image.h:200
Image outputImage
Output Image context.
Definition image.h:201
ImageAntiRollbackCallback imgAntiRollbackCallback
Anti-Rollback callback.
Definition image.h:205
Image context definition.
Definition image.h:153
VerifyContext verifyContext
Image verification context.
Definition image.h:178
Slot * activeSlot
Pointer to the slot to write the image in.
Definition image.h:158
uint32_t newBootImageIdx
Image index number used for a bootloader image.
Definition image.h:161
CipherEngine cipherEngine
Image cipher engine.
Definition image.h:172
uint8_t * checkDataPos
Position in image check data buffer.
Definition image.h:181
size_t checkDataSize
Image check data buffer size.
Definition image.h:183
size_t firmwareLength
Image data firmware length.
Definition image.h:164
uint8_t * bufferPos
Position in image processing buffer.
Definition image.h:155
uint32_t firmwareAddr
Image firmware data write address.
Definition image.h:163
uint32_t newImageIdx
Image index number.
Definition image.h:160
size_t checkDataLen
Current number of byte in image check data buffer.
Definition image.h:182
size_t written
Current written firmware data byte number.
Definition image.h:166
size_t bufferLen
Number of byte in image processing buffer.
Definition image.h:156
uint32_t pos
Image current firmware data write position.
Definition image.h:165
Memory Definition.
Definition memory.h:225
Slot Type definition.
Definition memory.h:181
Verification context.
Definition verify.h:181
CycloneBOOT Image data verification module.