Merge pull request #782 from betrusted-io/bootwait

Add bootwait to test console
This commit is contained in:
bunnie 2026-01-16 17:59:17 +08:00 committed by GitHub
commit af5a28ebc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 291 additions and 212 deletions

1
Cargo.lock generated
View file

@ -363,6 +363,7 @@ dependencies = [
"base45", "base45",
"bytemuck", "bytemuck",
"chrono", "chrono",
"keystore",
"log", "log",
"modals", "modals",
"num-derive 0.4.2", "num-derive 0.4.2",

Binary file not shown.

View file

@ -18,6 +18,10 @@ pub enum Opcode {
/// Ephemeral secret operations /// Ephemeral secret operations
EphemeralOp = 256, EphemeralOp = 256,
// ----- below are non-cryptographic opcodes but used to manipulate sensitive state -----
/// Set bootwait parameters
Bootwait = 4096,
/// Used to map unknown opcodes /// Used to map unknown opcodes
InvalidCall = 65535, InvalidCall = 65535,
} }

View file

@ -25,6 +25,7 @@ pddb = { path = "../pddb", optional = true }
xous-swapper = { path = "../xous-swapper", optional = true } xous-swapper = { path = "../xous-swapper", optional = true }
bytemuck = "1.24.0" bytemuck = "1.24.0"
susres = { package = "xous-api-susres", version = "0.9.68" } susres = { package = "xous-api-susres", version = "0.9.68" }
keystore = { path = "../keystore" }
# pddb testing # pddb testing
rand = { version = "0.8.5", features = ["getrandom"], optional = true } rand = { version = "0.8.5", features = ["getrandom"], optional = true }

View file

