From 00ce90508828ccc1099e7080bd84389f7348e7f8 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 7 Jan 2022 23:33:53 +0800 Subject: [PATCH] clean up hosted mode flow --- services/pddb/src/backend/hw.rs | 4 +- services/pddb/src/main.rs | 77 ++++++++++++++++++++------------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/services/pddb/src/backend/hw.rs b/services/pddb/src/backend/hw.rs index fb145a3a9..f94365f80 100644 --- a/services/pddb/src/backend/hw.rs +++ b/services/pddb/src/backend/hw.rs @@ -171,7 +171,7 @@ impl PddbOs { self.pddb_mr.dump_fs(&name); let mut export = Vec::::new(); if let Some(key) = self.system_basis_key { - log::info!("written key: {:x?}", key); + log::info!("(hosted mode debug) written key: {:x?}", key); let mut name = [0 as u8; 64]; for (&src, dst) in PDDB_DEFAULT_SYSTEM_BASIS.as_bytes().iter().zip(name.iter_mut()) { *dst = src; @@ -1205,7 +1205,9 @@ impl PddbOs { let mut checkblock_a = [0u8; BLOCK_SIZE]; self.rootkeys.decrypt_block(GenericArray::from_mut_slice(&mut checkblock_a)); + #[cfg(any(target_os = "none", target_os = "xous"))] // skip this dialog in hosted mode modals.show_notification(t!("pddb.checkpass", xous::LANG)).expect("notification failed"); + self.clear_password(); let mut checkblock_b = [0u8; BLOCK_SIZE]; self.rootkeys.decrypt_block(GenericArray::from_mut_slice(&mut checkblock_b)); diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index beb16faf8..afd07417d 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -486,44 +486,63 @@ fn xmain() -> ! { log::info!("PDDB mount operation finished successfully"); basis_cache.basis_add(sys_basis); } else { - log::debug!("PDDB did not mount; requesting format"); - modals.add_list_item(t!("pddb.okay", xous::LANG)).expect("couldn't build radio item list"); - modals.add_list_item(t!("pddb.cancel", xous::LANG)).expect("couldn't build radio item list"); - let do_format: bool; - match modals.get_radiobutton(t!("pddb.requestformat", xous::LANG)) { - Ok(response) => { - if response.as_str() == t!("pddb.okay", xous::LANG) { - do_format = true; - } else if response.as_str() == t!("pddb.cancel", xous::LANG) { - log::info!("PDDB format aborted by user"); - do_format = false; - } else { - panic!("Got unexpected return from radiobutton"); - } - } - _ => panic!("get_radiobutton failed"), - } - if do_format { - modals.add_list_item(t!("pddb.no", xous::LANG)).expect("couldn't build radio item list"); - modals.add_list_item(t!("pddb.yes", xous::LANG)).expect("couldn't build radio item list"); - let fast: bool; - match modals.get_radiobutton(t!("pddb.devbypass", xous::LANG)) { + #[cfg(any(target_os = "none", target_os = "xous"))] + { + log::debug!("PDDB did not mount; requesting format"); + modals.add_list_item(t!("pddb.okay", xous::LANG)).expect("couldn't build radio item list"); + modals.add_list_item(t!("pddb.cancel", xous::LANG)).expect("couldn't build radio item list"); + let do_format: bool; + match modals.get_radiobutton(t!("pddb.requestformat", xous::LANG)) { Ok(response) => { - if response.as_str() == t!("pddb.yes", xous::LANG) { - fast = true; - } else if response.as_str() == t!("pddb.no", xous::LANG) { - fast = false; + if response.as_str() == t!("pddb.okay", xous::LANG) { + do_format = true; + } else if response.as_str() == t!("pddb.cancel", xous::LANG) { + log::info!("PDDB format aborted by user"); + do_format = false; } else { panic!("Got unexpected return from radiobutton"); } } _ => panic!("get_radiobutton failed"), } - pddb_os.pddb_format(fast, Some(&modals)).expect("couldn't format PDDB"); + if do_format { + let fast: bool; + if false { + modals.add_list_item(t!("pddb.no", xous::LANG)).expect("couldn't build radio item list"); + modals.add_list_item(t!("pddb.yes", xous::LANG)).expect("couldn't build radio item list"); + match modals.get_radiobutton(t!("pddb.devbypass", xous::LANG)) { + Ok(response) => { + if response.as_str() == t!("pddb.yes", xous::LANG) { + fast = true; + } else if response.as_str() == t!("pddb.no", xous::LANG) { + fast = false; + } else { + panic!("Got unexpected return from radiobutton"); + } + } + _ => panic!("get_radiobutton failed"), + } + } else { + fast = false; + } - #[cfg(not(any(target_os = "none", target_os = "xous")))] + pddb_os.pddb_format(fast, Some(&modals)).expect("couldn't format PDDB"); + + if let Some(sys_basis) = pddb_os.pddb_mount() { + log::info!("PDDB mount operation finished successfully"); + basis_cache.basis_add(sys_basis); + } else { + log::error!("Despite formatting, no PDDB was found!"); + let mut err = String::from(t!("pddb.internalerror", xous::LANG)); + err.push_str(" #1"); // punt and leave an error code, because this "should" be rare + modals.show_notification(err.as_str()).expect("notification failed"); + } + } + } + #[cfg(not(any(target_os = "none", target_os = "xous")))] + { + pddb_os.pddb_format(false, Some(&modals)).expect("couldn't format PDDB"); pddb_os.dbg_dump(Some("full".to_string()), None); - if let Some(sys_basis) = pddb_os.pddb_mount() { log::info!("PDDB mount operation finished successfully"); basis_cache.basis_add(sys_basis);