Skip to content

About

For bug reports or questions, please use ticket system in alifsemi.com web page.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

FOTA Example for Alif Ensemble E1-E7

This folder contains an example to perform FOTA (application update) using MCUboot and mcumgr to be used with Alif Ensemble DevKit. Included applications are Bootloaders for both cores that are responsible for handling the applying the updates, Example application running in M55_HE that handles transporting the update to the device and Blinky application that represents application running on M55_HP.

Example verification public key has been generated from the MCUboot default RSA2048 private key. NOTE! This key is NOT suitable for production as it's distributed publicly as example key for MCUboot!

Supported configurations

This example is built to work on M55 HE and (optionally) M55 HP core(s). M55 HE acts as the update dowloader, storing the updates into MCUboot's secondary slots.

By default, both cores will apply the update via their respective bootloaders. If HE_UPDATES_BOTH is set to true in CMAKE configuration, HE bootloader will instruct the HP to shut down and then applies the update to both cores. In this scenario HP bootloader only validates the image before jumping into it.

Currently, this example supports OVERWRITE, SWAP and RAM_LOAD modes (see Bootloader design). Only supported storage is internal MRAM. Verification is supported with embedded key and enabled by default but encryption is not supported.

The update can be uploaded to the device and scheduled for updating by three different methods. Using mcumgr-cli though uart or usb, direct writing to MRAM by debugger or by writing the update via Alif Security Toolkit.

MRAM configuration

+-------------------+   0x8000 0000
|                   |
|  HE Bootloader    |
|                   |
+-------------------+   0x8001 0000
|                   |
|  HE primary slot  |
|                   |
+-------------------+   0x8002 0000
|                   |
| HE secondary slot |
|                   |
+-------------------+   0x8003 0000
|                   |
|  HE Scratch area  |
|                   |
+-------------------+   0x8003 1000
.                   .
+-------------------+   0x8003 F000
|                   |
|  HP Scratch area  |   (HP scratch area is not in use if HE_UPDATES_BOTH=ON)
|                   |
+-------------------+   0x8004 0000
|                   |
|  HP Bootloader    |
|                   |
+-------------------+   0x8005 0000
|                   |
|  HP primary slot  |
|                   |
+-------------------+   0x8006 0000
|                   |
| HP secondary slot |
|                   |
+-------------------+   0x8007 0000
|                   |
|   SERAM primary   |   (HE_UPDATES_BOTH=ON and HP_UPDATES_SERAM=ON)
|                   |
+-------------------+   0x800C 0000
|                   |
|   SERAM secondary |   (HE_UPDATES_BOTH=ON and HP_UPDATES_SERAM=ON)
|                   |
+-------------------+   0x8057 FFFF

TCM usage in RAM_LOAD configuration

In RAM_LOAD configuration, the layout of the MRAM remains the same as above but the image from the MRAM is loaded into the core's ITCM.

+-------------------+   0x0000 0000
|                   |
|     EMPTY (*)     |
|                   |
+-------------------+   0x0000 0800
|                   |
|   Image header    |
|                   |
+-------------------+   0x0000 1000
|                   |
| Application image |
|                   |
+-------------------+   0x0001 0000
.                   .
+-------------------+   <end of ITCM>

* = Due to the way the image signing tool works, RAM_LOAD target cannot start from address 0x0 so empty space is left in the beginning so that Application Image starts from next suitable address given the Vector table alignment requirement of Cortex-M55.

Building

This folder contains CMakeLists.txt for the project.

  1. Install and add to PATH:
    1. cmake 3.19 or above
    2. build tool (make/nmake)
    3. gcc-arm-none-eabi compiler (version 12.3 or above)
    4. Python 3
  2. Install the MCUboot imgtool requirements from libs/mcuboot/scripts/requirements.txt (pip install -r libs/mcuboot/scripts/requirements.txt).
  3. Create build folder and enter it. (mkdir build; cd build).
  4. Run cmake [path_to_this_folder]. (cmake ..).
  5. Run compilation command (depends on the selected generator of cmake; by default make for Linux and nmake for Windows). (make)
  6. The built elf-file, binary and map file will be generated in the bin directory under the build folder. Example applications are signed automatically.
  7. OPTIONAL: Install Go, download mcumgr-cli and follow building instruction from associated README.md to issue update commands via mcumgr-cli.

Building for RAM_LOAD

To build RAM_LOAD configuration, add parameter -DMCUBOOT_MODE=RAM_LOAD to cmake command.

