|
| 1 | +## wolfBoot port for rp2350 (Raspberry pi pico 2) |
| 2 | + |
| 3 | +### Support for TrustZone |
| 4 | + |
| 5 | +By default, TZEN=1 is enabled in the provided configuration. wolfBoot will run |
| 6 | +from the Secure domain, and will stage the application in the Non-Secure domain. |
| 7 | + |
| 8 | +The flash memory is divided as follows: |
| 9 | + |
| 10 | +- wolfBoot partition (0x10000000 - 0x1003FFFF), 224 KB |
| 11 | +- Non-secure callable partition (for secure gateway) (0x10038000 - 0x1003FFFF), 32 KB |
| 12 | +- Boot partition (0x10040000 - 0x1007FFFF), 768 KB |
| 13 | +- Update partition (0x10100000 - 0x1013FFFF), 768 KB |
| 14 | +- Unused flash space (0x101C1000 - 0x101FFFFF), 252 KB |
| 15 | +- Swap space (0x101C0000 - 0x101C0FFF), 4 KB |
| 16 | + |
| 17 | +The SRAM bank0 is assigned to the Secure domain, and enforced using both SAU and `ACCESS_CONTROL` registers. |
| 18 | + |
| 19 | +- Secure SRAM0-3: 0x20000000 - 0x2003FFFF, 256 KB |
| 20 | +- Non-secure SRAM4-7: 0x20040000 - 0x2007FFFF, 256 KB |
| 21 | +- Non-secure stack for application SRAM8-9: 0x20080000 - 0x20081FFF, 8 KB |
| 22 | + |
| 23 | + |
| 24 | +### Requirements |
| 25 | + |
| 26 | +#### External debugger |
| 27 | + |
| 28 | +As the two images (bootloader + application) are stored in different areas in |
| 29 | +the flash memory, a SWD connector is recommended to upload the binary images |
| 30 | +into the flash, as opposed to the default bootloader, allowing to upload |
| 31 | +non-signed applications into a storage device. |
| 32 | + |
| 33 | +The scripts used in this example expect a JLink to be connected to the SWD port |
| 34 | +as documented [here](https://kb.segger.com/Raspberry_Pi_Pico). |
| 35 | + |
| 36 | +There is documentation below on how to do this with `picotool` instead, the |
| 37 | +scripts to error that it cannot file the JLink if you wish to use `picotool` |
| 38 | +instead, but this can be ignored. |
| 39 | + |
| 40 | +#### PicoSDK |
| 41 | + |
| 42 | +Clone the repository from raspberrypi's github: |
| 43 | + |
| 44 | +``` |
| 45 | +git clone https://github.com/raspberrypi/pico-sdk.git |
| 46 | +``` |
| 47 | + |
| 48 | +Export the `PICO_SDK_PATH` environment variable to point to the pico-sdk directory: |
| 49 | + |
| 50 | +``` |
| 51 | +export PICO_SDK_PATH=/path/to/pico-sdk |
| 52 | +``` |
| 53 | + |
| 54 | +### Configuring wolfBoot to build with pico-sdk |
| 55 | + |
| 56 | +From wolfBoot root directory, copy the example configuration: |
| 57 | + |
| 58 | +``` |
| 59 | +cp config/examples/rp2350.config .config |
| 60 | +``` |
| 61 | + |
| 62 | +You can now edit the .config file to change partition sizes/offsets, algorithms, |
| 63 | +disable trustzone, add/remove features, etc. |
| 64 | + |
| 65 | +When TZEN=0, the application will run in the Secure domain. |
| 66 | + |
| 67 | +When the configuration is complete, run `make`. This will: |
| 68 | + |
| 69 | +- Build the key tools (keygen & sign): |
| 70 | +- Generate the configuration header `target.h` |
| 71 | +- Generate a new keypair (only once), and place the public key in the |
| 72 | +keystore |
| 73 | + |
| 74 | +The environment has now been prepared to build and flash the two images |
| 75 | +(wolfBoot + test application). |
| 76 | + |
| 77 | +### Building and uploading wolfBoot.bin |
| 78 | + |
| 79 | +After preparing the configuration and creating the keypair, |
| 80 | +return to the `IDE/pico-sdk/rp2350/` directory and run: |
| 81 | + |
| 82 | +``` |
| 83 | +cd wolfboot |
| 84 | +export PICO_SDK_PATH=... |
| 85 | +./build-wolfboot.sh |
| 86 | +``` |
| 87 | + |
| 88 | +The script above will compile wolfboot as rp2350 second-stage bootloader. |
| 89 | +This version of wolfboot incorporates the `.boot2` sequence needed to enable |
| 90 | +the QSPI device, provided by the pico-sdk and always embedded in all |
| 91 | +applications. |
| 92 | + |
| 93 | +wolfboot.bin contains the bootloader, and can be loaded into the RP2350, |
| 94 | +starting at address 0x10000000. The script will automatically upload the binary |
| 95 | +if a JLink debugger is connected. |
| 96 | + |
| 97 | +If you do not have a JLink you can install the binary using: |
| 98 | + |
| 99 | +``` |
| 100 | +picotool load build/wolfboot.uf2 |
| 101 | +``` |
| 102 | + |
| 103 | +### Building and uploading the application |
| 104 | + |
| 105 | +``` |
| 106 | +cd ../test-app |
| 107 | +./build-signed-app.sh |
| 108 | +``` |
| 109 | +The script above will compile the test application and sign it with the |
| 110 | +wolfBoot private key. The signed application is then uploaded to the boot |
| 111 | +partition of the flash memory, at address 0x10040000. |
| 112 | + |
| 113 | +The linker script included is modified to change the application entry point |
| 114 | +from 0x10000000 to 0x10040400, which is the start of the application code, |
| 115 | +taking into account the wolfBoot header size. |
| 116 | + |
| 117 | +The application is signed with the wolfBoot private key, and the signature is |
| 118 | +stored in the manifest header of the application binary. |
| 119 | + |
| 120 | +The output file `build/blink_v1_signed.bin` is automatically uploaded to the |
| 121 | +RP2350 if a JLink debugger is connected. |
| 122 | +The application image is stored in the boot partition, starting at address |
| 123 | +0x10040000. |
| 124 | +The entry point of the application (0x10040400), set in the linker script |
| 125 | +`hal/rp2350-app.ld`, is the start of the application code, taking into account |
| 126 | +the wolfBoot header size. |
| 127 | + |
| 128 | +To use `picotool` instead run: |
| 129 | + |
| 130 | +``` |
| 131 | +picotool load build/blink_v1_signed.bin -o 0x10040000 |
| 132 | +``` |
| 133 | + |
| 134 | +### Testing the application |
| 135 | + |
| 136 | +The application is a simple blinky example, which toggles the LED on the board |
| 137 | +every 500ms. |
| 138 | + |
| 139 | +If the above steps are successful, the LED on the board should start blinking. |
| 140 | + |
| 141 | +The code has been tested on a Seeed studio XIAO RP2350 board and a Raspberry Pi |
| 142 | +Pico 2 (non-WiFi version). |
| 143 | + |
0 commit comments