/* RP2040 (plain Raspberry Pi Pico) memory layout for rp2040-hal + cortex-m-rt.
   The RP2040 boots from a 256-byte second-stage bootloader at the start of flash
   (BOOT2), which then maps the rest of XIP flash and jumps to .text.

   The 2 MB flash is split: 1 MB for the app, 1 MB for the USB Mass Storage
   filesystem (a FAT volume the host reads/writes; written on-device via rp2040-flash). */
MEMORY {
    BOOT2      : ORIGIN = 0x10000000, LENGTH = 0x100
    FLASH      : ORIGIN = 0x10000100, LENGTH = 0x100000 - 0x100
    FILESYSTEM : ORIGIN = 0x10100000, LENGTH = 1M
    RAM        : ORIGIN = 0x20000000, LENGTH = 264K
}

EXTERN(BOOT2_FIRMWARE)

SECTIONS {
    /* The second-stage bootloader blob (rp2040_boot2::BOOT_LOADER_W25Q080) lives here. */
    .boot2 ORIGIN(BOOT2) :
    {
        KEEP(*(.boot2));
    } > BOOT2
} INSERT BEFORE .text;

SECTIONS {
    /* The Mass Storage filesystem region. NOLOAD: not part of the flashed image (so the UF2 stays
       small and a reflash doesn't wipe the user's files) — the host formats it on first use, and
       the device reads/writes it at runtime via raw-pointer reads + rp2040-flash erase/program. */
    .filesystem (NOLOAD) : ALIGN(4096)
    {
        KEEP(*(.filesystem));
    } > FILESYSTEM
} INSERT AFTER .text;
