Application Storage Interface#

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.


Example#

Snippet for the OTA use case:

* OTA Example
* Assuming the user has an upgrade image downloaded which will be used to upgrade the application
*
* Initialize the bootloader interface
* bootloader_init();
*
* Erase the storage slot in internal/SPI flash memory
* bootloader_eraseStorageSlot(0);
*
* Write the upgrade image (GBL file data) to the slot. blinkGbl  uint8 array holding the GBL data in memory
* bootloader_writeStorage(0, 0, blinkGbl, sizeof(blinkGbl));
*
* Reboot into the bootloader to install the new image
* bootloader_rebootAndInstall();
*
* The general flow for bootloader interface APIs from the application is:
*
* General flow
*
* Initialize the bootloader interface
* bootloader_init();
*
* Interface API accesses
* ……………
* ……………
* ……………
*
* De-initialize the bootloader interface
* bootloader_deinit();
* 

Modules#

BootloaderStorageSlot_t

BootloaderStorageImplementationInformation_t

BootloaderStorageInformation_t

BootloaderEraseStatus_t

BootloaderStorageFunctions_t

Enumerations#

enum
SPIFLASH
INTERNAL_FLASH
CUSTOM_STORAGE
}

Possible storage types.

Functions#

void
bootloader_getStorageInfo(BootloaderStorageInformation_t *info)

Get information about the storage component.

int32_t
bootloader_getStorageSlotInfo(uint32_t slotId, BootloaderStorageSlot_t *slot)

Get information about a storage slot.

int32_t
bootloader_readStorage(uint32_t slotId, uint32_t offset, uint8_t *buffer, size_t length)

Read data from a storage slot.

int32_t
bootloader_writeStorage(uint32_t slotId, uint32_t offset, uint8_t *buffer, size_t length)

Write data to a storage slot.

int32_t
bootloader_eraseWriteStorage(uint32_t slotId, uint32_t offset, uint8_t *buffer, size_t length)

Erase and write data to a storage slot.

int32_t

Erase all contents of a storage slot.

int32_t
bootloader_initChunkedEraseStorageSlot(uint32_t slotId, BootloaderEraseStatus_t *eraseStat)

Initialize chunked erase of a storage slot.

int32_t
bootloader_chunkedEraseStorageSlot(BootloaderEraseStatus_t *eraseStat)

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

int32_t
bootloader_setImagesToBootload(int32_t *slotIds, size_t length)

Set a prioritized list of images to attempt to bootload.

int32_t
bootloader_getImagesToBootload(int32_t *slotIds, size_t length)

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

int32_t

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

int32_t

Set a single image to attempt to bootload.

int32_t
bootloader_initVerifyImage(uint32_t slotId, void *context, size_t contextSize)

Initialize image verification.

int32_t
bootloader_continueVerifyImage(void *context, BootloaderParserCallback_t metadataCallback)

Continue image verification.

int32_t
bootloader_verifyImage(uint32_t slotId, BootloaderParserCallback_t metadataCallback)

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

int32_t
bootloader_getImageInfo(uint32_t slotId, ApplicationData_t *appInfo, uint32_t *bootloaderVersion)

Get application and bootloader upgrade metadata from the storage slot.

bool

Check whether the bootloader storage is busy.

int32_t
bootloader_readRawStorage(uint32_t address, uint8_t *buffer, size_t length)

Read raw data from storage.

int32_t
bootloader_writeRawStorage(uint32_t address, uint8_t *buffer, size_t length)

Write data to storage.

int32_t
bootloader_eraseRawStorage(uint32_t address, size_t length)

Erase data from storage.

int32_t

Get allocated DMA channel for MSC write.

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 (0x0210U)

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 (1U << 0)

ISSI IS25LQ040B SPI Flash.

#define
BOOTLOADER_STORAGE_ISSI_IS25LQ020B (1U << 1)

ISSI IS25LQ020B SPI Flash.

#define
BOOTLOADER_STORAGE_ISSI_IS25LQ010B (1U << 2)

ISSI IS25LQ010B SPI Flash.

#define
BOOTLOADER_STORAGE_ISSI_IS25LQ512B (1U << 3)

ISSI IS25LQ512B SPI Flash.

#define
BOOTLOADER_STORAGE_ISSI_IS25LQ025B (1U << 4)

ISSI IS25LQ025B SPI Flash.

