Merge pull request #846 from betrusted-io/target-adjustments

Target adjustments
This commit is contained in:
bunnie 2026-04-05 23:32:31 +08:00 committed by GitHub
commit d895f3c9c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 29 additions and 14 deletions

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() {
[s] if s == "confirm" => false,
[s, f] if s == "confirm" && f == "full" => true,
_ => {
return Err(Error::help( return Err(Error::help(
"Usage: 'baosec-init confirm'. WARNING: erases external storage!", "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);

View file

@ -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_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 SPINOR_LEN: u32 = bao1x_api::offsets::baosec::SPI_FLASH_LEN as _;
pub const PDDB_LOC: u32 = bao1x_api::offsets::baosec::PDDB_ORIGIN 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 _; 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 // Define the virtual region that memory-mapped FLASH should go to
// top 8 megs are reserved for staging updates, backups, etc. // top 8 megs are reserved for staging updates, backups, etc.

View file

@ -215,13 +215,14 @@ fn susres_service() {
} else { } else {
bio.update_bio_freq(24_000_000); 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(); clk_mgr.wfi();
// ~~~ time passes, but we're on carbonite so we don't notice ~~~ // ~~~ 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.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); bio.update_bio_freq(clk_mgr.fclk);
// when wfi() returns, it means we've resumed // when wfi() returns, it means we've resumed

View file

@ -108,6 +108,7 @@ board-baosec = [
"keystore/board-baosec", "keystore/board-baosec",
"aes/bao1x", "aes/bao1x",
] # USB form factor token ] # USB form factor token
oem-baosec-lite = []
hosted-baosec = [ hosted-baosec = [
"gen2", "gen2",
"bao1x-emu", "bao1x-emu",

View file

@ -96,8 +96,8 @@ pub(crate) struct SpaceUpdate {
// this checksum is "weak" but we are protecting against two scenarios: // this checksum is "weak" but we are protecting against two scenarios:
// 1. partially written SpaceUpdate record (so the last bytes or so are FF) // 1. partially written SpaceUpdate record (so the last bytes or so are FF)
// 2. a malicious attacker // 2. a malicious attacker
// In the case of (1), the occurence should be diminishingly small (expected to never happen, maybe // 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 occure a few times) // 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 // 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 // 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). // being treated as free space and getting erased (data loss, not disclosure).

View file

@ -814,6 +814,7 @@ fn wrapped_main() -> ! {
} }
} }
let modals = modals::Modals::new(&xns).expect("can't connect to Modals server"); 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() { match pddb_os.ensure_password() {
PasswordState::Correct => { PasswordState::Correct => {
// The behavior in gen2 is mount-or-format: no user approval // 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 // 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) { if !try_mount(&mut pddb_os, &mut basis_cache, &mut basis_monitor_notifications) {
log::warn!("PDDB not formatted - formatting the PDDB!"); 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( if !try_mount(
&mut pddb_os, &mut pddb_os,
&mut basis_cache, &mut basis_cache,
@ -833,7 +836,7 @@ fn wrapped_main() -> ! {
} }
PasswordState::Uninit => { PasswordState::Uninit => {
log::warn!("PDDB not formatted - formatting the PDDB!"); 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) { if !try_mount(&mut pddb_os, &mut basis_cache, &mut basis_monitor_notifications) {
panic!("Couldn't format & mount PDDB"); panic!("Couldn't format & mount PDDB");
} }
@ -843,7 +846,7 @@ fn wrapped_main() -> ! {
} }
PasswordState::Incorrect(_failcount) => { PasswordState::Incorrect(_failcount) => {
log::warn!("PDDB formatted, but keys rotated. Formatting PDDB!"); 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) { if !try_mount(&mut pddb_os, &mut basis_cache, &mut basis_monitor_notifications) {
panic!("Couldn't format & mount PDDB"); panic!("Couldn't format & mount PDDB");
} }