mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
add com trng seed, uptime on EC; EC reset test commands
This commit is contained in:
parent
d0a83b6865
commit
3f1ba5e279
7 changed files with 88 additions and 4 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
|
@ -418,6 +418,7 @@ dependencies = [
|
|||
"rkyv 0.4.3",
|
||||
"susres",
|
||||
"ticktimer-server",
|
||||
"trng",
|
||||
"typenum",
|
||||
"utralib",
|
||||
"xous",
|
||||
|
|
@ -428,7 +429,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "com_rs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/betrusted-io/com_rs.git?rev=ebbe15a5285cc4b9de7edf279949f034e82709dd#ebbe15a5285cc4b9de7edf279949f034e82709dd"
|
||||
source = "git+https://github.com/betrusted-io/com_rs.git?rev=5338f9959572d57f1014d04aa129804da5b4d339#5338f9959572d57f1014d04aa129804da5b4d339"
|
||||
|
||||
[[package]]
|
||||
name = "com_rs-ref"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ edition = "2018"
|
|||
description = "com_rs import package"
|
||||
|
||||
[dependencies]
|
||||
com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "ebbe15a5285cc4b9de7edf279949f034e82709dd" }
|
||||
com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "5338f9959572d57f1014d04aa129804da5b4d339" }
|
||||
#com_rs = { path = "../../../betrusted-ec/sw/com_rs" }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ typenum = "1.12"
|
|||
xous = {path = "../../xous-rs"}
|
||||
xous-ipc = {path = "../../xous-ipc"}
|
||||
xous-names = {path = "../xous-names"}
|
||||
trng = {path = "../trng"}
|
||||
|
||||
num-derive = {version = "0.3", default-features = false}
|
||||
num-traits = {version = "0.2", default-features = false}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,12 @@ pub struct FlashRecord {
|
|||
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub(crate) enum Opcode {
|
||||
/// Refresh the TRNG seed for the EC
|
||||
ReseedTrng,
|
||||
|
||||
/// Fetch the uptime of the EC
|
||||
GetUptime,
|
||||
|
||||
/// Battery stats
|
||||
BattStats,
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,22 @@ impl Com {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn reseed_ec_trng(&self) -> Result<(), xous::Error> {
|
||||
send_message(self.conn,
|
||||
Message::new_scalar(Opcode::ReseedTrng.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).map(|_| ())
|
||||
}
|
||||
pub fn get_ec_uptime(&self) -> Result<u64, xous::Error> {
|
||||
let response = send_message(self.conn,
|
||||
Message::new_blocking_scalar(Opcode::GetUptime.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
)?;
|
||||
if let xous::Result::Scalar2(lsb, msb) = response {
|
||||
Ok( lsb as u64 | (msb as u64) << 32)
|
||||
} else {
|
||||
Err(xous::Error::InternalError)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_wf200_fw_rev(&self) -> Result<(u8, u8, u8), xous::Error> {
|
||||
let response = send_message(self.conn,
|
||||
Message::new_blocking_scalar(Opcode::Wf200Rev.to_usize().unwrap(), 0, 0, 0, 0))?;
|
||||
|
|
|
|||
|
|
@ -331,6 +331,17 @@ fn xmain() -> ! {
|
|||
const FLASH_LEN: u32 = 0x10_0000;
|
||||
const FLASH_TIMEOUT: u32 = 250;
|
||||
|
||||
// initial seed of the COM trng
|
||||
let trng = trng::Trng::new(&xns).expect("couldn't connect to TRNG");
|
||||
com.txrx(ComState::TRNG_SEED.verb);
|
||||
for _ in 0..2 {
|
||||
let mut rng = trng.get_u64().expect("couldn't fetch rngs");
|
||||
for _ in 0..4 {
|
||||
com.txrx(rng as u16);
|
||||
rng >>= 16;
|
||||
}
|
||||
}
|
||||
|
||||
trace!("starting main loop");
|
||||
loop {
|
||||
let mut msg = xous::receive_message(com_sid).unwrap();
|
||||
|
|
@ -347,6 +358,25 @@ fn xmain() -> ! {
|
|||
com.txrx(ComState::BL_START.verb | (bl_main as u16) & 0x1f | (((bl_sec as u16) & 0x1f) << 5));
|
||||
}
|
||||
}),
|
||||
Some(Opcode::ReseedTrng) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
|
||||
com.txrx(ComState::TRNG_SEED.verb);
|
||||
for _ in 0..2 {
|
||||
let mut rng = trng.get_u64().expect("couldn't fetch rngs");
|
||||
for _ in 0..4 {
|
||||
com.txrx(rng as u16);
|
||||
rng >>= 16;
|
||||
}
|
||||
}
|
||||
}),
|
||||
Some(Opcode::GetUptime) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
let mut uptime: u64 = 0;
|
||||
com.txrx(ComState::UPTIME.verb);
|
||||
for _ in 0..4 {
|
||||
uptime >>= 16;
|
||||
uptime |= (com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u64) << 48;
|
||||
}
|
||||
xous::return_scalar2(msg.sender, uptime as usize, (uptime >> 32) as usize).expect("couldn't return uptime");
|
||||
}),
|
||||
Some(Opcode::FlashAcquire) => msg_blocking_scalar_unpack!(msg, id0, id1, id2, id3, {
|
||||
let acquired = if flash_id.is_none() {
|
||||
flash_id = Some([id0 as u32, id1 as u32, id2 as u32, id3 as u32]);
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ impl<'a> ShellCmdApi<'a> for Test {
|
|||
|
||||
self.state += 1;
|
||||
let mut ret = String::<1024>::new();
|
||||
write!(ret, "Test has run {} times.\n", self.state).unwrap();
|
||||
write!(ret, "Test has run {} times.", self.state).unwrap();
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
|
||||
|
|
@ -189,7 +189,10 @@ impl<'a> ShellCmdApi<'a> for Test {
|
|||
);
|
||||
}
|
||||
|
||||
env.ticktimer.sleep_ms(3000).unwrap(); // wait so we have some realistic delta on the datetime function
|
||||
let ut = env.com.get_ec_uptime().unwrap();
|
||||
env.llio.ec_reset().unwrap();
|
||||
|
||||
env.ticktimer.sleep_ms(4000).unwrap(); // wait so we have some realistic delta on the datetime function
|
||||
self.end_elapsed = Some(env.ticktimer.elapsed_ms());
|
||||
self.end_time = rtc_get(&mut env.llio);
|
||||
|
||||
|
|
@ -224,6 +227,14 @@ impl<'a> ShellCmdApi<'a> for Test {
|
|||
log::info!("{}|RTC|FAIL|NO_END|", SENTINEL);
|
||||
}
|
||||
|
||||
let ut_after = env.com.get_ec_uptime().unwrap();
|
||||
|
||||
if ut < ut_after || ut_after > 4200 {
|
||||
log::info!("{}|ECRESET|FAIL|{}|{}|", SENTINEL, ut, ut_after);
|
||||
} else {
|
||||
log::info!("{}|ECRESET|PASS|{}|{}|", SENTINEL, ut, ut_after);
|
||||
}
|
||||
|
||||
log::info!("{}|DONE|", SENTINEL);
|
||||
write!(ret, "Factory test script has run, check serial terminal for output").unwrap();
|
||||
env.llio.wfi_override(false).unwrap();
|
||||
|
|
@ -247,6 +258,25 @@ impl<'a> ShellCmdApi<'a> for Test {
|
|||
env.llio.wfi_override(false).unwrap();
|
||||
log::info!("{}|WFIRESET|", SENTINEL);
|
||||
}
|
||||
"wfioff" => {
|
||||
env.llio.wfi_override(true).unwrap();
|
||||
log::info!("{}|WFIOFF|", SENTINEL);
|
||||
}
|
||||
"vibe" => {
|
||||
env.llio.vibe(llio::VibePattern::Long).unwrap();
|
||||
log::info!("{}|VIBE|", SENTINEL);
|
||||
}
|
||||
"booston" => {
|
||||
env.llio.boost_on(true).unwrap();
|
||||
env.com.set_boost(true).unwrap();
|
||||
log::info!("{}|BOOSTON|", SENTINEL);
|
||||
}
|
||||
"boostoff" => {
|
||||
env.com.set_boost(false).unwrap();
|
||||
env.ticktimer.sleep_ms(50).unwrap();
|
||||
env.llio.boost_on(false).unwrap();
|
||||
log::info!("{}|BOOSTOFF|", SENTINEL);
|
||||
}
|
||||
"astart" => {
|
||||
self.freq = if let Some(freq_str) = tokens.next() {
|
||||
match freq_str.parse::<f32>() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue