From bec3dd00c3233f2fc6d5b53d77191e8136d268ec Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 Apr 2026 23:23:32 +0800 Subject: [PATCH] add option to fully reformat a swap partition in repl --- bao1x-boot/boot1/src/repl.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bao1x-boot/boot1/src/repl.rs b/bao1x-boot/boot1/src/repl.rs index ff78875bf..1bdfff610 100644 --- a/bao1x-boot/boot1/src/repl.rs +++ b/bao1x-boot/boot1/src/repl.rs @@ -7,6 +7,7 @@ use bao1x_api::pubkeys::BOOT0_TO_BOOT1; #[allow(unused_imports)] use bao1x_api::*; use bao1x_hal::acram::{OneWayCounter, SlotManager}; +use bao1x_hal::board::PDDB_LEN; use bao1x_hal::hardening::{Csprng, skipping_enabled}; use utralib::*; @@ -390,11 +391,15 @@ impl Repl { // ... and all was null and void! } "baosec-init" => { - if !matches!(args.as_slice(), [s] if s == "confirm") { - return Err(Error::help( - "Usage: 'baosec-init confirm'. WARNING: erases external storage!", - )); - } + let full = match args.as_slice() { + [s] if s == "confirm" => false, + [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 // erases the off-chip FLASH @@ -452,8 +457,10 @@ impl Repl { crate::println!(" {:x}...", addr); 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) - .step_by(SPINOR_BULK_ERASE_SIZE as usize) + let pddb_erase_len = + 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); flash_spim.flash_erase_block(addr, SPINOR_BULK_ERASE_SIZE as usize);