mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
Merge pull request #782 from betrusted-io/bootwait
Add bootwait to test console
This commit is contained in:
commit
af5a28ebc0
9 changed files with 291 additions and 212 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -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",
|
||||||
|
|
|
||||||
BIN
bao1x-boot/blobs/pubkey-extra-ifr-0x240.bin
Normal file
BIN
bao1x-boot/blobs/pubkey-extra-ifr-0x240.bin
Normal file
Binary file not shown.
|
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 }
|
||||||
|
|
|
||||||
|
|
@ -15,242 +15,260 @@ 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" => {
|
||||||
"timer" => {
|
let keystore = keystore::Keystore::new(&_env.xns);
|
||||||
let start = _env.ticktimer.elapsed_ms();
|
if args.len() != 1 {
|
||||||
log::info!("Starting test");
|
write!(ret, "bootwait [check | enable | disable]").ok();
|
||||||
let mut seconds = 0;
|
return Ok(Some(ret));
|
||||||
loop {
|
}
|
||||||
let elapsed = _env.ticktimer.elapsed_ms() - start;
|
if args[0] == "check" {
|
||||||
if elapsed > seconds * 1000 {
|
write!(ret, "bootwait is {:?}", keystore.bootwait(None).unwrap()).ok();
|
||||||
log::info!("{} s", seconds);
|
} else if args[0] == "enable" {
|
||||||
seconds += 1;
|
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" => {
|
||||||
|
let start = _env.ticktimer.elapsed_ms();
|
||||||
|
log::info!("Starting test");
|
||||||
|
let mut seconds = 0;
|
||||||
|
loop {
|
||||||
|
let elapsed = _env.ticktimer.elapsed_ms() - start;
|
||||||
|
if elapsed > seconds * 1000 {
|
||||||
|
log::info!("{} s", seconds);
|
||||||
|
seconds += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"time" => {
|
}
|
||||||
use chrono::{Local, Utc};
|
"time" => {
|
||||||
let systime = std::time::SystemTime::now();
|
use chrono::{Local, Utc};
|
||||||
let epoch = systime.duration_since(std::time::SystemTime::UNIX_EPOCH).unwrap();
|
let systime = std::time::SystemTime::now();
|
||||||
log::info!("Seconds since epoch: {}", epoch.as_secs());
|
let epoch = systime.duration_since(std::time::SystemTime::UNIX_EPOCH).unwrap();
|
||||||
log::info!("Systime: {:?}", systime);
|
log::info!("Seconds since epoch: {}", epoch.as_secs());
|
||||||
let now = Utc::now();
|
log::info!("Systime: {:?}", systime);
|
||||||
log::info!("UTC now {}", now.format("%Y-%m-%d %H:%M:%S UTC"));
|
let now = Utc::now();
|
||||||
let local_now = Local::now();
|
log::info!("UTC now {}", now.format("%Y-%m-%d %H:%M:%S UTC"));
|
||||||
log::info!("Local time: {}", local_now.format("%Y-%m-%d %H:%M:%S %Z"));
|
let local_now = Local::now();
|
||||||
|
log::info!("Local time: {}", local_now.format("%Y-%m-%d %H:%M:%S %Z"));
|
||||||
|
|
||||||
log::info!("Waiting 3 seconds");
|
log::info!("Waiting 3 seconds");
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
|
||||||
let systime = std::time::SystemTime::now();
|
let systime = std::time::SystemTime::now();
|
||||||
let epoch = systime.duration_since(std::time::SystemTime::UNIX_EPOCH).unwrap();
|
let epoch = systime.duration_since(std::time::SystemTime::UNIX_EPOCH).unwrap();
|
||||||
log::info!("Seconds since epoch: {}", epoch.as_secs());
|
log::info!("Seconds since epoch: {}", epoch.as_secs());
|
||||||
log::info!("Systime: {:?}", systime);
|
log::info!("Systime: {:?}", systime);
|
||||||
let now = Utc::now();
|
let now = Utc::now();
|
||||||
log::info!("UTC now {}", now.format("%Y-%m-%d %H:%M:%S UTC"));
|
log::info!("UTC now {}", now.format("%Y-%m-%d %H:%M:%S UTC"));
|
||||||
let local_now = Local::now();
|
let local_now = Local::now();
|
||||||
log::info!("Local time: {}", local_now.format("%Y-%m-%d %H:%M:%S %Z"));
|
log::info!("Local time: {}", local_now.format("%Y-%m-%d %H:%M:%S %Z"));
|
||||||
}
|
}
|
||||||
#[cfg(feature = "bmp180")]
|
#[cfg(feature = "bmp180")]
|
||||||
"temp" => {
|
"temp" => {
|
||||||
use bao1x_hal::bmp180::Bmp180;
|
use bao1x_hal::bmp180::Bmp180;
|
||||||
use bao1x_hal::i2c::I2c;
|
use bao1x_hal::i2c::I2c;
|
||||||
let mut i2c = I2c::new();
|
let mut i2c = I2c::new();
|
||||||
|
|
||||||
match Bmp180::new(&mut i2c) {
|
match Bmp180::new(&mut i2c) {
|
||||||
Ok(sensor) => match sensor.read_temperature(&mut i2c) {
|
Ok(sensor) => match sensor.read_temperature(&mut i2c) {
|
||||||
Ok(temp) => {
|
Ok(temp) => {
|
||||||
write!(ret, "BMP180 Temperature: {:.1}°C", temp).unwrap();
|
write!(ret, "BMP180 Temperature: {:.1}°C", temp).unwrap();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
write!(ret, "Failed to read temperature: {:?}", e).unwrap();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
write!(ret, "Failed to initialize BMP180 sensor: {:?}", e).unwrap();
|
write!(ret, "Failed to read temperature: {:?}", e).unwrap();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
write!(ret, "Failed to initialize BMP180 sensor: {:?}", e).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
|
"shipmode" => {
|
||||||
|
use bao1x_hal::i2c::I2c;
|
||||||
|
let mut i2c = I2c::new();
|
||||||
|
|
||||||
|
let mut axp2101 = bao1x_hal::axp2101::Axp2101::new(&mut i2c).expect("couldn't get AXP2101");
|
||||||
|
log::info!("sending shipmode to axp2101 pmic...in four seconds");
|
||||||
|
let tt = ticktimer::Ticktimer::new().unwrap();
|
||||||
|
tt.sleep_ms(4000).ok();
|
||||||
|
// shut down BLDO1 - this should disconnect the battery
|
||||||
|
axp2101.set_ldo(&mut i2c, None, bao1x_hal::axp2101::WhichLdo::Bldo1).ok();
|
||||||
|
// shut down PMIC
|
||||||
|
axp2101.powerdown(&mut i2c).ok();
|
||||||
|
log::info!("sent shutdown to axp2101");
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
|
"deepsleep" => {
|
||||||
|
let gfx = ux_api::service::gfx::Gfx::new(&_env.xns).unwrap();
|
||||||
|
log::info!("turn off display");
|
||||||
|
gfx.set_power(false).unwrap();
|
||||||
|
log::info!("display off");
|
||||||
|
use num_traits::*;
|
||||||
|
// monkey patch over the standard xous IP
|
||||||
|
let conn = _env
|
||||||
|
.xns
|
||||||
|
.request_connection_blocking(susres::api::SERVER_NAME_SUSRES)
|
||||||
|
.expect("Can't connect to SUSRES");
|
||||||
|
match xous::send_message(
|
||||||
|
conn,
|
||||||
|
xous::Message::new_blocking_scalar(
|
||||||
|
susres::api::Opcode::SuspendRequest.to_usize().unwrap(),
|
||||||
|
1, // this is a monkeypatch
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Ok(xous::Result::Scalar1(result)) => {
|
||||||
|
if result == 1 {
|
||||||
|
log::info!("Should be in deep sleep!");
|
||||||
|
} else {
|
||||||
|
log::error!("Couldn't initiate deep sleep")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => panic!("Couldn't send deep sleep message to susres"),
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "hosted-baosec"))]
|
}
|
||||||
"shipmode" => {
|
"seed" => {
|
||||||
use bao1x_hal::i2c::I2c;
|
let (_, value) = std::env::vars().find(|(key, _value)| key == "SEED").unwrap();
|
||||||
let mut i2c = I2c::new();
|
log::info!("Seed: {:?}", value);
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
|
"wfi" => {
|
||||||
|
let gfx = ux_api::service::gfx::Gfx::new(&_env.xns).unwrap();
|
||||||
|
log::info!("turn off display");
|
||||||
|
gfx.set_power(false).unwrap();
|
||||||
|
log::info!("display off");
|
||||||
|
let susres = susres::Susres::new_without_hook(&_env.xns).unwrap();
|
||||||
|
log::info!("initiating wfi from test shell...");
|
||||||
|
susres.initiate_suspend().unwrap();
|
||||||
|
log::info!("waiting after WFI return (system will be in WFI)");
|
||||||
|
_env.ticktimer.sleep_ms(100).ok();
|
||||||
|
log::info!("turn on display");
|
||||||
|
gfx.set_power(true).unwrap();
|
||||||
|
}
|
||||||
|
"proc" => {
|
||||||
|
// hard coded - debug feature - if the platform ABI changes its name or opcode map this
|
||||||
|
// can break, but also this routine is not meant for public
|
||||||
|
// consumption and coding it here avoids breaking dependencies to the Xous API crate.
|
||||||
|
let page_buf = xous::PageBuf::new();
|
||||||
|
xous::rsyscall(xous::SysCall::PlatformSpecific(2, page_buf.as_ptr(), 0, 0, 0, 0, 0)).unwrap();
|
||||||
|
|
||||||
let mut axp2101 =
|
log::info!("Process listing:");
|
||||||
bao1x_hal::axp2101::Axp2101::new(&mut i2c).expect("couldn't get AXP2101");
|
for line in page_buf.as_str().lines() {
|
||||||
log::info!("sending shipmode to axp2101 pmic...in four seconds");
|
log::info!("{}", line);
|
||||||
let tt = ticktimer::Ticktimer::new().unwrap();
|
|
||||||
tt.sleep_ms(4000).ok();
|
|
||||||
// shut down BLDO1 - this should disconnect the battery
|
|
||||||
axp2101.set_ldo(&mut i2c, None, bao1x_hal::axp2101::WhichLdo::Bldo1).ok();
|
|
||||||
// shut down PMIC
|
|
||||||
axp2101.powerdown(&mut i2c).ok();
|
|
||||||
log::info!("sent shutdown to axp2101");
|
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "hosted-baosec"))]
|
}
|
||||||
"deepsleep" => {
|
"freemem" => {
|
||||||
let gfx = ux_api::service::gfx::Gfx::new(&_env.xns).unwrap();
|
// hard coded - debug feature - if the platform ABI changes its name or opcode map this
|
||||||
log::info!("turn off display");
|
// can break, but also this routine is not meant for public
|
||||||
gfx.set_power(false).unwrap();
|
// consumption and coding it here avoids breaking dependencies to the Xous API crate.
|
||||||
log::info!("display off");
|
let page_buf = xous::PageBuf::new();
|
||||||
use num_traits::*;
|
xous::rsyscall(xous::SysCall::PlatformSpecific(1, page_buf.as_ptr(), 0, 0, 0, 0, 0)).unwrap();
|
||||||
// monkey patch over the standard xous IP
|
|
||||||
let conn = _env
|
log::info!("RAM usage:");
|
||||||
.xns
|
for line in page_buf.as_str().lines() {
|
||||||
.request_connection_blocking(susres::api::SERVER_NAME_SUSRES)
|
log::info!("{}", line);
|
||||||
.expect("Can't connect to SUSRES");
|
}
|
||||||
match xous::send_message(
|
}
|
||||||
conn,
|
"interrupts" => {
|
||||||
xous::Message::new_blocking_scalar(
|
// hard coded - debug feature - if the platform ABI changes its name or opcode map this
|
||||||
susres::api::Opcode::SuspendRequest.to_usize().unwrap(),
|
// can break, but also this routine is not meant for public
|
||||||
1, // this is a monkeypatch
|
// consumption and coding it here avoids breaking dependencies to the Xous API crate.
|
||||||
0,
|
let page_buf = xous::PageBuf::new();
|
||||||
0,
|
xous::rsyscall(xous::SysCall::PlatformSpecific(3, page_buf.as_ptr(), 0, 0, 0, 0, 0)).unwrap();
|
||||||
0,
|
|
||||||
),
|
log::info!("Interrupt handlers:");
|
||||||
) {
|
for line in page_buf.as_str().lines() {
|
||||||
Ok(xous::Result::Scalar1(result)) => {
|
log::info!("{}", line);
|
||||||
if result == 1 {
|
}
|
||||||
log::info!("Should be in deep sleep!");
|
}
|
||||||
} else {
|
#[cfg(feature = "board-baosec")]
|
||||||
log::error!("Couldn't initiate deep sleep")
|
"qrshow" => {
|
||||||
}
|
// note that 40 bytes gives 320 bits which fits nicely into a version 3 code,
|
||||||
|
// which allows 4 pixels per module rendering.
|
||||||
|
// if we have to move to 3 pixels per module, the next code up that optimally
|
||||||
|
// uses the full screen is version 6. This would give 102 bytes of transfer
|
||||||
|
// in a single scan.
|
||||||
|
//
|
||||||
|
// The equation for capacity is:
|
||||||
|
// `binary_bytes = floor((alphanumeric_capacity / 3) × 2)`
|
||||||
|
//
|
||||||
|
// where `alphameric_capacity` is the capacity of the QR code version
|
||||||
|
// per spec lookup table.
|
||||||
|
let modals = modals::Modals::new(&_env.xns).unwrap();
|
||||||
|
let mut test_data = [0u8; 40];
|
||||||
|
for (i, d) in test_data.iter_mut().enumerate() {
|
||||||
|
*d = i as u8;
|
||||||
|
}
|
||||||
|
let encoded = base45::encode(&test_data);
|
||||||
|
modals.show_notification("", Some(&encoded)).ok();
|
||||||
|
}
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
"qrget" => {
|
||||||
|
let gfx = ux_api::service::gfx::Gfx::new(&_env.xns).unwrap();
|
||||||
|
match gfx.acquire_qr() {
|
||||||
|
Ok(qr_data) => {
|
||||||
|
if let Some(meta) = qr_data.meta {
|
||||||
|
log::info!("QR code metadata: {}", meta);
|
||||||
}
|
}
|
||||||
_ => panic!("Couldn't send deep sleep message to susres"),
|
if let Some(coded) = qr_data.content {
|
||||||
}
|
match base45::decode(&coded) {
|
||||||
}
|
Ok(data) => {
|
||||||
"seed" => {
|
log::info!("Recovered: {:x?}", data);
|
||||||
let (_, value) = std::env::vars().find(|(key, _value)| key == "SEED").unwrap();
|
}
|
||||||
log::info!("Seed: {:?}", value);
|
Err(e) => {
|
||||||
}
|
log::info!("Base45 decode err: {:?}", e);
|
||||||
#[cfg(not(feature = "hosted-baosec"))]
|
|
||||||
"wfi" => {
|
|
||||||
let gfx = ux_api::service::gfx::Gfx::new(&_env.xns).unwrap();
|
|
||||||
log::info!("turn off display");
|
|
||||||
gfx.set_power(false).unwrap();
|
|
||||||
log::info!("display off");
|
|
||||||
let susres = susres::Susres::new_without_hook(&_env.xns).unwrap();
|
|
||||||
log::info!("initiating wfi from test shell...");
|
|
||||||
susres.initiate_suspend().unwrap();
|
|
||||||
log::info!("waiting after WFI return (system will be in WFI)");
|
|
||||||
_env.ticktimer.sleep_ms(100).ok();
|
|
||||||
log::info!("turn on display");
|
|
||||||
gfx.set_power(true).unwrap();
|
|
||||||
}
|
|
||||||
"proc" => {
|
|
||||||
// hard coded - debug feature - if the platform ABI changes its name or opcode map this
|
|
||||||
// can break, but also this routine is not meant for public
|
|
||||||
// consumption and coding it here avoids breaking dependencies to the Xous API crate.
|
|
||||||
let page_buf = xous::PageBuf::new();
|
|
||||||
xous::rsyscall(xous::SysCall::PlatformSpecific(2, page_buf.as_ptr(), 0, 0, 0, 0, 0))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
log::info!("Process listing:");
|
|
||||||
for line in page_buf.as_str().lines() {
|
|
||||||
log::info!("{}", line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"freemem" => {
|
|
||||||
// hard coded - debug feature - if the platform ABI changes its name or opcode map this
|
|
||||||
// can break, but also this routine is not meant for public
|
|
||||||
// consumption and coding it here avoids breaking dependencies to the Xous API crate.
|
|
||||||
let page_buf = xous::PageBuf::new();
|
|
||||||
xous::rsyscall(xous::SysCall::PlatformSpecific(1, page_buf.as_ptr(), 0, 0, 0, 0, 0))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
log::info!("RAM usage:");
|
|
||||||
for line in page_buf.as_str().lines() {
|
|
||||||
log::info!("{}", line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"interrupts" => {
|
|
||||||
// hard coded - debug feature - if the platform ABI changes its name or opcode map this
|
|
||||||
// can break, but also this routine is not meant for public
|
|
||||||
// consumption and coding it here avoids breaking dependencies to the Xous API crate.
|
|
||||||
let page_buf = xous::PageBuf::new();
|
|
||||||
xous::rsyscall(xous::SysCall::PlatformSpecific(3, page_buf.as_ptr(), 0, 0, 0, 0, 0))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
log::info!("Interrupt handlers:");
|
|
||||||
for line in page_buf.as_str().lines() {
|
|
||||||
log::info!("{}", line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(feature = "board-baosec")]
|
|
||||||
"qrshow" => {
|
|
||||||
// note that 40 bytes gives 320 bits which fits nicely into a version 3 code,
|
|
||||||
// which allows 4 pixels per module rendering.
|
|
||||||
// if we have to move to 3 pixels per module, the next code up that optimally
|
|
||||||
// uses the full screen is version 6. This would give 102 bytes of transfer
|
|
||||||
// in a single scan.
|
|
||||||
//
|
|
||||||
// The equation for capacity is:
|
|
||||||
// `binary_bytes = floor((alphanumeric_capacity / 3) × 2)`
|
|
||||||
//
|
|
||||||
// where `alphameric_capacity` is the capacity of the QR code version
|
|
||||||
// per spec lookup table.
|
|
||||||
let modals = modals::Modals::new(&_env.xns).unwrap();
|
|
||||||
let mut test_data = [0u8; 40];
|
|
||||||
for (i, d) in test_data.iter_mut().enumerate() {
|
|
||||||
*d = i as u8;
|
|
||||||
}
|
|
||||||
let encoded = base45::encode(&test_data);
|
|
||||||
modals.show_notification("", Some(&encoded)).ok();
|
|
||||||
}
|
|
||||||
#[cfg(feature = "board-baosec")]
|
|
||||||
"qrget" => {
|
|
||||||
let gfx = ux_api::service::gfx::Gfx::new(&_env.xns).unwrap();
|
|
||||||
match gfx.acquire_qr() {
|
|
||||||
Ok(qr_data) => {
|
|
||||||
if let Some(meta) = qr_data.meta {
|
|
||||||
log::info!("QR code metadata: {}", meta);
|
|
||||||
}
|
|
||||||
if let Some(coded) = qr_data.content {
|
|
||||||
match base45::decode(&coded) {
|
|
||||||
Ok(data) => {
|
|
||||||
log::info!("Recovered: {:x?}", data);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
log::info!("Base45 decode err: {:?}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
log::info!("QR error: {:?}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
Err(e) => {
|
||||||
/* // leave this around in case we have more swap bugs to debug
|
log::info!("QR error: {:?}", e);
|
||||||
// needs to have `swaptest1`` & `swaptest2` added to the image for this to work.
|
|
||||||
"swap" => {
|
|
||||||
log::info!("starting swap test");
|
|
||||||
let swaptest1 = _env.xns.request_connection("swaptest1").unwrap();
|
|
||||||
let swaptest2 = _env.xns.request_connection("swaptest2").unwrap();
|
|
||||||
for i in 1..4 {
|
|
||||||
log::info!("iter {}", i);
|
|
||||||
xous::send_message(swaptest1, xous::Message::new_scalar(0, i, 0, 0, 0)).unwrap();
|
|
||||||
xous::send_message(swaptest2, xous::Message::new_scalar(0, i + 1, 0, 0, 0)).unwrap();
|
|
||||||
}
|
}
|
||||||
log::info!("swaptest done");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
_ => {
|
|
||||||
write!(ret, "{}", helpstring).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
/* // leave this around in case we have more swap bugs to debug
|
||||||
write!(ret, "{}", helpstring).unwrap();
|
// needs to have `swaptest1`` & `swaptest2` added to the image for this to work.
|
||||||
|
"swap" => {
|
||||||
|
log::info!("starting swap test");
|
||||||
|
let swaptest1 = _env.xns.request_connection("swaptest1").unwrap();
|
||||||
|
let swaptest2 = _env.xns.request_connection("swaptest2").unwrap();
|
||||||
|
for i in 1..4 {
|
||||||
|
log::info!("iter {}", i);
|
||||||
|
xous::send_message(swaptest1, xous::Message::new_scalar(0, i, 0, 0, 0)).unwrap();
|
||||||
|
xous::send_message(swaptest2, xous::Message::new_scalar(0, i + 1, 0, 0, 0)).unwrap();
|
||||||
|
}
|
||||||
|
log::info!("swaptest done");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
_ => {
|
||||||
|
write!(ret, "{}", helpstring).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(ret))
|
Ok(Some(ret))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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};
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue