From dfc6444d78b6fbec142c5b37b4fad91f76b675b4 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 14 Sep 2021 20:15:03 +0800 Subject: [PATCH] add killkey test to the self test suite --- services/com/src/api.rs | 3 +++ services/com/src/lib.rs | 5 +++++ services/com/src/main.rs | 6 ++++++ services/llio/src/main.rs | 3 +++ services/rtc/src/main.rs | 1 + services/shellchat/src/cmds/ecup.rs | 3 +++ services/shellchat/src/cmds/test.rs | 12 +++++++++++- 7 files changed, 32 insertions(+), 1 deletion(-) diff --git a/services/com/src/api.rs b/services/com/src/api.rs index e83c4229e..1b41995d6 100644 --- a/services/com/src/api.rs +++ b/services/com/src/api.rs @@ -61,6 +61,9 @@ pub struct FlashRecord { #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] pub(crate) enum Opcode { + /// Reset the COM link - useful after an EC reset + LinkReset, + /// Refresh the TRNG seed for the EC ReseedTrng, diff --git a/services/com/src/lib.rs b/services/com/src/lib.rs index cbc3db964..4a22f7d83 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -78,6 +78,11 @@ impl Com { } } + pub fn link_reset(&self) -> Result<(), xous::Error> { + send_message(self.conn, + Message::new_blocking_scalar(Opcode::LinkReset.to_usize().unwrap(), 0, 0, 0, 0) + ).map(|_| ()) + } 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) diff --git a/services/com/src/main.rs b/services/com/src/main.rs index ea2e4b700..4c1f1299e 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -331,6 +331,7 @@ fn xmain() -> ! { const FLASH_LEN: u32 = 0x10_0000; const FLASH_TIMEOUT: u32 = 250; + let ticktimer = ticktimer_server::Ticktimer::new().unwrap(); // initial seed of the COM trng let trng = trng::Trng::new(&xns).expect("couldn't connect to TRNG"); com.txrx(ComState::TRNG_SEED.verb); @@ -358,6 +359,11 @@ fn xmain() -> ! { com.txrx(ComState::BL_START.verb | (bl_main as u16) & 0x1f | (((bl_sec as u16) & 0x1f) << 5)); } }), + Some(Opcode::LinkReset) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, { + com.txrx(ComState::LINK_SYNC.verb); + ticktimer.sleep_ms(200).unwrap(); // give some time for the link to reset - the EC does not have a guaranteed latency to respond to a link reset + xous::return_scalar(msg.sender, 1).unwrap(); + }), Some(Opcode::ReseedTrng) => xous::msg_scalar_unpack!(msg, _, _, _, _, { com.txrx(ComState::TRNG_SEED.verb); for _ in 0..2 { diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index a179d539d..483825627 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -247,6 +247,7 @@ mod implementation { // (these "should" be redundant) self.power_csr.rmwf(utra::power::POWER_SELF, 1); self.power_csr.rmwf(utra::power::POWER_STATE, 1); + self.power_csr.rmwf(utra::power::POWER_UP5K_ON, 1); self.event_susres.resume(); self.gpio_susres.resume(); @@ -400,6 +401,7 @@ mod implementation { } } pub fn ec_reset(&mut self) { + self.power_csr.rmwf(utra::power::POWER_UP5K_ON, 1); // make sure the power is "on" if we're resetting it self.power_csr.rmwf(utra::power::POWER_RESET_EC, 1); self.ticktimer.sleep_ms(20).unwrap(); self.power_csr.rmwf(utra::power::POWER_RESET_EC, 0); @@ -705,6 +707,7 @@ fn xmain() -> ! { // Create a new llio object let handler_conn = xous::connect(llio_sid).expect("can't create IRQ handler connection"); let mut llio = Llio::new(handler_conn, gpio_base); + llio.ec_power_on(); // ensure this is set correctly; if we're on, we always want the EC on. // register a suspend/resume listener let sr_cid = xous::connect(llio_sid).expect("couldn't create suspend callback connection"); diff --git a/services/rtc/src/main.rs b/services/rtc/src/main.rs index 5bcc3f9bc..d11ec467b 100644 --- a/services/rtc/src/main.rs +++ b/services/rtc/src/main.rs @@ -581,6 +581,7 @@ fn xmain() -> ! { // - GAM // - shellchat/rtc // - shellchat/sleep x2 + // - factory test // - UX thread (self, created without xns, so does not count) // - rootkeys (for coordinating reboot) let rtc_sid = xns.register_name(api::SERVER_NAME_RTC, Some(5)).expect("can't register server"); diff --git a/services/shellchat/src/cmds/ecup.rs b/services/shellchat/src/cmds/ecup.rs index e5f915d59..b835f65a2 100644 --- a/services/shellchat/src/cmds/ecup.rs +++ b/services/shellchat/src/cmds/ecup.rs @@ -357,6 +357,9 @@ impl<'a> ShellCmdApi<'a> for EcUpdate { } "reset" => { env.llio.ec_reset().unwrap(); + env.ticktimer.sleep_ms(4000).unwrap(); + env.com.link_reset().unwrap(); + env.com.reseed_ec_trng().unwrap(); write!(ret, "EC has been reset, and new firmware loaded.").unwrap(); } "wf200" => { diff --git a/services/shellchat/src/cmds/test.rs b/services/shellchat/src/cmds/test.rs index 1463175c5..01e5f436f 100644 --- a/services/shellchat/src/cmds/test.rs +++ b/services/shellchat/src/cmds/test.rs @@ -23,7 +23,7 @@ pub struct Test { right_play: bool, speaker_play: bool, freq: f32, - // rtc + //rtc: rtc::Rtc, start_time: Option, end_time: Option, start_elapsed: Option, @@ -55,6 +55,7 @@ impl Test { right_play: true, speaker_play: true, freq: 440.0, + //rtc: rtc::Rtc::new(&xns).unwrap(), start_time: None, end_time: None, start_elapsed: None, @@ -227,6 +228,8 @@ impl<'a> ShellCmdApi<'a> for Test { log::info!("{}|RTC|FAIL|NO_END|", SENTINEL); } + env.com.link_reset().unwrap(); + env.com.reseed_ec_trng().unwrap(); let ut_after = env.com.get_ec_uptime().unwrap(); if ut < ut_after || ut_after > 4200 { @@ -277,6 +280,13 @@ impl<'a> ShellCmdApi<'a> for Test { env.llio.boost_on(false).unwrap(); log::info!("{}|BOOSTOFF|", SENTINEL); } + "kill" => { + log::info!("{}|KILL|", SENTINEL); + env.ticktimer.sleep_ms(500).unwrap(); + env.llio.self_destruct(0x2718_2818).unwrap(); + env.llio.self_destruct(0x3141_5926).unwrap(); + env.ticktimer.sleep_ms(100).unwrap(); + } "astart" => { self.freq = if let Some(freq_str) = tokens.next() { match freq_str.parse::() {