From 1d5cc0806b23d6c4c1ae40a7c409e5f3c88bfbf0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 20 Oct 2025 02:20:45 +0800 Subject: [PATCH] update boot1 to use slotmanager API also add the hook for setting up/checking all the other slots --- bao1x-boot/boot1/src/platform/bao1x.rs | 1 + bao1x-boot/boot1/src/platform/bao1x/bao1x.rs | 2 ++ bao1x-boot/boot1/src/platform/bao1x/slots.rs | 9 +++++++++ bao1x-boot/boot1/src/repl.rs | 7 ++++--- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 bao1x-boot/boot1/src/platform/bao1x/slots.rs diff --git a/bao1x-boot/boot1/src/platform/bao1x.rs b/bao1x-boot/boot1/src/platform/bao1x.rs index 7cc53156b..92de862c2 100644 --- a/bao1x-boot/boot1/src/platform/bao1x.rs +++ b/bao1x-boot/boot1/src/platform/bao1x.rs @@ -3,6 +3,7 @@ pub use bao1x::*; pub mod debug; pub mod gfx; pub mod irq; +pub mod slots; pub mod usb; pub const UART_BAUD: u32 = 1_000_000; diff --git a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs index f38ae3fd0..41e990e2a 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs @@ -70,6 +70,8 @@ pub fn setup_dabao_se0_pin(iox: &T) -> (IoxPort, u8) { /// This can change the board type coding to a safer, simpler board type if the declared board type has /// problems booting. pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::BoardTypeCoding, u32) { + crate::platform::slots::check_slots(&board_type); + let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32); // setup board-specific I/Os - early boot set. These are items that have to be diff --git a/bao1x-boot/boot1/src/platform/bao1x/slots.rs b/bao1x-boot/boot1/src/platform/bao1x/slots.rs new file mode 100644 index 000000000..2e334d2e3 --- /dev/null +++ b/bao1x-boot/boot1/src/platform/bao1x/slots.rs @@ -0,0 +1,9 @@ +/// This function is designed to be called "frequently" to audit the state +/// of the security slots. Its role is to: +/// - Initialize any keys that have not yet been initialized +/// - Update the one-way counters to lock out re-initializations +/// - Verify that the ACLs have been set according to the spec +/// - Repair any ACLs that are not set correctly. "Repair" is expected on first boot at the factory, since +/// the chip comes blank. But repair is also useful in case an adversary manages to flip any ACL states +/// on us. +pub fn check_slots(board_type: &bao1x_api::BoardTypeCoding) {} diff --git a/bao1x-boot/boot1/src/repl.rs b/bao1x-boot/boot1/src/repl.rs index 77caacb7f..d6f5ff0f9 100644 --- a/bao1x-boot/boot1/src/repl.rs +++ b/bao1x-boot/boot1/src/repl.rs @@ -201,6 +201,8 @@ impl Repl { count += 1; } crate::println!("Board type set to {:?} after {} increments", new_type, count); + crate::platform::slots::check_slots(&new_type); + crate::println!("Key & data slots checked according to the new type"); } "audit" => { let owc = OneWayCounter::new(); @@ -214,9 +216,8 @@ impl Repl { ); crate::println!("Semver is: {}", crate::version::SEMVER); crate::println!("Description is: {}", crate::RELEASE_DESCRIPTION); - let slot_mgr = bao1x_hal::protected_rram::SlotManager::new(); - // TODO: replace with a proper `const` value once we have the slots defined properly - let sn = slot_mgr.read(&bao1x_hal::protected_rram::SlotIndex::Data(0)).unwrap(); + let slot_mgr = bao1x_hal::acram::SlotManager::new(); + let sn = slot_mgr.read(&bao1x_hal::board::SERIAL_NUMBER).unwrap(); crate::println!( "Device serializer: {:08x}-{:08x}-{:08x}-{:08x}", u32::from_le_bytes(sn[12..16].try_into().unwrap()),