Skip to content

Second stage bootloader for the RP2040, suitable for use with a Rust application.

Notifications You must be signed in to change notification settings

taunusflieger/rp2040-boot2-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi RP2040 Second-Stage Bootloader

This is a second stage bootloader for the Raspberry Pi RP2040 SoC. Currently only the W25Q080 flash chip (as used on the Pico) is supported.

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 main.rs:

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

Add to your application's Cargo.toml:

rp2040_boot2 = { version="0.1", features=["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:

rp2040_boot2 = { version="0.1", features=["at25sf128a"] }

As an alternative to setting features, you can pull a specific bootloader from this crate by name instead:

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

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 specify the feature flag 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

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.

About

Second stage bootloader for the RP2040, suitable for use with a Rust application.

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 58.7%
  • Assembly 37.5%
  • Rust 3.8%