add routines for manipulating and using the serial numbers in boot1 context

This commit is contained in:
bunnie 2025-11-04 13:15:28 +08:00
parent aaf1cbd2f9
commit 137c70a629
3 changed files with 25 additions and 4 deletions

View file

@ -126,10 +126,13 @@ pub fn get_descriptor_request(this: &mut CorigineUsb, value: u16, _index: usize,
ep0_buf[..4].copy_from_slice(&[4, USB_DT_STRING, 9, 4]);
4
} else {
let owc = bao1x_hal::acram::OneWayCounter::new();
let slot_mgr = bao1x_hal::acram::SlotManager::new();
let sn = bao1x_hal::usb::derive_usb_serial_number(&owc, &slot_mgr);
let s = match id {
1 => MANUFACTURER,
2 => PRODUCT,
_ => SERIAL,
_ => &sn,
};
let slen = 2 + s.len() * 2;
ep0_buf[0] = slen as u8;

View file

@ -136,8 +136,6 @@ const VENDOR_ID: u16 = 0x1209;
const PRODUCT_ID: u16 = 0x3613; // this needs to change! this is the Precursor product ID.
const MANUFACTURER: &'static str = "Baochip";
const PRODUCT: &'static str = "Dabao";
// no seriously, do this
const SERIAL: &'static str = "TODO";
impl DeviceDescriptor {
#[allow(dead_code)]

View file

@ -245,6 +245,22 @@ impl Repl {
return Err(Error::help("altboot [toggle]"));
}
}
"idmode" => {
let owc = OneWayCounter::new();
if args.len() == 0 {
crate::println!("ID mode is: {:?}", owc.get_decoded::<ExternalIdentifiers>());
self.abort_cmd();
return Ok(());
} else if args.len() != 1 {
return Err(Error::help("idmode [toggle]"));
}
if args[0] == "toggle" {
owc.inc_coded::<ExternalIdentifiers>().unwrap();
crate::println!("ID mode is now: {:?}", owc.get_decoded::<ExternalIdentifiers>());
} else {
return Err(Error::help("idmode [toggle]"));
}
}
"audit" => {
let owc = OneWayCounter::new();
let boardtype = owc.get_decoded::<BoardTypeCoding>().unwrap();
@ -261,6 +277,10 @@ impl Repl {
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)
);
crate::println!("Revocations:");
crate::println!("Stage key0 key1 key2 key3");
let key_array = [
@ -517,7 +537,7 @@ impl Repl {
_ => {
crate::println!("Command not recognized: {}", cmd);
crate::print!(
"Commands include: reset, echo, altboot, boot, bootwait, localecho, uf2, boardtype, audit, lockdown"
"Commands include: reset, echo, altboot, boot, bootwait, idmode, localecho, uf2, boardtype, audit, lockdown"
);
#[cfg(feature = "test-boot0-keys")]
crate::print!(", publock");