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