RP2040 boot

first, lets look at this docs

image

I'll prove this

the strange header

in bootrom_rt0.S contains a strange header like this

#include "hardware/regs/addressmap.h"
#include "hardware/regs/pads_bank0.h"
#include "hardware/regs/resets.h"
#include "hardware/regs/sio.h"
#include "hardware/regs/watchdog.h"
#include "hardware/regs/syscfg.h"
#include "hardware/regs/clocks.h"
#include "hardware/regs/vreg_and_chip_reset.h"
#include "hardware/regs/m0plus.h"
#include "git_info.h"

warn: this is just my speculation, the real location is in https://github.com/raspberrypi/pico-sdk/tree/master/src/rp2040/hardware_regs/include/hardware/regs, but the theory IDK. i just matching the file

please inform me if you find something intresting in https://github.com/raspberrypi/pico-sdk/blob/master/src/CMakeLists.txt

boot sequence

this is the most important stuff

image

boot2

image

first, we look at this file memmap_default.ld

this code idk what its used for, also where the variable coming-off

boot2 revision

this is the actual boot2 is located

note: how I find it? its manually set program counter register to 0x20041f00, from somewhere after ctrl + c is fired. we cant stop at 0x20041f00 because at that time. the second boot rom is not loaded yet.

another way, if you was find your "flash hardware driver", let's add breakpoint here, example

image

this will stop execution without hassle of hardware breakpoint, or watching program counter value.

if you curious how I find magic number 0x20041f00, please look at this file

image

linker script

there has various linker scripts

if we merge both memmap_default.ld and pico_flash_region.ld, we will got this

MEMORY
{
    FLASH(rx) : ORIGIN = 0x10000000, LENGTH = ${PICO_FLASH_SIZE_BYTES_STRING}
    RAM(rwx) : ORIGIN =  0x20000000, LENGTH = 256k
    SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
    SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
}

see missing part? yes, that is PICO_FLASH_SIZE_BYTES_STRING, lets find out in our *.elf.map

image

image

that is 2048K

Issue that I find

I think arm-none-eabi-objdump is mistaken arm-thumb-1 instruction as full 32 bit arm, so they just say .word 0xdeadbeef