mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
move test commands for USB status checkup from keys to USB
This commit is contained in:
parent
c7f9688b5f
commit
66e4d9f803
2 changed files with 53 additions and 23 deletions
|
|
@ -61,7 +61,7 @@ impl Keys {
|
||||||
impl<'a> ShellCmdApi<'a> for Keys {
|
impl<'a> ShellCmdApi<'a> for Keys {
|
||||||
cmd_api!(keys); // inserts boilerplate for command API
|
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;
|
use core::fmt::Write;
|
||||||
let mut ret = String::<1024>::new();
|
let mut ret = String::<1024>::new();
|
||||||
let helpstring = "keys [usblock] [usbunlock] [pddbrecycle]";
|
let helpstring = "keys [usblock] [usbunlock] [pddbrecycle]";
|
||||||
|
|
@ -106,14 +106,6 @@ impl<'a> ShellCmdApi<'a> for Keys {
|
||||||
write!(ret, "aes test failed").unwrap();
|
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" => {
|
"pddbrecycle" => {
|
||||||
// erase the page table, which should effectively trigger a reformat on the next boot
|
// 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");
|
self.spinor.bulk_erase(xous::PDDB_LOC, 1024 * 1024).expect("couldn't erase page table");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{ShellCmdApi, CommonEnv};
|
use crate::{ShellCmdApi, CommonEnv};
|
||||||
use usb_device_xous::{UsbHid, UsbDeviceState};
|
use usb_device_xous::{UsbHid, UsbDeviceState, UsbDeviceType};
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[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> {
|
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 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(' ');
|
let mut tokens = args.as_str().unwrap().split(' ');
|
||||||
|
|
||||||
if let Some(sub_cmd) = tokens.next() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
match sub_cmd {
|
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" => {
|
"send" => {
|
||||||
let mut val = String::new();
|
match self.usb_dev.get_current_core() {
|
||||||
join_tokens(&mut val, &mut tokens);
|
Ok(UsbDeviceType::Hid) => {
|
||||||
match self.usb_dev.send_str(&val) {
|
let mut val = String::new();
|
||||||
Ok(n) => write!(ret, "Sent {} chars", n).unwrap(),
|
join_tokens(&mut val, &mut tokens);
|
||||||
Err(_e) => write!(ret, "Can't send: are we connected to a host?").unwrap(),
|
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" => {
|
"status" => {
|
||||||
match self.usb_dev.status() {
|
match self.usb_dev.get_current_core() {
|
||||||
UsbDeviceState::Configured => write!(ret, "USB connected to host").unwrap(),
|
Ok(UsbDeviceType::Debug) => write!(ret, "Debug core connected").unwrap(),
|
||||||
UsbDeviceState::Suspend => write!(ret, "Host put us in suspend").unwrap(),
|
Ok(UsbDeviceType::Hid) => {
|
||||||
_ => write!(ret, "Not connected to USB host").unwrap(),
|
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" => {
|
"leds" => {
|
||||||
match self.usb_dev.get_led_state() {
|
match self.usb_dev.get_current_core() {
|
||||||
Ok(leds) => write!(ret, "LEDs: {:?}", leds).unwrap(),
|
Ok(UsbDeviceType::Hid) => {
|
||||||
_ => write!(ret, "Not connected to USB host or other error").unwrap(),
|
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();
|
write!(ret, "{}", helpstring).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue