Skip to content

Commit

Permalink
Add simple ROM test for SoC interface
Browse files Browse the repository at this point in the history
Create a small ROM image that interacts with the SoC-visible registers.
This is useful for running fast tests during initial Caliptra
integration into SoCs.
  • Loading branch information
jhand2 committed Jul 19, 2024
1 parent 089266b commit 73fa6f6
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
6 changes: 6 additions & 0 deletions builder/src/firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ pub mod rom_tests {
..BASE_FWID
};

pub const SOC_TESTS: FwId = FwId {
bin_name: "soc_tests",
..BASE_FWID
};

pub const TEST_FMC_WITH_UART: FwId = FwId {
crate_name: "caliptra-rom-test-fmc",
bin_name: "caliptra-rom-test-fmc",
Expand Down Expand Up @@ -428,6 +433,7 @@ pub const REGISTERED_FW: &[&FwId] = &[
&driver_tests::TRNG_DRIVER_RESPONDER,
&driver_tests::PERSISTENT,
&rom_tests::ASM_TESTS,
&rom_tests::SOC_TESTS,
&rom_tests::TEST_FMC_WITH_UART,
&rom_tests::FAKE_TEST_FMC_WITH_UART,
&rom_tests::TEST_FMC_INTERACTIVE,
Expand Down
5 changes: 5 additions & 0 deletions rom/dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ fips-test-hooks = ["caliptra-drivers/fips-test-hooks", "caliptra-image-verify/fi
[[bin]]
name = "asm_tests"
path = "test-fw/asm_tests.rs"

[[bin]]
name = "soc_tests"
path = "test-fw/soc_tests.rs"
required-features = ["riscv"]
73 changes: 73 additions & 0 deletions rom/dev/test-fw/soc_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Licensed under the Apache-2.0 license

#![no_std]
#![no_main]

core::arch::global_asm!(include_str!("../src/start.S"));

#[path = "../src/exception.rs"]
mod exception;

use caliptra_drivers::cprintln;
use caliptra_drivers::ExitCtrl;

#[no_mangle]
#[inline(never)]
extern "C" fn exception_handler(exception: &exception::ExceptionRecord) {
cprintln!(
"EXCEPTION mcause=0x{:08X} mscause=0x{:08X} mepc=0x{:08X}",
exception.mcause,
exception.mscause,
exception.mepc
);

ExitCtrl::exit(1);
}

#[no_mangle]
#[inline(never)]
extern "C" fn nmi_handler(exception: &exception::ExceptionRecord) {
cprintln!(
"NMI mcause=0x{:08X} mscause=0x{:08X} mepc=0x{:08X}",
exception.mcause,
exception.mscause,
exception.mepc
);

ExitCtrl::exit(1);
}

#[panic_handler]
#[inline(never)]
#[cfg(not(feature = "std"))]
fn handle_panic(pi: &core::panic::PanicInfo) -> ! {
match pi.location() {
Some(loc) => cprintln!("Panic at file {} line {}", loc.file(), loc.line()),
_ => {}
}
ExitCtrl::exit(1);
}

#[no_mangle]
pub extern "C" fn rom_entry() -> ! {
let mut soc_ifc = unsafe { caliptra_registers::soc_ifc::SocIfcReg::new() };

let fuse_wr_done: u32 = soc_ifc.regs_mut().cptra_fuse_wr_done().read().into();
let valid_pauser: u32 = soc_ifc
.regs_mut()
.cptra_mbox_valid_pauser()
.at(0)
.read()
.into();
let fuse_life_cycle: u32 = soc_ifc.regs_mut().fuse_life_cycle().read().into();

// Print some registers populated by SoC
cprintln!("FUSE_WR_DONE = {}", fuse_wr_done);
cprintln!("VALID_PAUSER[0] = {}", valid_pauser);
cprintln!("FUSE_LIFE_CYCLE = {}", fuse_life_cycle);

// Write to some registers read by SoC
soc_ifc.regs_mut().cptra_boot_status().write(|_| 0xff);

ExitCtrl::exit(0)
}
1 change: 1 addition & 0 deletions rom/dev/tests/rom_integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod test_image_validation;
mod test_mailbox_errors;
mod test_panic_missing;
mod test_rom_integrity;
mod test_soc_integration;
mod test_symbols;
mod test_update_reset;
mod test_version;
Expand Down
30 changes: 30 additions & 0 deletions rom/dev/tests/rom_integration_tests/test_soc_integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed under the Apache-2.0 license

use caliptra_builder::firmware;
use caliptra_hw_model::{BootParams, HwModel, InitParams};

#[test]
fn test_soc_integration() {
let rom = caliptra_builder::build_firmware_rom(&firmware::rom_tests::SOC_TESTS).unwrap();
let mut hw = caliptra_hw_model::new(
InitParams {
rom: &rom,
iccm: &vec![0x55u8; 128 * 1024],
dccm: &vec![0x66u8; 128 * 1024],
..Default::default()
},
BootParams::default(),
)
.unwrap();

let mut output = vec![];
hw.copy_output_until_exit_success(&mut output).unwrap();
assert_eq!(
std::str::from_utf8(&output),
Ok("FUSE_WR_DONE = 1\n\
VALID_PAUSER[0] = 1\n\
FUSE_LIFE_CYCLE = 0\n")
);

assert_eq!(hw.soc_ifc().cptra_boot_status().read(), 0xffu32);
}

0 comments on commit 73fa6f6

Please sign in to comment.