add option to fully reformat a swap partition in repl

This commit is contained in:
bunnie 2026-04-05 23:23:32 +08:00
parent 30ca5dec71
commit bec3dd00c3

View file

@ -7,6 +7,7 @@ use bao1x_api::pubkeys::BOOT0_TO_BOOT1;
#[allow(unused_imports)] #[allow(unused_imports)]
use bao1x_api::*; use bao1x_api::*;
use bao1x_hal::acram::{OneWayCounter, SlotManager}; use bao1x_hal::acram::{OneWayCounter, SlotManager};
use bao1x_hal::board::PDDB_LEN;
use bao1x_hal::hardening::{Csprng, skipping_enabled}; use bao1x_hal::hardening::{Csprng, skipping_enabled};
use utralib::*; use utralib::*;
@ -390,11 +391,15 @@ impl Repl {
// ... and all was null and void! // ... and all was null and void!
} }
"baosec-init" => { "baosec-init" => {
if !matches!(args.as_slice(), [s] if s == "confirm") { let full = match args.as_slice() {
return Err(Error::help( [s] if s == "confirm" => false,
"Usage: 'baosec-init confirm'. WARNING: erases external storage!", [s, f] if s == "confirm" && f == "full" => true,
)); _ => {
} return Err(Error::help(
"Usage: 'baosec-init confirm [full]'. WARNING: erases external storage!",
));
}
};
// this routine is used to initialize baosec products - sets the board type and // this routine is used to initialize baosec products - sets the board type and
// erases the off-chip FLASH // erases the off-chip FLASH
@ -452,8 +457,10 @@ impl Repl {
crate::println!(" {:x}...", addr); crate::println!(" {:x}...", addr);
flash_spim.flash_erase_block(addr, SPINOR_BULK_ERASE_SIZE as usize); flash_spim.flash_erase_block(addr, SPINOR_BULK_ERASE_SIZE as usize);
} }
for addr in (PDDB_ORIGIN..PDDB_ORIGIN + SPINOR_BULK_ERASE_SIZE as usize * 2) let pddb_erase_len =
.step_by(SPINOR_BULK_ERASE_SIZE as usize) if full { PDDB_LEN as usize } else { SPINOR_BULK_ERASE_SIZE as usize * 2 };
for addr in
(PDDB_ORIGIN..PDDB_ORIGIN + pddb_erase_len).step_by(SPINOR_BULK_ERASE_SIZE as usize)
{ {
crate::println!(" {:x}...", addr); crate::println!(" {:x}...", addr);
flash_spim.flash_erase_block(addr, SPINOR_BULK_ERASE_SIZE as usize); flash_spim.flash_erase_block(addr, SPINOR_BULK_ERASE_SIZE as usize);