fix mount/format on boot ordering

pddb is working again in hardware, this time with real keys
This commit is contained in:
bunnie 2025-11-11 08:18:57 +08:00
parent c2c135bfdc
commit dd42267eb9
2 changed files with 28 additions and 24 deletions

View file

@ -530,7 +530,7 @@ impl PddbOs {
let remaining_len = buf.len() - written; let remaining_len = buf.len() - written;
// this is OK here because we took care of any misaligned start data in step 1. // this is OK here because we took care of any misaligned start data in step 1.
let aligned_start = (offset + (SPINOR_ERASE_SIZE as usize - 1)) & !(SPINOR_ERASE_SIZE as usize - 1); let aligned_start = (offset + (SPINOR_ERASE_SIZE as usize - 1)) & !(SPINOR_ERASE_SIZE as usize - 1);
log::info!( log::debug!(
"aligned_start {:x} end {:x}", "aligned_start {:x} end {:x}",
aligned_start, aligned_start,
(aligned_start + (remaining_len + (SPINOR_ERASE_SIZE as usize - 1)) (aligned_start + (remaining_len + (SPINOR_ERASE_SIZE as usize - 1))

View file

@ -797,8 +797,6 @@ fn wrapped_main() -> ! {
#[cfg(feature = "gen2")] #[cfg(feature = "gen2")]
Opcode::TryMount => { Opcode::TryMount => {
xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, { xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
match pddb_os.ensure_password() {
PasswordState::Correct => {
fn try_mount( fn try_mount(
pddb_os: &mut PddbOs, pddb_os: &mut PddbOs,
basis_cache: &mut BasisCache, basis_cache: &mut BasisCache,
@ -808,17 +806,15 @@ fn wrapped_main() -> ! {
log::info!("PDDB mount operation finished successfully"); log::info!("PDDB mount operation finished successfully");
basis_cache.basis_add(sys_basis); basis_cache.basis_add(sys_basis);
if basis_monitor_notifications.len() > 0 { if basis_monitor_notifications.len() > 0 {
notify_basis_change( notify_basis_change(basis_monitor_notifications, basis_cache.basis_list());
basis_monitor_notifications,
basis_cache.basis_list(),
);
} }
true true
} else { } else {
false false
} }
} }
match pddb_os.ensure_password() {
PasswordState::Correct => {
// The behavior in gen2 is mount-or-format: no user approval // The behavior in gen2 is mount-or-format: no user approval
// is requested in case of format. This is silghtly dangerous in case // is requested in case of format. This is silghtly dangerous in case
// of data corruption but I think this is the "right" user experience // of data corruption but I think this is the "right" user experience
@ -833,11 +829,13 @@ fn wrapped_main() -> ! {
panic!("Couldn't format & mount PDDB"); panic!("Couldn't format & mount PDDB");
} }
} }
log::info!("{}PDDB.MOUNTED,{}", BOOKEND_START, BOOKEND_END);
xous::return_scalar2(msg.sender, 0, 0).expect("couldn't return scalar");
} }
PasswordState::Uninit => { PasswordState::Uninit => {
unimplemented!("Password is always available on gen2") log::warn!("PDDB not formatted - formatting the PDDB!");
pddb_os.pddb_format(false, None).expect("couldn't format PDDB");
if !try_mount(&mut pddb_os, &mut basis_cache, &mut basis_monitor_notifications) {
panic!("Couldn't format & mount PDDB");
}
} }
PasswordState::ForcedAbort(_failcount) => { PasswordState::ForcedAbort(_failcount) => {
unreachable!(); unreachable!();
@ -846,6 +844,12 @@ fn wrapped_main() -> ! {
unreachable!(); unreachable!();
} }
} }
// the above operation should either succeed or panic, so we are always "success" here
log::info!("{}PDDB.MOUNTED,{}", BOOKEND_START, BOOKEND_END);
xous::return_scalar2(msg.sender, 0, 0).expect("couldn't return scalar");
for requester in attempt_notifications.drain(..) {
xous::return_scalar2(requester, 0, 0).expect("couldn't return scalar");
}
}) })
} }
#[cfg(feature = "gen1")] #[cfg(feature = "gen1")]