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_GetMillisecondsFn_t *pGetMilliseconds; ///< Get the millisecond tick count.
62 McciBootloaderPlatform_GetUpdateFlagFn_t *pGetUpdate; ///< Find out whether firmware update was requested
63 McciBootloaderPlatform_SetUpdateFlagFn_t *pSetUpdate; ///< Set value of firmware-update flag
66 McciBootloaderPlatform_StorageInterface_t Storage;
67 McciBootloaderPlatform_SpiInterface_t Spi;
68 McciBootloaderPlatform_AnnunciatorInterface_t Annunciator;
69 };
70
71extern const McciBootloaderPlatform_Interface_t
73
74static inline void
79
80static inline void
85
86static inline bool
91
92static inline void
94 {
95 (*gk_McciBootloaderPlatformInterface.pSetUpdate)(fUpdate);
96 }
97
98static inline bool
100 volatile const void *targetAddress,
101 size_t targetSize
102 )
103 {
104 return (*gk_McciBootloaderPlatformInterface.pSystemFlashErase)(
105 targetAddress,
106 targetSize
107 );
108 }
109
110static inline bool
112 volatile const void *pDestination,
113 const void *pSource,
114 size_t nBytes
115 )
116 {
117 return (*gk_McciBootloaderPlatformInterface.pSystemFlashWrite)(
118 pDestination,
119 pSource,
120 nBytes
121 );
122 }
123
124void
127 McciBootloaderError_t errorCode
129
130static inline void
132 uint32_t ms
133 )
134 {
136 }
137
138static inline void
143
144static inline bool
147 uint8_t *pBuffer,
148 size_t nBuffer
149 )
150 {
151 return (*gk_McciBootloaderPlatformInterface.Storage.pRead)(
152 hAddress,
153 pBuffer,
154 nBuffer
155 );
156 }
157
160 {
161 return (*gk_McciBootloaderPlatformInterface.Storage.pGetPrimaryAddress)();
162 }
163
166 {
167 return (*gk_McciBootloaderPlatformInterface.Storage.pGetFallbackAddress)();
168 }
169
170static inline void
175
176static inline void
178 uint8_t *pRx,
179 const uint8_t *pTx,
180 size_t nBytes,
181 bool fContinue
182 )
183 {
184 (*gk_McciBootloaderPlatformInterface.Spi.pTransfer)(
185 pRx, pTx, nBytes, fContinue
186 );
187 }
188
189static inline void
194
195static inline void
198 )
199 {
200 (*gk_McciBootloaderPlatformInterface.Annunciator.pIndicateState)(state);
201 }
202
205 {
206 return (*gk_McciBootloaderPlatformInterface.pGetMilliseconds)();
207 }
208
209void
211
213void
215 const void *pAppBase
217
218const McciBootloader_AppInfo_t *
220 const void *pHeader,
221 size_t nHeader,
222 uintptr_t targetAddress,
223 size_t targetSize
224 );
225
226const McciBootloader_AppInfo_t *
228 const void *pHeader,
229 size_t nHeader
230 );
231
232const McciBootloader_SignatureBlock_t *
234 const McciBootloader_AppInfo_t *
235 );
236
238
239#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 McciBootloader_Milliseconds_t McciBootloaderPlatform_getMilliseconds(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
McciBootloader_Milliseconds_t() McciBootloaderPlatform_GetMillisecondsFn_t(void)
get current millisecond tick count
#define MCCI_BOOTLOADER_BEGIN_DECLS
#define MCCI_BOOTLOADER_NORETURN_SFX
#define MCCI_BOOTLOADER_END_DECLS
uint32_t McciBootloader_Milliseconds_t
Time (in milliseconds)
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_GetMillisecondsFn_t * pGetMilliseconds
Get the millisecond tick count.
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.