Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/test-configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,19 @@ jobs:
config-file: ./config/examples/sim.config
make-args: WOLFTPM=1 SIM_TPM=1

rp2040_test:
uses: ./.github/workflows/test-build.yml
with:
arch: arm
config-file: ./config/examples/rp2040.config

rp2040_dev_aids_test:
uses: ./.github/workflows/test-build.yml
with:
arch: arm
config-file: ./config/examples/rp2040.config
make-args: RP2040_RAM_LOG=1 RP2040_BOOT_GUARD=1 RP2040_XIP_QUAD=2 BOOT_BENCHMARK=1

rp2350_test:
uses: ./.github/workflows/test-build-pico-sdk.yml
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ tools/unit-tests/unit-pci-4gib
tools/unit-tests/unit-pkcs11-pin-zeroize
tools/unit-tests/unit-pkcs11_store-stalecache
tools/unit-tests/unit-rp2350-flash-write
tools/unit-tests/unit-rp2040-flash-write
tools/unit-tests/unit-samr21-erase-advance
tools/unit-tests/unit-samr21-flash-protect
tools/unit-tests/unit-sdhci-acmd41-timeout
Expand Down Expand Up @@ -732,6 +733,7 @@ tools/unit-tests/p1021_erase_fn_extract.h
tools/unit-tests/p1021_read_extract.h
tools/unit-tests/p1021_read_fn_extract.h
tools/unit-tests/rp2350_flash_write_extract.h
tools/unit-tests/rp2040_flash_write_extract.h
tools/unit-tests/stm32c0_write_extract.h
tools/unit-tests/stm32g4_write_extract.h
tools/unit-tests/stm32h7_flash_write_extract.h
Expand Down
20 changes: 20 additions & 0 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,26 @@ ifeq ($(ARCH),ARM)
PART_SWAP_EXT=1
endif

ifeq ($(TARGET),rp2040)
CORTEX_M0=1
Comment on lines +978 to +979
CFLAGS+=-Ihal
ARCH_FLASH_OFFSET=0x10000000
WOLFBOOT_ORIGIN=0x10000000
RP2040_SYS_MHZ?=125
CFLAGS+=-DRP2040_SYS_MHZ=$(RP2040_SYS_MHZ)
Comment thread
dgarske marked this conversation as resolved.
Resolved
ifneq ($(filter-out 0,$(RP2040_XIP_QUAD)),)
CFLAGS+=-DRP2040_XIP_QUAD=$(RP2040_XIP_QUAD)
endif
ifeq ($(RP2040_RAM_LOG),1)
CFLAGS+=-DRP2040_RAM_LOG
endif
ifeq ($(RP2040_BOOT_GUARD),1)
CFLAGS+=-DRP2040_BOOT_GUARD
# wolfBoot feeds the guard from its hash and sector-copy loops.
WATCHDOG=1
endif
endif

ifeq ($(TARGET),rp2350)
CORTEX_M33=1
CFLAGS+=-Ihal
Expand Down
54 changes: 54 additions & 0 deletions config/examples/rp2040.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
ARCH?=ARM
TARGET?=rp2040
SIGN?=ECC256
HASH?=SHA256
DEBUG?=0
VTOR?=1
CORTEX_M0?=1
NO_ASM?=0
NO_MPU=1
EXT_FLASH?=0
SPI_FLASH?=0
ALLOW_DOWNGRADE?=0
NVM_FLASH_WRITEONCE?=0
WOLFBOOT_VERSION?=1
V?=0
SPMATH?=1
RAM_CODE?=0
DUALBANK_SWAP?=0
DEBUG_UART?=1

# Cortex-M0+ has no unaligned word access.
CFLAGS_EXTRA+=-DWOLFSSL_USE_ALIGN

# clk_sys in MHz: 12 runs from the crystal, 63..133 from PLL_SYS.
RP2040_SYS_MHZ?=125

# Quad flash read at clk_sys / n (2 or 4), set up by wolfBoot at start and
# inherited by the application; 0 keeps the 03h serial read of the second
# stage. Needs a W25Q-compatible flash with its Quad Enable bit set (if it
# is clear, wolfBoot stays in serial read mode).
RP2040_XIP_QUAD?=0