#define
BOOTLOADER_STORAGE_NUMONYX_M25P16 (1U << 5)

Numonyx M25P16 SPI Flash.

#define
BOOTLOADER_STORAGE_NUMONYX_M25P80 (1U << 6)

Numonyx M25P80 SPI Flash.

#define
BOOTLOADER_STORAGE_NUMONYX_M25P40 (1U << 7)

Numonyx M25P40 SPI Flash.

#define
BOOTLOADER_STORAGE_NUMONYX_M25P20 (1U << 8)

Numonyx M25P20 SPI Flash.

#define
BOOTLOADER_STORAGE_ADESTO_AT25SF041 (1U << 9)

Adesto AT25SF041 SPI Flash.

#define
BOOTLOADER_STORAGE_ATMEL_AT25DF081A (1U << 10)

Atmel AT25DF081A SPI Flash.

#define
BOOTLOADER_STORAGE_ATMEL_AT25DF041A (1U << 11)

Atmel AT25DF041A SPI Flash.

#define
BOOTLOADER_STORAGE_MACRONIX_MX25R6435F (1U << 12)

Macronix MX25R6435F SPI Flash.

#define
BOOTLOADER_STORAGE_MACRONIX_MX25R3235F (1U << 13)

Macronix MX25R6435F SPI Flash.

#define
BOOTLOADER_STORAGE_MACRONIX_MX25U1635E (1U << 14)

Macronix MX25U1635E SPI Flash.

#define
BOOTLOADER_STORAGE_MACRONIX_MX25L1606E (1U << 15)

Macronix MX25L1606E SPI Flash.

#define
BOOTLOADER_STORAGE_MACRONIX_MX25R8035F (1U << 16)

Macronix MX25R8035F SPI Flash.

#define
BOOTLOADER_STORAGE_MACRONIX_MX25L8006E (1U << 17)

Macronix MX25L8006E SPI Flash.

#define
BOOTLOADER_STORAGE_MACRONIX_MX25L4006E (1U << 18)

Macronix MX25L4006E SPI Flash.

#define
BOOTLOADER_STORAGE_MACRONIX_MX25L2006E (1U << 19)

Macronix MX25L2006E SPI Flash.

#define
BOOTLOADER_STORAGE_WINBOND_W25Q80BV (1U << 20)

Winbond W25Q80BV SPI Flash.

#define
BOOTLOADER_STORAGE_WINBOND_W25X20BV (1U << 21)

Winbond W25X20BV SPI Flash.

#define
BOOTLOADER_STORAGE_SPANSION_S25FL208K (1U << 22)

Spansion S25L208K SPI Flash.

#define
BOOTLOADER_STORAGE_INTERNAL_STORAGE (1U << 30)

Internal storage.

#define
BOOTLOADER_STORAGE_JEDEC (1U << 31)

JEDEC Supported SPI Flash.

Enumeration Documentation#

BootloaderStorageType_t#

BootloaderStorageType_t

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 81 of file platform/bootloader/api/btl_interface_storage.h

Function Documentation#

bootloader_getStorageInfo#

void bootloader_getStorageInfo (BootloaderStorageInformation_t * info)

Get information about the storage component.

Parameters
[out]info

Information about the storage component.


Definition at line 297 of file platform/bootloader/api/btl_interface_storage.h

bootloader_getStorageSlotInfo#

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


Definition at line 308 of file platform/bootloader/api/btl_interface_storage.h

bootloader_readStorage#

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


Definition at line 322 of file platform/bootloader/api/btl_interface_storage.h

bootloader_writeStorage#

int32_t bootloader_writeStorage (uint32_t slotId, uint32_t offset, uint8_t * buffer, size_t length)

Write data to a storage slot.

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. Must be a multiple of 4.

Note

  • If DMA-based MSC write is enabled on the bootloader, writing data from flash to flash is not supported on Series-1 devices. DMA-based MSC write is enabled, both offset and buffer should be word aligned. In case the buffer is not aligned, the normal write procedure is used instead of DMA.

Returns


Definition at line 344 of file platform/bootloader/api/btl_interface_storage.h

bootloader_eraseWriteStorage#

int32_t bootloader_eraseWriteStorage (uint32_t slotId, uint32_t offset, uint8_t * buffer, size_t length)

Erase and write data to a storage slot.

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. Must be a multiple of 4.

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.

Returns


Definition at line 370 of file platform/bootloader/api/btl_interface_storage.h

