Skip to content

Commit f89c004

Browse files
petejohansonjhedberg
authored andcommitted
soc: raspberrypi: rpi_pico: Add RP2 bootloader support
Add an early init hook to check the boot mode and reset into the RP2 USB bootloader if requested. Includes a snippet to use with any RP2040/RP2350 board to enable the necessary DTS/Kconfig to use the functionality, and easy DTS includes for boards to use explicitly. Signed-off-by: Peter Johanson <[email protected]>
1 parent 6c01157 commit f89c004

File tree

11 files changed

+172
-0
lines changed

11 files changed

+172
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2025 Peter Johanson
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Be sure we don't overlap the reserved byte for storing the boot-mode
9+
*/
10+
&sram0 {
11+
reg = <0x20000004 ((DT_SIZE_K(264)) - 4)>;
12+
};
13+
14+
/ {
15+
chosen {
16+
zephyr,boot-mode = &boot_mode;
17+
};
18+
19+
/*
20+
* Placed at the start, to avoid the bootrom clobbering our RAM,
21+
* with it's stack.
22+
*/
23+
sram@20000000 {
24+
compatible = "zephyr,memory-region", "mmio-sram";
25+
reg = <0x20000000 0x4>;
26+
zephyr,memory-region = "RetainedMem";
27+
status = "okay";
28+
29+
retainedmem {
30+
compatible = "zephyr,retained-ram";
31+
status = "okay";
32+
#address-cells = <1>;
33+
#size-cells = <1>;
34+
35+
boot_mode: retention@0 {
36+
compatible = "zephyr,retention";
37+
status = "okay";
38+
reg = <0x0 0x1>;
39+
};
40+
};
41+
};
42+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025 Peter Johanson
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Be sure we don't overlap the reserved byte for storing the boot-mode
9+
*/
10+
&sram0 {
11+
reg = <0x20000004 ((DT_SIZE_K(520)) - 4)>;
12+
};
13+
14+
/ {
15+
chosen {
16+
zephyr,boot-mode = &boot_mode;
17+
};
18+
19+
/*
20+
* Placed at the start, to avoid anything clobbering our RAM
21+
*/
22+
sram@20000000 {
23+
compatible = "zephyr,memory-region", "mmio-sram";
24+
reg = <0x20000000 0x4>;
25+
zephyr,memory-region = "RetainedMem";
26+
status = "okay";
27+
28+
retainedmem {
29+
compatible = "zephyr,retained-ram";
30+
status = "okay";
31+
#address-cells = <1>;
32+
#size-cells = <1>;
33+
34+
boot_mode: retention@0 {
35+
compatible = "zephyr,retention";
36+
status = "okay";
37+
reg = <0x0 0x1>;
38+
};
39+
};
40+
};
41+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. _rp2-boot-mode-retention:
2+
3+
RP2040/RP2350 boot mode retention setup (rp2-boot-mode-retention)
4+
#################################################################
5+
6+
Overview
7+
********
8+
9+
This snippet sets up an RP2040/RP2350 based board for retaining the set boot
10+
mode via properly configured retained mem in SRAM, enabling the necessary
11+
Kconfig symbols for the retained mem drivers and retention system.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_RETAINED_MEM=y
2+
CONFIG_RETENTION=y
3+
CONFIG_RETENTION_BOOT_MODE=y
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: rp2-boot-mode-retention
2+
append:
3+
EXTRA_CONF_FILE: rp2-boot-mode-retention.conf
4+
5+
boards:
6+
/.*\/rp2040(/.*)?/:
7+
append:
8+
EXTRA_DTC_OVERLAY_FILE: soc/rp2040.overlay
9+
/.*/rp2350b?/.*/:
10+
append:
11+
EXTRA_DTC_OVERLAY_FILE: soc/rp2350.overlay
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_RETAINED_MEM=y
2+
CONFIG_RETENTION=y
3+
CONFIG_RETENTION_BOOT_MODE=y
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (c) 2025 Peter Johanson
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <vendor/raspberrypi/rp2040-boot-mode-retention.dtsi>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (c) 2025 Peter Johanson
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <vendor/raspberrypi/rp2350-boot-mode-retention.dtsi>

soc/raspberrypi/rpi_pico/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ if SOC_FAMILY_RPI_PICO
88

99
rsource "*/Kconfig"
1010

11+
config RPI_PICO_ROM_BOOTLOADER
12+
bool
13+
default y
14+
depends on RETENTION_BOOT_MODE
15+
1116
endif # SOC_FAMILY_RPI_PICO

soc/raspberrypi/rpi_pico/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ zephyr_include_directories(.)
66
zephyr_sources(
77
soc.c
88
)
9+
10+
zephyr_sources_ifdef(CONFIG_RPI_PICO_ROM_BOOTLOADER rom_bootloader.c)

0 commit comments

Comments
 (0)