diff --git a/bao1x-boot/boot0/src/main.rs b/bao1x-boot/boot0/src/main.rs index 22ae9d30b..b306ac113 100644 --- a/bao1x-boot/boot0/src/main.rs +++ b/bao1x-boot/boot0/src/main.rs @@ -13,6 +13,7 @@ use alloc::collections::VecDeque; #[cfg(feature = "unsafe-dev")] use core::cell::RefCell; +use bao1x_api::signatures::FunctionCode; #[cfg(feature = "unsafe-dev")] use critical_section::Mutex; use platform::*; @@ -81,11 +82,14 @@ pub unsafe extern "C" fn rust_entry() -> ! { bao1x_api::BOOT0_START as *const u32, bao1x_api::BOOT0_START as *const u32, bao1x_api::BOOT0_REVOCATION_OFFSET, + &[FunctionCode::Boot0 as u32], // only boot0 is allowed for boot0 false, ) .is_ok() { seal_boot0_keys(); + let allowed_functions = + [FunctionCode::Boot1 as u32, FunctionCode::UpdatedBoot1 as u32, FunctionCode::Developer as u32]; let one_way_access = bao1x_hal::acram::OneWayCounter::new(); match one_way_access.get_decoded::() { Ok(bao1x_api::AltBootCoding::PrimaryPartition) => { @@ -94,6 +98,7 @@ pub unsafe extern "C" fn rust_entry() -> ! { bao1x_api::BOOT1_START as *const u32, bao1x_api::BOOT0_START as *const u32, bao1x_api::BOOT0_REVOCATION_OFFSET, + &allowed_functions, true, ) .ok(); @@ -101,6 +106,7 @@ pub unsafe extern "C" fn rust_entry() -> ! { bao1x_api::LOADER_START as *const u32, bao1x_api::BOOT0_START as *const u32, bao1x_api::BOOT0_REVOCATION_OFFSET, + &allowed_functions, true, ) .ok(); @@ -111,6 +117,7 @@ pub unsafe extern "C" fn rust_entry() -> ! { bao1x_api::LOADER_START as *const u32, bao1x_api::BOOT0_START as *const u32, bao1x_api::BOOT0_REVOCATION_OFFSET, + &allowed_functions, true, ) .ok(); @@ -118,6 +125,7 @@ pub unsafe extern "C" fn rust_entry() -> ! { bao1x_api::BOOT1_START as *const u32, bao1x_api::BOOT0_START as *const u32, bao1x_api::BOOT0_REVOCATION_OFFSET, + &allowed_functions, true, ) .ok(); diff --git a/bao1x-boot/boot1/src/secboot.rs b/bao1x-boot/boot1/src/secboot.rs index 032e74fae..1cf2569d6 100644 --- a/bao1x-boot/boot1/src/secboot.rs +++ b/bao1x-boot/boot1/src/secboot.rs @@ -1,6 +1,13 @@ -use bao1x_api::*; +use bao1x_api::{signatures::FunctionCode, *}; use bao1x_hal::board::KeyPress; +const ALLOWED_FUNCTIONS: [u32; 5] = [ + FunctionCode::Baremetal as u32, + FunctionCode::UpdatedBaremetal as u32, + FunctionCode::Loader as u32, + FunctionCode::UpdatedLoader as u32, + FunctionCode::Developer as u32, +]; pub fn try_boot(board_type: &BoardTypeCoding, iox: &T) -> Option { if let Some(key) = crate::platform::get_key(board_type, iox) { // TODO: on baosec v2, we should not get Invalid keys. However, as we wait for the new @@ -26,6 +33,7 @@ pub fn try_boot(board_type: &BoardTypeCoding, iox: &T) -> O bao1x_api::LOADER_START as *const u32, bao1x_api::BOOT1_START as *const u32, bao1x_api::BOOT1_REVOCATION_OFFSET, + &ALLOWED_FUNCTIONS, true, ) { Ok(k) => crate::println!("**should be unreachable** Booted with key {}", k), @@ -55,6 +63,7 @@ pub fn boot_or_die() -> ! { bao1x_api::LOADER_START as *const u32, bao1x_api::BOOT1_START as *const u32, bao1x_api::BOOT1_REVOCATION_OFFSET, + &ALLOWED_FUNCTIONS, true, ) { Ok(k) => crate::println!("**should be unreachable** Booted with key {}", k),