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.
This commit is contained in:
bunnie 2026-01-15 16:58:22 +08:00
parent a5a6cc8e48
commit bf721e3b5c
No known key found for this signature in database
3 changed files with 9 additions and 5 deletions

View file

@ -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

View file

@ -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