-
Notifications
You must be signed in to change notification settings - Fork 13
Add support for PQC secure boot with MCXA 5xx family of MCUs #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
alamfarjadf
wants to merge
11
commits into
OpenDevicePartnership:main
Choose a base branch
from
alamfarjadf:mcxa-577-bootloader
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5ab9523
add MCXA577 bootloader, blinky app, and ec-slimloader-mcxa library
alamfarjadf e6c73e3
fix embassy dependency resolution and clippy warning
alamfarjadf 6377471
remove load.rs from PR (kept locally, unused)
alamfarjadf d5f2142
Merge branch 'main' into mcxa-577-bootloader
alamfarjadf 502cd91
git dep changes and SGI signature updates; add rustdoc comments
alamfarjadf e0f5580
Merge branch 'main' into mcxa-577-bootloader
alamfarjadf f185706
mcxa cmpa/cfpa provisioning
alamfarjadf 13e2e38
fix STRIDE / hyenas CWE issues
alamfarjadf 59d2344
Harden CMPA scratch lifecycle staging
alamfarjadf bbfa20c
Merge branch 'main' into mcxa-577-bootloader
alamfarjadf 27d4f5f
Merge branch 'main' into mcxa-577-bootloader
alamfarjadf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [build] | ||
| target = "thumbv8m.main-none-eabihf" | ||
|
|
||
| [target.thumbv8m.main-none-eabihf] | ||
| runner = "echo" | ||
|
|
||
| [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| rustflags = [ | ||
| "-C", "linker=flip-link", | ||
| "-C", "link-arg=-Tlink.x", | ||
| "-C", "link-arg=-Tdefmt.x", | ||
| "-C", "link-arg=--nmagic", | ||
| "-C", "force-frame-pointers=yes", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| [package] | ||
| name = "mcxa-577app" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| cortex-m = { version = "0.7", features = ["critical-section-single-core"] } | ||
| cortex-m-rt = { version = "0.7", features = ["set-sp", "set-vtor"] } | ||
| defmt = "1.0" | ||
| defmt-rtt = "1.0" | ||
| embassy-mcxa = { git = "https://github.com/embassy-rs/embassy", default-features = false, features = ["rt", "defmt", "mcxa5xx"] } | ||
| embassy-executor = { git = "https://github.com/embassy-rs/embassy", default-features = false, features = ["platform-cortex-m", "executor-thread"] } | ||
| embassy-time = { git = "https://github.com/embassy-rs/embassy", features = ["defmt", "defmt-timestamp-uptime"] } | ||
| panic-probe = { version = "1.0", features = ["print-defmt"] } | ||
|
|
||
| [profile.dev] | ||
| panic = "abort" | ||
|
|
||
| [profile.release] | ||
| lto = false # Disable LTO to prevent stripping debug patterns | ||
| opt-level = 2 # Standard optimization | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| use std::env; | ||
| use std::fs::File; | ||
| use std::io::Write; | ||
| use std::path::PathBuf; | ||
|
|
||
| fn main() { | ||
| // Put `memory.x` in our output directory and ensure it's | ||
| // on the linker search path. | ||
| let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| File::create(out.join("memory.x")) | ||
| .unwrap() | ||
| .write_all(include_bytes!("memory.x")) | ||
| .unwrap(); | ||
| println!("cargo:rustc-link-search={}", out.display()); | ||
|
|
||
| // By default, Cargo will re-run a build script whenever | ||
| // any file in the project changes. By specifying `memory.x` | ||
| // here, we ensure the build script is only re-run when | ||
| // `memory.x` is changed. | ||
| println!("cargo:rerun-if-changed=memory.x"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| MEMORY | ||
| { | ||
| /* MCXA577 app memory map */ | ||
| /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| /* Bootloader uses 0x0000_0000..0x0000_FFFF (64KiB). App starts at slot_a = 0x0001_0000. */ | ||
| FLASH (rx) : ORIGIN = 0x00010000, LENGTH = 0x001F0000 | ||
| RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K | ||
| } | ||
|
|
||
| /* Stack grows down from end of RAM */ | ||
| _stack_start = ORIGIN(RAM) + LENGTH(RAM); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #![no_std] | ||
| #![no_main] | ||
|
|
||
| use embassy_executor::Spawner; | ||
| use embassy_time::Timer; | ||
| use hal::bind_interrupts; | ||
| use hal::dma::DmaChannel; | ||
| use hal::gpio::{DriveStrength, Level, Output, SlewRate}; | ||
| use hal::peripherals::SGI0; | ||
| use hal::sgi::hash::{DmaHasher, HashSize}; | ||
| use hal::sgi::{InterruptHandler, Sgi}; | ||
| use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | ||
|
|
||
| bind_interrupts!(struct Irqs { | ||
| SGI => InterruptHandler<SGI0>; | ||
| }); | ||
|
|
||
| #[embassy_executor::main] | ||
| async fn main(_spawner: Spawner) { | ||
| let mut p = hal::init(hal::config::Config::default()); | ||
|
|
||
| defmt::info!("Blinky example with a sprinkle of SGI hashing"); | ||
|
|
||
| let mut dma_ch0 = DmaChannel::new(p.DMA0_CH0.reborrow()); | ||
| let mut hash_result = [0u8; 48]; | ||
| let mut input_data = [0u8; 256]; | ||
|
|
||
| for (index, byte) in input_data.iter_mut().enumerate() { | ||
| *byte = index as u8; | ||
| } | ||
|
|
||
| let sgi = Sgi::new(p.SGI0.reborrow(), Irqs).unwrap(); | ||
| match DmaHasher::start_and_finalize(sgi, &mut dma_ch0, HashSize::Sha384, &input_data, &mut hash_result) | ||
| .await | ||
| { | ||
| Ok(()) => defmt::info!("DMA hash: {=[u8]:x}", &hash_result), | ||
| Err(e) => defmt::error!("DMA hash failed: {:?}", defmt::Debug2Format(&e)), | ||
| } | ||
|
|
||
| let mut red = Output::new(p.P2_14, Level::High, DriveStrength::Normal, SlewRate::Fast); | ||
| let mut green = Output::new(p.P2_22, Level::High, DriveStrength::Normal, SlewRate::Fast); | ||
| let mut blue = Output::new(p.P2_23, Level::High, DriveStrength::Normal, SlewRate::Fast); | ||
|
|
||
| let mut rate = 250; | ||
|
|
||
| defmt::info!("It's showtime..."); | ||
|
|
||
| loop { | ||
| if rate > 1000 { | ||
| rate = 250; // wrap rate to avoid overflow and excessively long timers. | ||
| } | ||
| red.toggle(); | ||
| Timer::after_millis(rate).await; | ||
|
|
||
| red.toggle(); | ||
| green.toggle(); | ||
| Timer::after_millis(rate).await; | ||
|
|
||
| green.toggle(); | ||
| blue.toggle(); | ||
| Timer::after_millis(rate).await; | ||
| blue.toggle(); | ||
|
|
||
| Timer::after_millis(rate).await; | ||
| rate = rate.wrapping_add(100); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [build] | ||
| target = "thumbv8m.main-none-eabihf" | ||
|
|
||
| [target.thumbv8m.main-none-eabihf] | ||
| runner = "probe-rs run --chip MCXA577 --chip-description-path MCXA_custom.yaml" | ||
|
|
||
| [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| rustflags = [ | ||
| "-C", "linker=flip-link", | ||
| "-C", "link-arg=-Tlink.x", | ||
| "-C", "link-arg=-Tdefmt.x", | ||
| "-C", "link-arg=--nmagic", | ||
| "-C", "force-frame-pointers=yes", | ||
| ] | ||
|
|
||
| [env] | ||
| DEFMT_LOG = "trace" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| [package] | ||
| name = "mcxa-577app-bootloader" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [features] | ||
| default = ["defmt"] | ||
| defmt = ["dep:defmt", "dep:defmt-or-log", "dep:defmt-rtt", "defmt-or-log/defmt"] | ||
| log = ["dep:defmt-or-log", "defmt-or-log/log"] | ||
|
|
||
| [[bin]] | ||
| name = "mcxa-577app-bootloader" | ||
| path = "src/main.rs" | ||
|
|
||
| [dependencies] | ||
| cortex-m = { version = "0.7", features = ["critical-section-single-core"], default-features = false } | ||
| cortex-m-rt = "0.7" | ||
| panic-halt = "0.2" | ||
| defmt = { version = "1.0", optional = true } | ||
| defmt-or-log = { version = "0.2.3", optional = true } | ||
| defmt-rtt = { version = "1.0", optional = true } | ||
|
|
||
| ec-slimloader-mcxa = { path = "../../../libs/ec-slimloader-mcxa", default-features = false, features = ["internal-only", "mcxa5xx", "defmt"] } | ||
| ec-slimloader = { path = "../../../libs/ec-slimloader", default-features = false } | ||
|
|
||
| embassy-executor = { git = "https://github.com/embassy-rs/embassy", default-features = false, features = ["platform-cortex-m", "executor-thread"] } | ||
|
|
||
| [patch.crates-io] | ||
| embassy-time = { git = "https://github.com/embassy-rs/embassy" } | ||
| embassy-time-driver = { git = "https://github.com/embassy-rs/embassy" } | ||
| embassy-time-queue-utils = { git = "https://github.com/embassy-rs/embassy" } | ||
|
|
||
| [profile.release] | ||
| debug = 2 # Full DWARF info for defmt/probe-rs decoding | ||
| lto = false # Disable LTO to prevent stripping debug patterns | ||
| opt-level = 2 # Standard optimization | ||
| panic = "abort" # Smaller binaries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| use std::env; | ||
| use std::fs::File; | ||
| use std::io::Write; | ||
| use std::path::PathBuf; | ||
|
|
||
| fn main() { | ||
| // Put `memory.x` in our output directory and ensure it's | ||
| // on the linker search path. | ||
| let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| File::create(out.join("memory.x")) | ||
| .unwrap() | ||
| .write_all(include_bytes!("memory.x")) | ||
| .unwrap(); | ||
| println!("cargo:rustc-link-search={}", out.display()); | ||
|
|
||
| // Only re-run if memory.x changes. | ||
| println!("cargo:rerun-if-changed=memory.x"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| MEMORY | ||
| { | ||
| /* MCXA577 has 2MB flash total. | ||
| * This example reserves the first 64KB for the bootloader. | ||
| * Secure alias: 0x1000_0000 (Matrix0 Target Port0, Secure, All Initiators). | ||
| */ | ||
| FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K | ||
|
|
||
| /* Secure SRAM alias: 0x3000_0000 (Matrix0 Target Port 4, Secure, All Initiators). | ||
| */ | ||
| RAM (rwx) : ORIGIN = 0x30000000, LENGTH = 64K | ||
| } | ||
|
|
||
| /* Stack grows down from end of RAM */ | ||
| _stack_start = ORIGIN(RAM) + LENGTH(RAM); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #![no_std] | ||
| #![no_main] | ||
|
|
||
| #[cfg(any(feature = "defmt", feature = "log"))] | ||
| use defmt_or_log::info; | ||
| #[cfg(feature = "defmt")] | ||
| use defmt_rtt as _; | ||
| use embassy_executor::Spawner; | ||
| use panic_halt as _; | ||
|
|
||
| const JOURNAL_BUFFER_SIZE: usize = 4096; | ||
|
|
||
| #[cfg(feature = "defmt")] | ||
| defmt::timestamp!("{=u32}", 0); | ||
|
|
||
| #[embassy_executor::main] | ||
| async fn main(_spawner: Spawner) -> ! { | ||
| #[cfg(any(feature = "defmt", feature = "log"))] | ||
| info!("Starting MCXA bootloader"); | ||
| ec_slimloader::start::<ec_slimloader_mcxa::McxaBoard, JOURNAL_BUFFER_SIZE>(ec_slimloader_mcxa::Config).await | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ impl<C: ImxrtConfig + BootStatePolicy> Board for Imxrt<C> { | |
| &mut self.journal | ||
| } | ||
|
|
||
| async fn check_and_boot(&mut self, slot: &Slot) -> BootError { | ||
| async fn check_and_boot<const JOURNAL_BUFFER_SIZE: usize>(&mut self, slot: &Slot) -> BootError { | ||
| let Some(slot_partition) = self.slots.get_mut(u8::from(*slot) as usize) else { | ||
| return BootError::SlotUnknown; | ||
| }; | ||
|
|
@@ -204,4 +204,16 @@ impl<C: ImxrtConfig + BootStatePolicy> Board for Imxrt<C> { | |
| cortex_m::asm::wfi(); | ||
| } | ||
| } | ||
|
|
||
| fn arm_mcu_reset(&mut self) -> ! { | ||
| const AIRCR: *mut u32 = 0xE000ED0C as *mut u32; | ||
| const AIRCR_VECTKEY: u32 = 0x5FA << 16; | ||
| const AIRCR_SYSRESETREQ: u32 = 1 << 2; | ||
| unsafe { | ||
| core::ptr::write_volatile(AIRCR, AIRCR_VECTKEY | AIRCR_SYSRESETREQ); | ||
| } | ||
|
Comment on lines
+209
to
+214
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| loop { | ||
| cortex_m::asm::wfi(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the
MCXA_custom.yamlcommitted here... Could we fix that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alamfarjadf is this a file you're maintaining locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can add.