From bf721e3b5cf883b3abfbc9e337d81d690fdded66 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 15 Jan 2026 16:58:22 +0800 Subject: [PATCH] adjust permissions on serial number; make chip init more permissive It is not clear if I can get the factory to burn the serial number (wafer lot, ID, x/y location) into the location I want it to be. So, I am allowing this to be updated by the firmware on boot, thus necessitating the permissions to be writeable for the serial number field. Furthermore, if there is any error in initializing the chip's identity in the factory, right now the chip goes into a mode where it has crashed and can't run diagnostic code. Write errors in this stage are thus turned into .ok() instead of .unwrap() because we want to allow the chip to go through the whole flow and then diagnose any issues later on. --- bao1x-boot/blobs/ac-block-0x3dc000.bin | Bin 32 -> 32 bytes bao1x-boot/boot1/src/platform/bao1x/slots.rs | 12 ++++++++---- libs/bao1x-api/src/offsets/common.rs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bao1x-boot/blobs/ac-block-0x3dc000.bin b/bao1x-boot/blobs/ac-block-0x3dc000.bin index 73552f63173b9cb58669d5c51533ccee7e0b1ace..2679947d1509f14b05a44eebb5e831ed095051f0 100644 GIT binary patch literal 32 QcmZQzKm|+;9~h7^03L7y$p8QV literal 32 RcmZQ#_`rY+n1Fm_3;;UN1iJtL diff --git a/bao1x-boot/boot1/src/platform/bao1x/slots.rs b/bao1x-boot/boot1/src/platform/bao1x/slots.rs index 995fcbf87..9f313bf9f 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/slots.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/slots.rs @@ -43,19 +43,22 @@ pub fn check_slots(board_type: &bao1x_api::BoardTypeCoding) { if slot_mgr.read(&CP_ID).unwrap().iter().all(|&b| b == 0 || b == 0xFF) { let cp_id = unsafe { core::slice::from_raw_parts(IFR_CP_ID_BASE as *const u8, SLOT_ELEMENT_LEN_BYTES) }; - slot_mgr.write(&mut rram, &CP_ID, cp_id.try_into().unwrap()).unwrap(); + // don't fail on write failure - otherwise we get stuck here and can't debug the chip + slot_mgr.write(&mut rram, &CP_ID, cp_id.try_into().unwrap()).ok(); } // this one may allocate a TRNG, which takes >50 ms to warm up. if slot_mgr.read(&SERIAL_NUMBER).unwrap().iter().all(|&b| b == 0 || b == 0xFF) { let trng = maybe_trng.get_or_insert_with(|| super::trng::ManagedTrng::new(&board_type)); let k = trng.generate_key(); - slot_mgr.write(&mut rram, &SERIAL_NUMBER, &k).unwrap(); + // don't fail on write failure - otherwise we get stuck here and can't debug the chip + slot_mgr.write(&mut rram, &SERIAL_NUMBER, &k).ok(); } if slot_mgr.read(&UUID).unwrap().iter().all(|&b| b == 0 || b == 0xFF) { let trng = maybe_trng.get_or_insert_with(|| super::trng::ManagedTrng::new(&board_type)); let k = trng.generate_key(); - slot_mgr.write(&mut rram, &UUID, &k).unwrap(); + // don't fail on write failure - otherwise we get stuck here and can't debug the chip + slot_mgr.write(&mut rram, &UUID, &k).ok(); } if slot_mgr.read(&IFR_HASH).unwrap().iter().all(|&b| b == 0 || b == 0xFF) { use digest::Digest; @@ -65,7 +68,8 @@ pub fn check_slots(board_type: &bao1x_api::BoardTypeCoding) { unsafe { core::slice::from_raw_parts(bao1x_api::IFR_BASE as *const u8, bao1x_api::IFR_LEN) }; hasher.update(&ifr_slice); let digest = hasher.finalize(); - slot_mgr.write(&mut rram, &IFR_HASH, digest.as_slice().try_into().unwrap()).unwrap(); + // don't fail on write failure - otherwise we get stuck here and can't debug the chip + slot_mgr.write(&mut rram, &IFR_HASH, digest.as_slice().try_into().unwrap()).ok(); } // once all values are written, advance the CP_BOOT_SETUP_DONE state // safety: the offset is correct because we're pulling it from our pre-defined constants and diff --git a/libs/bao1x-api/src/offsets/common.rs b/libs/bao1x-api/src/offsets/common.rs index 364941872..96e3571dc 100644 --- a/libs/bao1x-api/src/offsets/common.rs +++ b/libs/bao1x-api/src/offsets/common.rs @@ -191,7 +191,7 @@ pub const BOOT0_REVOCATION_OFFSET: usize = BOOT1_REVOCATION_OFFSET + PUBKEY_SLOT /// nor does it have any guarantee of being a monotonic or smoothly spaced out. It could /// even be all zeros (in which case LOT_CODE should be used). However, nominally, the plan /// is for SERIAL_NUMBER to be exactly the CP_ID field. -pub const SERIAL_NUMBER: SlotIndex = SlotIndex::Data(0, PartitionAccess::All, RwPerms::ReadOnly); +pub const SERIAL_NUMBER: SlotIndex = SlotIndex::Data(0, PartitionAccess::Open, RwPerms::ReadWrite); /// `UUID` is a 256-bit random number that can be used as a UUID for the chip. It is publicly /// readable and generated by a TRNG. This is suitable for putting into a KDF and generating