From f11d096a275cadaca64bb111b80ff6194dea3f6b Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 6 Mar 2026 19:17:19 +0800 Subject: [PATCH 1/6] add utility routine for creating an empty uf2 file this is useful for resetting devices in CI --- tools/src/bin/xous-app-uf2.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/src/bin/xous-app-uf2.rs b/tools/src/bin/xous-app-uf2.rs index cb2f99008..4728e1376 100644 --- a/tools/src/bin/xous-app-uf2.rs +++ b/tools/src/bin/xous-app-uf2.rs @@ -71,12 +71,30 @@ fn main() -> Result<(), Box> { .required(false) .help("Explicit git describe version for swap signing (e.g., 'v0.10.0-19-g0d934e1'). If not specified, uses git describe."), ) + .arg( + Arg::with_name("empty-loader") + .long("empty-loader") + .required(false) + .help("When specified, creates a short loader file with all 0's as data. Used for resetting device state in CI testing.") + ) .get_matches(); let mut process_names = ProcessNames::new(); let mut pid: u32 = 1; + if matches.is_present("empty-loader") { + let empty_uf2 = "empty.uf2"; + let empty = vec![0u8; 16384]; + let uf2_blob = + bin_to_uf2(&empty, bao1x_api::BAOCHIP_1X_UF2_FAMILY, bao1x_api::common::LOADER_START as _)?; + let mut f = + File::create(empty_uf2).unwrap_or_else(|_| panic!("Couldn't create output file {}", empty_uf2)); + f.write(&uf2_blob)?; + println!("Created empty UF2 at {}", empty_uf2); + return Ok(()); + } + let anti_rollback = if let Some(arb) = matches.value_of("antirollback") { parse_u32(arb).map_err(|_| String::from("Antirollback should be a number"))? } else { From 3ac87613d133066351d92fc859d638cb1902e7ee Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 6 Mar 2026 19:17:43 +0800 Subject: [PATCH 2/6] add UI feedback on baosec targets for PDDB init useful for MP flow progress monitoring --- services/pddb/src/backend/hw.rs | 16 ---------------- services/pddb/src/main.rs | 7 ++++--- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/services/pddb/src/backend/hw.rs b/services/pddb/src/backend/hw.rs index 9eddd154b..e7f796d90 100644 --- a/services/pddb/src/backend/hw.rs +++ b/services/pddb/src/backend/hw.rs @@ -2261,7 +2261,6 @@ impl PddbOs { // step 1. Erase the entire PDDB region - leaves the state in all 1's if !fast { log::info!("Erasing the PDDB region"); - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals .start_progress( @@ -2311,7 +2310,6 @@ impl PddbOs { } } } - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals.update_progress(PDDB_A_LOC + PDDB_A_LEN as u32).expect("couldn't update progress bar"); modals.finish_progress().expect("couldn't dismiss progress bar"); @@ -2321,7 +2319,6 @@ impl PddbOs { } // step 2. fill in the page table with junk, which marks it as cryptographically empty - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals .start_progress(t!("pddb.initpt", locales::LANG), 0, size_of::() as u32, 0) @@ -2337,7 +2334,6 @@ impl PddbOs { } } } - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals .update_progress(size_of::() as u32) @@ -2355,7 +2351,6 @@ impl PddbOs { } self.patch_pagetable_raw(&temp, remainder_start as u32); } - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals.finish_progress().expect("couldn't dismiss progress bar"); #[cfg(feature = "ux-swap-delay")] @@ -2367,7 +2362,6 @@ impl PddbOs { //if !self.rootkeys.ensure_aes_password() { // return Err(Error::new(ErrorKind::PermissionDenied, "unlock password was incorrect")); //} - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals .start_progress(t!("pddb.key", locales::LANG), 0, 100, 0) @@ -2394,7 +2388,6 @@ impl PddbOs { self.system_basis_key = Some(BasisKeys { pt: system_basis_key_pt, data: system_basis_key }); // this causes system_basis_key to be owned by self and go out of scope let mut crypto_keys = StaticCryptoData::default(); crypto_keys.version = SCD_VERSION; // should already be set by `default()` but let's be sure. - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals.update_progress(50).expect("couldn't update progress bar"); #[cfg(feature = "ux-swap-delay")] @@ -2414,7 +2407,6 @@ impl PddbOs { self.entropy.borrow_mut().get_slice(&mut crypto_keys.salt_base); // commit keys self.patch_keys(crypto_keys.deref(), 0); - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals.update_progress(100).expect("couldn't update progress bar"); #[cfg(feature = "ux-swap-delay")] @@ -2436,7 +2428,6 @@ impl PddbOs { // step 5. fscb handling // pick a set of random pages from the free pool and assign it to the fscb // pass the generator an empty cache - this causes it to treat the entire disk as free space - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals .start_progress(t!("pddb.fastspace", locales::LANG), 0, 100, 0) @@ -2448,7 +2439,6 @@ impl PddbOs { for (&src, dst) in free_pool.iter().zip(fast_space.free_pool.iter_mut()) { *dst = src; } - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals.update_progress(50).expect("couldn't update progress bar"); #[cfg(feature = "ux-swap-delay")] @@ -2470,7 +2460,6 @@ impl PddbOs { // step 5. salt the free space with random numbers. this can take a while, we might need a "progress // report" of some kind... this is coded using "direct disk" offsets...under the assumption // that we only ever really want to do this here, and not re-use this routine elsewhere. - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals .start_progress( @@ -2524,7 +2513,6 @@ impl PddbOs { #[cfg(all(feature = "gen2", target_os = "xous"))] self.patch(&temp, offset); } - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals.update_progress(PDDB_A_LEN as u32).expect("couldn't update progress bar"); #[cfg(feature = "ux-swap-delay")] @@ -2535,7 +2523,6 @@ impl PddbOs { } // step 6. create the system basis root structure - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals .start_progress(t!("pddb.structure", locales::LANG), 0, 100, 0) @@ -2553,7 +2540,6 @@ impl PddbOs { // step 7. Create a hashmap for our reverse PTE, allocate sectors, and add it to the Pddb's cache self.fast_space_read(); // we reconstitute our fspace map even though it was just generated, partially as a sanity check that everything is ok - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals.update_progress(33).expect("couldn't update progress bar"); #[cfg(feature = "ux-swap-delay")] @@ -2590,7 +2576,6 @@ impl PddbOs { let syskey = self.system_basis_key.take().unwrap(); // take the key out self.data_encrypt_and_patch_page_with_commit(&syskey.data, &aad, &mut block, &pp); self.system_basis_key = Some(syskey); // put the key back - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals.update_progress(66).expect("couldn't update progress bar"); #[cfg(feature = "ux-swap-delay")] @@ -2603,7 +2588,6 @@ impl PddbOs { // mark the entry as clean, as it has been sync'd to disk phys.set_clean(true); } - #[cfg(feature = "gen1")] if let Some(modals) = progress { modals.update_progress(100).expect("couldn't update progress bar"); #[cfg(feature = "ux-swap-delay")] diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index d3150653d..a3b556ee8 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -813,6 +813,7 @@ fn wrapped_main() -> ! { false } } + let modals = modals::Modals::new(&xns).expect("can't connect to Modals server"); match pddb_os.ensure_password() { PasswordState::Correct => { // The behavior in gen2 is mount-or-format: no user approval @@ -820,7 +821,7 @@ 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, None).expect("couldn't format PDDB"); + pddb_os.pddb_format(false, Some(&modals)).expect("couldn't format PDDB"); if !try_mount( &mut pddb_os, &mut basis_cache, @@ -832,7 +833,7 @@ fn wrapped_main() -> ! { } PasswordState::Uninit => { log::warn!("PDDB not formatted - formatting the PDDB!"); - pddb_os.pddb_format(false, None).expect("couldn't format PDDB"); + pddb_os.pddb_format(false, 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"); } @@ -842,7 +843,7 @@ fn wrapped_main() -> ! { } PasswordState::Incorrect(_failcount) => { log::warn!("PDDB formatted, but keys rotated. Formatting PDDB!"); - pddb_os.pddb_format(false, None).expect("couldn't format PDDB"); + pddb_os.pddb_format(false, 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 017ab2a5fdb91c25919f786ae6b235b6a9d22948 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 6 Mar 2026 19:18:05 +0800 Subject: [PATCH 3/6] report QR code when test code is scanned --- services/bao-video/src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/bao-video/src/main.rs b/services/bao-video/src/main.rs index e5c864251..3deaf70c4 100644 --- a/services/bao-video/src/main.rs +++ b/services/bao-video/src/main.rs @@ -621,6 +621,14 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { // stop on the next frame. if let Some(mut envelope) = qr_request.take() { let metadata = format!("{:?}", meta); + if content.starts_with("test://") { + log::info!( + "{}{},{}", + bao1x_hal::board::BOOKEND_START, + content, + bao1x_hal::board::BOOKEND_END + ); + } let acquisition = QrAcquisition { content: Some(content), meta: Some(metadata) }; let mut response = unsafe { From cc7b4740ac0d91cbde69a75ee0c0eb0e00e28785 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 6 Mar 2026 19:18:37 +0800 Subject: [PATCH 4/6] cleanup baosec-lite forming routine --- bao1x-boot/boot1/src/repl.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bao1x-boot/boot1/src/repl.rs b/bao1x-boot/boot1/src/repl.rs index a88582db6..ff78875bf 100644 --- a/bao1x-boot/boot1/src/repl.rs +++ b/bao1x-boot/boot1/src/repl.rs @@ -398,7 +398,7 @@ impl Repl { // this routine is used to initialize baosec products - sets the board type and // erases the off-chip FLASH - use bao1x_api::{baosec::PDDB_LEN, baosec::PDDB_ORIGIN}; + use bao1x_api::baosec::PDDB_ORIGIN; use bao1x_hal::{ board::SPINOR_BULK_ERASE_SIZE, ifram::IframRange, @@ -446,8 +446,15 @@ impl Repl { return Err(Error::help("Supported SPI device not found. Aborting operation.")); } - crate::println!("Erasing from {:x}-{:x}...", 0, PDDB_ORIGIN + PDDB_LEN); - for addr in (0..PDDB_ORIGIN + PDDB_LEN).step_by(SPINOR_BULK_ERASE_SIZE as usize) { + crate::println!("Erasing headers..."); + for addr in (0..SPINOR_BULK_ERASE_SIZE as usize * 2).step_by(SPINOR_BULK_ERASE_SIZE as usize) + { + 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) + { crate::println!(" {:x}...", addr); flash_spim.flash_erase_block(addr, SPINOR_BULK_ERASE_SIZE as usize); } @@ -485,15 +492,13 @@ impl Repl { #[cfg(not(feature = "oem-baosec-lite"))] { crate::println!("{}BOOT1.SETBOARD,{}", BOOKEND_START, BOOKEND_END); - crate::println!("Board type set to baosec, rebooting so boot1 can provision keys!"); + crate::println!("Board type set to baosec"); } #[cfg(feature = "oem-baosec-lite")] { - crate::println!("Board type set to baosec-lite, rebooting so boot1 can provision keys!"); + crate::println!("Board type set to baosec-lite"); crate::println!("{}BOOT1.SETBOARD-LITE,{}", BOOKEND_START, BOOKEND_END); } - let mut rcurst = CSR::new(utra::sysctrl::HW_SYSCTRL_BASE as *mut u32); - rcurst.wo(utra::sysctrl::SFR_RCURST0, 0x55AA); } "ifr" => { // safety: the IFR region is aligned and exists here. It is sealed by hardware in USER mode, From 3035143172ea933b48e4efd4520c07377257ab24 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 6 Mar 2026 21:26:22 +0800 Subject: [PATCH 5/6] fix hosted mode --- services/bao-video/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/services/bao-video/src/main.rs b/services/bao-video/src/main.rs index 3deaf70c4..21b099c7f 100644 --- a/services/bao-video/src/main.rs +++ b/services/bao-video/src/main.rs @@ -621,6 +621,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { // stop on the next frame. if let Some(mut envelope) = qr_request.take() { let metadata = format!("{:?}", meta); + #[cfg(not(feature = "hosted-baosec"))] if content.starts_with("test://") { log::info!( "{}{},{}", From c5b3b71f16501b9060b110ddb1810d107cb1863c Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Mar 2026 19:31:04 +0800 Subject: [PATCH 6/6] add a convenience target to the signer --- baosign.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/baosign.ps1 b/baosign.ps1 index e3e03e636..c7401e5e4 100644 --- a/baosign.ps1 +++ b/baosign.ps1 @@ -9,7 +9,7 @@ param( [Parameter(Mandatory = $true)] - [ValidateSet("baremetal", "dabao", "baosec", "bootloader", "kernel", "loader", "swap", "apps", "boot1", "alt-boot1")] + [ValidateSet("baremetal", "dabao", "baosec", "bootloader", "kernel", "loader", "swap", "apps", "boot1", "alt-boot1", "baosec-lite")] [string]$Config, [Parameter(Mandatory = $false)] @@ -44,6 +44,13 @@ $configurations = @{ @{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } @{ Image = "swap.img"; FunctionCode = "swap" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } ) + "baosec-lite" = @( + @{ Image = "loader.bin"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } + @{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } + @{ Image = "swap.img"; FunctionCode = "swap" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } + @{ Image = "bao1x-boot1.img"; FunctionCode = "boot1" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" }, + @{ Image = "bao1x-alt-boot1.img"; FunctionCode = "loader" ; TargetDir = "target\riscv32imac-unknown-none-elf\release" } + ) "kernel" = @( @{ Image = "xous.img"; FunctionCode = "kernel" ; TargetDir = "target\riscv32imac-unknown-xous-elf\release" } )