From fb2626b4089641e893f72dbc4bf7118380a10869 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 22 Dec 2025 16:15:22 +0800 Subject: [PATCH 1/6] try "z" flags for smaller code size --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c91b3bd8d..436dcdd09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -155,7 +155,7 @@ strip = false lto = "fat" incremental = true #panic = "abort" # Remove panic output, which can reduce file size -opt-level = "s" # z,s: Optimize for size instead of performance; 1 for easier debugging; comment out for "best performance" (but in Rust 1.72 this causes regressions) +opt-level = "z" # z,s: Optimize for size instead of performance; 1 for easier debugging; comment out for "best performance" (but in Rust 1.72 this causes regressions) # prefer hardware-accelerated versions of services [patch.crates-io] From bfdea56dffdd57a7c9d4c205a5bc97a895ae020f Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 22 Dec 2025 16:15:34 +0800 Subject: [PATCH 2/6] add provisional baosec-lite target what does it take to fit baosec without swap.... --- xtask/src/main.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 009ac10ec..490f078ca 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -794,6 +794,57 @@ fn main() -> Result<(), Box> { // builder.add_feature("modal-testing"); } + Some("baosec-lite") => { + let board = "board-baosec"; + let sigblock_size = 0x300; + update_flash_origin( + "loader/src/platform/bao1x/link.x", + (bao1x_api::LOADER_START + sigblock_size + STATICS_LEN) as u32, + )?; + // select the board + builder.set_board(board); + builder.add_feature(board); + builder.add_loader_feature(board); + builder.add_kernel_feature(board); + builder.set_sigblock_size(sigblock_size); + + // needs a filesystem, which has to be implemented in...128k :-O + let bao_rram_pkgs = [ + "xous-ticktimer", + "keystore", + "xous-log", + "xous-names", + "usb-bao1x", + "bao1x-hal-service", + "modals", + "bao-video", + "vault2", + ] + .to_vec(); + let bao_swap_pkgs = [].to_vec(); + if !builder.is_swap_set() { + // reserve 3MiB for system services: ultimately, "pddb, modals, and bao-video" + builder.set_swap(0, bao1x_api::offsets::baosec::SWAP_RAM_LEN as _); + } + + builder.add_loader_feature("debug-print"); + // the following feature needs to be uncommented if we also enable + builder.add_kernel_feature("v2p"); + builder.target_bao1x_soc(); + + for service in bao_rram_pkgs { + builder.add_service(service, LoaderRegion::Flash); + } + builder.add_services(&get_cratespecs()); + for service in bao_swap_pkgs { + builder.add_service(service, LoaderRegion::Swap); + } + for app in get_cratespecs() { + builder.add_service(&app, LoaderRegion::Swap); + } + // builder.add_feature("modal-testing"); + } + Some("baosec-improper-keystore") => { let board = "board-baosec"; let sigblock_size = 0x300; From c297ca5f2ecdf98fd4e9f1a760d7098f6d9ff991 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 22 Dec 2025 16:16:21 +0800 Subject: [PATCH 3/6] add free space computation on kernel image generation --- tools/src/sign_image.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/src/sign_image.rs b/tools/src/sign_image.rs index 02f31251f..36146448b 100644 --- a/tools/src/sign_image.rs +++ b/tools/src/sign_image.rs @@ -267,6 +267,12 @@ pub fn sign_image( target, ); return Err(String::from("Image doesn't fit").into()); + } else { + println!( + "=== Kernel is {} bytes: {} bytes free remaining ===", + dest_file.len(), + target - dest_file.len() + ); } } Ok(dest_file) From 88a64924813f033f8154936f521adf7f37226e49 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 22 Dec 2025 16:17:08 +0800 Subject: [PATCH 4/6] make the signature check/security elements more clearly optional the problem with it being default in most configurations is that it pulls in a sha-2 and ed25519 dependency into routines that never rely on them. now libs that rely on the sigcheck need to specify the feature explicitly to pull in the depedency. --- libs/bao1x-hal/Cargo.toml | 8 +++----- libs/bao1x-hal/src/lib.rs | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/libs/bao1x-hal/Cargo.toml b/libs/bao1x-hal/Cargo.toml index 67f85735b..1a73e3a09 100644 --- a/libs/bao1x-hal/Cargo.toml +++ b/libs/bao1x-hal/Cargo.toml @@ -70,7 +70,6 @@ board-baosec = [ "utralib/bao1x", "ux-api/board-baosec", "ux-api/std", - "sigcheck", ] # USB form factor token loader-baosec = [ "utralib/bao1x", @@ -79,7 +78,6 @@ loader-baosec = [ "axp2101", "bmp180", "ux-api/loader-baosec", - "sigcheck", ] kernel = [] kernel-baosec = ["utralib/bao1x", "kernel"] @@ -93,11 +91,10 @@ board-baosor = [ "axp2101", "utralib/bao1x", "ux-api/std", - "sigcheck", ] # Precursor form factor loader-baosor = [] -board-dabao = ["utralib/bao1x", "sigcheck"] # Dev board form factor -loader-dabao = ["sigcheck"] +board-dabao = ["utralib/bao1x"] # Dev board form factor +loader-dabao = [] verilator-only = ["utralib/bao1x"] mpw = ["utralib/bao1x"] hdl-test = ["utralib/bao1x"] @@ -107,6 +104,7 @@ debug-print-duart = ["debug-print", "debug-countermeasures"] debug-print-uart = ["debug-print"] debug-countermeasures = [] debug-wfi = [] +security = ["sigcheck"] udma-stress-test = [ ] # For RTL simulation testing - aggravates a key corner case diff --git a/libs/bao1x-hal/src/lib.rs b/libs/bao1x-hal/src/lib.rs index be53682ad..bb66f02c9 100644 --- a/libs/bao1x-hal/src/lib.rs +++ b/libs/bao1x-hal/src/lib.rs @@ -36,7 +36,7 @@ pub mod buram; pub mod clocks; #[cfg(not(feature = "hosted-baosec"))] pub mod coreuser; -#[cfg(all(not(feature = "hosted-baosec"), not(feature = "kernel")))] +#[cfg(feature = "security")] pub mod hardening; #[cfg(feature = "std")] pub mod i2c; @@ -48,7 +48,7 @@ pub mod mbox; pub mod rram; #[cfg(not(feature = "hosted-baosec"))] pub mod rtc; -#[cfg(all(not(feature = "hosted-baosec"), not(feature = "kernel")))] +#[cfg(feature = "security")] pub mod sigcheck; #[cfg(not(feature = "hosted-baosec"))] pub mod sram_trim; From 544a0368fc0bcf3d5ab750bcef6155682b9be5f3 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 22 Dec 2025 16:18:21 +0800 Subject: [PATCH 5/6] setup the security dependency to pull in sigcheck in crates that use it --- apps-baosec/vault2/Cargo.toml | 2 ++ bao1x-boot/boot0/Cargo.toml | 1 + bao1x-boot/boot1/Cargo.toml | 1 + baremetal/Cargo.toml | 1 + loader/Cargo.toml | 2 ++ 5 files changed, 7 insertions(+) diff --git a/apps-baosec/vault2/Cargo.toml b/apps-baosec/vault2/Cargo.toml index dde095ffc..5c3872317 100644 --- a/apps-baosec/vault2/Cargo.toml +++ b/apps-baosec/vault2/Cargo.toml @@ -68,6 +68,7 @@ enum-iterator = "0.6.0" board-baosec = [ "bao1x-hal-service", "ux-api/board-baosec", + "ux-api/bip39entry", "blitstr2/board-baosec", "usb-bao1x/board-baosec", "persistent_store/board-baosec", @@ -75,6 +76,7 @@ board-baosec = [ ] hosted-baosec = [ "bao1x-emu", + "ux-api/bip39entry", "ux-api/hosted-baosec", "usb-bao1x/hosted-baosec", "ctap-crypto/hosted-baosec", diff --git a/bao1x-boot/boot0/Cargo.toml b/bao1x-boot/boot0/Cargo.toml index 3568b3a71..8cbf48c64 100644 --- a/bao1x-boot/boot0/Cargo.toml +++ b/bao1x-boot/boot0/Cargo.toml @@ -24,6 +24,7 @@ bao1x = [ "utralib/bao1x", "linked_list_allocator", "bao1x-hal/loader-baosec", + "bao1x-hal/security", "bao1x-api", # "bao1x-hal/debug-print-duart", ] diff --git a/bao1x-boot/boot1/Cargo.toml b/bao1x-boot/boot1/Cargo.toml index 6547ba5f7..b0453ba65 100644 --- a/bao1x-boot/boot1/Cargo.toml +++ b/bao1x-boot/boot1/Cargo.toml @@ -34,6 +34,7 @@ bao1x = [ "utralib/bao1x", "linked_list_allocator", "bao1x-hal/loader-baosec", + "bao1x-hal/security", # "bao1x-hal/debug-print-duart", "bao1x-api", # needed for the boot logo diff --git a/baremetal/Cargo.toml b/baremetal/Cargo.toml index 675e188d4..c474c6408 100644 --- a/baremetal/Cargo.toml +++ b/baremetal/Cargo.toml @@ -43,6 +43,7 @@ bao1x = [ "utralib/bao1x", "linked_list_allocator", "bao1x-hal/debug-print-uart", + "bao1x-hal/security", "bao1x-api", "digest", "sha2-bao1x", diff --git a/loader/Cargo.toml b/loader/Cargo.toml index 15c09e55c..e62792238 100644 --- a/loader/Cargo.toml +++ b/loader/Cargo.toml @@ -106,12 +106,14 @@ board-baosec = [ "digest", "ux-api/loader-baosec", "aes/loader-baosec", + "bao1x-hal/security", ] board-baosor = ["bao1x-hal/loader-baosor"] board-dabao = [ "bao1x-hal/loader-dabao", "bao1x-hal/board-dabao", "aes/loader-dabao", + "bao1x-hal/security", ] atsama5d27 = ["utralib/atsama5d27", "armv7", "dep:atsama5d27"] From fd44f19fb784db3c01e981c00e39444da5bf78d8 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 22 Dec 2025 16:32:14 +0800 Subject: [PATCH 6/6] "z" doesn't work leads to an 'illegal instruction' panic in the bootloader. turn it off for now. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 436dcdd09..c91b3bd8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -155,7 +155,7 @@ strip = false lto = "fat" incremental = true #panic = "abort" # Remove panic output, which can reduce file size -opt-level = "z" # z,s: Optimize for size instead of performance; 1 for easier debugging; comment out for "best performance" (but in Rust 1.72 this causes regressions) +opt-level = "s" # z,s: Optimize for size instead of performance; 1 for easier debugging; comment out for "best performance" (but in Rust 1.72 this causes regressions) # prefer hardware-accelerated versions of services [patch.crates-io]