From 4cc5ab9474773148dd8976e22f3fb6f5e270cd3a Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sun, 16 Feb 2025 12:34:48 +1100 Subject: [PATCH] Add rp235x imagedef features (based on rp2040 boot2 features) rp235x firmwares need an Image Definition if they want to be called from the rp235x bootrom. Currently this Image Definition is manually added to each project/example, but for most users it will always be the default (Secure Exe). This commit adds crate features to allow users to configure this, with the default of including a Secure Exe Image Definition in. Just like the boot2-* features, this includes an opt-out (imagedef-none) to allow the user to not make use of this included Image Definition. --- embassy-rp/Cargo.toml | 25 ++++++++++++++++++++++++- embassy-rp/src/lib.rs | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index 4e5c66feb..d65e281ee 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -83,7 +83,7 @@ boot2-ram-memcpy = [] boot2-w25q080 = [] ## Use boot2 with support for Winbond W25X10CL SPI flash. boot2-w25x10cl = [] -## Have embassy not provide the boot2 so you can use your own. +## Have embassy-rp not provide the boot2 so you can use your own. ## Place your own in the ".boot2" section like: ## ``` ## #[link_section = ".boot2"] @@ -92,6 +92,29 @@ boot2-w25x10cl = [] ## ``` boot2-none = [] +#! ### Image Definition support +#! RP2350's internal bootloader will only execute firmware if it has a valid Image Definition. +#! There are other tags that can be used (for example, you can tag an image as "DATA") +#! but programs will want to have an exe header. "SECURE_EXE" is usually what you want. +#! Use imagedef-none if you want to configure the Image Definition manually +#! If none are selected, imagedef-secure-exe will be used + +## Image is executable and starts in Secure mode +imagedef-secure-exe = [] +## Image is executable and starts in Non-secure mode +imagedef-nonsecure-exe = [] + +## Have embassy-rp not provide the Image Definition so you can use your own. +## Place your own in the ".start_block" section like: +## ``` +## use embassy_rp::block::ImageDef; +## +## #[link_section = ".start_block"] +## #[used] +## static IMAGE_DEF: ImageDef = ImageDef::secure_exe(); // Update this with your own implementation. +## ``` +imagedef-none = [] + ## Configure the hal for use with the rp2040 rp2040 = ["rp-pac/rp2040"] _rp235x = ["rp-pac/rp235x"] diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 80ee47802..de60af890 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -456,6 +456,30 @@ select_bootloader! { default => BOOT_LOADER_W25Q080 } +#[cfg(all(not(feature = "imagedef-none"), feature = "_rp235x"))] +macro_rules! select_imagedef { + ( $( $feature:literal => $imagedef:ident, )+ default => $default:ident ) => { + $( + #[cfg(feature = $feature)] + #[link_section = ".start_block"] + #[used] + static IMAGE_DEF: crate::block::ImageDef = crate::block::ImageDef::$imagedef(); + )* + + #[cfg(not(any( $( feature = $feature),* )))] + #[link_section = ".start_block"] + #[used] + static IMAGE_DEF: crate::block::ImageDef = crate::block::ImageDef::$default(); + } +} + +#[cfg(all(not(feature = "imagedef-none"), feature = "_rp235x"))] +select_imagedef! { + "imagedef-secure-exe" => secure_exe, + "imagedef-nonsecure-exe" => non_secure_exe, + default => secure_exe +} + /// Installs a stack guard for the CORE0 stack in MPU region 0. /// Will fail if the MPU is already configured. This function requires /// a `_stack_end` symbol to be defined by the linker script, and expects