October 1, 2023

Raspberry Pi Pico - USB in the bootrom

Since we have source code for the bootrom, this seems like a likely place to take a first look at USB for the rp2040.

The entire rom fits into 16K, so the USB code can't get too elaborate.

Building the bootrom

While this won't be of much use in the end, the process can be instructive, and it demonstrates that we aren't missing any pieces.
git clone https://github.com/raspberrypi/pico-bootrom
cd pico-bootrom
git submodule update --init
 (clones pico-bootrom/pico_sdk)
mkdir build
cd build
cmake ..
make
Sounds nice, but it doesn't work:
[100%] Built target generate
[ 25%] No install step for 'generator'
[ 28%] Completed 'generator'
[ 28%] Built target generator
[ 32%] Generating /u1/Projects/rp2040/pico-bootrom/build/generated.h
[ 32%] Built target generate_header
[ 35%] Generating /u1/Projects/rp2040/pico-bootrom/build/git_info.h
[ 35%] Built target update_git_info
[ 39%] Building ASM object CMakeFiles/bootrom.dir/bootrom/bootrom_rt0.S.obj
[ 42%] Building ASM object CMakeFiles/bootrom.dir/bootrom/bit_functions.S.obj
[ 46%] Building C object CMakeFiles/bootrom.dir/bootrom/bootrom_main.c.obj
[ 50%] Building ASM object CMakeFiles/bootrom.dir/bootrom/bootrom_misc.S.obj
[ 53%] Building C object CMakeFiles/bootrom.dir/bootrom/program_flash_generic.c.obj
[ 57%] Building C object CMakeFiles/bootrom.dir/bootrom/usb_boot_device.c.obj
[ 60%] Building C object CMakeFiles/bootrom.dir/bootrom/virtual_disk.c.obj
[ 64%] Building C object CMakeFiles/bootrom.dir/bootrom/async_task.c.obj
[ 67%] Building ASM object CMakeFiles/bootrom.dir/bootrom/mufplib.S.obj
[ 71%] Building ASM object CMakeFiles/bootrom.dir/bootrom/mufplib-double.S.obj
[ 75%] Building C object CMakeFiles/bootrom.dir/usb_device_tiny/runtime.c.obj
[ 78%] Building C object CMakeFiles/bootrom.dir/usb_device_tiny/usb_device.c.obj
[ 82%] Building C object CMakeFiles/bootrom.dir/usb_device_tiny/usb_msc.c.obj
[ 85%] Building C object CMakeFiles/bootrom.dir/usb_device_tiny/usb_stream_helper.c.obj
[ 89%] Building C object CMakeFiles/bootrom.dir/pico_sdk/src/rp2_common/pico_platform/platform.c.obj
[ 92%] Building C object CMakeFiles/bootrom.dir/pico_sdk/src/rp2_common/hardware_sync/sync.c.obj
[ 96%] Building C object CMakeFiles/bootrom.dir/pico_sdk/src/rp2_common/hardware_claim/claim.c.obj
[100%] Linking C executable bootrom.elf
/usr/lib/gcc/arm-none-eabi/13.2.0/../../../../arm-none-eabi/bin/ld: bootrom.elf section `.text' will not fit in region `ROM'
/usr/lib/gcc/arm-none-eabi/13.2.0/../../../../arm-none-eabi/bin/ld: region `ROM' overflowed by 16384 bytes
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/bootrom.dir/build.make:349: bootrom.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:764: CMakeFiles/bootrom.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
No telling why the code won't fit. Perhaps/probably I am using a different compiler than was used by the engineers. The Makefile isn't giving me verbose output, so I can't really see what the build process is doing. Typing "make VERBOSE=1" gives more, but nothing that sheds light on the code being too big.

They say the version on the chip was built using GCC 9.3.1 . It is curious that the error message says the size was overflowed by 16384 (exactly 16K). 16K is the size of the ROM region it is expected to fit in.

We will ignore this and press on.

usb_device_tiny

This directory holds 3021 lines of code that seem to provide the USB for the bootrom. There are 9 ".h" files and 4 ".c" files.
The 4 C files are as follows: This directory is not the whole story though -- the "bootrom" directory has: Along with a fair bit of code in bootrom_main.c and async_task.c. Honestly, apart from dealing with the flash chip, the bootrom code is all about dealing with USB.


Have any comments? Questions? Drop me a line!

Tom's electronics pages / [email protected]