This example demonstrates simple secure firmware update by wolfBoot. A sample application v1 is securely updated to v2. Both versions behave the same except displaying its version of v1 or v2. They are compiled by e2Studio and running on the target board.
In this demo, you may download two versions of the application binary file by Renesas Flash Programmer. You can download and execute wolfBoot by e2Studio debugger. Use a USB connection between PC and the board for the debugger and flash programmer.
Please see Readme_wSCE.md for Renesas SCE use case.
| Item | Name/Version | Note |
|---|---|---|
| Board | Renesas EK-RA6M4 | |
| Device | R7FA6M4AF3CFB | |
| Toolchain | GCC ARM Embedded 10.3.1.20210824 | Included in GCC for Renesas RA |
| FSP Version | 3.6.0 | Download from Renesas site |
| IDE | e2studio 2022-01 | Download from Renesas site |
| Flash Writer | Renesas Flash Programmer v3 | Download from Renesas site |
| Binary tool | aarch64-none-elf-objcopy 10.3-2021.07 | Download from GNU site |
| Key tool | keygen and sign | Included in wolfBoot |
| FIT Components | Version |
|---|---|
| Board Support Package Common Files | v3.6.0 |
| I/O Port | v3.6.0 |
| Arm CMSIS Version 5 - Core (M) | v5.8.0+fsp.3.6.0 |
| RA6M4-EK Board Support Files | v3.6.0 |
| Board support package for R7FA6M4AF3CFB | v3.6.0 |
| Board support package for RA6M4 | v3.6.0 |
| Board support package for RA6M4 - FSP Data | v3.6.0 |
| Flash Memory High Performance | v3.6.0 |
e2Studio Project:
wolfBoot IDE/Renesas/e2studio/RA6M4/wolfBoot
Sample app IDE/Renesas/e2studio/RA6M4/app_RA
Flash Allocation:
+---------------------------+------------------------+-----+
| B |H| |H| | |
| o |e| Primary |e| Update |Swap |
| o |a| Partition |a| Partition |Sect |
| t |d| |d| | |
+---------------------------+------------------------+-----+
0x00000000: wolfBoot
0x00010000: Primary partition (Header)
0x00010200: Primary partition (Application image)
0x00080000: Update partition (Header)
0x00080200: Update partition (Application image)
0x000F0000: Swap sector
This section describes about how to build wolfBoot and application and use them.
It has key tools running under the host environment such as Linux, Windows or MacOS. For compiling the tools, follow the instruction described in the user manual.
$ cd <wolfBoot>
$ export PATH=$PATH:<wolfBoot>/tools/keytools
$ keygen --ecc256 -g ./pri-ecc256.der # ECC256
$ keygen --rsa2048 -g ./pri-rsa2048.der # RSA2048
The keygen tool generates a pair of private and public key with -g option.
The private key is stored in the specified file.
The public key is stored in a key store as a C source code in "src/keystore.c" so that it can be compiled and linked with wolfBoot.
If you have an existing key pair, you can use -i option to import the public key to the store.
You can specify various signature algorithms such as
--ed25519 --ed448 --ecc256 --ecc384 --ecc521 --rsa2048 --rsa3072 --rsa4096
Open project under IDE/Renesas/e2studio/RA6M4/wolfBoot with e2Studio, and build the project. Project properties are preset for the demo.
PRINTF_ENABLED is for debug information about partitions. Eliminate them for operational use.
- Click File->New->
RA C/C++ Project. - Select
EK-RA6M4from Drop-down list. - Check
Static Library. - Select
No RTOSfrom RTOS selection. Click Next. - Check
Bare Metal Minimal. Click Finish. - Open Smart Configurator by clicking configuration.xml in the project
- Go to
BSPtab and increase Main Stack Size underRA Commonon Properties page, e.g. 0x2000 - Go to
BSPtab and increase Heap Size underRA Commonon Properties page, e.g. 0x10000 - Go to
Stackstab - Add
SCE Protected Modestack fromNew Stack->Security - Add
g_flash0 Flash(r_flash_hp)stack fromNew Stack->Storage
Modify g_flash0 Flash(r_flash_hp) properties as follows:
| Property | Value |
|---|---|
| Data Flash Background Operation | Disabled |
- Save
dummy_libraryFSP configuration - Copy configuration.xml and pincfg under
dummy_librarytowolfBoot - Open Smart Configurator by clicking copied configuration.xml
- Click
Generate Project Contenton Smart Configurator - Set
BSP_FEATURE_FLASH_SUPPORTS_ACCESS_WINDOWto 1) - Build
wolfBootproject
Open project under IDE/Renesas/e2studio/RA6M4/app_RA with e2Studio, and build the project. Project properties are preset for the demo.
-
Download J-Link software from Segger
-
Choose
J-Link Software and Documentation Pack -
Copy sample program files below from
Installed SEGGERfolder,e.g C:\Program Files\SEGGER\JLink\Samples\RTT, to /path/to/wolfBoot/IDE/Reenesas/e2studio/RA6M4/app_RA/src/SEGGER_RTT\SEGGER_RTT.c
SEGGER_RTT.h
SEGGER_RTT_Conf.h
SEGGER_RTT_printf.c -
Open
SEGGER_RTT_Conf.hand SetSEGGER_RTT_MEMCPY_USE_BYTELOOPto1 -
To connect RTT block, you can configure RTT viewer configuration based on where RTT block is in map file
e.g.[app_RA.map]
```
.bss._SEGGER_RTT
0x2000094c 0xa8 ./src/SEGGER_RTT/SEGGER_RTT.o
0x2000094c _SEGGER_RTT
````
you can specify "RTT control block" to 0x2000094c by Address
OR
you can specify "RTT control block" to 0x20000000 0x1000 by Search Range
- Click File->New->
RA C/C++ Project. - Select
EK-RA6M4from Drop-down list. - Check
Executable. - Select
No RTOSfrom RTOS selection. Click Next. - Check
Bare Metal Minimal. Click Finish. - Go to
BSPtab and Addg_flash0 Flash(r_flash_hp)stack fromNew Stack->Storage
Modify g_flash0 Flash(r_flash_hp) properties as follows:
| Property | Value |
|---|---|
| Data Flash Background Operation | Disabled |
- Save
dummy_applicationFSP configuration - Copy configuration.xml and pincfg under
dummy_applicationtoapp_RA - Open Smart Configurator by clicking copied configuration.xml
- Click
Generate Project Contenton Smart Configurator - Set
BSP_FEATURE_FLASH_SUPPORTS_ACCESS_WINDOWto 1) - Build
app_RAproject
Code Origin and entry point is "0x00010200". app_RA.elf is generated under Debug.
You can derive the binary file (app_RA.bin) using objcopy command as follows:
$ aarch64-none-elf-objcopy.exe -O binary -j .text -j .data app_RA.elf app_RA.bin
"sign" command under tools/keytools generates a signature for the binary with a specified version. It generates a file contain a partition header and application image. The partition header contain generated signature and other control fields. Output file name is made up from the input file name and version like app_RenesasRx01_v1.0_signed.bin.
$ sign --ecc256 app_RA.bin ../../../../../pri-ecc256.der 1.0
$ sign --rsa2048 app_RA.bin ../../../../../pri-rsa2048.der 1.0
wolfBoot KeyTools (Compiled C version)
wolfBoot version 10E0000
Update type: Firmware
Input image: app_RA.bin
Selected cipher: RSA2048
Selected hash : SHA256
Public key: ./pri-rsa2048.der
Output image: app_RA_v1.0_signed.bin
Target partition id : 1
Calculating SHA256 digest...
Signing the digest...
Output image(s) successfully created.
You can convert the binary file to hex format and download it to the board by Flash Programmer. The partition starts at "0x00010000".
$ aarch64-none-elf-objcopy.exe -I binary -O srec --change-addresses=0x00010000 app_RA_v1.0_signed.bin app_RA_v1.0_signed.hex
Now, you can download and start wolfBoot program by e2Studio debugger.
After starting the program, you can see the partition information as follows.
If the boot program succeeds integrity and authenticity check, it initiate the application V1. To initially run wolfBoot project,
1.) Right-Click the Project name.
2.) Select Debug As -> Renesas GDB Hardware Debugging
3.) Select J-Link ARM. Click OK.
4.) Select R7FA6M4AF. Click OK.
| ------------------------------------------------------------------- |
| Renesas RA User Application in BOOT partition started by wolfBoot |
| ------------------------------------------------------------------- |
WOLFBOOT_PARTITION_SIZE: 0x00060000
WOLFBOOT_PARTITION_BOOT_ADDRESS: 0x00010000
WOLFBOOT_PARTITION_UPDATE_ADDRESS: 0x00080000
Application Entry Address: 0x00010200
=== Boot Partition[00010000] ===
Magic: WOLF
Version: 01
Status: FF
Trailer Magic:
=== Update Partition[00080000] ===
Magic:
Version: 00
Status: FF
Trailer Magic:
Current Firmware Version : 1
Calling wolfBoot_success()
The application is calling wolfBoot_success() to set boot partition state.
Called wolfBoot_success()
=== Boot Partition[00010000] ===
Magic: WOLF
Version: 01
Status: 00
Trailer Magic: BOOT
=== Update Partition[00080000] ===
Magic:
Version: 00
Status: FF
Trailer Magic:
You can see the state is Success("00") and Trailer Magic number becomes "BOOT". You can also see flashing each LED light in 1 second. Notable things about V1 application, it will also call wolfBoot_update_trigger() so that it tells wolfBoot that new version exists. We are going to generate and download V2 application into "Update partition".
Similar to V1, you can sign and generate a binary of V2. The update partition starts at "0x00080000". You can download it by the flash programmer.
Updtate partition: -change-addresses=0x00080000
$ sign --ecc256 app_RA.bin ../../../../../pri-ecc256.der 2.0
$ sign --rsa2048 app_RA.bin ../../../../../pri-rsa2048.der 2.0
$ aarch64-none-elf-objcopy.exe -I binary -O srec --change-addresses=0x00080000 app_RA_v2.0_signed.bin app_RA_v2.0_signed.hex
The boot program checks integrity and authenticity of V2, swap the partition safely and initiates V2. You will see following message after the partition information. You can also see flashing each LED light in 5 second.
| ------------------------------------------------------------------- |
| Renesas RA User Application in BOOT partition started by wolfBoot |
| ------------------------------------------------------------------- |
WOLFBOOT_PARTITION_SIZE: 0x00060000
WOLFBOOT_PARTITION_BOOT_ADDRESS: 0x00010000
WOLFBOOT_PARTITION_UPDATE_ADDRESS: 0x00080000
Application Entry Address: 0x00010200
=== Boot Partition[00010000] ===
Magic: WOLF
Version: 02
Status: 00
Trailer Magic: BOOT
=== Update Partition[00080000] ===
Magic: WOLF
Version: 01
Status: FF
Trailer Magic:
Current Firmware Version : 2
Calling wolfBoot_success()
Called wolfBoot_success()
=== Boot Partition[00010000] ===
Magic: WOLF
Version: 02
Status: 00
Trailer Magic: BOOT
=== Update Partition[00080000] ===
Magic: WOLF
Version: 01
Status: FF
Trailer Magic:
You can see "Current Firmware Version : 2". The state is Success("00") and Tailer Magic number becomes "BOOT". You can also see flashing each LED light in 5 second at this new version.