|
| 1 | +# wolfBoot for Renesas RA6M4 |
| 2 | + |
| 3 | +## 1. Overview |
| 4 | + |
| 5 | +It demonstrates simple secure firmware update by wolfBoot. A sample application v1 is |
| 6 | +securely updated to v2. Both versions behave the same except displaying its version of v1 or v2. |
| 7 | +They are compiled by e2Studio and running on the target board. |
| 8 | + |
| 9 | +In this demo, you may download two versions of application binary file by Renesas Flash Programmer. |
| 10 | +You can download and excute wolfBoot by e2Studio debugger. Use a USB connection between PC and the |
| 11 | +board for the debugger and flash programmer. |
| 12 | + |
| 13 | +## 2. Components and Tools |
| 14 | + |
| 15 | + |
| 16 | +|Item|Name/Version|Note| |
| 17 | +|:--|:--|:--| |
| 18 | +|Board|Renesas EK-RA6M4|| |
| 19 | +|Device|R7FA6M4AF3CFB|| |
| 20 | +|Toolchain|GCC ARM Embedded 10.3.1.20210824|Included in GCC for Renesas RA| |
| 21 | +|FSP Version|3.6.0|Download from Renesas site| |
| 22 | +|IDE|e2studio 2022-01|Download from Renesas site| |
| 23 | +|Flash Writer|Renesas Flash Programmer v3|Download from Renesas site| |
| 24 | +|Binary tool|aarch64-none-elf-objcopy 10.3-2021.07|Download from GNU site| |
| 25 | +|Key tool|keygen and sign|Included in wolfBoot| |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +|FIT Components|Version| |
| 30 | +|:--|:--| |
| 31 | +|Board Support Package Common Files|v3.6.0| |
| 32 | +|I/O Port|v3.6.0| |
| 33 | +|Arm CMSIS Version 5 - Core (M)|v5.8.0+fsp.3.6.0| |
| 34 | +|RA6M4-EK Board Support Files|v3.6.0| |
| 35 | +|Board support package for R7FA6M4AF3CFB|v3.6.0| |
| 36 | +|Board support package for RA6M4|v3.6.0| |
| 37 | +|Board support package for RA6M4 - FSP Data|v3.6.0| |
| 38 | +|Flash Memory High Performance|v3.6.0| |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +e2Studio Project:\ |
| 43 | +wolfBoot IDE/Renesas/e2studio/RA6M4/wolfBoot\ |
| 44 | +Sample app IDE/Renesas/e2studio/RA6M4/app_RA |
| 45 | + |
| 46 | + |
| 47 | +Flash Allocation: |
| 48 | +``` |
| 49 | ++---------------------------+------------------------+-----+ |
| 50 | +| B |H| |H| | | |
| 51 | +| o |e| Primary |e| Update |Swap | |
| 52 | +| o |a| Partition |a| Partition |Sect | |
| 53 | +| t |d| |d| | | |
| 54 | ++---------------------------+------------------------+-----+ |
| 55 | +0x00000000: wolfBoot |
| 56 | +0x00010000: Primary partition (Header) |
| 57 | +0x00010200: Primary partition (Application image) |
| 58 | +0x00080000: Update partition (Header) |
| 59 | +0x00080200: Update partition (Application image) |
| 60 | +0x000F0000: Swap sector |
| 61 | +``` |
| 62 | + |
| 63 | +## 2. How to build and use |
| 64 | +This section describes about how to build wolfBoot and application and use them. |
| 65 | + |
| 66 | +### 1) Key generation |
| 67 | +It has key tools running under the host environment such as Linux, Windows or MacOS. |
| 68 | +For comiling the tools, follow the instruction described in the user manual. |
| 69 | + |
| 70 | + |
| 71 | +``` |
| 72 | +$ cd <wolfBoot> |
| 73 | +$ export PATH=$PATH:<wolfBoot>/tools/keytools |
| 74 | +$ keygen --ecc256 -g ./pri-ecc256.der # ECC256 |
| 75 | +$ keygen --rsa2048 -g ./pri-rsa2048.der # RSA2048 |
| 76 | +``` |
| 77 | + |
| 78 | +It generates a pair of private and public key with -g option. The private key is stored |
| 79 | +in the specified file. The public key is stored in a key store as a C source code |
| 80 | +in "src/keystore.c" so that it can be compiled and linked with wolfBoot. |
| 81 | +If you have an existing key pair, you can use -i option to import the pablic |
| 82 | +key to the store. |
| 83 | + |
| 84 | +You can specify various signature algorithms such as |
| 85 | + |
| 86 | +```les |
| 87 | +--ed25519 --ed448 --ecc256 --ecc384 --ecc521 --rsa2048 --rsa3072 --rsa4096 |
| 88 | +``` |
| 89 | + |
| 90 | +### 2) Compile wolfBoot |
| 91 | + |
| 92 | +Open project under IDE/Renesas/e2studio/RA6M4/wolfBoot with e2Studio, and build the project. |
| 93 | +Project properties are preset for the demo.\ |
| 94 | + |
| 95 | +WOLFBOOT_PARTION_INFO is for debug information about partitions. |
| 96 | +Eliminate them for operational use. |
| 97 | + |
| 98 | + |
| 99 | +### 3) Compile the sample application |
| 100 | + |
| 101 | +Open project under IDE/Renesas/e2studio/RA6M4/app_RA with e2Studio, and build the project. |
| 102 | +Project properties are preset for the demo. |
| 103 | + |
| 104 | + #### 3-1). Prepare SEGGER_RTT for logging |
| 105 | + + Download J-Link software from [Segger](https://www.segger.com/downloads/jlink) |
| 106 | + + Choose `J-Link Software and Documentation Pack` |
| 107 | + + Copy sample program files below from `Installed SEGGER` folder, `e.g C:\Program Files\SEGGER\JLink\Samples\RTT`, to /path/to/wolfBoot/IDE/Reenesas/e2studio/RA6M4/app_RA/src/SEGGER_RTT\ |
| 108 | + |
| 109 | + SEGGER_RTT.c\ |
| 110 | + SEGGER_RTT.h\ |
| 111 | + SEGGER_RTT_Conf.h\ |
| 112 | + SEGGER_RTT_printf.c |
| 113 | + |
| 114 | + + To connect RTT block, you can configure RTT viewer configuration based on where RTT block is in map file\ |
| 115 | + |
| 116 | + e.g.[app_RA.map] |
| 117 | + |
| 118 | + ``` |
| 119 | + .bss._SEGGER_RTT |
| 120 | + 0x2000094c 0xa8 ./src/SEGGER_RTT/SEGGER_RTT.o |
| 121 | + 0x2000094c _SEGGER_RTT |
| 122 | + ```` |
| 123 | + |
| 124 | + you can specify "RTT control block" to 0x2000094c by Address |
| 125 | + OR |
| 126 | + you can specify "RTT control block" to 0x20000000 0x1000 by Search Range |
| 127 | + |
| 128 | +
|
| 129 | +Need to set: |
| 130 | +#define BSP_FEATURE_FLASH_SUPPORTS_ACCESS_WINDOW (1)\ |
| 131 | +
|
| 132 | +Code Origin and entry point is "0x00010200". app_RA.elf is gnerated under Debug. |
| 133 | +
|
| 134 | +### 4) Generate Signature for app V1 |
| 135 | +You can derive bair binary file (app_RA.bin) by objcopy command as follows. |
| 136 | +
|
| 137 | +``` |
| 138 | +$ aarch64-none-elf-objcopy.exe -O binary -j .text -j .data app_RA.elf app_RA.bin |
| 139 | +``` |
| 140 | +
|
| 141 | +"sign" command under tools/keytools benerates a signature for the binary with a specified version. |
| 142 | +It generates a file contain a partition header and application image. The partition header |
| 143 | +contain generated signature and other control fields. Output file name is made up from |
| 144 | +the input file name and version like app_RenesasRx01_v1.0_signed.bin. |
| 145 | +
|
| 146 | +``` |
| 147 | +$ sign --ecc256 app_RA.bin ../../../../../pri-ecc256.der 1.0 |
| 148 | +$ sign --rsa2048 app_RA.bin ../../../../../pri-rsa2048.der 1.0 |
| 149 | +wolfBoot KeyTools (Compiled C version) |
| 150 | +wolfBoot version 10E0000 |
| 151 | +Update type: Firmware |
| 152 | +Input image: app_RA.bin |
| 153 | +Selected cipher: RSA2048 |
| 154 | +Selected hash : SHA256 |
| 155 | +Public key: ./pri-rsa2048.der |
| 156 | +Output image: app_RA_v1.0_signed.bin |
| 157 | +Target partition id : 1 |
| 158 | +Calculating SHA256 digest... |
| 159 | +Signing the digest... |
| 160 | +Output image(s) successfully created. |
| 161 | +``` |
| 162 | +
|
| 163 | +### 5) Download the app V1 |
| 164 | +
|
| 165 | +You can convert the binary file to hex format and download it to the board by Flash Programmer. |
| 166 | +The partition starts at "0x00010000". |
| 167 | +
|
| 168 | +``` |
| 169 | +$ aarch64-none-elf-objcopy.exe -I binary -O srec --change-addresses=0x00010000 app_RA_v1.0_signed.bin app_RA_v1.0_signed.hex |
| 170 | +``` |
| 171 | +
|
| 172 | +
|
| 173 | +### 6) Execute inital boot |
| 174 | +
|
| 175 | +Now, you can download and start wolfBoot program by e2Studio debugger. |
| 176 | +After starting the program, you can see the partition information as follows. |
| 177 | +If the boot program succeeds integlity and authenticity check, it initiate the |
| 178 | +application V1. |
| 179 | +
|
| 180 | +``` |
| 181 | +| ------------------------------------------------------------------- | |
| 182 | +| Renesas RA User Application in BOOT partition started by wolfBoot | |
| 183 | +| ------------------------------------------------------------------- | |
| 184 | + |
| 185 | + |
| 186 | +WOLFBOOT_PARTITION_SIZE: 0x00060000 |
| 187 | +WOLFBOOT_PARTITION_BOOT_ADDRESS: 0x00010000 |
| 188 | +WOLFBOOT_PARTITION_UPDATE_ADDRESS: 0x00080000 |
| 189 | + |
| 190 | +Application Entry Address: 0x00010200 |
| 191 | + |
| 192 | +=== Boot Partition[00010000] === |
| 193 | +Magic: WOLF |
| 194 | +Version: 01 |
| 195 | +Status: FF |
| 196 | +Tail Mgc: |
| 197 | + |
| 198 | +=== Update Partition[00080000] === |
| 199 | +Magic: |
| 200 | +Version: 00 |
| 201 | +Status: FF |
| 202 | +Tail Mgc: |
| 203 | +Current Firmware Version : 1 |
| 204 | + |
| 205 | +Calling wolfBoot_success() |
| 206 | + |
| 207 | +``` |
| 208 | +
|
| 209 | +The application is calling wolfBoot_success() to set boot partition state. |
| 210 | +
|
| 211 | +
|
| 212 | +``` |
| 213 | +Called wolfBoot_success() |
| 214 | +=== Boot Partition[00010000] === |
| 215 | +Magic: WOLF |
| 216 | +Version: 01 |
| 217 | +Status: 00 |
| 218 | +Tail Mgc: BOOT |
| 219 | + |
| 220 | +=== Update Partition[00080000] === |
| 221 | +Magic: |
| 222 | +Version: 00 |
| 223 | +Status: FF |
| 224 | +Tail Mgc: |
| 225 | +``` |
| 226 | +You can see the state is Success("00") and Tail Magic number becomes "BOOT". You can also see flashing each LED light in 1 second. |
| 227 | +Notable things about V1 application, it will also call wolfBoot_update_trigger() so that it tells wolfBoot that new version exists. |
| 228 | +We are going to generate and download V2 application into "Update pertition". |
| 229 | +
|
| 230 | +### 7) Generate Signed app V2 and download it |
| 231 | +
|
| 232 | +Similar to V1, you can signe and generate a binary of V2. The update partition starts at "0x00080000". |
| 233 | +You can download it by the flash programmer. |
| 234 | +
|
| 235 | +Updtate partition: |
| 236 | +-change-addresses=0x00080000 |
| 237 | +
|
| 238 | +``` |
| 239 | +$ sign --ecc256 app_RA.bin ../../../../../pri-ecc256.der 2.0 |
| 240 | +$ sign --rsa2048 app_RA.bin ../../../../../pri-rsa2048.der 2.0 |
| 241 | +$ aarch64-none-elf-objcopy.exe -I binary -O srec --change-addresses=0x00080000 app_RA_v2.0_signed.bin app_RA_v2.0_signed.hex |
| 242 | +``` |
| 243 | +
|
| 244 | +
|
| 245 | +### 8) Re-boot and secure update to V2 |
| 246 | +
|
| 247 | +The boot program checks integlity and authenticity of V2, swap the partition |
| 248 | +safely and initiates V2. You will see following message after the partition |
| 249 | +information. |
| 250 | +
|
| 251 | +``` |
| 252 | +| ------------------------------------------------------------------- | |
| 253 | +| Renesas RA User Application in BOOT partition started by wolfBoot | |
| 254 | +| ------------------------------------------------------------------- | |
| 255 | + |
| 256 | + |
| 257 | +WOLFBOOT_PARTITION_SIZE: 0x00060000 |
| 258 | +WOLFBOOT_PARTITION_BOOT_ADDRESS: 0x00010000 |
| 259 | +WOLFBOOT_PARTITION_UPDATE_ADDRESS: 0x00080000 |
| 260 | + |
| 261 | +Application Entry Address: 0x00010200 |
| 262 | + |
| 263 | +=== Boot Partition[00010000] === |
| 264 | +Magic: WOLF |
| 265 | +Version: 02 |
| 266 | +Status: 00 |
| 267 | +Tail Mgc: BOOT |
| 268 | + |
| 269 | +=== Update Partition[00080000] === |
| 270 | +Magic: WOLF |
| 271 | +Version: 01 |
| 272 | +Status: FF |
| 273 | +Tail Mgc: |
| 274 | +Current Firmware Version : 2 |
| 275 | + |
| 276 | +Calling wolfBoot_success() |
| 277 | +Called wolfBoot_success() |
| 278 | +=== Boot Partition[00010000] === |
| 279 | +Magic: WOLF |
| 280 | +Version: 02 |
| 281 | +Status: 00 |
| 282 | +Tail Mgc: BOOT |
| 283 | + |
| 284 | +=== Update Partition[00080000] === |
| 285 | +Magic: WOLF |
| 286 | +Version: 01 |
| 287 | +Status: FF |
| 288 | +Tail Mgc: |
| 289 | +``` |
| 290 | +You can see "Current Firmware Version : 2". The state is Success("00") and Tail Magic number becomes "BOOT". |
| 291 | +You can also see flashing each LED light in 5 second at this new version. |
| 292 | +
|
| 293 | +
|
0 commit comments