move test commands for USB status checkup from keys to USB

This commit is contained in:
bunnie 2022-05-17 02:25:59 +08:00
parent c7f9688b5f
commit 66e4d9f803
2 changed files with 53 additions and 23 deletions

View file

@ -61,7 +61,7 @@ impl Keys {
impl<'a> ShellCmdApi<'a> for Keys {
cmd_api!(keys); // inserts boilerplate for command API
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
fn process(&mut self, args: String::<1024>, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
use core::fmt::Write;
let mut ret = String::<1024>::new();
let helpstring = "keys [usblock] [usbunlock] [pddbrecycle]";
@ -106,14 +106,6 @@ impl<'a> ShellCmdApi<'a> for Keys {
write!(ret, "aes test failed").unwrap();
}
}
"usblock" => {
env.llio.debug_usb(Some(true)).unwrap();
write!(ret, "USB debug port locked out; one word at 0x80000000 is disclosable via USB.").unwrap();
}
"usbunlock" => {
env.llio.debug_usb(Some(false)).unwrap();
write!(ret, "USB debug port unlocked: all secrets are readable via USB!").unwrap();
}
"pddbrecycle" => {
// erase the page table, which should effectively trigger a reformat on the next boot
self.spinor.bulk_erase(xous::PDDB_LOC, 1024 * 1024).expect("couldn't erase page table");

View file

@ -1,5 +1,5 @@
use crate::{ShellCmdApi, CommonEnv};
use usb_device_xous::{UsbHid, UsbDeviceState};
use usb_device_xous::{UsbHid, UsbDeviceState, UsbDeviceType};
use std::fmt::Write;
#[derive(Debug)]
@ -20,33 +20,71 @@ impl<'a> ShellCmdApi<'a> for Usb {
fn process(&mut self, args: xous_ipc::String::<1024>, _env: &mut CommonEnv) -> Result<Option<xous_ipc::String::<1024>>, xous::Error> {
let mut ret = xous_ipc::String::<1024>::new();
let helpstring = "usb [send <string>] [status] [leds]";
let helpstring = "usb [hid] [debug] [send <string>] [status] [leds] [lock] [unlock]";
let mut tokens = args.as_str().unwrap().split(' ');
if let Some(sub_cmd) = tokens.next() {
match sub_cmd {
"hid" => {
self.usb_dev.switch_to_core(usb_device_xous::UsbDeviceType::Hid).unwrap();
write!(ret, "USB connected to HID core").unwrap();
}
"debug" => {
self.usb_dev.switch_to_core(usb_device_xous::UsbDeviceType::Debug).unwrap();
write!(ret, "USB connected to Debug core").unwrap();
}
"send" => {
let mut val = String::new();
join_tokens(&mut val, &mut tokens);
match self.usb_dev.send_str(&val) {
Ok(n) => write!(ret, "Sent {} chars", n).unwrap(),
Err(_e) => write!(ret, "Can't send: are we connected to a host?").unwrap(),
match self.usb_dev.get_current_core() {
Ok(UsbDeviceType::Hid) => {
let mut val = String::new();
join_tokens(&mut val, &mut tokens);
match self.usb_dev.send_str(&val) {
Ok(n) => write!(ret, "Sent {} chars", n).unwrap(),
Err(_e) => write!(ret, "Can't send: are we connected to a host?").unwrap(),
}
}
Ok(UsbDeviceType::Debug) => {
write!(ret, "HID core not connected: please issue 'usb hid' first").unwrap();
}
_ => write!(ret, "Invalid response checking status").unwrap(),
}
}
"status" => {
match self.usb_dev.status() {
UsbDeviceState::Configured => write!(ret, "USB connected to host").unwrap(),
UsbDeviceState::Suspend => write!(ret, "Host put us in suspend").unwrap(),
_ => write!(ret, "Not connected to USB host").unwrap(),
match self.usb_dev.get_current_core() {
Ok(UsbDeviceType::Debug) => write!(ret, "Debug core connected").unwrap(),
Ok(UsbDeviceType::Hid) => {
match self.usb_dev.status() {
UsbDeviceState::Configured => write!(ret, "HID core connected to host").unwrap(),
UsbDeviceState::Suspend => write!(ret, "HID in suspend").unwrap(),
_ => write!(ret, "HID not connected to USB host").unwrap(),
}
}
_ => write!(ret, "Invalid response checking status").unwrap(),
}
}
"leds" => {
match self.usb_dev.get_led_state() {
Ok(leds) => write!(ret, "LEDs: {:?}", leds).unwrap(),
_ => write!(ret, "Not connected to USB host or other error").unwrap(),
match self.usb_dev.get_current_core() {
Ok(UsbDeviceType::Hid) => {
match self.usb_dev.get_led_state() {
Ok(leds) => write!(ret, "LEDs: {:?}", leds).unwrap(),
_ => write!(ret, "Not connected to USB host or other error").unwrap(),
}
}
Ok(UsbDeviceType::Debug) => {
write!(ret, "HID core not connected: please issue 'usb hid' first").unwrap();
}
_ => write!(ret, "Invalid response checking status").unwrap(),
}
}
"lock" => {
self.usb_dev.restrict_debug_access(true).unwrap();
write!(ret, "USB debug port locked out; one word at 0x80000000 is disclosable via USB.").unwrap();
}
"unlock" => {
self.usb_dev.restrict_debug_access(false).unwrap();
write!(ret, "USB debug port unlocked: all secrets are readable via USB!").unwrap();
}
_ => {
write!(ret, "{}", helpstring).unwrap();
}