Application Storage InterfaceApplication Interface

Description

Application interface for interfacing with the bootloader storage.

Note
These Bootloader APIs are not reentrant and should be wrapped in critical section where needed.

The Storage Interface is only available on bootloaders that declare they support BOOTLOADER_CAPABILITY_STORAGE .

Data Structures

struct BootloaderStorageSlot_t
Information about a storage slot.
struct BootloaderStorageImplementationInformation_t
struct BootloaderStorageInformation_t
struct BootloaderEraseStatus_t
Erase status struct.
struct BootloaderStorageFunctions
Storage API accessible from the application.

Macros

#define BOOTLOADER_STORAGE_VERIFICATION_CONTEXT_SIZE (384)
Context size for bootloader verification context.
#define BOOTLOADER_STORAGE_INFO_VERSION (0x30000U)
Current version of the BootloaderStorageInformation_t struct.
#define BOOTLOADER_STORAGE_IMPL_INFO_VERSION (0x0201U)
Current version of the BootloaderStorageImplementationInformation_t struct.
#define BOOTLOADER_STORAGE_IMPL_INFO_VERSION_MAJOR (0x0200U)
Major version of the BootloaderStorageImplementationInformation_t struct.
#define BOOTLOADER_STORAGE_IMPL_INFO_VERSION_MAJOR_MASK (0xFF00U)
Major version mask for BOOTLOADER_STORAGE_IMPL_INFO_VERSION .
#define BOOTLOADER_STORAGE_IMPL_CAPABILITY_ERASE_SUPPORTED (1 << 0)
Spiflash capability indicating that it supports erase.
#define BOOTLOADER_STORAGE_IMPL_CAPABILITY_PAGE_ERASE_REQUIRED (1 << 1)
Spiflash capability indicating it requires full page erases before new data can be written.
#define BOOTLOADER_STORAGE_IMPL_CAPABILITY_BLOCKING_WRITE (1 << 2)
Spiflash capability indicating that the write function is blocking.
#define BOOTLOADER_STORAGE_IMPL_CAPABILITY_BLOCKING_ERASE (1 << 3)
Spiflash capability indicating that the erase function is blocking.
#define BOOTLOADER_STORAGE_ISSI_IS25LQ040B (1 << 0)
ISSI IS25LQ040B SPI Flash.
#define BOOTLOADER_STORAGE_ISSI_IS25LQ020B (1 << 1)
ISSI IS25LQ020B SPI Flash.
#define BOOTLOADER_STORAGE_ISSI_IS25LQ010B (1 << 2)
ISSI IS25LQ010B SPI Flash.
#define BOOTLOADER_STORAGE_ISSI_IS25LQ512B (1 << 3)
ISSI IS25LQ512B SPI Flash.
#define BOOTLOADER_STORAGE_ISSI_IS25LQ025B (1 << 4)
ISSI IS25LQ025B SPI Flash.
#define BOOTLOADER_STORAGE_NUMONYX_M25P16 (1 << 5)
Numonyx M25P16 SPI Flash.
#define BOOTLOADER_STORAGE_NUMONYX_M25P80 (1 << 6)
Numonyx M25P80 SPI Flash.
#define BOOTLOADER_STORAGE_NUMONYX_M25P40 (1 << 7)
Numonyx M25P40 SPI Flash.
#define BOOTLOADER_STORAGE_NUMONYX_M25P20 (1 << 8)
Numonyx M25P20 SPI Flash.
#define BOOTLOADER_STORAGE_ADESTO_AT25SF041 (1 << 9)
Adesto AT25SF041 SPI Flash.
#define BOOTLOADER_STORAGE_ATMEL_AT25DF081A (1 << 10)
Atmel AT25DF081A SPI Flash.
#define BOOTLOADER_STORAGE_ATMEL_AT25DF041A (1 << 11)
Atmel AT25DF041A SPI Flash.
#define BOOTLOADER_STORAGE_MACRONIX_MX25R6435F (1 << 12)
Macronix MX25R6435F SPI Flash.
#define BOOTLOADER_STORAGE_MACRONIX_MX25R3235F (1 << 13)
Macronix MX25R6435F SPI Flash.
#define BOOTLOADER_STORAGE_MACRONIX_MX25U1635E (1 << 14)
Macronix MX25U1635E SPI Flash.
#define BOOTLOADER_STORAGE_MACRONIX_MX25L1606E (1 << 15)
Macronix MX25L1606E SPI Flash.
#define BOOTLOADER_STORAGE_MACRONIX_MX25R8035F (1 << 16)
Macronix MX25R8035F SPI Flash.
#define BOOTLOADER_STORAGE_MACRONIX_MX25L8006E (1 << 17)
Macronix MX25L8006E SPI Flash.
#define BOOTLOADER_STORAGE_MACRONIX_MX25L4006E (1 << 18)
Macronix MX25L4006E SPI Flash.
#define BOOTLOADER_STORAGE_MACRONIX_MX25L2006E (1 << 19)
Macronix MX25L2006E SPI Flash.
#define BOOTLOADER_STORAGE_WINBOND_W25Q80BV (1 << 20)
Winbond W25Q80BV SPI Flash.
#define BOOTLOADER_STORAGE_WINBOND_W25X20BV (1 << 21)
Winbond W25X20BV SPI Flash.
#define BOOTLOADER_STORAGE_SPANSION_S25FL208K (1 << 22)
Spansion S25L208K SPI Flash.
#define BOOTLOADER_STORAGE_INTERNAL_STORAGE (1 << 30)
Internal storage.
#define BOOTLOADER_STORAGE_JEDEC (1 << 31)
JEDEC Supported SPI Flash.

Typedefs

typedef struct BootloaderStorageFunctions BootloaderStorageFunctions_t
Storage API accessible from the application.

Enumerations

enum BootloaderStorageType_t {
SPIFLASH ,
INTERNAL_FLASH ,
CUSTOM_STORAGE
}
Possible storage types.

Functions

void bootloader_getStorageInfo ( BootloaderStorageInformation_t *info)
int32_t bootloader_getStorageSlotInfo (uint32_t slotId, BootloaderStorageSlot_t *slot)
int32_t bootloader_readStorage (uint32_t slotId, uint32_t offset, uint8_t *buffer, size_t length)
int32_t bootloader_writeStorage (uint32_t slotId, uint32_t offset, uint8_t *buffer, size_t length)
int32_t bootloader_eraseWriteStorage (uint32_t slotId, uint32_t offset, uint8_t *buffer, size_t length)
int32_t bootloader_eraseStorageSlot (uint32_t slotId)
int32_t bootloader_initChunkedEraseStorageSlot (uint32_t slotId, BootloaderEraseStatus_t *eraseStat)
int32_t bootloader_chunkedEraseStorageSlot ( BootloaderEraseStatus_t *eraseStat)
int32_t bootloader_setImagesToBootload (int32_t *slotIds, size_t length)
int32_t bootloader_getImagesToBootload (int32_t *slotIds, size_t length)
int32_t bootloader_appendImageToBootloadList (int32_t slotId)
int32_t bootloader_setImageToBootload (int32_t slotId)
int32_t bootloader_initVerifyImage (uint32_t slotId, void *context, size_t contextSize)
int32_t bootloader_continueVerifyImage (void *context, BootloaderParserCallback_t metadataCallback)
int32_t bootloader_verifyImage (uint32_t slotId, BootloaderParserCallback_t metadataCallback)
int32_t bootloader_getImageInfo (uint32_t slotId, ApplicationData_t *appInfo, uint32_t *bootloaderVersion)
bool bootloader_storageIsBusy (void)
int32_t bootloader_readRawStorage (uint32_t address, uint8_t *buffer, size_t length)
int32_t bootloader_writeRawStorage (uint32_t address, uint8_t *buffer, size_t length)
int32_t bootloader_eraseRawStorage (uint32_t address, size_t length)
int32_t bootloader_getAllocatedDMAChannel (void)

Enumeration Type Documentation

Possible storage types.

Enumerator
SPIFLASH

Storage backend is a SPI flash.

INTERNAL_FLASH

Storage backend is internal flash.

CUSTOM_STORAGE

Storage backend is custom.

Definition at line 44 of file btl_interface_storage.h .

Function Documentation

void bootloader_getStorageInfo ( BootloaderStorageInformation_t * info )

Get information about the storage component.

Parameters
[out] info Information about the storage component.
int32_t bootloader_getStorageSlotInfo ( uint32_t slotId,
BootloaderStorageSlot_t * slot
)

