Skip to content

Add native RP2040 target for the Raspberry Pi Pico and W5100S-EVB-Pico - #1018

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:rp2040
Open

dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:rp2040

Conversation

@dgarske

@dgarske dgarske commented Dec 2, 2026

Copy link
Copy Markdown
Member

Native Makefile target for the RP2040 (dual Cortex-M0+, external QSPI flash executed in place). No pico-sdk, picotool or CMake. The RP2040 has no secure boot or OTP key storage, so this provides authenticated updates with rollback, not a hardware root of trust.

  • hal/rp2040.c, .h, .ld - clocks, UART, its own 256-byte second-stage boot, flash erase/program through the boot ROM routines
  • config/examples/rp2040.config - ECC256 + SHA256, 64 KB wolfBoot, two 960 KB partitions
  • arch.mk, test-app/, tools/scripts/rp2040/rp2040_uf2.py, flash unit test, docs/Targets.md section, two CI jobs

Validated on a WIZnet W5100S-EVB-Pico with the wolfIP application as the image: boot, update with swap, rejection of a tampered update, rollback. The UART console and test-app/app_rp2040.c are build-tested only.

The existing pico-sdk based rp2350 target is not touched.

Copilot AI balanced review requested due to automatic review settings December 2, 2026 00:33
@dgarske dgarske self-assigned this Dec 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Flash writes lack multicore/DMA protection, and images can overlap the trailer sector erased during update triggering, risking faults and image corruption.

6 open issues
What changed in this PR

Adds native, Makefile-based RP2040 support for the Raspberry Pi Pico and W5100S-EVB-Pico, providing authenticated updates and rollback without a hardware root of trust. The RP2350 target remains unchanged.

Changes:

  • Adds startup, flash, clock and UART support with a default partition layout.
  • Provides a test application, UF2 conversion tool and target documentation.
  • Adds mocked flash-operation tests and two CI build configurations.
File Description
tools/​unit-tests/​unit-rp2040-flash-write.c Tests flash writes, alignment and erases.
tools/​unit-tests/​Makefile Registers and builds the flash tests.
tools/​scripts/​rp2040/​rp2040_uf2.py Converts binaries to UF2 and validates boot2 checksums.
test-app/​Makefile Adds RP2040 compiler and linker settings.
test-app/​ARM-rp2040.ld Defines application memory placement.
test-app/​app_rp2040.c Demonstrates confirmation, update triggering and console controls.
hal/​rp2040.ld Places boot2, bootloader code and RAM routines.
hal/​rp2040.h Defines registers, flash geometry and the BOOTSEL interface.
hal/​rp2040.c Implements startup, peripherals and ROM-backed flash operations.
docs/​Targets.md Documents configuration, flashing and validation results.
config/​examples/​rp2040.config Supplies default signing, clock and partition settings.
arch.mk Integrates RP2040 target options.
.gitignore Excludes generated test artifacts.
.github/​workflows/​test-configs.yml Adds default and development-option builds.

Review effort: Balanced

Comment thread hal/rp2040.c Resolved
Comment thread test-app/ARM-rp2040.ld Resolved
Comment thread arch.mk Resolved
Comment thread hal/rp2040.c Resolved
Comment thread hal/rp2040.c Resolved
Comment thread docs/Targets.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

With RAM_CODE=1, bootloader self-update erases boot2 and flash-resident HAL wrappers while misplacing the replacement by 256 bytes, potentially leaving the board unbootable.

1 open issue
6 resolved since last review

Review effort: Balanced

Comment thread arch.mk
Comment on lines +978 to +979
ifeq ($(TARGET),rp2040)
CORTEX_M0=1

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #1018

Scan targets checked: wolfboot-src, wolfboot-bugs
Not reviewed (no scan target covers them): .github/workflows/test-configs.yml, .gitignore, arch.mk, config/examples/rp2040.config, docs/Targets.md, hal/rp2040.h, hal/rp2040.ld, test-app/ARM-rp2040.ld, test-app/Makefile, tools/config.mk, tools/scripts/rp2040/rp2040_uf2.py, tools/unit-tests/Makefile
Coverage: 1 of 3 in-scope changed file(s) opened by the reviewer; not opened: test-app/app_rp2040.c, tools/unit-tests/unit-rp2040-flash-write.c

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Max

Comment thread hal/rp2040.c

RP2040_REG(SSI_SSIENR) = 0;
RP2040_REG(SSI_SER) = 1;
RP2040_REG(SSI_BAUDR) = baud_div;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RP2040_XIP_QUAD accepts divider values that stop the flash clock and hang wolfBoot · HAL implementation flaws

RP2040_XIP_QUAD goes straight into SSI_BAUDR, and nothing rejects 1 or other values whose SCKDV ends up 0. A zero divider stops sclk_out, so the status-register poll at line 345 spins forever with interrupts off. A user who sets RP2040_XIP_QUAD=1 as a boolean gets a board that hangs in hal_init on every boot.

Suggested fix: Add a compile-time #error in hal/rp2040.c unless RP2040_XIP_QUAD is an even value from 2 to 65534, as is already done for RP2040_SYS_MHZ.
Basis: RP2040 Datasheet, SSI clock ratios / BAUDR.SCKDV (DW_apb_ssi): SCKDV holds only even values, and when it is 0 the serial clock sclk_out is disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants