mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
test case now failing, now we can solve the problem faster
This commit is contained in:
parent
0234b4b22d
commit
0ccd487f5a
6 changed files with 136 additions and 103 deletions
|
|
@ -1268,7 +1268,7 @@ impl<'a> Modal<'a> {
|
|||
xous::create_thread_3(crate::forwarding_thread, addr, size, offset).expect("couldn't spawn a helper thread");
|
||||
}
|
||||
|
||||
pub fn redraw(&mut self) {
|
||||
pub fn redraw(&self) {
|
||||
log::debug!("modal redraw");
|
||||
let canvas_size = self.gam.get_canvas_bounds(self.canvas).unwrap();
|
||||
let do_redraw = self.top_dirty || self.bot_dirty;
|
||||
|
|
@ -1404,6 +1404,8 @@ impl<'a> Modal<'a> {
|
|||
};
|
||||
|
||||
let style = if let Some(style) = update_style {
|
||||
self.top_dirty = true;
|
||||
self.bot_dirty = true;
|
||||
style
|
||||
} else {
|
||||
self.style
|
||||
|
|
@ -1460,7 +1462,6 @@ impl<'a, 'b> ProgressBar<'a, 'b> {
|
|||
Some(crate::ActionType::Slider(*self.slider)),
|
||||
None, false, None, false, None);
|
||||
self.modal.redraw(); // stage the modal box pixels to the back buffer
|
||||
self.modal.gam.redraw().expect("couldn't cause back buffer to be sent to the screen");
|
||||
xous::yield_slice(); // this gives time for the GAM to do the sending
|
||||
self.current_progress_percent = new_percent;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -485,15 +485,15 @@ mod implementation {
|
|||
// a stub to try to avoid breaking hosted mode for as long as possible.
|
||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||
mod implementation {
|
||||
pub struct JtagMach {
|
||||
pub struct JtagPhy {
|
||||
}
|
||||
|
||||
impl JtagMach {
|
||||
pub fn new() -> JtagMach {
|
||||
JtagMach {
|
||||
impl JtagPhy {
|
||||
pub fn new() -> JtagPhy {
|
||||
JtagPhy {
|
||||
}
|
||||
}
|
||||
fn sync(&mut self, tdi: bool, tms: bool) -> bool {
|
||||
pub fn sync(&mut self, tdi: bool, tms: bool) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,9 +75,9 @@
|
|||
"en-audio": "Unplug the charging cable so I can reboot!"
|
||||
},
|
||||
"rootkeys.init.finished": {
|
||||
"en": "Reboot in 5 seconds...\n\n\n",
|
||||
"en": "Rebooting now...\n\n\n",
|
||||
"zh": "准备重启...\n\n",
|
||||
"en-audio": "Reboot in 5 seconds."
|
||||
"en-audio": "Rebooting now."
|
||||
},
|
||||
"rootkeys.init.fail_verify": {
|
||||
"en": "Verification failed,\naborting!",
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ pub(crate) enum Opcode {
|
|||
UxGetPolicy,
|
||||
UxPolicyReturn,
|
||||
UxTryReboot,
|
||||
UxDoReboot,
|
||||
/// provision a gateware update with our secret data
|
||||
UxUpdateGateware,
|
||||
/// self-sign kernel/loader
|
||||
|
|
|
|||
|
|
@ -956,10 +956,12 @@ impl<'a> RootKeys {
|
|||
self.spinor.set_staging_write_protect(false).expect("couldn't un-protect the staging area");
|
||||
|
||||
// finalize the progress bar on exit -- always leave at 100%
|
||||
pb.update_text(t!("rootkeys.init.finished", xous::LANG));
|
||||
pb.set_percentage(100);
|
||||
|
||||
self.ticktimer.sleep_ms(2000).expect("couldn't show final message");
|
||||
self.ticktimer.sleep_ms(500).expect("couldn't show final message");
|
||||
|
||||
// the stop emoji, when sent to the slider action bar in progress mode, will cause it to close and relinquish focus
|
||||
rootkeys_modal.key_event(['🛑', '\u{0000}', '\u{0000}', '\u{0000}']);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -975,60 +977,86 @@ impl<'a> RootKeys {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "hazardous-debug")]
|
||||
pub fn test(&mut self) -> bool {
|
||||
let pcache: &mut PasswordCache = unsafe{&mut *(self.pass_cache.as_mut_ptr() as *mut PasswordCache)};
|
||||
pub fn test(&mut self, rootkeys_modal: &mut Modal, main_cid: xous::CID) -> Result<(), RootkeyResult> {
|
||||
let mut progress_action = Slider::new(main_cid, Opcode::UxGutter.to_u32().unwrap(),
|
||||
0, 100, 10, Some("%"), 0, true, true
|
||||
);
|
||||
progress_action.set_is_password(true);
|
||||
// now show the init wait note...
|
||||
rootkeys_modal.modify(
|
||||
Some(ActionType::Slider(progress_action)),
|
||||
Some(t!("rootkeys.setup_wait", xous::LANG)), false,
|
||||
None, true, None);
|
||||
rootkeys_modal.activate();
|
||||
|
||||
// setup the local cache
|
||||
let sensitive_slice = self.sensitive_data.as_slice_mut::<u32>();
|
||||
for addr in 0..256 {
|
||||
self.keyrom.wfo(utra::keyrom::ADDRESS_ADDRESS, addr);
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[addr as usize] = self.keyrom.rf(utra::keyrom::DATA_DATA);
|
||||
log::info!("{:02x}: 0x{:08x}", addr, self.sensitive_data.borrow_mut().as_slice::<u32>()[addr as usize]);
|
||||
xous::yield_slice(); // give some time to the GAM to render
|
||||
// capture the progress bar elements in a convenience structure
|
||||
let mut pb = ProgressBar::new(rootkeys_modal, &mut progress_action);
|
||||
|
||||
// kick the progress bar to indicate we've entered the routine
|
||||
for i in 1..100 {
|
||||
pb.set_percentage(i);
|
||||
self.ticktimer.sleep_ms(50).unwrap();
|
||||
}
|
||||
self.ticktimer.sleep_ms(1000).unwrap();
|
||||
// the stop emoji, when sent to the slider action bar in progress mode, will cause it to close and relinquish focus
|
||||
rootkeys_modal.key_event(['🛑', '\u{0000}', '\u{0000}', '\u{0000}']);
|
||||
|
||||
for (word, key) in sensitive_slice[KeyRomLocs::FPGA_KEY as usize..KeyRomLocs::FPGA_KEY as usize + 256/(size_of::<u32>()*8)].iter()
|
||||
.zip(pcache.fpga_key.chunks_mut(4).into_iter()) {
|
||||
for (&s, d) in word.to_be_bytes().iter().zip(key.iter_mut()) {
|
||||
*d = s;
|
||||
#[cfg(feature = "hazardous-debug")]
|
||||
{
|
||||
let pcache: &mut PasswordCache = unsafe{&mut *(self.pass_cache.as_mut_ptr() as *mut PasswordCache)};
|
||||
|
||||
// setup the local cache
|
||||
let sensitive_slice = self.sensitive_data.as_slice_mut::<u32>();
|
||||
for addr in 0..256 {
|
||||
self.keyrom.wfo(utra::keyrom::ADDRESS_ADDRESS, addr);
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[addr as usize] = self.keyrom.rf(utra::keyrom::DATA_DATA);
|
||||
log::info!("{:02x}: 0x{:08x}", addr, self.sensitive_data.borrow_mut().as_slice::<u32>()[addr as usize]);
|
||||
}
|
||||
|
||||
for (word, key) in sensitive_slice[KeyRomLocs::FPGA_KEY as usize..KeyRomLocs::FPGA_KEY as usize + 256/(size_of::<u32>()*8)].iter()
|
||||
.zip(pcache.fpga_key.chunks_mut(4).into_iter()) {
|
||||
for (&s, d) in word.to_be_bytes().iter().zip(key.iter_mut()) {
|
||||
*d = s;
|
||||
}
|
||||
}
|
||||
pcache.fpga_key_valid = 1;
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[KeyRomLocs::CONFIG as usize] |= keyrom_config::INITIALIZED.ms(1);
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[0x30] = 0xc0de_600d;
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[0x31] = 0x1234_5678;
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[0x32] = 0x8000_0000;
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[0x33] = 0x5555_3333;
|
||||
|
||||
// one time only
|
||||
/*
|
||||
match self.make_gateware_backup(30, 50, progress_modal, progress_action) {
|
||||
Err(e) => {
|
||||
log::error!("got spinor error: {:?}", e);
|
||||
panic!("got spinor error, halting");
|
||||
}
|
||||
_ => ()
|
||||
};*/
|
||||
|
||||
// make the oracles
|
||||
assert!(pcache.fpga_key_valid == 1);
|
||||
// copy from staging
|
||||
let src_oracle = BitstreamOracle::new(&pcache.fpga_key, &pcache.fpga_key, self.staging(), self.staging_base()).unwrap();
|
||||
// write to gateware
|
||||
let dst_oracle = BitstreamOracle::new(&pcache.fpga_key, &pcache.fpga_key, self.gateware(), self.gateware_base()).unwrap();
|
||||
|
||||
// TEST
|
||||
if self.gateware_copy_and_patch(&src_oracle, &dst_oracle, None).is_err() {
|
||||
log::error!("error occured in patch_keys.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.verify_gateware(&dst_oracle, None).is_err() {
|
||||
log::error!("error occurred in gateware verification");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
pcache.fpga_key_valid = 1;
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[KeyRomLocs::CONFIG as usize] |= keyrom_config::INITIALIZED.ms(1);
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[0x30] = 0xc0de_600d;
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[0x31] = 0x1234_5678;
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[0x32] = 0x8000_0000;
|
||||
self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[0x33] = 0x5555_3333;
|
||||
|
||||
// one time only
|
||||
/*
|
||||
match self.make_gateware_backup(30, 50, progress_modal, progress_action) {
|
||||
Err(e) => {
|
||||
log::error!("got spinor error: {:?}", e);
|
||||
panic!("got spinor error, halting");
|
||||
}
|
||||
_ => ()
|
||||
};*/
|
||||
|
||||
// make the oracles
|
||||
assert!(pcache.fpga_key_valid == 1);
|
||||
// copy from staging
|
||||
let src_oracle = BitstreamOracle::new(&pcache.fpga_key, &pcache.fpga_key, self.staging(), self.staging_base()).unwrap();
|
||||
// write to gateware
|
||||
let dst_oracle = BitstreamOracle::new(&pcache.fpga_key, &pcache.fpga_key, self.gateware(), self.gateware_base()).unwrap();
|
||||
|
||||
// TEST
|
||||
if self.gateware_copy_and_patch(&src_oracle, &dst_oracle, None).is_err() {
|
||||
log::error!("error occured in patch_keys.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.verify_gateware(&dst_oracle, None).is_err() {
|
||||
log::error!("error occurred in gateware verification");
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// copy data from a source region to a destination region, re-encrypting and patching as we go along.
|
||||
|
|
|
|||
|
|
@ -33,20 +33,23 @@ mod implementation {
|
|||
use gam::{ActionType, ProgressBar};
|
||||
use num_traits::*;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct RootKeys {
|
||||
password_type: Option<PasswordType>,
|
||||
jtag: jtag::Jtag,
|
||||
xns: xous_names::XousNames,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl RootKeys {
|
||||
pub fn new() -> RootKeys {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let jtag = jtag::Jtag::new(&xns).expect("couldn't connect to jtag server");
|
||||
RootKeys {
|
||||
password_type: None,
|
||||
xns,
|
||||
// must occupy tihs connection for the system to boot properly
|
||||
jtag: jtag::Jtag::new(&xns).expect("couldn't connect to jtag server"),
|
||||
jtag,
|
||||
}
|
||||
}
|
||||
pub fn suspend(&self) {
|
||||
|
|
@ -103,7 +106,7 @@ fn xmain() -> ! {
|
|||
use crate::implementation::RootKeys;
|
||||
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::set_max_level(log::LevelFilter::Debug);
|
||||
log::info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
|
@ -185,9 +188,10 @@ fn xmain() -> ! {
|
|||
Opcode::ModalDrop.to_u32().unwrap(),
|
||||
);
|
||||
|
||||
let mut reboot_initiated = false;
|
||||
loop {
|
||||
let msg = xous::receive_message(keys_sid).unwrap();
|
||||
log::trace!("message: {:?}", msg);
|
||||
log::debug!("message: {:?}", msg);
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(Opcode::SuspendResume) => msg_scalar_unpack!(msg, token, _, _, _, {
|
||||
keys.suspend();
|
||||
|
|
@ -204,9 +208,16 @@ fn xmain() -> ! {
|
|||
|
||||
// UX flow opcodes
|
||||
Some(Opcode::UxTryInitKeys) => msg_scalar_unpack!(msg, _, _, _, _, {
|
||||
if false { // short-circuit for testing subroutines
|
||||
#[cfg(feature = "hazardous-debug")]
|
||||
let _success = keys.test();
|
||||
if true { // short-circuit for testing subroutines
|
||||
let _success = keys.test(&mut rootkeys_modal, main_cid);
|
||||
|
||||
keys.finish_key_init();
|
||||
log::info!("going to into reboot arc");
|
||||
send_message(main_cid,
|
||||
xous::Message::new_scalar(Opcode::UxTryReboot.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).expect("couldn't initiate dialog box");
|
||||
|
||||
continue;
|
||||
} else {
|
||||
// overall flow:
|
||||
// - setup the init
|
||||
|
|
@ -321,25 +332,17 @@ fn xmain() -> ! {
|
|||
// this routine will update the rootkeys_modal with the current Ux state
|
||||
let result = keys.do_key_init(&mut rootkeys_modal, main_cid);
|
||||
|
||||
// the stop emoji, when sent to the slider action bar in progress mode, will cause it to close and relinquish focus
|
||||
rootkeys_modal.key_event(['🛑', '\u{0000}', '\u{0000}', '\u{0000}']);
|
||||
log::info!("set_ux_password result: {:?}", result);
|
||||
|
||||
// clear all the state, re-enable suspend/resume
|
||||
keys.finish_key_init();
|
||||
|
||||
match result {
|
||||
Ok(_) => {
|
||||
keys.finish_key_init();
|
||||
|
||||
// summon a modal that brings us to a reboot
|
||||
dismiss_modal_action.set_action_opcode(Opcode::UxTryReboot.to_u32().unwrap());
|
||||
rootkeys_modal.modify(
|
||||
Some(ActionType::Notification(dismiss_modal_action)),
|
||||
Some(t!("rootkeys.init.finished", xous::LANG)), false,
|
||||
None, false, None);
|
||||
rootkeys_modal.activate();
|
||||
|
||||
log::info!("going to into reboot arc");
|
||||
send_message(main_cid,
|
||||
xous::Message::new_scalar(Opcode::UxTryReboot.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't initiate dialog box");
|
||||
|
||||
continue;
|
||||
xous::Message::new_scalar(Opcode::UxTryReboot.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).expect("couldn't initiate dialog box");
|
||||
}
|
||||
Err(RootkeyResult::AlignmentError) => {
|
||||
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
|
||||
|
|
@ -378,9 +381,6 @@ fn xmain() -> ! {
|
|||
xous::yield_slice();
|
||||
}
|
||||
}
|
||||
|
||||
// clear all the state, re-enable suspend/resume
|
||||
keys.finish_key_init();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -388,6 +388,7 @@ fn xmain() -> ! {
|
|||
}
|
||||
},
|
||||
Some(Opcode::UxTryReboot) => {
|
||||
log::info!("entering reboot handler");
|
||||
// ensure the boost is off so that the reboot will not fail
|
||||
com.set_boost(false).unwrap();
|
||||
llio.boost_on(false).unwrap();
|
||||
|
|
@ -403,45 +404,47 @@ fn xmain() -> ! {
|
|||
Some(t!("rootkeys.init.unplug_power", xous::LANG)), false,
|
||||
None, false, None);
|
||||
rootkeys_modal.activate();
|
||||
rootkeys_modal.redraw();
|
||||
xous::yield_slice();
|
||||
ticktimer.sleep_ms(500).unwrap();
|
||||
|
||||
send_message(main_cid,
|
||||
xous::Message::new_scalar(Opcode::UxTryReboot.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).expect("couldn't initiate dialog box");
|
||||
|
||||
log::info!("vbus is high, holding off on reboot");
|
||||
} else {
|
||||
dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap());
|
||||
log::info!("initiating reboot");
|
||||
dismiss_modal_action.set_action_opcode(Opcode::UxTryReboot.to_u32().unwrap());
|
||||
rootkeys_modal.modify(
|
||||
Some(ActionType::Notification(dismiss_modal_action)),
|
||||
Some(t!("rootkeys.init.finished", xous::LANG)), false,
|
||||
None, false, None);
|
||||
log::info!("calling activate");
|
||||
rootkeys_modal.activate();
|
||||
xous::yield_slice(); // these are necessary to get the messages in place to do a full redraw before the reboot happens
|
||||
rootkeys_modal.redraw();
|
||||
xous::yield_slice();
|
||||
|
||||
log::info!("going to reboot state");
|
||||
send_message(main_cid,
|
||||
xous::Message::new_scalar(Opcode::UxDoReboot.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).expect("couldn't initiate dialog box");
|
||||
}
|
||||
}
|
||||
Some(Opcode::UxDoReboot) => {
|
||||
ticktimer.sleep_ms(1500).unwrap();
|
||||
if !reboot_initiated {
|
||||
// set a wakeup alarm a couple seconds from now -- this is the coldboot
|
||||
rtc.set_wakeup_alarm(4).unwrap();
|
||||
rtc.set_wakeup_alarm(3).unwrap();
|
||||
|
||||
// allow EC to snoop, so that it can wake up the system
|
||||
llio.allow_ec_snoop(true).unwrap();
|
||||
// allow the EC to power me down
|
||||
llio.allow_power_off(true).unwrap();
|
||||
// now send the power off command
|
||||
com.power_off_soc().unwrap();
|
||||
com.power_off_soc().unwrap(); // not that at this point, the screen freezes with the last thing displayed...
|
||||
|
||||
log::info!("reboot in 4 seconds!");
|
||||
// pause execution, nothing after this should be reachable
|
||||
ticktimer.sleep_ms(5000).unwrap();
|
||||
log::info!("if you can read this, reboot failed!");
|
||||
|
||||
// try it again, anyways...
|
||||
send_message(main_cid,
|
||||
xous::Message::new_scalar(Opcode::UxTryReboot.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).expect("couldn't initiate dialog box");
|
||||
log::info!("rebooting now!");
|
||||
reboot_initiated = true;
|
||||
}
|
||||
|
||||
// refresh the message if it goes away
|
||||
send_message(main_cid,
|
||||
xous::Message::new_scalar(Opcode::UxTryReboot.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).expect("couldn't initiate dialog box");
|
||||
}
|
||||
Some(Opcode::UxUpdateGateware) => {
|
||||
unimplemented!();
|
||||
|
|
|
|||
Loading…
Reference in a new issue