Get information about a storage slot.

Parameters
[in] slotId ID of the slot to get information about
[out] slot Information about the storage slot
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_readStorage ( uint32_t slotId,
uint32_t offset,
uint8_t * buffer,
size_t length
)

Read data from a storage slot.

Parameters
[in] slotId ID of the slot
[in] offset Offset into the slot to start reading from
[out] buffer Buffer to store the data
[in] length Amount of data to read
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_writeStorage ( uint32_t slotId,
uint32_t offset,
uint8_t * buffer,
size_t length
)

Write data to a storage slot.

Note
If DMA-based MSC write is enabled on the bootloader, writing data from flash to flash is not supported on Series-1 devices.
Parameters
[in] slotId ID of the slot
[in] offset Offset into the slot to start writing to
[in] buffer Buffer to read data to write from
[in] length Amount of data to write
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_eraseWriteStorage ( uint32_t slotId,
uint32_t offset,
uint8_t * buffer,
size_t length
)

Erase and write data to a storage slot.

Note
This function automatically erases the following Flash page whenever the written data crosses a page boundary. In other words, the function can't be used to perform multiple sequential writes to the same address range unless the range starts at a page boundary. For a sequential write, the first call to this function should have a start address at a page boundary. Otherwise, the corresponding page of the starting address needs to be erased explicitly. If DMA-based MSC write is enabled on the bootloader, writing data from flash to flash is not supported on Series-1 devices.
Parameters
[in] slotId ID of the slot
[in] offset Offset into the slot to start writing to
[in] buffer Buffer to read data to write from
[in] length Amount of data to write
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_eraseStorageSlot ( uint32_t slotId )

Erase all contents of a storage slot.

Parameters
[in] slotId ID of the slot
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_initChunkedEraseStorageSlot ( uint32_t slotId,
BootloaderEraseStatus_t * eraseStat
)

Initialize chunked erase of a storage slot.

Note
This function must be called before calling bootloader_chunkedEraseStorageSlot in a loop.
Parameters
[in] slotId ID of the slot
[in] eraseStat Erase status struct
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_chunkedEraseStorageSlot ( BootloaderEraseStatus_t * eraseStat )

Erase one page from a storage slot according to the struct BootloaderEraseStatus_t .

Note
bootloader_initChunkedEraseStorageSlot must be called before calling this function, in order to prepare BootloaderEraseStatus_t .
This can be called sequentially to, for example, erase all contents of a storage slot.
Parameters
[in] eraseStat Erase status struct
Returns
BOOTLOADER_ERROR_STORAGE_CONTINUE if erasing a page was successful. Erase can be continued by calling this function again. BOOTLOADER_OK if the entire slot has been erased, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_setImagesToBootload ( int32_t * slotIds,
size_t length
)

Set a prioritized list of images to attempt to bootload. The last call to this function determines which slot will be installed when bootloader_rebootAndInstall is called.

Parameters
[in] slotIds Prioritized list of slot IDs to attempt to bootload. The first image to pass verification will be bootloaded.
[in] length Length of the slotIds array
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_BOOTLOAD_BASE range
int32_t bootloader_getImagesToBootload ( int32_t * slotIds,
size_t length
)

Get the prioritized list of images the bootloader will attempt to bootload.

Parameters
[out] slotIds Prioritized list of slot IDs to attempt to bootload. The first image to pass verification will be bootloaded.
[in] length Length of the slotIds array
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_BOOTLOAD_BASE range
int32_t bootloader_appendImageToBootloadList ( int32_t slotId )

Append a single image to the list of images to attempt to bootload.

Parameters
[in] slotId ID of the slot to append
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_BOOTLOAD_BASE range
int32_t bootloader_setImageToBootload ( int32_t slotId )

Set a single image to attempt to bootload.

Parameters
[in] slotId ID of the slot
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_BOOTLOAD_BASE range
int32_t bootloader_initVerifyImage ( uint32_t slotId,
void * context,
size_t contextSize
)

Initialize image verification.

Initialize verification of an upgrade image stored in a bootloader storage slot.

