MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mcci_bootloader_platform.h
Go to the documentation of this file.
1/*
2
3Module: mcci_bootloader_platform.h
4
5Function:
6 Definitions for the platform API
7
8Copyright and License:
9 This file copyright (C) 2021 by
10
11 MCCI Corporation
12 3520 Krums Corners Road
13 Ithaca, NY 14850
14
15 See accompanying LICENSE file for copyright and license information.
16
17Author:
18 fullname, MCCI Corporation March 2021
19
20*/
21
22#ifndef _mcci_bootloader_platform_h_
23#define _mcci_bootloader_platform_h_ /* prevent multiple includes */
24
25#pragma once
26
27#ifndef _mcci_bootloader_platform_types_h_
29#endif
30
32
33/// \brief interface for storage
41
47
53
54/// \brief interface structure to platform functions
56 {
57 McciBootloaderPlatform_SystemInitFn_t *pSystemInit; ///< System init provider function
59 McciBootloaderPlatform_FailFn_t *pFail; ///< Stop the boot, due to a failure
60 McciBootloaderPlatform_DelayMsFn_t *pDelayMs; ///< Delay execution some number of milliseconds
61 McciBootloaderPlatform_GetUpdateFlagFn_t *pGetUpdate; ///< Find out whether firmware update was requested
62 McciBootloaderPlatform_SetUpdateFlagFn_t *pSetUpdate; ///< Set value of firmware-update flag
65 McciBootloaderPlatform_StorageInterface_t Storage;
66 McciBootloaderPlatform_SpiInterface_t Spi;
67 McciBootloaderPlatform_AnnunciatorInterface_t Annunciator;
68 };
69
70extern const McciBootloaderPlatform_Interface_t
72
73static inline void
78
79static inline void
84
85static inline bool
90
91static inline void
93 {
94 (*gk_McciBootloaderPlatformInterface.pSetUpdate)(fUpdate);
95 }
96
97static inline bool
99 volatile const void *targetAddress,
100 size_t targetSize
101 )
102 {
103 return (*gk_McciBootloaderPlatformInterface.pSystemFlashErase)(
104 targetAddress,
105 targetSize
106 );
107 }
108
109static inline bool
111 volatile const void *pDestination,
112 const void *pSource,
113 size_t nBytes
114 )
115 {
116 return (*gk_McciBootloaderPlatformInterface.pSystemFlashWrite)(
117 pDestination,
118 pSource,
119 nBytes
120 );
121 }
122
123void
126 McciBootloaderError_t errorCode
128
129static inline void
131 uint32_t ms
132 )
133 {
135 }
136
137static inline void
142
143static inline bool
146 uint8_t *pBuffer,
147 size_t nBuffer
148 )
149 {
150 return (*gk_McciBootloaderPlatformInterface.Storage.pRead)(
151 hAddress,
152 pBuffer,
153 nBuffer
154 );
155 }
156
159 {
160 return (*gk_McciBootloaderPlatformInterface.Storage.pGetPrimaryAddress)();
161 }
162
165 {
166 return (*gk_McciBootloaderPlatformInterface.Storage.pGetFallbackAddress)();
167 }
168
169static inline void
174
175static inline void
177 uint8_t *pRx,
178 const uint8_t *pTx,
179 size_t nBytes,
180 bool fContinue
181 )
182 {
183 (*gk_McciBootloaderPlatformInterface.Spi.pTransfer)(
184 pRx, pTx, nBytes, fContinue
185 );
186 }
187
188static inline void
193
194static inline void
197 )
198 {
199 (*gk_McciBootloaderPlatformInterface.Annunciator.pIndicateState)(state);
200 }
201
202void
204
206void
208 const void *pAppBase
210
211const McciBootloader_AppInfo_t *
213 const void *pHeader,
214 size_t nHeader,
215 uintptr_t targetAddress,
216 size_t targetSize
217 );
218
219const McciBootloader_AppInfo_t *
221 const void *pHeader,
222 size_t nHeader
223 );
224
225const McciBootloader_SignatureBlock_t *
227 const McciBootloader_AppInfo_t *
228 );
229
231
232#endif /* _mcci_bootloader_platform_h_ */
MCCI_BOOTLOADER_NORETURN_PFX void McciBootloaderPlatform_startApp(const void *pAppBase) MCCI_BOOTLOADER_NORETURN_SFX
static void McciBootloaderPlatform_storageInit(void)
static McciBootloaderStorageAddress_t McciBootloaderPlatform_getPrimaryStorageAddress(void)
static bool McciBootloaderPlatform_systemFlashWrite(volatile const void *pDestination, const void *pSource, size_t nBytes)
static McciBootloaderStorageAddress_t McciBootloaderPlatform_getFallbackStorageAddress(void)
void MCCI_BOOTLOADER_NORETURN_PFX McciBootloaderPlatform_fail(McciBootloaderError_t errorCode) MCCI_BOOTLOADER_NORETURN_SFX
static void McciBootloaderPlatform_systemInit(void)
static bool McciBootloaderPlatform_getUpdateFlag(void)
static void McciBootloaderPlatform_annunciatorIndicateState(McciBootloaderState_t state)
static void McciBootloaderPlatform_setUpdateFlag(bool fUpdate)
const McciBootloader_AppInfo_t * McciBootloaderPlatform_getAppInfo(const void *pHeader, size_t nHeader)
static void McciBootloaderPlatform_prepareForLaunch(void)
static void McciBootloaderPlatform_delayMs(uint32_t ms)
static bool McciBootloaderPlatform_systemFlashErase(volatile const void *targetAddress, size_t targetSize)
const McciBootloaderPlatform_Interface_t gk_McciBootloaderPlatformInterface
static bool McciBootloaderPlatform_storageRead(McciBootloaderStorageAddress_t hAddress, uint8_t *pBuffer, size_t nBuffer)
const McciBootloader_AppInfo_t * McciBootloaderPlatform_checkImageValid(const void *pHeader, size_t nHeader, uintptr_t targetAddress, size_t targetSize)
static void McciBootloaderPlatform_annunciatorInit(void)
static void McciBootloaderPlatform_spiTransfer(uint8_t *pRx, const uint8_t *pTx, size_t nBytes, bool fContinue)
const McciBootloader_SignatureBlock_t * McciBootloaderPlatform_getSignatureBlock(const McciBootloader_AppInfo_t *)
void McciBootloaderPlatform_entry(void)
static void McciBootloaderPlatform_spiInit(void)
void() McciBootloaderPlatform_FailFn_t(McciBootloaderError_t errorCode)
function for reporting a fatal error
bool() McciBootloaderPlatform_SystemFlashEraseFn_t(volatile const void *targetAddress, size_t targetSize)
Erase a region of internal flash.
void() McciBootloaderPlatform_StorageInitFn_t(void)
Initialize the storage driver.
bool() McciBootloaderPlatform_SystemFlashWriteFn_t(volatile const void *pDestination, const void *pSource, size_t nBytes)
Program a chunk of internal flash.
McciBootloaderStorageAddress_t() McciBootloaderPlatform_GetPrimaryStorageAddressFn_t(void)
get the start address of the primary image in the storage
bool() McciBootloaderPlatform_StorageReadFn_t(McciBootloaderStorageAddress_t startAddress, uint8_t *pBuffer, size_t nBuffer)
Read bytes from the storage.
MCCI_BOOTLOADER_BEGIN_DECLS typedef void() McciBootloaderPlatform_SystemInitFn_t(void)
function type for platform intialization function
bool() McciBootloaderPlatform_GetUpdateFlagFn_t(void)
Get the "update flag".
void() McciBootloaderPlatform_SetUpdateFlagFn_t(bool state)
Set the "update flag".
void() McciBootloaderPlatform_SpiTransferFn_t(uint8_t *pRx, const uint8_t *pTx, size_t nBytes, bool fContinue)
send/receive data over the SPI bus
void() McciBootloaderPlatform_AnnunciatorInitFn_t(void)
Initialize the annuciator system.
void() McciBootloaderPlatform_DelayMsFn_t(uint32_t ms)
delay execution
void() McciBootloaderPlatform_SpiInitFn_t(void)
initialize the SPI driver for storage use
void() McciBootloaderPlatform_PrepareForLaunchFn_t(void)
function type for preparing to launch an application
void() McciBootloaderPlatform_AnnunciatorIndicateStateFn_t(McciBootloaderState_t state)
Indicate the current state.
McciBootloaderStorageAddress_t() McciBootloaderPlatform_GetFallbackStorageAddressFn_t(void)
get the start address of the fallback image in the storage
#define MCCI_BOOTLOADER_BEGIN_DECLS
#define MCCI_BOOTLOADER_NORETURN_SFX
#define MCCI_BOOTLOADER_END_DECLS
uint32_t McciBootloaderState_t
Current boot system state.
uint32_t McciBootloaderError_t
error codes for the bootloader
#define MCCI_BOOTLOADER_NORETURN_PFX
uint32_t McciBootloaderStorageAddress_t
Abstract type for storage byte addresses.
McciBootloaderPlatform_AnnunciatorIndicateStateFn_t * pIndicateState
record the current state
McciBootloaderPlatform_AnnunciatorInitFn_t * pInit
initialize the annunciator system
interface structure to platform functions
McciBootloaderPlatform_SystemInitFn_t * pSystemInit
System init provider function.
McciBootloaderPlatform_DelayMsFn_t * pDelayMs
Delay execution some number of milliseconds.
McciBootloaderPlatform_PrepareForLaunchFn_t * pPrepareForLaunch
Prepare to launch application.
McciBootloaderPlatform_StorageInterface_t Storage
McciBootloaderPlatform_SystemFlashWriteFn_t * pSystemFlashWrite
Write block to flash.
McciBootloaderPlatform_GetUpdateFlagFn_t * pGetUpdate
Find out whether firmware update was requested.
McciBootloaderPlatform_SpiInterface_t Spi
McciBootloaderPlatform_SystemFlashEraseFn_t * pSystemFlashErase
Erase flash.
McciBootloaderPlatform_FailFn_t * pFail
Stop the boot, due to a failure.
McciBootloaderPlatform_SetUpdateFlagFn_t * pSetUpdate
Set value of firmware-update flag.
McciBootloaderPlatform_AnnunciatorInterface_t Annunciator
McciBootloaderPlatform_SpiInitFn_t * pInit
Initialize SPI.
McciBootloaderPlatform_SpiTransferFn_t * pTransfer
do a SPI write/read.
McciBootloaderPlatform_GetFallbackStorageAddressFn_t * pGetFallbackAddress
Get address of fall-back firmware region.
McciBootloaderPlatform_GetPrimaryStorageAddressFn_t * pGetPrimaryAddress
Get address of primary firmware region.
McciBootloaderPlatform_StorageReadFn_t * pRead
Read from storage.
McciBootloaderPlatform_StorageInitFn_t * pInit
Initialize storage.