4 releases (2 breaking)

0.3.0 May 5, 2023
0.2.1 Aug 11, 2022
0.2.0 Oct 18, 2021
0.1.2 Jan 25, 2021

#266 in Hardware support

Download history 2902/week @ 2024-06-30 2535/week @ 2024-07-07 2958/week @ 2024-07-14 3600/week @ 2024-07-21 2447/week @ 2024-07-28 3401/week @ 2024-08-04 3349/week @ 2024-08-11 4918/week @ 2024-08-18 9354/week @ 2024-08-25 10034/week @ 2024-09-01 7876/week @ 2024-09-08 7433/week @ 2024-09-15 8035/week @ 2024-09-22 4185/week @ 2024-09-29 3837/week @ 2024-10-06 6376/week @ 2024-10-13

22,987 downloads per month
Used in 47 crates (38 directly)

BSD-3-Clause

75KB
1K SLoC

GNU Style Assembly 850 SLoC // 0.4% comments Rust 153 SLoC // 0.0% comments Shell 16 SLoC // 0.2% comments

Raspberry Pi RP2040 Second-Stage Bootloader

This is a second stage bootloader for the Raspberry Pi RP2040 SoC.

You can use this crate to include a second-stage bootloader in your application. Simply ensure that your linker script puts the array exported by this crate at the start of your flash image (0x000 to 0x100).

Instructions

Add to your application's Cargo.toml:

rp2040_boot2 = { version = "0.2" }

Add to your main.rs:

#[link_section = ".boot_loader"]
#[used]
pub static BOOT_LOADER: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;

This will include support for the W25Q080 flash part on the Raspberry Pi Pico. If you have a board that uses the AT25SF128A (like the Arduino Nano Connect), you can instead use:

#[link_section = ".boot_loader"]
#[used]
pub static BOOT_LOADER: [u8; 256] = rp2040_boot2::BOOT_LOADER_AT25SF128A;

Finally, add to your application's memory.x:

MEMORY
{
  /* NOTE 1 K = 1 KiBi = 1024 bytes */
  /* To suit Raspberry Pi RP2040 SoC */
  BOOT_LOADER : ORIGIN = 0x10000000, LENGTH = 0x100
  /* Adjust this to suit the size of your specific flash chip */
  FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
  RAM : ORIGIN = 0x20000000, LENGTH = 264K
}

SECTIONS {

  /* ### Boot loader */
  .boot_loader ORIGIN(BOOT_LOADER) :
  {
    KEEP(*(.boot_loader*));
  } > BOOT_LOADER

} INSERT BEFORE .text;

Booting from RAM

If you want the bootloader to copy your application from flash to RAM before booting, you can use the boot loader BOOT_LOADER_RAM_MEMCPY, this will move all the contents from flash to RAM (up to RAM length). Using this strategy allows for faster execution and flash availability for persistent storage.

Additionally, you need to change your linker script in order to specify the VMAs & LMAs for all the RAM sections, as in this example

    .text : {
      ...
    } > RAM AT > FLASH

Adding or changing an existing bootloader

In order to remove the need for GCC for users of this crate, we link against prebuilt versions of each of the bootloaders by default.

If you wish to add or change an existing bootloader you should install GCC and build with the feature assemble

UPDATE_PRECOMPILED_BINARIES=true cargo build --features=assemble

To add a new bootloader to the build you need to add it to SOURCE_FILES in build.rs and add an entry for it in lib.rs

Once you are done testing, add the padded binary file in the bin folder (example: bin/boot2_w25q080.padded.bin) to git

You can run check-blobs.sh to verify that you have built your latest sources before making a Pull Request.

Licence

Some of the assembly source files are Copyright Raspberry Pi Trading and licensed under a BSD 3-clause licence. See source files for details.

The remaining files in this crate are licensed as CC0.

No runtime deps