AM261x MCU+ SDK: Using FOTA Agent (FSS Switch To B)

| AM261x MCU+ SDK 26.00.00 |

Using FOTA Agent (FSS Switch To B)

# Introduction

This example provides a simple use case on how to implement a FOTAAgent in a FOTA use case. FOTAAgent is used to write files received on the interface to the flash.

Hello world application is being embedded into this example as a C array which is then programmed using `FOTAAgent` (FOTA Agent) APIs. However, in a real-world use case, a new application will be received on some interface (eg. CAN, Ethernet, etc.) in some packets.

This application, flash the program using the following loop:

for (uint32_t cnt = 0; cnt < hello_world_release_xip_size; cnt++)
{
/*
as and when a byte is being recv, it is being sent to agent which will handle
all the intricacies.
*/
uint8_t byte = hello_world_release_xip[cnt];
status = FOTAAgent_writeUpdate(&gFotaAgentHandle, &byte, 1);
DebugP_assert(status == SystemP_SUCCESS);
}

In the actual application, for loop can be replaced with a while loop, which would terminate when all the packets have been received.

Typically, after application compilation, TI post-build step produces .mcelf and .mcelf_xip files. It is required to flash these 2 files in the flash. Therefore, it is required to call `FOTAAgent` API 2 times on these 2 files.

Once both the files are flashed in the external flash, it is required to update the boot sector of the flash.

offset = BOOINFO_ADDRESS;
CacheP_inv((void *)(SOC_getFlashDataBaseAddr() + offset), ERASE_SECTOR_SIZE, CacheP_TYPE_ALL);
memcpy((void *)&bootinfo.bin, (void *)(SOC_getFlashDataBaseAddr() + offset), ERASE_SECTOR_SIZE);
bootinfo.fields.bootRegion = BOOT_REGION_B;
status = FLSOPSKD_erase(&gFotaAgentHandle.flopsHandle, offset);
DebugP_assert(status == SystemP_SUCCESS);
status = FLSOPSKD_write(&gFotaAgentHandle.flopsHandle, offset, (uint8_t *)&bootinfo.bin, ERASE_SECTOR_SIZE);
DebugP_assert(status == SystemP_SUCCESS);
CacheP_inv((void *)(SOC_getFlashDataBaseAddr() + offset), ERASE_SECTOR_SIZE, CacheP_TYPE_ALL);

The above code does that.

If the SBL OSPI SWAP is being used, the on next board reset, hello world application will run instead of this application.

# Supported Combinations

Parameter | Value
--- | ---
CPU + OS | r5fss0-0 nortos
Toolchain | ti-arm-clang
Boards | am261x-lp
Example folder | examples/drivers/fss/fss_switch_b

# Steps to Run the Example

- When using makefiles to build
  - please make sure to build and run example FSS1 XIP Hello World Project to validate.
  - using python3, run python script bin_to_c_array.py.
  - note the required combination (Supported Combinations) and build using make command (see Using SDK with Makefiles)
- Load the application using SBL OSPI SWAP

# Sample Output

Starting OSPI Bootloader ...
KPI_DATA: [BOOTLOADER_PROFILE] Boot Media : NOR SPI FLASH
KPI_DATA: [BOOTLOADER_PROFILE] Boot Media Clock : 166.667 MHz
KPI_DATA: [BOOTLOADER_PROFILE] Boot Image Size : 65 KB
KPI_DATA: [BOOTLOADER_PROFILE] Cores present :
KPI_DATA: [BOOTLOADER PROFILE] System_init : 443us
KPI_DATA: [BOOTLOADER PROFILE] Drivers_open : 94us
KPI_DATA: [BOOTLOADER PROFILE] LoadHsmRtFw : 6251us
KPI_DATA: [BOOTLOADER PROFILE] Board_driversOpen : 22850us
KPI_DATA: [BOOTLOADER PROFILE] CPU load : 4323us
KPI_DATA: [BOOTLOADER PROFILE] SBL End : 9us
KPI_DATA: [BOOTLOADER_PROFILE] SBL Total Time Taken : 33973us
Image loading done, switching to application ...
Starting application
Receiving application...
Got MCELF file
Got MCELF_XIP file
Done writing new application to flash...
Updating Flash's Boot Sector...
Finish Updating Flash's Boot Sector... Please reset board to start new application
Starting OSPI Bootloader ...
KPI_DATA: [BOOTLOADER_PROFILE] Boot Media : NOR SPI FLASH
KPI_DATA: [BOOTLOADER_PROFILE] Boot Media Clock : 166.667 MHz
KPI_DATA: [BOOTLOADER_PROFILE] Boot Image Size : 5 KB
KPI_DATA: [BOOTLOADER_PROFILE] Cores present :
KPI_DATA: [BOOTLOADER PROFILE] System_init : 443us
KPI_DATA: [BOOTLOADER PROFILE] Drivers_open : 94us
KPI_DATA: [BOOTLOADER PROFILE] LoadHsmRtFw : 6251us
KPI_DATA: [BOOTLOADER PROFILE] Board_driversOpen : 24701us
KPI_DATA: [BOOTLOADER PROFILE] CPU load : 3963us
KPI_DATA: [BOOTLOADER PROFILE] SBL End : 9us
KPI_DATA: [BOOTLOADER_PROFILE] SBL Total Time Taken : 35464us
Image loading done, switching to application ...
Hello World!