Skip to content

Commit 6748474

Browse files
committed
bootloader: switch to baremetal
The pico-sdk kept causing issues with the psram-bootloader project. Drop the pico-sdk and move to a custom baremetal bootloader. Signed-off-by: Jesse Taube <Mr.Bossman075@gmail.com>
1 parent 6300460 commit 6748474

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3515
-564
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
psram-bootloader/build
2-
psram-bootloader/demo/build
1+
package/pico2-bootloader/bootloader/build
2+
package/pico2-bootloader/bootloader/*.uf2
3+
package/pico2-bootloader/bootloader/*.bin
4+
package/pico2-bootloader/bootloader/demo/build

Config.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
source "$BR2_EXTERNAL_RPI_PICO2_PATH/package/pico2-bootloader/Config.in"

Dockerfile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
FROM ubuntu:24.04
2-
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates patch git make binutils gcc g++ file wget cpio unzip rsync bc bzip2 g++ cmake python3 && \
2+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates patch git make binutils gcc file wget cpio unzip rsync bc bzip2 g++ && \
33
rm -rf /var/lib/apt/lists/* && \
44
apt-get clean
55

6-
RUN wget https://github.com/raspberrypi/pico-sdk-tools/releases/download/v2.0.0-5/riscv-toolchain-14-x86_64-lin.tar.gz && \
7-
mkdir -p ~/toolchain && \
8-
tar -vxzf riscv-toolchain-14-x86_64-lin.tar.gz -C ~/toolchain && \
9-
rm riscv-toolchain-14-x86_64-lin.tar.gz
10-
116
RUN git clone --recurse-submodules https://github.com/Mr-Bossman/pi-pico2-linux
127

138
WORKDIR pi-pico2-linux
149
RUN make -C buildroot BR2_EXTERNAL=$PWD/ raspberrypi-pico2_defconfig && \
15-
make -C buildroot && \
16-
PICO_TOOLCHAIN_PATH=~/toolchain/ PICO_SDK_FETCH_FROM_GIT=1 make -C psram-bootloader
10+
make -C buildroot
1711

18-
CMD make -C psram-bootloader flash-kernel
12+
CMD picotool load -fu buildroot/output/images/flash-image.uf2
1913

2014
# docker build -t pi-pico2-linux .
2115
# docker run -v $(pwd):/root/ -it --entrypoint /bin/bash pi-pico2-linux

README.md

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,13 @@ make -C buildroot BR2_EXTERNAL=$PWD/ raspberrypi-pico2_defconfig
1515

1616
make -C buildroot
1717

18-
make -C psram-bootloader flash-kernel
18+
picotool load -fu buildroot/output/images/flash-image.uf2
1919
```
2020

2121
## Designed to work with [SparkFun Pro Micro - RP2350](https://www.sparkfun.com/products/24870)
2222

2323
![Image of boot](images/booting.png)
2424

25-
#### NOTES on SDK
26-
This project uses the sdk and tools installed to `~/.pico-sdk/`.
27-
To use the tools and sdk installed to another location see [this issue](https://github.com/raspberrypi/pico-sdk/pull/1820#issuecomment-2291611448)
28-
or the following.
29-
30-
```bash
31-
export PICO_SDK_PATH=~/example_sdk/sdk/2.0.0/
32-
export PICO_TOOLCHAIN_PATH=~/example_sdk/toolchain/13_2_Rel1
33-
export pioasm_DIR=~/example_sdk/tools/2.0.0/pioasm
34-
export picotool_DIR=~/example_sdk/picotool/2.0.0/picotool
35-
36-
make flash-kernel
37-
```
38-
3925
#### NOTES on Atomics
4026
On page 307 of the RP2350 Datasheet MCAUSE register CODE 7 says:
4127
> Store/AMO access fault. A store/AMO failed a PMP check, or
@@ -50,8 +36,5 @@ Most implementations assume `lr` and `sr` will eventually succeed.
5036

5137
This only works on the RP2350 RISC-V cores.
5238

53-
If you want to run this on other boards, please change the `PICO_BOARD` variable in `CMakeLists.txt`.
54-
`set(PICO_BOARD sparkfun_promicro_rp2350 CACHE STRING "Board type")`
55-
56-
You will also need to set the psram CS pin with the `SFE_RP2350_XIP_CSI_PIN` macro in `bootloader.c`.
39+
If you want to run this on other boards, please change the psram CS pin with the `RP2350_XIP_CSI_PIN` macro in `package/pico2-bootloader/bootloader/src/main.c`.
5740
As of now the only psram chip tested is the `APS6404L` and any others may not work.

board/raspberrypi/raspberrypi-pico2/genimage.cfg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ image flash-image.bin {
33
partition-table-type = "none"
44
}
55

6+
partition bootloader {
7+
in-partition-table = "no"
8+
image = "bootloader.bin"
9+
offset = 0
10+
}
11+
612
partition raspberrypi-pico2.dtb {
713
in-partition-table = "no"
814
image = "raspberrypi-pico2.dtb"
9-
offset = 0
1015
}
1116

1217
partition Image {

board/raspberrypi/raspberrypi-pico2/post-build.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
shift
3+
support/scripts/genimage.sh "$@"
4+
5+
if picotool version > /dev/null; then
6+
picotool uf2 convert "${BINARIES_DIR}/flash-image.bin" \
7+
"${BINARIES_DIR}/flash-image.uf2" --family rp2350-riscv
8+
else
9+
echo "picotool not found, skipping uf2 conversion"
10+
echo "Please run \`picotool uf2 convert ${BINARIES_DIR}/flash-image.bin \
11+
${BINARIES_DIR}/flash-image.uf2 --family rp2350-riscv\` insead."
12+
fi
13+
tput smso 2>/dev/null
14+
echo "Run \`picotool load -fu ${BINARIES_DIR}/flash-image.uf2\` to flash to pi pico2."
15+
tput rmso 2>/dev/null

configs/raspberrypi-pico2_defconfig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ BR2_OPTIMIZE_S=y
1515
BR2_TARGET_ROOTFS_INITRAMFS=y
1616
BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL)/board/raspberrypi/raspberrypi-pico2/rootfs_overlay"
1717

18+
# Bootloader
19+
BR2_PACKAGE_PICO2_BOOTLOADER=y
20+
1821
# Image
19-
BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh"
20-
BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL)/board/raspberrypi/raspberrypi-pico2/post-build.sh"
21-
BR2_ROOTFS_POST_SCRIPT_ARGS="-c $(BR2_EXTERNAL)/board/raspberrypi/raspberrypi-pico2/genimage.cfg"
22+
BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL)/board/raspberrypi/raspberrypi-pico2/post-image.sh"
23+
BR2_ROOTFS_POST_IMAGE_SCRIPT_ARGS="-c $(BR2_EXTERNAL)/board/raspberrypi/raspberrypi-pico2/genimage.cfg"
2224

2325
# Linux headers same as kernel
2426
BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_6_15=y

package/pico2-bootloader/Config.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
config BR2_PACKAGE_PICO2_BOOTLOADER
2+
bool "raspberry pi pico 2 bootloader"
3+
help
4+
Custom bootloader for raspberry pi pico 2
5+
to load linux.

psram-bootloader/CMakeLists.txt renamed to package/pico2-bootloader/bootloader/CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@ pico_sdk_init()
4242

4343
# Add executable. Default name is the project name, version 0.1
4444

45+
add_compile_definitions(PICO_SDK)
46+
47+
include_directories(psram-bootloader
48+
src
49+
)
50+
4551
add_executable(psram-bootloader
46-
src/bootloader.c
47-
)
52+
src/main.c
53+
src/image.c
54+
src/qmi.c
55+
)
4856

4957
# pull in common dependencies
5058
target_link_libraries(psram-bootloader pico_stdlib)
5159

5260
pico_enable_stdio_usb(psram-bootloader 1)
5361
pico_enable_stdio_uart(psram-bootloader 1)
5462

55-
# add partition table
56-
pico_embed_pt_in_binary(psram-bootloader ${CMAKE_CURRENT_LIST_DIR}/partition_table.json)
57-
58-
# create absolute uf2, and package in flash
59-
pico_set_uf2_family(psram-bootloader "absolute")
60-
pico_package_uf2_output(psram-bootloader 0x10000000)
63+
pico_set_binary_type(psram-bootloader copy_to_ram)
6164

6265
# create map/bin/hex file etc.
6366
pico_add_extra_outputs(psram-bootloader)

0 commit comments

Comments
 (0)