Note
This function must be called before calling bootloader_continueVerifyImage in a loop.
The context pointer must point to memory allocated by the caller. The required size of this context may depend on the version of the bootloader. The required size for the bootloader associated with this version of the application interface is given by the define BOOTLOADER_STORAGE_VERIFICATION_CONTEXT_SIZE .
Instead of calling bootloader_initVerifyImage followed by bootloader_continueVerifyImage , call bootloader_verifyImage if no time-critical tasks are needed and sufficient stack space is available for the automatically allocated context. The purpose of the init-and-continue functions is to allow the caller to service system needs during verification.
Parameters
[in] slotId ID of the slot to check.
context Pointer to memory used to hold the parser context.
[in] contextSize Size of the context. An error is returned if the supplied context is too small.
Returns
BOOTLOADER_OK if the image parser was initialized, else error code.
int32_t bootloader_continueVerifyImage ( void * context,
BootloaderParserCallback_t metadataCallback
)

Continue image verification.

Continue verification of an upgrade image stored in a bootloader storage slot.

Note
This function must be called in a loop until anything other than BOOTLOADER_ERROR_PARSE_CONTINUE is returned.
bootloader_initVerifyImage must be called before calling this function to reset the parser.
Instead of calling bootloader_initVerifyImage followed by bootloader_continueVerifyImage , call bootloader_verifyImage if no time-critical tasks are needed. The purpose of the init-and-continue functions is to allow the caller to service system needs during verification.
Parameters
context Pointer to a context structure that has been initialized by calling bootloader_initVerifyImage()
[in] metadataCallback Function pointer, which is called when the binary metadata in the image is currently verified. Set to NULL if not required.
Returns
BOOTLOADER_ERROR_PARSE_CONTINUE if parsing was successful, and the parser expects more data. BOOTLOADER_ERROR_PARSE_SUCCESS if the parser has successfully parsed the image and it passes verification. Else error code.
int32_t bootloader_verifyImage ( uint32_t slotId,
BootloaderParserCallback_t metadataCallback
)

Verify that the image in the given storage slot is valid.

Parameters
[in] slotId ID of the slot to check
[in] metadataCallback Function pointer, which is called when binary metadata is present in the storage slot. Set to NULL if not required.
Note
This function allocates a context structure of the size given by BOOTLOADER_STORAGE_VERIFICATION_CONTEXT_SIZE on the caller's stack. To manage memory and allocate the context elsewhere (on the heap, as a global variable, and so on), use bootloader_initVerifyImage and bootloader_continueVerifyImage functions instead.
Returns
BOOTLOADER_OK if the image is valid, else error code.
int32_t bootloader_getImageInfo ( uint32_t slotId,
ApplicationData_t * appInfo,
uint32_t * bootloaderVersion
)

Get application and bootloader upgrade metadata from the storage slot.

Parameters
[in] slotId ID of the slot to check
[out] appInfo Pointer to ApplicationData_t struct
[out] bootloaderVersion Pointer to an integer representing bootloader version
Returns
BOOTLOADER_OK if metadata was filled successfully
bool bootloader_storageIsBusy ( void )

Check whether the bootloader storage is busy.

Returns
True if the storage is busy
int32_t bootloader_readRawStorage ( uint32_t address,
uint8_t * buffer,
size_t length
)

Read raw data from storage.

Parameters
[in] address Address to start reading from
[out] buffer Buffer to store the data
[in] length Amount of data to read
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_writeRawStorage ( uint32_t address,
uint8_t * buffer,
size_t length
)

Write data to storage.

Note
If DMA-based MSC write is enabled on the bootloader, writing data from flash to flash is not supported on Series-1 devices.
Parameters
[in] address Address to start writing to
[in] buffer Buffer to read data to write from
[in] length Amount of data to write
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_eraseRawStorage ( uint32_t address,
size_t length
)

Erase data from storage.

Note
Erasing storage must adhere to the limitations of the underlying storage medium, such as requiring full page erases. Use bootloader_getStorageInfo to learn about the limitations of the configured storage medium.
Parameters
[in] address Address to start erasing from
[in] length Length of data to erase
Returns
BOOTLOADER_OK on success, else error code in BOOTLOADER_ERROR_STORAGE_BASE range
int32_t bootloader_getAllocatedDMAChannel ( void )

Get allocated DMA channel for MSC write.

Returns
A positive number channel. -1 if DMA-based MSC write is not enabled. Otherwise, the error code BOOTLOADER_ERROR_INIT_STORAGE.