From 6e528f96782f65f1ca2ba227228878d199ceb5de Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 Apr 2026 23:22:45 +0800 Subject: [PATCH 1/3] fix regression on wfi vs bio setting --- services/bao1x-hal-service/src/servers/susres.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/bao1x-hal-service/src/servers/susres.rs b/services/bao1x-hal-service/src/servers/susres.rs index f21e4936a..fe7568bed 100644 --- a/services/bao1x-hal-service/src/servers/susres.rs +++ b/services/bao1x-hal-service/src/servers/susres.rs @@ -215,13 +215,14 @@ fn susres_service() { } else { bio.update_bio_freq(24_000_000); } - clk_mgr.set_fclk_fd(0xff); // set divider to 1:1 ratio + // clk_mgr.set_fclk_fd(0xff); // set divider to 1:1 ratio clk_mgr.wfi(); // ~~~ time passes, but we're on carbonite so we don't notice ~~~ + // clk_mgr.set_fclk_fd(fclk_fd_backup); // restore the FD before restoring potentially + // fast PLL setting clk_mgr.restore_wfi(); - clk_mgr.set_fclk_fd(fclk_fd_backup); // restore the FD before restoring potentially fast PLL setting bio.update_bio_freq(clk_mgr.fclk); // when wfi() returns, it means we've resumed From 30ca5dec711a2d296ff5256f2cd023f028423254 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 Apr 2026 23:23:11 +0800 Subject: [PATCH 2/3] adjust disk space usage for lite platform --- libs/bao1x-hal/src/board/baosec.rs | 3 +++ services/pddb/Cargo.toml | 1 + services/pddb/src/backend/fastspace.rs | 4 ++-- services/pddb/src/main.rs | 9 ++++++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libs/bao1x-hal/src/board/baosec.rs b/libs/bao1x-hal/src/board/baosec.rs index 47061cfea..51c1ddc03 100644 --- a/libs/bao1x-hal/src/board/baosec.rs +++ b/libs/bao1x-hal/src/board/baosec.rs @@ -18,7 +18,10 @@ pub const SPINOR_ERASE_SIZE: u32 = bao1x_api::offsets::baosec::SPINOR_ERASE_SIZE pub const SPINOR_BULK_ERASE_SIZE: u32 = bao1x_api::offsets::baosec::SPINOR_BULK_ERASE_SIZE; pub const SPINOR_LEN: u32 = bao1x_api::offsets::baosec::SPI_FLASH_LEN as _; pub const PDDB_LOC: u32 = bao1x_api::offsets::baosec::PDDB_ORIGIN as _; +#[cfg(not(feature = "oem-baosec-lite"))] pub const PDDB_LEN: u32 = bao1x_api::offsets::baosec::PDDB_LEN as _; +#[cfg(feature = "oem-baosec-lite")] +pub const PDDB_LEN: u32 = 2560 * 1024; // 2.5MiB length // Define the virtual region that memory-mapped FLASH should go to // top 8 megs are reserved for staging updates, backups, etc. diff --git a/services/pddb/Cargo.toml b/services/pddb/Cargo.toml index 5557196fd..7d84687c6 100644 --- a/services/pddb/Cargo.toml +++ b/services/pddb/Cargo.toml @@ -108,6 +108,7 @@ board-baosec = [ "keystore/board-baosec", "aes/bao1x", ] # USB form factor token +oem-baosec-lite = [] hosted-baosec = [ "gen2", "bao1x-emu", diff --git a/services/pddb/src/backend/fastspace.rs b/services/pddb/src/backend/fastspace.rs index 8cd055d1d..4c53a9f17 100644 --- a/services/pddb/src/backend/fastspace.rs +++ b/services/pddb/src/backend/fastspace.rs @@ -96,8 +96,8 @@ pub(crate) struct SpaceUpdate { // this checksum is "weak" but we are protecting against two scenarios: // 1. partially written SpaceUpdate record (so the last bytes or so are FF) // 2. a malicious attacker - // In the case of (1), the occurence should be diminishingly small (expected to never happen, maybe - // a very unstable system that's "blinking" power constantly would have it occure a few times) + // In the case of (1), the occurrence should be diminishingly small (expected to never happen, maybe + // a very unstable system that's "blinking" power constantly would have it occur a few times) // In the case of (2), an attacker has a chance of generating a collision, but the result is // also unlikely to generate a valid PhysAddr, and if it does, the consequence is some valid data // being treated as free space and getting erased (data loss, not disclosure). diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index a3b556ee8..b3cf98c93 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -814,6 +814,7 @@ fn wrapped_main() -> ! { } } let modals = modals::Modals::new(&xns).expect("can't connect to Modals server"); + let fast_format = if cfg!(feature = "oem-baosec-lite") { true } else { false }; match pddb_os.ensure_password() { PasswordState::Correct => { // The behavior in gen2 is mount-or-format: no user approval @@ -821,7 +822,9 @@ fn wrapped_main() -> ! { // of data corruption but I think this is the "right" user experience if !try_mount(&mut pddb_os, &mut basis_cache, &mut basis_monitor_notifications) { log::warn!("PDDB not formatted - formatting the PDDB!"); - pddb_os.pddb_format(false, Some(&modals)).expect("couldn't format PDDB"); + pddb_os + .pddb_format(fast_format, Some(&modals)) + .expect("couldn't format PDDB"); if !try_mount( &mut pddb_os, &mut basis_cache, @@ -833,7 +836,7 @@ fn wrapped_main() -> ! { } PasswordState::Uninit => { log::warn!("PDDB not formatted - formatting the PDDB!"); - pddb_os.pddb_format(false, Some(&modals)).expect("couldn't format PDDB"); + pddb_os.pddb_format(fast_format, Some(&modals)).expect("couldn't format PDDB"); if !try_mount(&mut pddb_os, &mut basis_cache, &mut basis_monitor_notifications) { panic!("Couldn't format & mount PDDB"); } @@ -843,7 +846,7 @@ fn wrapped_main() -> ! { } PasswordState::Incorrect(_failcount) => { log::warn!("PDDB formatted, but keys rotated. Formatting PDDB!"); - pddb_os.pddb_format(false, Some(&modals)).expect("couldn't format PDDB"); + pddb_os.pddb_format(fast_format, Some(&modals)).expect("couldn't format PDDB"); if !try_mount(&mut pddb_os, &mut basis_cache, &mut basis_monitor_notifications) { panic!("Couldn't format & mount PDDB"); } From bec3dd00c3233f2fc6d5b53d77191e8136d268ec Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 Apr 2026 23:23:32 +0800 Subject: [PATCH 3/3] 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);