@ -15,16 +15,40 @@ impl<'a> ShellCmdApi<'a> for Test {
let mut ret = String::new(); let mut ret = String::new();
#[allow(unused_variables)] #[allow(unused_variables)]
let helpstring = "test [proc] [freemem] [interrupts]; see code for other test commands."; let helpstring = "test [proc] [freemem] [interrupts] [bootwait]; see code for other test commands.";
#[cfg(feature = "bmp180")] #[cfg(feature = "bmp180")]
let helpstring = "Usage: let helpstring = "Usage:
temp - reads temperature from bmp180."; temp - reads temperature from bmp180.";
let mut tokens = args.split(' '); let mut parts = args.split_whitespace();
let cmd = parts.next().unwrap_or("").to_string();
let args: Vec<String> = parts.map(|s| s.to_string()).collect();
if let Some(sub_cmd) = tokens.next() { match cmd.as_str() {
match sub_cmd { "bootwait" => {
let keystore = keystore::Keystore::new(&_env.xns);
if args.len() != 1 {
write!(ret, "bootwait [check | enable | disable]").ok();
return Ok(Some(ret));
}
if args[0] == "check" {
write!(ret, "bootwait is {:?}", keystore.bootwait(None).unwrap()).ok();
} else if args[0] == "enable" {
keystore.bootwait(Some(true)).unwrap();
write!(ret, "bootwait enabled").ok();
log::info!(
"{}BOOTWAIT.ENABLED,{}",
bao1x_hal::board::BOOKEND_START,
bao1x_hal::board::BOOKEND_END
);
} else if args[0] == "disable" {
keystore.bootwait(Some(false)).unwrap();
write!(ret, "bootwait disabled").ok();
} else {
write!(ret, "bootwait [check | enable | disable]").ok();
}
}
"timer" => { "timer" => {
let start = _env.ticktimer.elapsed_ms(); let start = _env.ticktimer.elapsed_ms();
log::info!("Starting test"); log::info!("Starting test");
@ -85,8 +109,7 @@ impl<'a> ShellCmdApi<'a> for Test {
use bao1x_hal::i2c::I2c; use bao1x_hal::i2c::I2c;
let mut i2c = I2c::new(); let mut i2c = I2c::new();
let mut axp2101 = let mut axp2101 = bao1x_hal::axp2101::Axp2101::new(&mut i2c).expect("couldn't get AXP2101");
bao1x_hal::axp2101::Axp2101::new(&mut i2c).expect("couldn't get AXP2101");
log::info!("sending shipmode to axp2101 pmic...in four seconds"); log::info!("sending shipmode to axp2101 pmic...in four seconds");
let tt = ticktimer::Ticktimer::new().unwrap(); let tt = ticktimer::Ticktimer::new().unwrap();
tt.sleep_ms(4000).ok(); tt.sleep_ms(4000).ok();
@ -151,8 +174,7 @@ impl<'a> ShellCmdApi<'a> for Test {
// can break, but also this routine is not meant for public // can break, but also this routine is not meant for public
// consumption and coding it here avoids breaking dependencies to the Xous API crate. // consumption and coding it here avoids breaking dependencies to the Xous API crate.
let page_buf = xous::PageBuf::new(); let page_buf = xous::PageBuf::new();
xous::rsyscall(xous::SysCall::PlatformSpecific(2, page_buf.as_ptr(), 0, 0, 0, 0, 0)) xous::rsyscall(xous::SysCall::PlatformSpecific(2, page_buf.as_ptr(), 0, 0, 0, 0, 0)).unwrap();
.unwrap();
log::info!("Process listing:"); log::info!("Process listing:");
for line in page_buf.as_str().lines() { for line in page_buf.as_str().lines() {
@ -164,8 +186,7 @@ impl<'a> ShellCmdApi<'a> for Test {
// can break, but also this routine is not meant for public // can break, but also this routine is not meant for public
// consumption and coding it here avoids breaking dependencies to the Xous API crate. // consumption and coding it here avoids breaking dependencies to the Xous API crate.
let page_buf = xous::PageBuf::new(); let page_buf = xous::PageBuf::new();
xous::rsyscall(xous::SysCall::PlatformSpecific(1, page_buf.as_ptr(), 0, 0, 0, 0, 0)) xous::rsyscall(xous::SysCall::PlatformSpecific(1, page_buf.as_ptr(), 0, 0, 0, 0, 0)).unwrap();
.unwrap();
log::info!("RAM usage:"); log::info!("RAM usage:");
for line in page_buf.as_str().lines() { for line in page_buf.as_str().lines() {
@ -177,8 +198,7 @@ impl<'a> ShellCmdApi<'a> for Test {
// can break, but also this routine is not meant for public // can break, but also this routine is not meant for public
// consumption and coding it here avoids breaking dependencies to the Xous API crate. // consumption and coding it here avoids breaking dependencies to the Xous API crate.
let page_buf = xous::PageBuf::new(); let page_buf = xous::PageBuf::new();
xous::rsyscall(xous::SysCall::PlatformSpecific(3, page_buf.as_ptr(), 0, 0, 0, 0, 0)) xous::rsyscall(xous::SysCall::PlatformSpecific(3, page_buf.as_ptr(), 0, 0, 0, 0, 0)).unwrap();
.unwrap();
log::info!("Interrupt handlers:"); log::info!("Interrupt handlers:");
for line in page_buf.as_str().lines() { for line in page_buf.as_str().lines() {
@ -248,9 +268,7 @@ impl<'a> ShellCmdApi<'a> for Test {
write!(ret, "{}", helpstring).unwrap(); write!(ret, "{}", helpstring).unwrap();
} }
} }
} else {
write!(ret, "{}", helpstring).unwrap();
}
Ok(Some(ret)) Ok(Some(ret))
} }
} }

View file

@ -169,6 +169,29 @@ impl Keystore {
#[inline(always)] #[inline(always)]
pub(crate) fn get_dec_backend(&self) -> KeystoreDec<'_> { KeystoreDec(self) } pub(crate) fn get_dec_backend(&self) -> KeystoreDec<'_> { KeystoreDec(self) }
/// Returns the previous bootwait state
pub fn bootwait(&self, enable: Option<bool>) -> Result<bool, xous::Error> {
match xous::send_message(
self.conn,
xous::Message::new_blocking_scalar(
Opcode::Bootwait.to_usize().unwrap(),
if enable.is_some() { 1 } else { 0 },
if enable.unwrap_or(false) { 1 } else { 0 },
0,
0,
),
)? {
xous::Result::Scalar5(_, last, _, _, _) => {
if last != 0 {
Ok(true)
} else {
Ok(false)
}
}
_ => unimplemented!(),
}
}
} }
use core::sync::atomic::{AtomicU32, Ordering}; use core::sync::atomic::{AtomicU32, Ordering};

View file

@ -44,6 +44,22 @@ pub fn keystore(sid: SID) -> ! {
// this will use the backup_mgr to store ephemeral secrets // this will use the backup_mgr to store ephemeral secrets
todo!() todo!()
} }
Opcode::Bootwait => {
if let Some(scalar) = msg.body.scalar_message_mut() {
let is_some = scalar.arg1 != 0;
let enable = scalar.arg2 != 0;
match store.set_bootwait(if is_some { Some(enable) } else { None }) {
Ok(last) => {
if last {
scalar.arg1 = 1;
} else {
scalar.arg1 = 0;
}
}
_ => panic!("Couldn't set bootwait"),
}
}
}
Opcode::InvalidCall => { Opcode::InvalidCall => {
log::error!("Invalid call in keystore: {:?}", opcode); log::error!("Invalid call in keystore: {:?}", opcode);
} }

View file

@ -1,7 +1,8 @@
use aes::Aes256; use aes::Aes256;
use aes::cipher::{BlockDecrypt, BlockEncrypt, KeyInit, generic_array::GenericArray}; use aes::cipher::{BlockDecrypt, BlockEncrypt, KeyInit, generic_array::GenericArray};
use bao1x_api::{ use bao1x_api::{
BOOT0_PUBKEY_FAIL, BoardTypeCoding, CP_ID, DEVELOPER_MODE, OEM_MODE, SLOT_ELEMENT_LEN_BYTES, UUID, BOOT0_PUBKEY_FAIL, BoardTypeCoding, BootWaitCoding, CP_ID, DEVELOPER_MODE, OEM_MODE,
SLOT_ELEMENT_LEN_BYTES, UUID,
}; };
use bao1x_hal::board::{BOOKEND_END, BOOKEND_START}; use bao1x_hal::board::{BOOKEND_END, BOOKEND_START};
use bao1x_hal::{ use bao1x_hal::{
@ -356,4 +357,19 @@ impl KeyStore {
}; };
Ok(()) Ok(())
} }
pub fn set_bootwait(&self, enable: Option<bool>) -> Result<bool, xous::Error> {
let previous = self.owc.get_decoded::<bao1x_api::BootWaitCoding>().expect("couldn't fetch flag");
if let Some(enable) = enable {
while self.owc.get_decoded::<bao1x_api::BootWaitCoding>().expect("couldn't fetch flag")
!= if enable { bao1x_api::BootWaitCoding::Enable } else { bao1x_api::BootWaitCoding::Disable }
{
self.owc.inc_coded::<bao1x_api::BootWaitCoding>().unwrap();
}
}
match previous {
BootWaitCoding::Enable => Ok(true),
BootWaitCoding::Disable => Ok(false),
}
}
} }

View file

@ -136,7 +136,7 @@ pub fn keystore(sid: SID) -> ! {
Opcode::EphemeralOp => { Opcode::EphemeralOp => {
todo!() todo!()
} }
Opcode::InvalidCall => { _ => {
log::error!("Invalid call in keystore: {:?}", opcode); log::error!("Invalid call in keystore: {:?}", opcode);
} }
} }