mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
add commands to check mount status and to initiate mount manually
This commit is contained in:
parent
19f95e6bab
commit
5523d81669
4 changed files with 163 additions and 99 deletions
|
|
@ -66,6 +66,9 @@ pub(crate) const PDDB_MODAL_NAME: &'static str = "pddb modal";
|
||||||
|
|
||||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||||
pub(crate) enum Opcode {
|
pub(crate) enum Opcode {
|
||||||
|
IsMounted,
|
||||||
|
TryMount,
|
||||||
|
|
||||||
ListBasis,
|
ListBasis,
|
||||||
LatestBasis,
|
LatestBasis,
|
||||||
/// Note that creating a basis does not automatically open it!
|
/// Note that creating a basis does not automatically open it!
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,7 @@ impl BasisCache {
|
||||||
Some(self.cache.len() - 1)
|
Some(self.cache.len() - 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub(crate) fn basis_count(&self) -> usize {self.cache.len()}
|
||||||
|
|
||||||
/// Adds a dictionary with `name` to:
|
/// Adds a dictionary with `name` to:
|
||||||
/// - if `basis_name` is None, the most recently opened basis
|
/// - if `basis_name` is None, the most recently opened basis
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,26 @@ impl Pddb {
|
||||||
trng: trng::Trng::new(&xns).unwrap(),
|
trng: trng::Trng::new(&xns).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn is_mounted(&self) -> bool {
|
||||||
|
let ret = send_message(self.conn, Message::new_blocking_scalar(
|
||||||
|
Opcode::IsMounted.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't execute IsMounted query");
|
||||||
|
match ret {
|
||||||
|
xous::Result::Scalar1(code) => {
|
||||||
|
if code == 0 {false} else {true}
|
||||||
|
},
|
||||||
|
_ => panic!("Internal error"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn try_mount(&self) -> bool {
|
||||||
|
let ret = send_message(self.conn, Message::new_blocking_scalar(
|
||||||
|
Opcode::TryMount.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't execute IsMounted query");
|
||||||
|
match ret {
|
||||||
|
xous::Result::Scalar1(code) => {
|
||||||
|
if code == 0 {false} else {true}
|
||||||
|
},
|
||||||
|
_ => panic!("Internal error"),
|
||||||
|
}
|
||||||
|
}
|
||||||
/// return a list of all open bases
|
/// return a list of all open bases
|
||||||
pub fn list_basis(&self) -> Vec::<String> {
|
pub fn list_basis(&self) -> Vec::<String> {
|
||||||
let list_alloc = PddbBasisList {
|
let list_alloc = PddbBasisList {
|
||||||
|
|
|
||||||
|
|
@ -455,105 +455,8 @@ fn xmain() -> ! {
|
||||||
// try to mount the PDDB automatically before starting the server
|
// try to mount the PDDB automatically before starting the server
|
||||||
if pddb_os.rootkeys_initialized() {
|
if pddb_os.rootkeys_initialized() {
|
||||||
tt.sleep_ms(1000).unwrap(); // wait 1 second after boot before attempting to mount, to let the boot screen finish redrawing (cometic issue).
|
tt.sleep_ms(1000).unwrap(); // wait 1 second after boot before attempting to mount, to let the boot screen finish redrawing (cometic issue).
|
||||||
log::info!("Requesting login password");
|
if ensure_password(&modals, &mut pddb_os) {
|
||||||
let mut done = false;
|
try_mount_or_format(&modals, &mut pddb_os, &mut basis_cache);
|
||||||
let mut skip = false;
|
|
||||||
while !done {
|
|
||||||
done = pddb_os.try_login();
|
|
||||||
if !done {
|
|
||||||
pddb_os.clear_password(); // clear the bad password entry
|
|
||||||
modals.add_list_item(t!("pddb.yes", xous::LANG)).expect("couldn't build radio item list");
|
|
||||||
modals.add_list_item(t!("pddb.no", xous::LANG)).expect("couldn't build radio item list");
|
|
||||||
match modals.get_radiobutton(t!("pddb.badpass", xous::LANG)) {
|
|
||||||
Ok(response) => {
|
|
||||||
if response.as_str() == t!("pddb.yes", xous::LANG) {
|
|
||||||
done = false;
|
|
||||||
} else if response.as_str() == t!("pddb.no", xous::LANG) {
|
|
||||||
done = true;
|
|
||||||
skip = true;
|
|
||||||
} else {
|
|
||||||
panic!("Got unexpected return from radiobutton");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => panic!("get_radiobutton failed"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !skip {
|
|
||||||
log::info!("Attempting to mount the PDDB");
|
|
||||||
if let Some(sys_basis) = pddb_os.pddb_mount() {
|
|
||||||
log::info!("PDDB mount operation finished successfully");
|
|
||||||
basis_cache.basis_add(sys_basis);
|
|
||||||
} else {
|
|
||||||
#[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.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 {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
} 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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// main server loop
|
// main server loop
|
||||||
|
|
@ -572,6 +475,33 @@ fn xmain() -> ! {
|
||||||
basis_cache.suspend(&mut pddb_os);
|
basis_cache.suspend(&mut pddb_os);
|
||||||
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
||||||
}),
|
}),
|
||||||
|
Some(Opcode::IsMounted) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||||
|
if basis_cache.basis_count() > 0 { // if there's anything in the cache, we're mounted.
|
||||||
|
xous::return_scalar(msg.sender, 1).expect("couldn't return scalar");
|
||||||
|
} else {
|
||||||
|
xous::return_scalar(msg.sender, 0).expect("couldn't return scalar");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
Some(Opcode::TryMount) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||||
|
if basis_cache.basis_count() > 0 {
|
||||||
|
xous::return_scalar(msg.sender, 1).expect("couldn't return scalar");
|
||||||
|
} else {
|
||||||
|
if !pddb_os.rootkeys_initialized() {
|
||||||
|
// can't mount if we have no root keys
|
||||||
|
xous::return_scalar(msg.sender, 0).expect("could't return scalar");
|
||||||
|
} else {
|
||||||
|
if ensure_password(&modals, &mut pddb_os) {
|
||||||
|
if try_mount_or_format(&modals, &mut pddb_os, &mut basis_cache) {
|
||||||
|
xous::return_scalar(msg.sender, 1).expect("couldn't return scalar");
|
||||||
|
} else {
|
||||||
|
xous::return_scalar(msg.sender, 0).expect("couldn't return scalar");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
xous::return_scalar(msg.sender, 0).expect("couldn't return scalar");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
Some(Opcode::ListBasis) => {
|
Some(Opcode::ListBasis) => {
|
||||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||||
let mut list_ipc = buffer.to_original::<PddbBasisList, _>().unwrap();
|
let mut list_ipc = buffer.to_original::<PddbBasisList, _>().unwrap();
|
||||||
|
|
@ -1082,6 +1012,116 @@ fn xmain() -> ! {
|
||||||
xous::terminate_process(0)
|
xous::terminate_process(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ensure_password(modals: &modals::Modals, pddb_os: &mut PddbOs) -> bool {
|
||||||
|
log::info!("Requesting login password");
|
||||||
|
let mut done = false;
|
||||||
|
let mut skip = false;
|
||||||
|
while !done {
|
||||||
|
done = pddb_os.try_login();
|
||||||
|
if !done {
|
||||||
|
pddb_os.clear_password(); // clear the bad password entry
|
||||||
|
modals.add_list_item(t!("pddb.yes", xous::LANG)).expect("couldn't build radio item list");
|
||||||
|
modals.add_list_item(t!("pddb.no", xous::LANG)).expect("couldn't build radio item list");
|
||||||
|
match modals.get_radiobutton(t!("pddb.badpass", xous::LANG)) {
|
||||||
|
Ok(response) => {
|
||||||
|
if response.as_str() == t!("pddb.yes", xous::LANG) {
|
||||||
|
done = false;
|
||||||
|
} else if response.as_str() == t!("pddb.no", xous::LANG) {
|
||||||
|
done = true;
|
||||||
|
skip = true;
|
||||||
|
} else {
|
||||||
|
panic!("Got unexpected return from radiobutton");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => panic!("get_radiobutton failed"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
!skip
|
||||||
|
}
|
||||||
|
fn try_mount_or_format(modals: &modals::Modals, pddb_os: &mut PddbOs, basis_cache: &mut BasisCache) -> bool {
|
||||||
|
log::info!("Attempting to mount the PDDB");
|
||||||
|
if let Some(sys_basis) = pddb_os.pddb_mount() {
|
||||||
|
log::info!("PDDB mount operation finished successfully");
|
||||||
|
basis_cache.basis_add(sys_basis);
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
#[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.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 {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
true
|
||||||
|
} 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");
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[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);
|
||||||
|
true
|
||||||
|
} 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");
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Test cases that have been coded to run directly on hardware (that is, they do not require host-OS debug features)
|
// Test cases that have been coded to run directly on hardware (that is, they do not require host-OS debug features)
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn manual_testcase(hw: &mut PddbOs) {
|
pub(crate) fn manual_testcase(hw: &mut PddbOs) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue