diff --git a/bao1x-boot/boot1/src/repl.rs b/bao1x-boot/boot1/src/repl.rs index 6c35dd939..a663e9bc6 100644 --- a/bao1x-boot/boot1/src/repl.rs +++ b/bao1x-boot/boot1/src/repl.rs @@ -515,7 +515,7 @@ impl Repl { } use bao1x_hal::board::{BOOKEND_END, BOOKEND_START}; crate::println!( - "{}PUB_MUT,{},{}", + "{}SEC.PUBMUT-{},{}", BOOKEND_START, if pass { "PASS" } else { "FAIL" }, BOOKEND_END diff --git a/baremetal/Cargo.toml b/baremetal/Cargo.toml index 789ce422d..7458496e5 100644 --- a/baremetal/Cargo.toml +++ b/baremetal/Cargo.toml @@ -77,8 +77,8 @@ dabao-selftest = [ "xous-bio-bdma/baremetal", "xous-bio-bdma/bao1x", ] -test-boot0-writeprotect = [] +ci-security = [] spim-tests = [] verilator-only = [] -default = ["bao1x-usb"] +default = ["bao1x-usb", "ci-security"] diff --git a/baremetal/src/main.rs b/baremetal/src/main.rs index ed10cb787..2906e13bc 100644 --- a/baremetal/src/main.rs +++ b/baremetal/src/main.rs @@ -66,33 +66,6 @@ pub unsafe extern "C" fn rust_entry() -> ! { crate::platform::early_init(); crate::println!("\n~~Baremetal up!~~\n"); - // Test code for figuring out if boot0 write-protect is working or not. - // Keep this around because it's a quick test to make sure that the fuses were set correctly - // on a device. - // - // The test only passes when the IFR protection bits are set. - // Also, this only works once we're in baremetal - boot0 can always write boot0, and - // the coreuser setup doesn't take us out of boot0 until this stage (note that boot1, - // despite being named this, actually operates in the boot0 privilege level). - #[cfg(feature = "test-boot0-writeprotect")] - { - crate::println!("Write protection test"); - let mut rram = bao1x_hal::rram::Reram::new(); - // boot0 should end at 0x2_0000; boot1 ends at 0x6_0000 - // expected result: the first four should have the update fail - // the fifth value (in boot1) should update - let regions = [0xF000, 0x1_1000, 0x1_F000, 0x2_1000, 0x5_0000]; - for (i, ®ion) in regions.iter().enumerate() { - let test_data = - unsafe { core::slice::from_raw_parts((region + utralib::HW_RERAM_MEM) as *const u8, 32) }; - let base = test_data[0]; // increment whatever is in the original area - let test = [base + 1 + i as u8; 32]; - crate::println!("orig ({:x}): {:x?}", region, test_data); - rram.write_slice(region, &test).unwrap(); - crate::println!("update ({:x}): {:x?} vs {:x?}", region, test_data, test); - } - } - #[cfg(feature = "artyvexii")] crate::platform::test_virtual_memory(); diff --git a/baremetal/src/repl.rs b/baremetal/src/repl.rs index 816e40fb8..8884439aa 100644 --- a/baremetal/src/repl.rs +++ b/baremetal/src/repl.rs @@ -7,6 +7,8 @@ use alloc::vec::Vec; #[cfg(feature = "bao1x")] use bao1x_api::*; #[allow(unused_imports)] +use bao1x_hal::board::{BOOKEND_END, BOOKEND_START}; +#[allow(unused_imports)] use utralib::*; #[cfg(any(feature = "artybio", feature = "bao1x-bio"))] use xous_bio_bdma::*; @@ -904,6 +906,56 @@ impl Repl { crate::platform::clockset_wrapper(800_000_000); crate::println!("exiting wfi"); } + #[cfg(feature = "ci-security")] + // write protection only works after we leave the boot environment, thus it has to be tested in + // baremetal + "boot0-wp" => { + crate::println!("Write protection test"); + let mut rram = bao1x_hal::rram::Reram::new(); + // boot0 should end at 0x2_0000; boot1 ends at 0x6_0000 + // expected result: the first four should have the update fail + // the fifth value (in boot1) should update + let regions = + [(false, 0x0), (false, 0xF000), (false, 0x1_1000), (false, 0x1_F000), (true, 0x5_F000)]; + let mut passing = true; + for (i, &(writable, region)) in regions.iter().enumerate() { + let ref_data = unsafe { + core::slice::from_raw_parts((region + utralib::HW_RERAM_MEM) as *const u8, 32) + }; + let base = ref_data[0]; // increment whatever is in the original area + let try_write = [base + 1 + i as u8; 32]; + // crate::println!("orig ({:x}): {:x?}", region, test_data); + rram.write_slice(region, &try_write).unwrap(); + if writable { + if ref_data != try_write { + crate::println!( + "Failure on writeable {:?} ({:x}): {:x?} vs {:x?}", + writable, + region, + ref_data, + try_write + ); + passing = false; + } + } else { + if ref_data == try_write { + crate::println!( + "Failure on writeable {:?} ({:x}): {:x?} vs {:x?}", + writable, + region, + ref_data, + try_write + ); + passing = false; + } + } + } + if passing { + crate::println!("{}SEC.BOOT0WP-PASS,{}", BOOKEND_START, BOOKEND_END); + } else { + crate::println!("{}SEC.BOOT0WP-FAIL,{}", BOOKEND_START, BOOKEND_END); + } + } #[cfg(feature = "bao1x-trng")] "trngro" => { use base64::{Engine as _, engine::general_purpose};