|
| 1 | +## wolfBoot for Renesas RX71M (CC-RX, e2 studio) |
| 2 | + |
| 3 | +## 1. Overview |
| 4 | + |
| 5 | +This example builds wolfBoot and a sample application for the Renesas Starter |
| 6 | +Kit+ for RX71M with the CC-RX compiler in e2 studio. The application v1 is |
| 7 | +updated to v2 by wolfBoot. Both versions are the same program; they print |
| 8 | +their version and the state of the two partitions. |
| 9 | + |
| 10 | +- Signature ECC256, hash SHA256, 256-byte image header, software crypto (the |
| 11 | + RX71M has no TSIP). |
| 12 | +- The flash layout, image header and partition flags are the same as in the |
| 13 | + GCC build (`config/examples/renesas-rx71m.config`). Build wolfBoot and the |
| 14 | + application with the same compiler: the GCC wolfBoot calls the address |
| 15 | + stored at the application start, while the CC-RX wolfBoot jumps to the |
| 16 | + application start. See |
| 17 | + [docs/Targets.md](../../../../docs/Targets.md#renesas-rx71m). |
| 18 | +- `printf` and `getchar` use the BSP stdio, which goes to the e2 studio |
| 19 | + **Renesas Debug Virtual Console**. It works only while an e2 studio debug |
| 20 | + session is connected: without one, wolfBoot waits at its first `printf`. |
| 21 | + For console output without the debugger, use the GCC build with |
| 22 | + `DEBUG_UART=1` (SCI7). |
| 23 | + |
| 24 | +| Region | Address | Size | |
| 25 | +| --- | --- | --- | |
| 26 | +| Update partition | 0xFFC00000 | 0x1D0000 | |
| 27 | +| Boot partition (application) | 0xFFE00000 | 0x1D0000 | |
| 28 | +| Swap sector | 0xFFFD0000 | 0x8000 | |
| 29 | +| wolfBoot, with the vector tables | 0xFFFF0000 | 0x10000 | |
| 30 | + |
| 31 | +## 2. Components and Tools |
| 32 | + |
| 33 | +| Item | Name/Version | Note | |
| 34 | +| :-- | :-- | :-- | |
| 35 | +| Board | Renesas Starter Kit+ for RX71M | R5F571MLCDFC, 24 MHz crystal | |
| 36 | +| IDE | e2 studio 2026-10 | | |
| 37 | +| Compiler | CC-RX V3.08.00 | | |
| 38 | +| BSP | r_bsp 7.71 | Downloaded by the Smart Configurator | |
| 39 | +| Flash programmer | Renesas Flash Programmer V3 (GUI or `rfp-cli`) | E2 emulator Lite | |
| 40 | +| rx-elf-objcopy | GCC for Renesas RX | Used by `make_images.sh` | |
| 41 | +| Key tools | keygen and sign | Included in wolfBoot | |
| 42 | + |
| 43 | +Board settings: SW4 pins 1 and 2 OFF (single-chip mode). Power the board from |
| 44 | +its 5V jack; in the debug configuration set "Power Target From The Emulator" |
| 45 | +to No. |
| 46 | + |
| 47 | +## 3. How to build and use |
| 48 | + |
| 49 | +### 3-1 Key generation |
| 50 | + |
| 51 | +``` |
| 52 | +$ cd <wolfBoot> |
| 53 | +$ make keytools |
| 54 | +$ ./tools/keytools/keygen --ecc256 -g ./wolfboot_signing_private_key.der |
| 55 | +``` |
| 56 | + |
| 57 | +The public key is written to `src/keystore.c`, which the wolfBoot project |
| 58 | +compiles. Rebuild wolfBoot after generating a new key, and sign the |
| 59 | +application with the same private key. |
| 60 | + |
| 61 | +### 3-2 Import the projects and generate the BSP code |
| 62 | + |
| 63 | +1. In e2 studio, File > Import > General > Existing Projects into Workspace, |
| 64 | + select `<wolfBoot>/IDE/Renesas/e2studio/RX71M`, and import `wolfBoot` and |
| 65 | + `app_RenesasRX01`. Do not tick "Copy projects into workspace": the |
| 66 | + projects link to the wolfBoot sources by relative path. |
| 67 | +2. Open `wolfBoot.scfg`, let the Smart Configurator download r_bsp 7.71 if |
| 68 | + asked, and press "Generate Code". Do the same with |
| 69 | + `app_RenesasRX01.scfg`. The code goes to `src/smc_gen` of each project. |
| 70 | + |
| 71 | +The Smart Configurator settings are already made: |
| 72 | + |
| 73 | +| Setting | wolfBoot | app_RenesasRX01 | |
| 74 | +| :-- | :-- | :-- | |
| 75 | +| Clocks | Main 24 MHz, PLL x10: ICLK 240 MHz, PCLKA 120 MHz, PCLKB/C/D 60 MHz, FCLK 60 MHz | same | |
| 76 | +| `BSP_CFG_USER_STACK_ENABLE` | 0 | 1 (`0x1000` bytes) | |
| 77 | +| `BSP_CFG_ISTACK_BYTES` | `0x2000` | `0x400` | |
| 78 | +| `BSP_CFG_HEAP_BYTES` | `0xF000` | `0x400` | |
| 79 | +| `BSP_CFG_IO_LIB_ENABLE` | 1 | 1 | |
| 80 | + |
| 81 | +### 3-3 Build |
| 82 | + |
| 83 | +Build both projects (configuration HardwareDebug). The project settings are |
| 84 | +preset: |
| 85 | + |
| 86 | +| Setting | wolfBoot | app_RenesasRX01 | |
| 87 | +| :-- | :-- | :-- | |
| 88 | +| Macros | `__WOLFBOOT`, `TARGET_rx71m`, `__RX__`, `WOLFSSL_USER_SETTINGS` | `WOLFBOOT_RENESAS_APP`, `TARGET_rx71m`, `__RX__`, `WOLFSSL_USER_SETTINGS`, `XMEMCPY=memcpy` | |
| 89 | +| Pre-include | `../../include/user_settings.h`, `../../include/target.h` | same | |
| 90 | +| Compiler options | `-branch=32`, `-goptimize` | same | |
| 91 | +| Linker optimization | `-optimize=symbol_delete` (unreferenced functions and variables are removed) | same | |
| 92 | +| ROM to RAM mapped sections | `D=R`, `D_1=R_1`, `D_2=R_2`, `PFRAM=RPFRAM` | same | |
| 93 | +| Code start | `0xFFFF0000` | `0xFFE00100` (after the 256-byte header) | |
| 94 | + |
| 95 | +The flash driver in `hal/renesas-rx.c` and the flash update code run from RAM: |
| 96 | +they are placed in section `PFRAM` (`#pragma section FRAM`), linked at |
| 97 | +`RPFRAM` in the RAM section group that starts at `0x1000`, and copied there by |
| 98 | +`hal_flash_init()`, which prints the `RPFRAM` address range. |
| 99 | + |
| 100 | +An application of your own that calls `wolfBoot_success()` or |
| 101 | +`wolfBoot_update_trigger()` needs the same: compile `hal/renesas-rx.c`, |
| 102 | +`src/libwolfboot.c` and `src/string.c` into it, map `PFRAM=RPFRAM`, place |
| 103 | +`RPFRAM` in RAM in the `-start` option, and call `hal_init()` (which calls |
| 104 | +`hal_flash_init()`) before either function. |
| 105 | + |
| 106 | +The outputs are `wolfBoot.x` and `app_RenesasRX01.x` under each project's |
| 107 | +`HardwareDebug` folder. |
| 108 | + |
| 109 | +### 3-4 Make the images |
| 110 | + |
| 111 | +``` |
| 112 | +$ ./IDE/Renesas/e2studio/RX71M/make_images.sh <RX_ELF_BIN_DIR> ./wolfboot_signing_private_key.der <OUTPUT_DIR> |
| 113 | +``` |
| 114 | + |
| 115 | +`<RX_ELF_BIN_DIR>` is the folder containing `rx-elf-objcopy`. The script |
| 116 | +writes: |
| 117 | + |
| 118 | +| File | Address | |
| 119 | +| :-- | :-- | |
| 120 | +| `wolfboot.bin` | 0xFFFF0000 (64 KB, wolfBoot and the vector tables) | |
| 121 | +| `app_RenesasRX01_v1_signed.bin` | 0xFFE00000 (boot partition) | |
| 122 | +| `app_RenesasRX01_v2_signed.bin` | 0xFFC00000 (update partition) | |
| 123 | + |
| 124 | +The images contain code flash only. The BSP also places the option-setting |
| 125 | +memory (`0x00120040`, OFS0/OFS1/MDE) in every CC-RX output; the script leaves |
| 126 | +it out, so it is never written by accident. |
| 127 | + |
| 128 | +### 3-5 Program the board |
| 129 | + |
| 130 | +With Renesas Flash Programmer, program the three binary files at the |
| 131 | +addresses above, for example: |
| 132 | + |
| 133 | +``` |
| 134 | +rfp-cli -if uart -t e2l -device RX71x -pv -auth id FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF \ |
| 135 | + -bin FFFF0000 wolfboot.bin \ |
| 136 | + -bin FFE00000 app_RenesasRX01_v1_signed.bin \ |
| 137 | + -bin FFC00000 app_RenesasRX01_v2_signed.bin |
| 138 | +``` |
| 139 | + |
| 140 | +`-pv` erases only the blocks that are written. Do not program the `.mot` or |
| 141 | +`.abs` files: they include the option-setting memory. |
| 142 | + |
| 143 | +### 3-6 Run with the e2 studio debugger |
| 144 | + |
| 145 | +Create a "Renesas GDB Hardware Debugging" configuration: |
| 146 | + |
| 147 | +- Main: C/C++ Application `wolfBoot/HardwareDebug/wolfBoot.x`. |
| 148 | +- Debugger: E2 Lite, target R5F571ML, JTAG connection, EXTAL 24 MHz, |
| 149 | + "Power Target From The Emulator" No. |
| 150 | +- Startup: in "Load image and symbols", set the `wolfBoot.x` entry to |
| 151 | + **Symbols only**. Downloading the image would also write the option-setting |
| 152 | + memory; the board already holds the programmed images. |
| 153 | + |
| 154 | +Start the debug session, open Window > Show View > Renesas Debug Virtual |
| 155 | +Console, and resume. wolfBoot verifies and starts v1: |
| 156 | + |
| 157 | +``` |
| 158 | +RAM Function start = 0x1a748 |
| 159 | +RAM Function end = 0x1b504 |
| 160 | +RAM Function size = 3516 |
| 161 | +Boot partition: ffe00000 (sz 17618, ver 0x1, type 0x201) |
| 162 | +Update partition: ffc00000 (sz 17618, ver 0x2, type 0x201) |
| 163 | +Boot partition: ffe00000 (sz 17618, ver 0x1, type 0x201) |
| 164 | +Booting version: 0x1 |
| 165 | +Checking integrity...done |
| 166 | +Verifying signature...done |
| 167 | +app_offset 0xffe00100 |
| 168 | +RAM Function start = 0xaf18 |
| 169 | +RAM Function end = 0xb5cd |
| 170 | +RAM Function size = 1717 |
| 171 | +| ------------------------------------------------------------------- | |
| 172 | +| Renesas RX User Application in BOOT partition started by wolfBoot | |
| 173 | +| ------------------------------------------------------------------- | |
| 174 | +
|
| 175 | +
|
| 176 | +=== Boot Partition[ffe00000] === |
| 177 | +Magic: WOLF |
| 178 | +Version: 01 |
| 179 | +Status: ff (New) |
| 180 | +Trailer Mgc: none |
| 181 | +
|
| 182 | +=== Update Partition[ffc00000] === |
| 183 | +Magic: WOLF |
| 184 | +Version: 02 |
| 185 | +Status: ff (New) |
| 186 | +Trailer Mgc: none |
| 187 | +
|
| 188 | +Current Firmware Version: 1 |
| 189 | +Hit any key to call wolfBoot_success the firmware. |
| 190 | +``` |
| 191 | + |
| 192 | +Type a key in the virtual console. The application calls |
| 193 | +`wolfBoot_success()` (boot partition `00 (Success)`), then waits for a second |
| 194 | +key and calls `wolfBoot_update_trigger()` (update partition `70 (Updating)`). |
| 195 | +Breakpoints in the application make its hash check fail; to debug the |
| 196 | +application, load `app_RenesasRX01.x` as symbols only and use hardware |
| 197 | +breakpoints. |
| 198 | + |
| 199 | +### 3-7 Update to v2 |
| 200 | + |
| 201 | +Reset and resume in e2 studio. wolfBoot swaps the partitions and starts v2: |
| 202 | + |
| 203 | +``` |
| 204 | +Starting Update (fallback allowed 0) |
| 205 | +Versions: Current 0x1, Update 0x2 |
| 206 | +Copy sector 0 (part 1->2) |
| 207 | +Copy sector 0 (part 0->1) |
| 208 | +Copy sector 0 (part 2->0) |
| 209 | +Erasing remainder of partition (55 sectors)... |
| 210 | +Copy sector 55 (part 0->2) |
| 211 | +Copied boot sector to swap |
| 212 | +Booting version: 0x2 |
| 213 | +Checking integrity...done |
| 214 | +Verifying signature...done |
| 215 | +... |
| 216 | +=== Boot Partition[ffe00000] === |
| 217 | +Magic: WOLF |
| 218 | +Version: 02 |
| 219 | +Status: 10 (Testing) |
| 220 | +Trailer Mgc: BOOT |
| 221 | +``` |
| 222 | + |
| 223 | +Type a key to call `wolfBoot_success()`. If v2 is reset before that, |
| 224 | +wolfBoot rolls back to v1. |
| 225 | + |
| 226 | +## 4. Notes |
| 227 | + |
| 228 | +- Code flash is rated for 1,000 erase cycles per block, and an update erases |
| 229 | + the flag sectors several times per image sector. See |
| 230 | + [docs/Targets.md](../../../../docs/Targets.md#renesas-rx71m). |
| 231 | +- `include/user_settings.h` sets the include guard of the wolfBoot |
| 232 | + `include/user_settings.h`, which CC-RX could otherwise find next to the |
| 233 | + wolfBoot headers and add to this configuration. |
0 commit comments