# Console is UART0 at 115200 on GP0 (TX) / GP1 (RX). Other pins:
# CFLAGS_EXTRA+=-DRP2040_UART_TX_PIN=12 -DRP2040_UART_RX_PIN=13

# Development aids for a board with no debug probe or UART adapter:
# RP2040_RAM_LOG=1 also keep the console text in the SRAM4 scratch bank
# (0x20040000) for the application to read back; needs
# DEBUG_UART=1
# RP2040_BOOT_GUARD=1 enter the boot ROM USB loader if wolfBoot hangs or
# finds nothing to boot, instead of staying there
RP2040_RAM_LOG?=0
RP2040_BOOT_GUARD?=0

# 2 MB QSPI flash (Pico, W5100S-EVB-Pico), 4 KB erase sectors:
# 0x10000000 boot2 (256 bytes) + wolfBoot 64 KB
# 0x10010000 BOOT partition 960 KB
# 0x10100000 UPDATE partition 960 KB
# 0x101F0000 SWAP 4 KB
WOLFBOOT_SECTOR_SIZE?=0x1000
WOLFBOOT_PARTITION_SIZE?=0xF0000
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x10010000
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x10100000
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x101F0000
89 changes: 89 additions & 0 deletions docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ This README describes configuration of supported targets.
* [Qemu x86-64 UEFI](#qemu-x86-64-uefi)
* [NVIDIA Jetson Orin (aarch64_efi)](#nvidia-jetson-orin-aarch64_efi)
* [NVIDIA Jetson Orin (NVIDIA Tegra234) BL33 firmware](#nvidia-jetson-orin-nvidia-tegra234-bl33-firmware)
* [Raspberry Pi Pico (rp2040)](#raspberry-pi-pico-rp2040)
* [Raspberry Pi pico 2 (rp2350)](#raspberry-pi-pico-rp2350)
* [RealTek RTL8735B (AmebaPro2)](#realtek-rtl8735b-amebapro2)
* [Renesas RA6M4](#renesas-ra6m4)
Expand Down Expand Up @@ -8503,6 +8504,94 @@ make test-sim-internal-flash-with-update
Note: This also works on Mac OS, but `objcopy` does not exist. Install with `brew install binutils` and make using `OBJCOPY=/usr/local/Cellar//binutils/2.41/bin/objcopy make`.


## Raspberry Pi Pico rp2040

The RP2040 is a dual Cortex-M0+ with 264 KB of SRAM and no internal flash: code executes in place from an external QSPI NOR flash (2 MB W25Q16 on the Pico and on the WIZnet W5100S-EVB-Pico) mapped at `0x10000000`. This is a native wolfBoot target: no pico-sdk, picotool or CMake is needed.

The RP2040 has no secure boot and no OTP key storage, and its boot ROM starts whatever is in flash. wolfBoot on this part therefore provides authenticated firmware updates with rollback; it is not a hardware root of trust, because an attacker with write access to the flash can replace wolfBoot itself.

Hardware-validated on a W5100S-EVB-Pico: boot of a signed image, update with sector swap, rejection of a tampered update and rollback of an unconfirmed one. The UART console was not available on the test setup and is build-tested only.

### Flash layout

```
0x10000000 second-stage boot (256 bytes) + wolfBoot 64 KB
0x10010000 BOOT partition 960 KB
0x10100000 UPDATE partition 960 KB
0x101F0000 SWAP 4 KB
```

The boot ROM loads the first 256 bytes of flash to RAM, checks their CRC-32 and runs them. `hal/rp2040.c` carries its own second stage, which puts the flash interface into `03h` serial read mode, a command every SPI NOR flash supports. wolfBoot keeps a copy of it in RAM to return to XIP mode after an erase or program, which are done with the boot ROM flash routines from a single RAM function with interrupts disabled. Interrupts are disabled only on the calling core: an application that writes flash through wolfBoot (`wolfBoot_success()`, `wolfBoot_update_trigger()`) while core 1 or a DMA channel reads flash must stop them first. wolfBoot and the test application use one core and no DMA.

### Building

```sh
cp config/examples/rp2040.config .config
make
```

Options, on the make command line or in `.config`:

| Option | Meaning |
|---|---|
| `RP2040_SYS_MHZ` | `clk_sys`: 12 (crystal, PLL off) or 63..133, default 125 |
| `RP2040_XIP_QUAD=n` | Switch the flash to quad read at `clk_sys / n` (2 or 4) when wolfBoot starts; the application inherits it. Needs a W25Q-compatible flash with its Quad Enable bit set, otherwise wolfBoot stays in serial read mode. Default 0 (off) |
| `DEBUG_UART` | Console on UART0 at 115200, GP0 (TX) / GP1 (RX) |
| `RP2040_RAM_LOG=1` | Also keep the console text in the SRAM4 scratch bank at `0x20040000` (magic `WBLG`, length, text) for the application to read back; needs `DEBUG_UART=1` |
| `RP2040_BOOT_GUARD=1` | Arm the watchdog while wolfBoot runs; if wolfBoot hangs or finds nothing to boot, the next reset enters the boot ROM USB loader. wolfBoot feeds it from its hash and copy loops; the longest watchdog period is about 8.4 s, which a single slow signature check at `RP2040_SYS_MHZ=12` can exceed (ED25519, ECC384) |

The last two are development aids for a board with no debug probe or UART adapter and should be left off in production.

### Flashing

The boot ROM USB loader takes UF2 files. Hold BOOTSEL while plugging in USB and copy the file to the `RPI-RP2` drive:

```sh
tools/scripts/rp2040/rp2040_uf2.py uf2 factory.bin factory.uf2
cp factory.uf2 /media/$USER/RPI-RP2/
```

`factory.bin` ends with the signed image. On a board that has run wolfBoot before, pad it to the end of the layout so the UF2 also blanks the UPDATE partition, SWAP and the partition trailers; otherwise an update left pending or half-swapped from before can act on the new image:

```sh
arm-none-eabi-objcopy -I binary -O binary --pad-to=0x1F1000 --gap-fill=0xFF factory.bin factory_full.bin
tools/scripts/rp2040/rp2040_uf2.py uf2 factory_full.bin factory.uf2
```

A signed update can be placed in the UPDATE partition the same way:

```sh
tools/keytools/sign --ecc256 --sha256 test-app/image.bin wolfboot_signing_private_key.der 2
tools/scripts/rp2040/rp2040_uf2.py uf2 test-app/image_v2_signed.bin update.uf2 --base 0x10100000
```

### Test application

`test-app/app_rp2040.c` prints its version on the console, confirms itself with `wolfBoot_success()` when the version is 2 or higher, and takes the keys `u` (trigger the update and reset), `r` (reset) and `b` (reboot into the USB loader).

A network firmware update example, TFTP over a W5100S Ethernet controller, is in wolfIP under `src/port/rp2040_w5100s`.

### Verification time

Measured with `BOOT_BENCHMARK=1` on an RP2040 at 125 MHz, 88 KB image, flash in serial read mode. SHA-256 of the image takes 146 ms (260 ms for SHA-384); with `RP2040_XIP_QUAD=2` it takes 105 ms for a 92 KB image. Size is the wolfBoot `.text` section.

| Signature | Verify | wolfBoot size |
|---|---|---|
| RSA2048 | 44 ms | 16.3 KB |
| ML-DSA-44 | 74 ms | 21.5 KB |
| ML-DSA-65 | 112 ms | 22.2 KB |
| RSA4096 | 164 ms | 16.8 KB |
| ECC256 (default, Thumb assembly) | 170 ms | 21.6 KB |
| LMS L1-H10-W8 | 357 ms | 12.8 KB |
| ECC384 | 732 ms | 30.6 KB |
| ECC256, `NO_ASM=1` | 1128 ms | 18.7 KB |
| ED25519 | 1566 ms | 16.8 KB |

ML-DSA needs `IMAGE_HEADER_SIZE=8192` and therefore `WOLFBOOT_SECTOR_SIZE=0x2000`, for example `make SIGN=ML_DSA ML_DSA_LEVEL=2 IMAGE_SIGNATURE_SIZE=2420 IMAGE_HEADER_SIZE=8192 WOLFBOOT_SECTOR_SIZE=0x2000`.

An update of an 88 KB image took 21 seconds from the trigger to the new application being back on the network, most of it the sector swap and the erase of the rest of the partition.


## Raspberry Pi Pico rp2350

See instructions in [IDE/pico-sdk/rp2350/README.md](/IDE/pico-sdk/rp2350/README.md)
Expand Down
Loading
Loading