bootloader_eraseStorageSlot#

int32_t bootloader_eraseStorageSlot (uint32_t slotId)

Erase all contents of a storage slot.

Parameters
[in]slotId

ID of the slot

Returns


Definition at line 383 of file platform/bootloader/api/btl_interface_storage.h

bootloader_initChunkedEraseStorageSlot#

int32_t bootloader_initChunkedEraseStorageSlot (uint32_t slotId, BootloaderEraseStatus_t * eraseStat)

Initialize chunked erase of a storage slot.

Parameters
[in]slotId

ID of the slot

[in]eraseStat

Erase status struct

Note

Returns


Definition at line 397 of file platform/bootloader/api/btl_interface_storage.h

bootloader_chunkedEraseStorageSlot#

int32_t bootloader_chunkedEraseStorageSlot (BootloaderEraseStatus_t * eraseStat)

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

Parameters
[in]eraseStat

Erase status struct

Note

Returns


Definition at line 418 of file platform/bootloader/api/btl_interface_storage.h

bootloader_setImagesToBootload#

int32_t bootloader_setImagesToBootload (int32_t * slotIds, size_t length)

Set a prioritized list of images to attempt to bootload.

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

The last call to this function determines which slot will be installed when bootloader_rebootAndInstall is called.

Returns


Definition at line 432 of file platform/bootloader/api/btl_interface_storage.h

bootloader_getImagesToBootload#

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


Definition at line 444 of file platform/bootloader/api/btl_interface_storage.h

bootloader_appendImageToBootloadList#

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


Definition at line 454 of file platform/bootloader/api/btl_interface_storage.h

bootloader_setImageToBootload#

int32_t bootloader_setImageToBootload (int32_t slotId)

Set a single image to attempt to bootload.

Parameters
[in]slotId

ID of the slot

Returns


Definition at line 464 of file platform/bootloader/api/btl_interface_storage.h

bootloader_initVerifyImage#

int32_t bootloader_initVerifyImage (uint32_t slotId, void * context, size_t contextSize)

Initialize image verification.

Parameters
[in]slotId

ID of the slot to check.

N/Acontext

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.

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 caller must ensure that the context pointer is 32 bit aligned. 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.

Returns

  • BOOTLOADER_OK if the image parser was initialized, else error code.


Definition at line 500 of file platform/bootloader/api/btl_interface_storage.h

bootloader_continueVerifyImage#

int32_t bootloader_continueVerifyImage (void * context, BootloaderParserCallback_t metadataCallback)

Continue image verification.

Parameters
N/Acontext

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.

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

Note

Returns


Definition at line 540 of file platform/bootloader/api/btl_interface_storage.h

bootloader_verifyImage#

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

Returns


Definition at line 564 of file platform/bootloader/api/btl_interface_storage.h

bootloader_getImageInfo#

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


Definition at line 580 of file platform/bootloader/api/btl_interface_storage.h

bootloader_storageIsBusy#

bool bootloader_storageIsBusy (void )

Check whether the bootloader storage is busy.

Parameters
N/A

Returns

  • True if the storage is busy


Definition at line 589 of file platform/bootloader/api/btl_interface_storage.h

bootloader_readRawStorage#

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


Definition at line 602 of file platform/bootloader/api/btl_interface_storage.h

bootloader_writeRawStorage#

int32_t bootloader_writeRawStorage (uint32_t address, uint8_t * buffer, size_t length)

Write data to storage.

Parameters
[in]address

Address to start writing to

[in]buffer

Buffer to read data to write from

[in]length

Amount of data to write. Must be a multiple of 4.

Note

  • If DMA-based MSC write is enabled on the bootloader, writing data from flash to flash is not supported on Series-1 devices.

Returns


Definition at line 620 of file platform/bootloader/api/btl_interface_storage.h

bootloader_eraseRawStorage#

int32_t bootloader_eraseRawStorage (uint32_t address, size_t length)

Erase data from storage.

Parameters
[in]address

Address to start erasing from

[in]length

Length of data to erase

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.

Returns


Definition at line 638 of file platform/bootloader/api/btl_interface_storage.h

bootloader_getAllocatedDMAChannel#

int32_t bootloader_getAllocatedDMAChannel (void )

Get allocated DMA channel for MSC write.

Parameters
N/A

Returns

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


Definition at line 648 of file platform/bootloader/api/btl_interface_storage.h