add test code for boot0 write protection

this is a test stub that can be activated in baremetal that
confirms whether or not the bits blown to protect the boot0
region work or not.

This test should be run as part of the check-off process for the golden
image sent for production.
This commit is contained in:
bunnie 2025-10-26 02:01:00 +08:00
parent 6dd2a1f554
commit b8613797e5
No known key found for this signature in database
2 changed files with 13 additions and 6 deletions

View file

@ -76,6 +76,7 @@ dabao-selftest = [
"xous-bio-bdma/baremetal",
"xous-bio-bdma/bao1x",
]
test-boot0-writeprotect = []
verilator-only = []
default = ["bao1x-usb", "dabao-selftest"]

View file

@ -66,15 +66,21 @@ 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.
// we can get rid of this once we've got the settings right on the IFR for this feature.
// need to program in the updated IFR protection bits to test this.
// 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.
if false {
// 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, &region) in regions.iter().enumerate() {
let test_data =