The RAM_LOAD configuration does not support / require image test and confirmation, the later image is always loaded. All uploads will be stored to the secondary slot preserving the initial flashed application as 'golden image' in primary slot.

Building with different Alif boards

Default board is DevKit-7. To build with another Alif board, for example DevKit-e8, add the following after cmake .. : -DTARGET_BOARD=DevKit-e8. Available board values: AppKit-e7, DevKit-e1c, DevKit-e4, DevKit-e7 and DevKit-e8.

Deployment

  1. Build the MCUboot application and example applications, see Building.
  2. Write MCUboot application and the signed example application to internal MRAM using Alif Security Toolkit. See alif_mcuboot.json in this folder.
  3. Observe logs from UART2 and UART4, serial settings 115200-8-N-1, to verify the applications are running.

Updating the application using mcumgr-cli

Preparations

  1. Build the project with selected transport mechanism. Uart is built by default, usb transport mechanism can be configured with cmake .. -DTRANSPORT=usb.
  2. Establish connection between your computer and the development board. For uart, UART3 is used by default. This requires attaching an FTDI cable to pins P1_2 and P1_3 (or P2_4 and P2_5 on E1C) on the board. For usb, attach an usb cable to 'SoC USB' port.
  3. Create connection profile for the mcumgr-cli, for example: mcumgr conn add uart type=serial connstring="dev=/dev/ttyACM0,baud=115200". Connection type and baud rate are same for uart and usb connections.
  4. Test the connection between mcumgr-cli and the device: mcumgr -cuart echo "Echo test". The command should print out 'Echo test' to indicate the device returned same string it was sent.

Uploading the update

  1. Query existing images on the device: mcumgr -cuart image list.

  2. Upload the update: mcumgr -cuart image upload build/bin/alif-example-app-update_signed.bin -w1.

  3. Query existing images on the device: mcumgr -cuart image list.

    $ ./mcumgr -cuart image list
    Images:
     image=0 slot=0
        version: 1.0.0
        bootable: true
        flags: active confirmed
        hash: 06147dfeb20df969eeea5b01028ec6635a9a54adea43035997a050618417cb97
     image=0 slot=1
        version: 2.0.0
        bootable: true
        flags:
        hash: 5d2f3bf869e7aafd29825a932e285daafc42ac7aaa00958096dfde09dd3c2fb9
    Split status: N/A (0)
    

Setting the update pending and updating the application

  1. Mark the image to be test-booted on next reset: mcumgr -cuart image test <hash>.
    • The image hash can be seen in the output of the mcumgr -cuart image list command, under image= 0 slot=1
  2. Reset the device: mcumgr -cuart reset.
  3. Validate new image is running: mcumgr -cuart image list.

Reverting the update

  1. After update, query existing images on the device: mcumgr -cuart image list.
  2. Reset the device: mcumgr -cuart reset.
  3. Validate the old firmware is now running: mcumgr -cuart image list.

Setting the updated image as confirmed

  1. After update, query existing images on the device: mcumgr -cuart image list.
  2. Confirm the update so it won't be reverted on next reset: mcumgr -cuart image confirm <hash>.
  3. Reset the device: mcumgr -cuart reset.
  4. Validate new image is still running: mcumgr -cuart image list.

Updating the application using debugger (direct MRAM writing)

This flow can be used to inspect the application-side logic only. Debugger writing directly to the MRAM is used as transport layer.

Uploading the update

With JLink debugger:

  1. Ensure JLink folder is in the path when running cmake.
  2. Run make update in the build directory.
  3. Observe the logs from UART2, the application should indicate update is available to be set pending.

With other tools:

  1. Write [build_folder]/bin/alif-example-app-update_signed.bin into address 0x80020000 with any tool.
  2. Reboot the board/SoC by pressing SW2 (RESET).
  3. Observe the logs from UART2, the application should indicate update is available to be set pending.

Setting the update pending and updating the application

  1. Press the SW1 button on the development board to set the update pending.
  2. Reboot the board/SoC by pressing SW2 (RESET).
  3. Observe logs from UART2, the blinking led also changes to different color blink.

Reverting the update

  1. After update, observe logs from UART2.
  2. Reboot the board/SoC by pressing SW2 (RESET) without pressing the SW1 button on the development board.
  3. Observe logs from UART2, the blinking led also changes to different color blink when original image is loaded again.
  4. The update can be set pending again by pressing the SW1 button on the development board.

Setting the updated image as confirmed

  1. Press the SW1 button on the development board after update has been done.
  2. Reboot the board/SoC by pressing SW2 (RESET).
  3. Observe logs from UART2, updated image is loaded consistently through resets.

