Skip to content

Commit 67b6df7

Browse files
authored
Merge pull request #524 from danielinux/rp2350
Support for Raspberry-pi pico2 (rp2350)
2 parents 456a6f8 + 6f350ff commit 67b6df7

25 files changed

+1323
-9
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Wolfboot Reusable Build Workflow for Raspberry Pi Pico2 (rp2350)
2+
3+
on:
4+
5+
workflow_call:
6+
inputs:
7+
arch:
8+
required: true
9+
type: string
10+
config-file:
11+
required: true
12+
type: string
13+
make-args:
14+
required: false
15+
type: string
16+
target:
17+
required: true
18+
type: string
19+
20+
jobs:
21+
22+
build:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v3
27+
with:
28+
submodules: true
29+
30+
- uses: actions/checkout@main
31+
with:
32+
repository: raspberrypi/pico-sdk
33+
path: pico-sdk
34+
35+
- name: Workaround for sources.list
36+
run: sudo sed -i 's|http://azure.archive.ubuntu.com/ubuntu/|http://mirror.arizona.edu/ubuntu/|g' /etc/apt/sources.list
37+
38+
- name: Update repository
39+
run: sudo apt-get update
40+
41+
- name: Install cross compilers
42+
run: |
43+
sudo apt-get install -y gcc-arm-none-eabi
44+
45+
- name: make distclean
46+
run: |
47+
make distclean
48+
49+
- name: Select config
50+
run: |
51+
cp ${{inputs.config-file}} .config && make include/target.h
52+
53+
- name: Build tools
54+
run: |
55+
make -C tools/keytools && make -C tools/bin-assemble
56+
57+
- name: pre-build wolfboot
58+
run: |
59+
make
60+
- name: build wolfboot with pico-sdk
61+
run: |
62+
cd IDE/pico-sdk/${{inputs.target}}/wolfboot
63+
mkdir build
64+
cd build
65+
cmake ../ -DPICO_SDK_PATH="$GITHUB_WORKSPACE/pico-sdk" -DPICO_PLATFORM=${{inputs.target}}
66+
make

.github/workflows/test-configs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,10 @@ jobs:
439439
with:
440440
arch: host
441441
config-file: ./config/examples/sim-wolfHSM.config
442+
443+
rp2350_test:
444+
uses: ./.github/workflows/test-build-pico-sdk.yml
445+
with:
446+
arch: arm
447+
config-file: ./config/examples/rp2350.config
448+
target: rp2350

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ IDE/Renesas/e2studio/RX72N/app_RenesasRX01/src/smc_gen
231231
IDE/Renesas/e2studio/RX72N/wolfBoot/HardwareDebug
232232
IDE/Renesas/e2studio/RX72N/wolfBoot/src/smc_gen
233233

234+
# IDE pico-sdk build directories
235+
IDE/pico-sdk/rp2350/wolfboot/build
236+
IDE/pico-sdk/rp2350/test-app/build
237+
238+
# Third party test application distributed off-tree
239+
IDE/pico-sdk/rp2350/test-app/blink.c
240+
234241
# Renesas Libraries
235242
lib/r_bsp
236243
lib/r_config

IDE/pico-sdk/rp2350/README.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
set(WOLFBOOT_PATH ../../../../)
3+
set(CMAKE_CXX_COMPILER arm-none-eabi-gcc)
4+
set(LIB_PICO_RUNTIME_INIT=0)
5+
6+
include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
7+
8+
set(PICOTOOL_FETCH_FROM_GIT_PATH ../wolfboot/build/picotool)
9+
set(BOOT_STAGE2_FILE ${CMAKE_CURRENT_LIST_DIR}/boot2_empty.S)
10+
set(PICO_NO_RUNTIME 1)
11+
12+
project(blink)
13+
14+
# initialize the Raspberry Pi Pico SDK
15+
pico_sdk_init()
16+
17+
18+
add_executable(blink
19+
blink.c
20+
runtime.c
21+
)
22+
23+
target_compile_options(blink PRIVATE
24+
-DPICO_RUNTIME_NO_INIT_BOOTROM_RESET=1
25+
-DPICO_RUNTIME_NO_INIT_CLOCKS=1
26+
-DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=1
27+
)
28+
target_compile_definitions(blink PRIVATE PICO_NO_RUNTIME=1)
29+
30+
pico_set_linker_script(blink ../../../../../hal/rp2350-app.ld)
31+
target_link_libraries(blink pico_stdlib)
32+
33+
# create map/bin/hex/uf2 file etc.
34+
pico_add_extra_outputs(blink)
35+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
mkdir -p build
4+
cd build
5+
cmake .. -DPICO_SDK_PATH=$PICO_SDK_PATH -DPICO_PLATFORM=rp2350
6+
7+
# Get off-tree source file from raspberry pico-examples
8+
curl -o blink.c https://raw.githubusercontent.com/raspberrypi/pico-examples/refs/tags/sdk-2.1.0/blink/blink.c
9+
10+
make clean && make
11+
12+
IMAGE_HEADER_SIZE=1024 ../../../../../tools/keytools/sign --sha256 --ecc256 blink.bin \
13+
../../../../../wolfboot_signing_private_key.der 1
14+
15+
cd ..
16+
17+
JLinkExe -Device RP2350_M33_0 -If swd -Speed 4000 -CommanderScript flash_app.jlink
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
connect
2+
r
3+
loadfile build/blink_v1_signed.bin 0x10040000
4+
r
5+
g
6+
exit
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* runtime.c
2+
*
3+
* Custom pre-init for non-secure application, staged by wolfBoot.
4+
* Wolfboot test application for raspberry-pi pico2 (rp2350)
5+
*
6+
* Copyright (C) 2025 wolfSSL Inc.
7+
*
8+
* This file is part of wolfBoot.
9+
*
10+
* wolfBoot is free software; you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation; either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* wolfBoot is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program; if not, write to the Free Software
22+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
23+
*/
24+
#include <stdint.h>
25+
typedef void (*preinit_fn_t)(void);
26+
27+
void runtime_init_cpasr(void)
28+
{
29+
volatile uint32_t *cpasr_ns = (volatile uint32_t*) 0xE000ED88;
30+
*cpasr_ns |= 0xFF;
31+
}
32+
33+
preinit_fn_t __attribute__((section(".nonsecure_preinit_array"))) nonsecure_preinit[] =
34+
{ &runtime_init_cpasr };
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tar rem:3333
2+
file build/wolfboot.elf
3+
add-symbol-file ../test-app/build/blink.elf
4+
foc c
5+

0 commit comments

Comments
 (0)