MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mcci_bootloader.h
Go to the documentation of this file.
1/*
2
3Module: mcci_bootloader.h
4
5Function:
6 Main header file for MCCI bootloader for STM32L0
7
8Copyright notice:
9 This file copyright (C) 2020, 2026 by
10
11 MCCI Corporation
12 3520 Krums Corners Road
13 Ithaca, NY 14850
14
15 An unpublished work. All rights reserved.
16
17 This file is proprietary information, and may not be disclosed or
18 copied without the prior permission of MCCI Corporation.
19
20Author:
21 Terry Moore, MCCI Corporation July 2020
22
23*/
24
25#ifndef _MCCI_BOOTLOADER_H_ /* prevent multiple includes */
26#define _MCCI_BOOTLOADER_H_
27
28#ifndef _MCCI_BOOTLOADER_TYPES_H_
30#endif
31
32#ifndef _mcci_tweetnacl_sign_h_
33# include "mcci_tweetnacl_sign.h"
34#endif
35
37␌
38/****************************************************************************\
39|
40| Boot error codes
41|
42\****************************************************************************/
43
45 {
46 McciBootloaderError_OK = 0, ///< successful
47 McciBootloaderError_BootloaderNotValid, ///< bootloader image isn't valid
48 McciBootloaderError_ResetClockNotValid, ///< post-reset clock not valid
49 McciBootloaderError_NoAppImage, ///< app image not valid, no fallback available.
51 McciBootloaderError_ReadFailed, ///< storage read failed during program
52 McciBootloaderError_FlashWriteFailed, ///< flash write failed during programming
53 McciBootloaderError_FlashVerifyFailed, ///< flash verify failed after programming
54 McciBootloaderError_FlashNotFound, ///< flash didn't reply properly to SFDP
55 McciBootloaderError_FlashNotSupported, ///< flash SFDP contents are prior to JESD216B, or otherwise not suitable.
56 McciBootloaderError_InternalConsistency, ///< an internal consistency check failed.
57 McciBootloaderError_I2cBegin, ///< I2c bus failed begin.
58 McciBootloaderError_PmicProbeFailed, ///< failed to probe PMIC.
59 McciBootloaderError_PmicInitFailed, ///< failed to initialize PMIC.
60 McciBootloaderError_StoragePowerUpFailed, ///< failed to initialize storage power.
61 McciBootloaderError_StoragePowerDownFailed, ///< failed to turn off storage power.
62 };
63// typedef uint32_t McciBootloaderError_t; -- in mcci_bootloader_types.h.
64
76
77/****************************************************************************\
78|
79| Parameters from link script
80|
81\****************************************************************************/
82
83/// \brief base address of the bootloader in flash (linker-defined).
84extern const uint8_t gk_McciBootloader_BootBase[];
85/// \brief first address past end of the bootloader in flash (linker-defined).
86extern const uint8_t gk_McciBootloader_BootTop[];
87/// \brief bootloader image size in bytes (linker-computed integer; use as
88/// \c (uint32_t) \c &gk_McciBootloader_ImageSize[0] to get the value).
89extern const uint8_t gk_McciBootloader_ImageSize[];
90
91/// \brief base address of the application region in flash (linker-defined).
92extern const uint8_t gk_McciBootloader_AppBase[];
93/// \brief first address past end of the application region (linker-defined).
94extern const uint8_t gk_McciBootloader_AppTop[];
95/// \brief base address of the manufacturing data region in flash (linker-defined).
96extern const uint8_t gk_McciBootloader_MfgBase[];
97/// \brief first address past end of the manufacturing data region (linker-defined).
98extern const uint8_t gk_McciBootloader_MfgTop[];
99
100/// \brief base address of the SoC RAM (linker-defined).
101extern uint8_t g_McciBootloader_SocRamBase[];
102/// \brief first address past end of the SoC RAM (linker-defined).
103extern uint8_t g_McciBootloader_SocRamTop[];
104
105/// \brief address in flash of the initializer data for the .data section (linker-defined).
106extern const uint8_t gk_McciBootloader_DataImageBase[];
107/// \brief base address of the .data section in RAM (linker-defined).
108extern uint8_t g_McciBootloader_DataBase[];
109/// \brief first address past end of the .data section in RAM (linker-defined).
110extern uint8_t g_McciBootloader_DataTop[];
111/// \brief base address of the .bss section in RAM (linker-defined).
112extern uint8_t g_McciBootloader_BssBase[];
113/// \brief first address past end of the .bss section in RAM (linker-defined).
114extern uint8_t g_McciBootloader_BssTop[];
115/// \brief initial stack pointer value (top of stack, linker-defined).
116extern uint8_t g_McciBootloader_StackTop[];
117
118/****************************************************************************\
119|
120| Various utilities
121|
122\****************************************************************************/
123␌
124/*
125
126Name: McciBootloader_codeSize()
127
128Function:
129 Return size of code region given pointers
130
131Definition:
132 size_t McciBootloader_codeSize(
133 const void *base,
134 const void *top
135 );
136
137Description:
138 `base` points to the first byte in the region; `top`
139 points one byte past the last byte in the region. The result is the number
140 of bytes in the region. Note that a zero-size region
141 is indicated by top being equal to base (as a uint8_t),
142 and it's not possible to represent a region that's larger
143 than SIZE_MAX.
144
145Returns:
146 Number of bytes in region.
147
148Notes:
149 The result can't represent the entire address space.
150
151*/
152
153static inline
154size_t McciBootloader_codeSize(const void *base, const void *top)
155 {
156 return (const uint8_t *)top - (const uint8_t *)base;
157 }
158
159/****************************************************************************\
160|
161| APIs
162|
163\****************************************************************************/
164
165void
167
168bool
170 const void *pBase,
171 size_t numBytes
172 );
173
174bool
177 McciBootloader_AppInfo_t *pAppInfo,
178 const mcci_tweetnacl_sign_publickey_t *pPublicKey
179 );
180
184 const McciBootloader_AppInfo_t *pAppInfo
185 );
186
187extern uint8_t g_McciBootloader_imageBlock[4096];
188
190
191#endif /* _MCCI_BOOTLOADER_H_ */
uint8_t g_McciBootloader_BssBase[]
base address of the .bss section in RAM (linker-defined).
uint8_t g_McciBootloader_SocRamBase[]
base address of the SoC RAM (linker-defined).
uint8_t g_McciBootloader_DataBase[]
base address of the .data section in RAM (linker-defined).
const uint8_t gk_McciBootloader_MfgTop[]
first address past end of the manufacturing data region (linker-defined).
bool McciBootloader_checkStorageImage(McciBootloaderStorageAddress_t address, McciBootloader_AppInfo_t *pAppInfo, const mcci_tweetnacl_sign_publickey_t *pPublicKey)
const uint8_t gk_McciBootloader_AppTop[]
first address past end of the application region (linker-defined).
uint8_t g_McciBootloader_BssTop[]
first address past end of the .bss section in RAM (linker-defined).
const uint8_t gk_McciBootloader_DataImageBase[]
address in flash of the initializer data for the .data section (linker-defined).
const uint8_t gk_McciBootloader_BootBase[]
base address of the bootloader in flash (linker-defined).
const uint8_t gk_McciBootloader_MfgBase[]
base address of the manufacturing data region in flash (linker-defined).
uint8_t g_McciBootloader_imageBlock[4096]
bool McciBootloader_checkCodeValid(const void *pBase, size_t numBytes)
const uint8_t gk_McciBootloader_ImageSize[]
bootloader image size in bytes (linker-computed integer; use as (uint32_t) &gk_McciBootloader_ImageSi...
McciBootloaderState_e
@ McciBootloaderState_CheckingFallbackStorageHash
@ McciBootloaderState_WritingApp
@ McciBootloaderState_ErasingApp
@ McciBootloaderState_CheckingPrimaryStorageSignature
@ McciBootloaderState_CheckingFallbackStorageSignature
@ McciBootloaderState_CheckingPrimaryStorageHash
@ McciBootloaderState_Initial
initial state when annunciator launched
@ McciBootloaderState_CheckingApp
McciBootloaderError_t McciBootloader_programAndCheckFlash(McciBootloaderStorageAddress_t address, const McciBootloader_AppInfo_t *pAppInfo)
static size_t McciBootloader_codeSize(const void *base, const void *top)
const uint8_t gk_McciBootloader_BootTop[]
first address past end of the bootloader in flash (linker-defined).
const uint8_t gk_McciBootloader_AppBase[]
base address of the application region in flash (linker-defined).
uint8_t g_McciBootloader_SocRamTop[]
first address past end of the SoC RAM (linker-defined).
uint8_t g_McciBootloader_DataTop[]
first address past end of the .data section in RAM (linker-defined).
void McciBootloader_main(void)
McciBootloaderError_e
@ McciBootloaderError_I2cBegin
I2c bus failed begin.
@ McciBootloaderError_StoragePowerDownFailed
failed to turn off storage power.
@ McciBootloaderError_FlashNotFound
flash didn't reply properly to SFDP
@ McciBootloaderError_FlashWriteFailed
flash write failed during programming
@ McciBootloaderError_NoAppImage
app image not valid, no fallback available.
@ McciBootloaderError_ReadFailed
storage read failed during program
@ McciBootloaderError_InternalConsistency
an internal consistency check failed.
@ McciBootloaderError_OK
successful
@ McciBootloaderError_StoragePowerUpFailed
failed to initialize storage power.
@ McciBootloaderError_FlashVerifyFailed
flash verify failed after programming
@ McciBootloaderError_EraseFailed
erase failed
@ McciBootloaderError_FlashNotSupported
flash SFDP contents are prior to JESD216B, or otherwise not suitable.
@ McciBootloaderError_ResetClockNotValid
post-reset clock not valid
@ McciBootloaderError_PmicProbeFailed
failed to probe PMIC.
@ McciBootloaderError_BootloaderNotValid
bootloader image isn't valid
@ McciBootloaderError_PmicInitFailed
failed to initialize PMIC.
uint8_t g_McciBootloader_StackTop[]
initial stack pointer value (top of stack, linker-defined).
#define MCCI_BOOTLOADER_BEGIN_DECLS
#define MCCI_BOOTLOADER_END_DECLS
uint32_t McciBootloaderError_t
error codes for the bootloader
uint32_t McciBootloaderStorageAddress_t
Abstract type for storage byte addresses.