From c1b7612e7ec16dcccc2787f8fc10752edd70fc5c Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 10 Feb 2026 03:28:31 +0800 Subject: [PATCH 1/3] add one-way counter offset for auto-audit for the first few boots (3 in this case), automatically print an audit to the console. This is used to verify that the chip was programmed correctly in chip probe. --- libs/bao1x-api/src/lib.rs | 7 +++++++ libs/bao1x-api/src/offsets/common.rs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/libs/bao1x-api/src/lib.rs b/libs/bao1x-api/src/lib.rs index f3d199bc7..9efda4583 100644 --- a/libs/bao1x-api/src/lib.rs +++ b/libs/bao1x-api/src/lib.rs @@ -50,6 +50,13 @@ pub const SERVER_NAME_KBD: &str = "_Matrix keyboard driver_"; /// circular dependencies on the IFRAM block. pub const SERVER_NAME_BAO1X_HAL: &str = "_bao1x-SoC HAL_"; +/// Number of boots to trigger the 'audit' command. It's set to be bigger than 1, because +/// the chip tester may power cycle the chip during the provisioning process before the +/// log can be displayed. Once we have seen the actual chip tester infrastructure working, +/// we can dial this down; but 3 times should be enough for us to capture a log during +/// tester bring-up. +pub const AUTO_AUDIT_LIMIT: u32 = 3; + /// Flags register in the backup register bank. Used to track system state between soft resets. #[bitfield(u32)] #[derive(PartialEq, Eq, Debug)] diff --git a/libs/bao1x-api/src/offsets/common.rs b/libs/bao1x-api/src/offsets/common.rs index 12741c764..ca0ac9e42 100644 --- a/libs/bao1x-api/src/offsets/common.rs +++ b/libs/bao1x-api/src/offsets/common.rs @@ -66,6 +66,12 @@ macro_rules! encode_oneway { // =========== ONE WAY COUNTER SLOTS ============== +/// This is used to count the number of boots, up to a certain threshold. The main +/// purpose is to turn off the "audit" auto-print which is used to verify chip testing. +pub const EARLY_BOOT_COUNT: usize = 47; + +// gap of 8 slots [48..=55] left in case more anti-rollback slots are desired + /// Anti-rollback counters only count up and are used to note what is the minimum rollback /// version allowed for a firmware stage. Note that this is different from a semver because /// semvers can change without there being security problems. Anti-rollback counter is in From 7588d8bf43331ea907714e6ade3607382214bf93 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 10 Feb 2026 03:29:41 +0800 Subject: [PATCH 2/3] add auto-audit capability; add boot hashes the "audit" command is moved to its own file, as it has turned into A Thing. auto-audit now happens on the first few boots to help verify chip probe infrastructure. hashes of the boot regions are also printed as a diagnostic in the audit code. --- Cargo.lock | 1 + bao1x-boot/boot1/Cargo.toml | 1 + bao1x-boot/boot1/src/audit.rs | 274 ++++++++++++++++++++++++++++++++++ bao1x-boot/boot1/src/main.rs | 11 ++ bao1x-boot/boot1/src/repl.rs | 227 +--------------------------- 5 files changed, 289 insertions(+), 225 deletions(-) create mode 100644 bao1x-boot/boot1/src/audit.rs diff --git a/Cargo.lock b/Cargo.lock index a3c78322e..390e5a049 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -473,6 +473,7 @@ dependencies = [ "critical-section", "digest 0.10.7", "ed25519-dalek-bao1x", + "hex 0.4.3", "linked_list_allocator", "rand_chacha 0.3.1", "riscv", diff --git a/bao1x-boot/boot1/Cargo.toml b/bao1x-boot/boot1/Cargo.toml index a0f1871ba..23c99563d 100644 --- a/bao1x-boot/boot1/Cargo.toml +++ b/bao1x-boot/boot1/Cargo.toml @@ -27,6 +27,7 @@ xous-bio-bdma = { path = "../../libs/xous-bio-bdma", default-features = false, f "baremetal", ] } rand_chacha = { version = "0.3.1", default-features = false } +hex = { version = "0.4.3", default-features = false } [features] # Baochip feature tree below diff --git a/bao1x-boot/boot1/src/audit.rs b/bao1x-boot/boot1/src/audit.rs new file mode 100644 index 000000000..ea3ee63b5 --- /dev/null +++ b/bao1x-boot/boot1/src/audit.rs @@ -0,0 +1,274 @@ +use core::convert::TryInto; + +use bao1x_api::pubkeys::{BOOT0_SELF_CHECK, BOOT0_TO_BOOT1, BOOT1_TO_LOADER_OR_BAREMETAL}; +use bao1x_api::signatures::{SignatureInFlash, UNSIGNED_LEN}; +use bao1x_api::*; +use bao1x_hal::acram::OneWayCounter; +use bao1x_hal::sigcheck::ERASE_VALUE; +use digest::Digest; +use sha2_bao1x::Sha512; + +#[cfg(not(feature = "alt-boot1"))] +pub fn early_audit() { + let owc = bao1x_hal::acram::OneWayCounter::new(); + let boot_count = owc.get(bao1x_api::EARLY_BOOT_COUNT).unwrap_or(bao1x_api::AUTO_AUDIT_LIMIT); + if boot_count < AUTO_AUDIT_LIMIT { + audit(); + // safety: the constant is vetted to be in-range + unsafe { owc.inc(bao1x_api::EARLY_BOOT_COUNT).ok() }; + } +} + +fn hash_region(region: &[u8], description: &str) { + let mut hasher = Sha512::new(); + hasher.update(®ion); + let digest: [u8; 64] = hasher.finalize().try_into().unwrap(); + let mut buffer = [0u8; 128]; + hex::encode_to_slice(digest, &mut buffer).unwrap(); + let hex_str = core::str::from_utf8(&buffer).unwrap(); + crate::println!("{}: {}", description, hex_str); +} + +pub fn audit() { + let owc = OneWayCounter::new(); + let boardtype = owc.get_decoded::().unwrap(); + crate::println!("Board type reads as: {:?}", boardtype); + crate::println!("Boot partition is: {:?}", owc.get_decoded::()); + crate::println!("Semver is: {}", crate::version::SEMVER); + crate::println!("Description is: {}", crate::RELEASE_DESCRIPTION); + 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()), + u32::from_le_bytes(sn[8..12].try_into().unwrap()), + u32::from_le_bytes(sn[4..8].try_into().unwrap()), + u32::from_le_bytes(sn[..4].try_into().unwrap()) + ); + crate::println!("Public serial number: {}", bao1x_hal::usb::derive_usb_serial_number(&owc, &slot_mgr)); + let uuid = slot_mgr.read(&bao1x_hal::board::UUID).unwrap(); + crate::println!( + "UUID: {:08x}-{:08x}-{:08x}-{:08x}", + u32::from_le_bytes(uuid[12..16].try_into().unwrap()), + u32::from_le_bytes(uuid[8..12].try_into().unwrap()), + u32::from_le_bytes(uuid[4..8].try_into().unwrap()), + u32::from_le_bytes(uuid[..4].try_into().unwrap()) + ); + crate::println!( + "Paranoid mode: {}/{}", + owc.get(PARANOID_MODE).unwrap(), + owc.get(PARANOID_MODE_DUPE).unwrap() + ); + // this number may be non-zero because some of the sensors are on a hair-trigger + crate::println!("Possible attack attempts: {}", owc.get(POSSIBLE_ATTACKS).unwrap()); + crate::println!("Revocations:"); + // only checks the main array, not the duplicate array + crate::println!("Stage key0 key1 key2 key3"); + let key_array = [ + ("boot0 ", BOOT0_REVOCATION_OFFSET), + ("boot1 ", BOOT1_REVOCATION_OFFSET), + ("next stage ", LOADER_REVOCATION_OFFSET), + ]; + for (img_type, start) in key_array { + crate::print!("{}", img_type); + for offset in start..(start + PUBKEY_SLOTS) { + if owc.get(offset).unwrap_or(1) == 0 { + crate::print!("enabled "); + } else { + crate::print!("revoked "); + } + } + crate::println!(""); + } + + match bao1x_hal::sigcheck::validate_image(BOOT0_SELF_CHECK, None, None) { + Ok((k, k2, tag, target)) => crate::println!( + "Boot0: key {}/{} ({}) -> {:x}", + k, + !k2, + core::str::from_utf8(&tag).unwrap_or("invalid tag"), + target ^ u32::from_le_bytes(tag) + ), + Err(e) => crate::println!("Boot0 did not validate: {:?}", e), + } + match bao1x_hal::sigcheck::validate_image(BOOT0_TO_BOOT1, None, None) { + Ok((k, k2, tag, target)) => crate::println!( + "Boot1: key {}/{} ({}) -> {:x}", + k, + !k2, + core::str::from_utf8(&tag).unwrap_or("invalid tag"), + target ^ u32::from_le_bytes(tag) + ), + Err(e) => crate::println!("Boot1 did not validate: {:?}", e), + } + match bao1x_hal::sigcheck::validate_image(BOOT1_TO_LOADER_OR_BAREMETAL, None, None) { + Ok((k, k2, tag, target)) => crate::println!( + "Next stage: key {}/{} ({}) -> {:x}", + k, + !k2, + core::str::from_utf8(&tag).unwrap_or("invalid tag"), + target ^ u32::from_le_bytes(tag) + ), + Err(e) => crate::println!("Next stage did not validate: {:?}", e), + } + + // leak info about the erase proof coupon - this makes CI testing *so much easier* + // the erase proof coupon is a "key" that's treated in a similar fashion in terms of lifecyle + // to all the other keys, except its purpose is to be inspected. + let erase_check = slot_mgr.read(&bao1x_hal::board::ERASE_PROOF).unwrap(); + // check length is a subset of the full 256-bit key, just because...why leak the whole thing + // if you don't need to? 96 bits is a pretty big collision space for a single pair of values. + const CHECK_LEN: usize = 12; + let erased_state = [ERASE_VALUE; CHECK_LEN]; + let uninit_state = [0u8; CHECK_LEN]; + if &erase_check[..CHECK_LEN] == &erased_state { + crate::println!("Erase proof: erased"); + } else if &erase_check[..CHECK_LEN] == &uninit_state { + crate::println!("Erase proof: uninit or access denied"); + } else { + crate::println!("Erase proof: not erased"); + } + + // sanity check the auto-audit limit + crate::println!("auto-audit limit: {}", owc.get(EARLY_BOOT_COUNT).unwrap()); + // hash reports + let boot0_region = unsafe { + core::slice::from_raw_parts( + bao1x_api::BOOT0_START as *const u8, + bao1x_api::BOOT1_START - bao1x_api::BOOT0_START, + ) + }; + // includes free space in the partition + hash_region(boot0_region, "boot0 partition"); + + let b0_pk_ptr = bao1x_api::BOOT0_START as *const SignatureInFlash; + let b0_pk: &SignatureInFlash = unsafe { b0_pk_ptr.as_ref().unwrap() }; + let boot0_used = unsafe { + core::slice::from_raw_parts( + (bao1x_api::BOOT0_START + UNSIGNED_LEN) as *const u8, + b0_pk.sealed_data.signed_len as usize, + ) + }; + // only the portion that's protected by signature + hash_region(boot0_used, "boot0 code only"); + + let boot1_region = unsafe { + core::slice::from_raw_parts( + bao1x_api::BOOT1_START as *const u8, + bao1x_api::LOADER_START - bao1x_api::BOOT1_START, + ) + }; + // includes free space + hash_region(boot1_region, "boot1 partition"); + + // detailed state checks + let mut secure = true; + // check that boot1 pubkeys match the indelible entries + let pubkey_ptr = bao1x_api::BOOT1_START as *const bao1x_api::signatures::SignatureInFlash; + let pk_src: &bao1x_api::signatures::SignatureInFlash = unsafe { pubkey_ptr.as_ref().unwrap() }; + let reference_keys = + [bao1x_api::BAO1_PUBKEY, bao1x_api::BAO2_PUBKEY, bao1x_api::BETA_PUBKEY, bao1x_api::DEV_PUBKEY]; + let slot_mgr = bao1x_hal::acram::SlotManager::new(); + let mut good_compare = true; + for (boot0_key, ref_key) in pk_src.sealed_data.pubkeys.iter().zip(reference_keys.iter()) { + let ref_data = slot_mgr.read(&ref_key).unwrap(); + if ref_data != &boot0_key.pk { + good_compare = false; + } + } + if !good_compare { + crate::println!("== BOOT1 FAILED PUBKEY CHECK =="); + // this may "not" be a security failure if boot1 was intentionally replaced + // but in that case, the developer customizing the image should have also edited this + // check out. + secure = false; + } + // check developer mode + if owc.get(DEVELOPER_MODE).unwrap() != 0 { + crate::println!("== IN DEVELOPER MODE =="); + secure = false; + } + if owc.get(BOOT0_PUBKEY_FAIL).unwrap() != 0 { + crate::println!("== BOOT0 REPORTED PUBKEY CHECK FAILURE =="); + secure = false; + } + if owc.get(BOOT1_PUBKEY_FAIL).unwrap() != 0 { + crate::println!("== BOOT1 REPORTED PUBKEY CHECK FAILURE =="); + secure = false; + } + if owc.get(CP_BOOT_SETUP_DONE).unwrap() == 0 { + crate::println!("== CP SETUP FAILED =="); + secure = false; + } + if owc.get(IN_SYSTEM_BOOT_SETUP_DONE).unwrap() == 0 { + crate::println!("In-system keys have NOT been generated"); + secure = false; + } else { + crate::println!("In-system keys have been generated"); + } + let ifr = unsafe { core::slice::from_raw_parts(0x6040_0180 as *const u8, 0x10) }; + let ref_value = + [0x00u8, 0x00, 0x00, 0x00, 0x82, 0x8c, 0x42, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + if ifr == &ref_value { + crate::println!("CM7 & debug confirmed fused off"); + } else { + crate::println!("Factory configuration error - CM7 or debug is enabled!"); + secure = false; + } + let collateral = slot_mgr.read(&COLLATERAL).unwrap(); + let check_val = alloc::vec![bao1x_hal::sigcheck::ERASE_VALUE; COLLATERAL.len() * SLOT_ELEMENT_LEN_BYTES]; + let uninit_val = alloc::vec![0; COLLATERAL.len() * SLOT_ELEMENT_LEN_BYTES]; + // these strings below are used in CI. If they are changed, CI needs to be updated + if collateral == &check_val { + crate::println!("Collateral erased"); + } else if collateral == &uninit_val { + crate::println!("Collateral is uninitialized or access is denied"); + } else { + crate::println!("Collateral is set"); + } + let boot1_block_ptr = bao1x_api::BOOT1_START as *const bao1x_api::signatures::SignatureInFlash; + let boot1_block: &bao1x_api::signatures::SignatureInFlash = unsafe { boot1_block_ptr.as_ref().unwrap() }; + let mut receipts_ok = true; + for (key, slot) in boot1_block.sealed_data.pubkeys.iter().zip(BOOT1_RECEIPT_SLOTS) { + let receipt = slot_mgr.read(&slot).unwrap(); + if &key.pk != receipt { + receipts_ok = false; + break; + } + } + if !receipts_ok { + crate::println!("Boot1 receipts do not match"); + secure = false; + } else { + crate::println!("Boot1 receipts OK"); + } + let claimed_function: bao1x_api::signatures::FunctionCode = boot1_block + .sealed_data + .function_code + .try_into() + .unwrap_or(bao1x_api::signatures::FunctionCode::Invalid); + let arb_offset = claimed_function.to_anti_rollback_counter(); + match arb_offset { + Some(arb) => { + let arb_value = owc.get(arb).expect("Can't read anti-rollback value"); + if arb_value != boot1_block.sealed_data.anti_rollback { + crate::println!( + "Anti-rollback code mismatch! Counter {} / image {}", + arb_value, + boot1_block.sealed_data.anti_rollback + ); + secure = false; + } else { + crate::println!("Boot1 anti-rollback OK"); + } + } + None => { + crate::println!("Anti-rollback counter offset invalid!"); + secure = false; + } + } + + if !secure { + crate::println!("** System did not meet minimum requirements for security **"); + } +} diff --git a/bao1x-boot/boot1/src/main.rs b/bao1x-boot/boot1/src/main.rs index a1486c995..f365ff07f 100644 --- a/bao1x-boot/boot1/src/main.rs +++ b/bao1x-boot/boot1/src/main.rs @@ -4,6 +4,7 @@ extern crate alloc; // contains runtime setup mod asm; +mod audit; mod platform; mod repl; mod secboot; @@ -162,6 +163,16 @@ pub unsafe extern "C" fn rust_entry() -> ! { // has a chance to be updated. bao1x_hal::hardening::apply_attack_policy(&mut csprng, &one_way); + // This causes the chip to automatically emit an audit log on the first few boots. The main + // purpose of this is to get a reading out of the chip probe station if the chip was programmed + // correctly or not. Apparently it is "impossible" to send serial data to the chip, and it's + // questionable even if I can attach a serial adapter to the probe station - the chip tester + // is claiming the best they can do is "give me an oscilloscope trace of the serial line". + // I think there is some restriction on what equipment is allowed to connect to the tester, but + // everyone is being super-dodgy about answering any question I have about this. + #[cfg(not(feature = "alt-boot1"))] + crate::audit::early_audit(); + // Below is our first divergence out of boot1, and thus, all security checks must happen above // this line! if boot_wait == BootWaitCoding::Disable && current_key.is_none() { diff --git a/bao1x-boot/boot1/src/repl.rs b/bao1x-boot/boot1/src/repl.rs index f17102aab..09422b912 100644 --- a/bao1x-boot/boot1/src/repl.rs +++ b/bao1x-boot/boot1/src/repl.rs @@ -2,14 +2,12 @@ use alloc::format; use alloc::string::{String, ToString}; use alloc::vec::Vec; -use core::convert::TryInto; -use bao1x_api::pubkeys::{BOOT0_SELF_CHECK, BOOT0_TO_BOOT1, BOOT1_TO_LOADER_OR_BAREMETAL}; +use bao1x_api::pubkeys::BOOT0_TO_BOOT1; #[allow(unused_imports)] use bao1x_api::*; use bao1x_hal::acram::OneWayCounter; use bao1x_hal::hardening::Csprng; -use bao1x_hal::sigcheck::ERASE_VALUE; use utralib::*; pub struct Error { @@ -304,228 +302,7 @@ impl Repl { } } "audit" => { - let owc = OneWayCounter::new(); - let boardtype = owc.get_decoded::().unwrap(); - crate::println!("Board type reads as: {:?}", boardtype); - crate::println!("Boot partition is: {:?}", owc.get_decoded::()); - crate::println!("Semver is: {}", crate::version::SEMVER); - crate::println!("Description is: {}", crate::RELEASE_DESCRIPTION); - 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()), - u32::from_le_bytes(sn[8..12].try_into().unwrap()), - u32::from_le_bytes(sn[4..8].try_into().unwrap()), - u32::from_le_bytes(sn[..4].try_into().unwrap()) - ); - crate::println!( - "Public serial number: {}", - bao1x_hal::usb::derive_usb_serial_number(&owc, &slot_mgr) - ); - let uuid = slot_mgr.read(&bao1x_hal::board::UUID).unwrap(); - crate::println!( - "UUID: {:08x}-{:08x}-{:08x}-{:08x}", - u32::from_le_bytes(uuid[12..16].try_into().unwrap()), - u32::from_le_bytes(uuid[8..12].try_into().unwrap()), - u32::from_le_bytes(uuid[4..8].try_into().unwrap()), - u32::from_le_bytes(uuid[..4].try_into().unwrap()) - ); - crate::println!( - "Paranoid mode: {}/{}", - owc.get(PARANOID_MODE).unwrap(), - owc.get(PARANOID_MODE_DUPE).unwrap() - ); - // this number may be non-zero because some of the sensors are on a hair-trigger - crate::println!("Possible attack attempts: {}", owc.get(POSSIBLE_ATTACKS).unwrap()); - crate::println!("Revocations:"); - // only checks the main array, not the duplicate array - crate::println!("Stage key0 key1 key2 key3"); - let key_array = [ - ("boot0 ", BOOT0_REVOCATION_OFFSET), - ("boot1 ", BOOT1_REVOCATION_OFFSET), - ("next stage ", LOADER_REVOCATION_OFFSET), - ]; - for (img_type, start) in key_array { - crate::print!("{}", img_type); - for offset in start..(start + PUBKEY_SLOTS) { - if owc.get(offset).unwrap_or(1) == 0 { - crate::print!("enabled "); - } else { - crate::print!("revoked "); - } - } - crate::println!(""); - } - - match bao1x_hal::sigcheck::validate_image(BOOT0_SELF_CHECK, None, None) { - Ok((k, k2, tag, target)) => crate::println!( - "Boot0: key {}/{} ({}) -> {:x}", - k, - !k2, - core::str::from_utf8(&tag).unwrap_or("invalid tag"), - target ^ u32::from_le_bytes(tag) - ), - Err(e) => crate::println!("Boot0 did not validate: {:?}", e), - } - match bao1x_hal::sigcheck::validate_image(BOOT0_TO_BOOT1, None, None) { - Ok((k, k2, tag, target)) => crate::println!( - "Boot1: key {}/{} ({}) -> {:x}", - k, - !k2, - core::str::from_utf8(&tag).unwrap_or("invalid tag"), - target ^ u32::from_le_bytes(tag) - ), - Err(e) => crate::println!("Boot1 did not validate: {:?}", e), - } - match bao1x_hal::sigcheck::validate_image(BOOT1_TO_LOADER_OR_BAREMETAL, None, None) { - Ok((k, k2, tag, target)) => crate::println!( - "Next stage: key {}/{} ({}) -> {:x}", - k, - !k2, - core::str::from_utf8(&tag).unwrap_or("invalid tag"), - target ^ u32::from_le_bytes(tag) - ), - Err(e) => crate::println!("Next stage did not validate: {:?}", e), - } - - // leak info about the erase proof coupon - this makes CI testing *so much easier* - // the erase proof coupon is a "key" that's treated in a similar fashion in terms of lifecyle - // to all the other keys, except its purpose is to be inspected. - let erase_check = slot_mgr.read(&bao1x_hal::board::ERASE_PROOF).unwrap(); - // check length is a subset of the full 256-bit key, just because...why leak the whole thing - // if you don't need to? 96 bits is a pretty big collision space for a single pair of values. - const CHECK_LEN: usize = 12; - let erased_state = [ERASE_VALUE; CHECK_LEN]; - let uninit_state = [0u8; CHECK_LEN]; - if &erase_check[..CHECK_LEN] == &erased_state { - crate::println!("Erase proof: erased"); - } else if &erase_check[..CHECK_LEN] == &uninit_state { - crate::println!("Erase proof: uninit or access denied"); - } else { - crate::println!("Erase proof: not erased"); - } - - // detailed state checks - let mut secure = true; - // check that boot1 pubkeys match the indelible entries - let pubkey_ptr = bao1x_api::BOOT1_START as *const bao1x_api::signatures::SignatureInFlash; - let pk_src: &bao1x_api::signatures::SignatureInFlash = - unsafe { pubkey_ptr.as_ref().unwrap() }; - let reference_keys = [ - bao1x_api::BAO1_PUBKEY, - bao1x_api::BAO2_PUBKEY, - bao1x_api::BETA_PUBKEY, - bao1x_api::DEV_PUBKEY, - ]; - let slot_mgr = bao1x_hal::acram::SlotManager::new(); - let mut good_compare = true; - for (boot0_key, ref_key) in pk_src.sealed_data.pubkeys.iter().zip(reference_keys.iter()) { - let ref_data = slot_mgr.read(&ref_key).unwrap(); - if ref_data != &boot0_key.pk { - good_compare = false; - } - } - if !good_compare { - crate::println!("== BOOT1 FAILED PUBKEY CHECK =="); - // this may "not" be a security failure if boot1 was intentionally replaced - // but in that case, the developer customizing the image should have also edited this - // check out. - secure = false; - } - // check developer mode - if owc.get(DEVELOPER_MODE).unwrap() != 0 { - crate::println!("== IN DEVELOPER MODE =="); - secure = false; - } - if owc.get(BOOT0_PUBKEY_FAIL).unwrap() != 0 { - crate::println!("== BOOT0 REPORTED PUBKEY CHECK FAILURE =="); - secure = false; - } - if owc.get(BOOT1_PUBKEY_FAIL).unwrap() != 0 { - crate::println!("== BOOT1 REPORTED PUBKEY CHECK FAILURE =="); - secure = false; - } - if owc.get(CP_BOOT_SETUP_DONE).unwrap() == 0 { - crate::println!("== CP SETUP FAILED =="); - secure = false; - } - if owc.get(IN_SYSTEM_BOOT_SETUP_DONE).unwrap() == 0 { - crate::println!("In-system keys have NOT been generated"); - secure = false; - } else { - crate::println!("In-system keys have been generated"); - } - let ifr = unsafe { core::slice::from_raw_parts(0x6040_0180 as *const u8, 0x10) }; - let ref_value = [ - 0x00u8, 0x00, 0x00, 0x00, 0x82, 0x8c, 0x42, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, - ]; - if ifr == &ref_value { - crate::println!("CM7 & debug confirmed fused off"); - } else { - crate::println!("Factory configuration error - CM7 or debug is enabled!"); - secure = false; - } - let collateral = slot_mgr.read(&COLLATERAL).unwrap(); - let check_val = - alloc::vec![bao1x_hal::sigcheck::ERASE_VALUE; COLLATERAL.len() * SLOT_ELEMENT_LEN_BYTES]; - let uninit_val = alloc::vec![0; COLLATERAL.len() * SLOT_ELEMENT_LEN_BYTES]; - // these strings below are used in CI. If they are changed, CI needs to be updated - if collateral == &check_val { - crate::println!("Collateral erased"); - } else if collateral == &uninit_val { - crate::println!("Collateral is uninitialized or access is denied"); - } else { - crate::println!("Collateral is set"); - } - let boot1_block_ptr = - bao1x_api::BOOT1_START as *const bao1x_api::signatures::SignatureInFlash; - let boot1_block: &bao1x_api::signatures::SignatureInFlash = - unsafe { boot1_block_ptr.as_ref().unwrap() }; - let mut receipts_ok = true; - for (key, slot) in boot1_block.sealed_data.pubkeys.iter().zip(BOOT1_RECEIPT_SLOTS) { - let receipt = slot_mgr.read(&slot).unwrap(); - if &key.pk != receipt { - receipts_ok = false; - break; - } - } - if !receipts_ok { - crate::println!("Boot1 receipts do not match"); - secure = false; - } else { - crate::println!("Boot1 receipts OK"); - } - let claimed_function: bao1x_api::signatures::FunctionCode = boot1_block - .sealed_data - .function_code - .try_into() - .unwrap_or(bao1x_api::signatures::FunctionCode::Invalid); - let arb_offset = claimed_function.to_anti_rollback_counter(); - match arb_offset { - Some(arb) => { - let arb_value = owc.get(arb).expect("Can't read anti-rollback value"); - if arb_value != boot1_block.sealed_data.anti_rollback { - crate::println!( - "Anti-rollback code mismatch! Counter {} / image {}", - arb_value, - boot1_block.sealed_data.anti_rollback - ); - secure = false; - } else { - crate::println!("Boot1 anti-rollback OK"); - } - } - None => { - crate::println!("Anti-rollback counter offset invalid!"); - secure = false; - } - } - - if !secure { - crate::println!("** System did not meet minimum requirements for security **"); - } + crate::audit::audit(); } "lockdown" => match bao1x_hal::sigcheck::validate_image(BOOT0_TO_BOOT1, None, None) { Ok((k, _k2, _tag, _target)) => { From 8ef78f592f38c43e805f9702af994d382c8cfe29 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 10 Feb 2026 03:31:39 +0800 Subject: [PATCH 3/3] add notes about how bootloader releases will work --- bao1x-boot/RELEASES.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 bao1x-boot/RELEASES.md diff --git a/bao1x-boot/RELEASES.md b/bao1x-boot/RELEASES.md new file mode 100644 index 000000000..93f0736d6 --- /dev/null +++ b/bao1x-boot/RELEASES.md @@ -0,0 +1,10 @@ +# Release Process for Bootloaders / Reproducible Builds + +This is a work in progress, but the final boot0/boot1 artifacts are built using guix. Here's what's been decided so far: + +- A release is tagged at a specific commit hash +- Rust is pinned to 1.90 for the build +- boot0/boot1 are built using guix, and the hashes are checked against a third party verifier (Sylvain Bellemare) for reproducibility +- The artifacts are signed using the Baochip signing token +- They are uploaded to CI, and the release-CI is run +- Upon a full pass, the artifacts are transferred to chip probe for burning onto the chips