Observing update flow while flashing with Alif Security Toolkit only

In this flow, both the 'initial' example application and the update candidate is written using Alif Security Toolkit.

  1. Use alif_mcuboot_with_update.json as Alif Security Toolkit atoc configuration file.
  2. Observe the logs from UART2, the application should indicate update is available to be set pending.
  3. Press the SW1 button on the development board to set the update pending.
  4. Reboot the board/SoC by pressing SW2 (RESET).
  5. Observe logs from UART2, the blinking led also changes to different color blink.

Verification using UART2 output

Example output during normal boot (after writing initial images with Alif Security Toolkit)

INF: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
INF: Scratch: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
INF: Boot source: primary slot
INF: Image index: 0, Swap type: none            << Internal MCUboot logging

Loading image, version 1.0.0 (build: 0)         << Bootloader app prints, see bootloader_app/src/main.c
  image size: 38112.

Example app running!                            << Example app print, see example_app/src/main.c
PRIMARY slot:
  offset:    0x80010000
  size:      0x10000
  magic:     3
  swap_type: 1
  copy_done: 3
  image_ok:  3
  image_num: 0
  version:   1.0.0
SECONDARY slot:
  offset:    0x80020000
  size:      0x10000
  magic:     3
  swap_type: 1
  copy_done: 3
  image_ok:  3
  image_num: 0
ERR: Bad image magic 0x0
No update available.

Example output when update is available

INF: Image index: 0, Swap type: none            << Internal MCUboot logging

Loading image, version 1.0.0 (build: 0)         << Bootloader app prints, see bootloader_app/src/
  image size: 29808.

Example app running!                            << Example app print, see example_app/src/main.c
PRIMARY slot:
  offset:    0x80010000
  size:      0x10000
  magic:     3
  swap_type: 1
  copy_done: 3
  image_ok:  3
  image_num: 3
  version:   1.0.0
SECONDARY slot:
  offset:    0x80020000
  size:      0x10000
  magic:     3
  swap_type: 1
  copy_done: 3
  image_ok:  3
  image_num: 0
  version:   2.0.0
Press button to pend update.

Example output during update

INF: Image index: 0, Swap type: perm            << Internal MCUboot logging
INF: Image 0 upgrade secondary slot -> primary slot
INF: Erasing the primary slot
INF: Image 0 copying the secondary slot to the primary slot: 0xzx bytes
DBG: writing magic; fa_id=1 off=0xfff0 (0x8001fff0)
DBG: erasing secondary header
DBG: erasing secondary trailer

Loading image, version 2.0.0 (build: 0)         << Bootloader app prints, see bootloader_app/src/
  image size: 29808.

Updated app running!                            << Example app print, see example_app/src/main.c
PRIMARY slot:
  offset:    0x80010000
  size:      0x10000
  magic:     1
  swap_type: 2
  copy_done: 1
  image_ok:  3
  image_num: 0
  version:   2.0.0
SECONDARY slot:
  offset:    0x80020000
  size:      0x10000
  magic:     3
  swap_type: 1
  copy_done: 3
  image_ok:  3
  image_num: 0
ERR: Bad image magic 0x0
No update available.

Example output on subsequent resets after app is updated

INF: Image index: 0, Swap type: none            << Internal MCUboot logging

Loading image, version 2.0.0 (build: 0)         << Bootloader app prints, see bootloader_app/src/
  image size: 29808.

Updated app running!                            << Example app print, see example_app/src/main.c
PRIMARY slot:
  offset:    0x80010000
  size:      0x10000
  magic:     1
  swap_type: 1
  copy_done: 3
  image_ok:  3
  image_num: 0
  version:   2.0.0
SECONDARY slot:
  offset:    0x80020000
  size:      0x10000
  magic:     3
  swap_type: 1
  copy_done: 3
  image_ok:  3
  image_num: 0
ERR: Bad image magic 0x0
No update available.

SERAM update feature

To use the SERAM update feature, the following criteria must be met:

  1. Both HE_UPDATES_BOTH and HP_UPDATES_SERAM must be enabled.
  2. A full SERAM update image, with a version matching the one currently running on the device, must be signed using imgtool.py.
  3. The signed SERAM update image with the matching version must be placed in image 2, slot 0 (0x80070000).
  4. A full SoC reset is required to perform a test boot e.g., by pressing the physical reset button.

About

For bug reports or questions, please use ticket system in alifsemi.com web page.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages