diff --git a/drivers/tests/drivers_integration_tests/main.rs b/drivers/tests/drivers_integration_tests/main.rs index 12d0400014..ae9090ae81 100644 --- a/drivers/tests/drivers_integration_tests/main.rs +++ b/drivers/tests/drivers_integration_tests/main.rs @@ -34,13 +34,13 @@ fn default_init_params() -> InitParams<'static> { fn start_driver_test(test_rom: &'static FwId) -> Result> { let rom = caliptra_builder::build_firmware_rom(test_rom)?; - caliptra_hw_model::new(BootParams { - init_params: InitParams { + caliptra_hw_model::new( + InitParams { rom: &rom, ..default_init_params() }, - ..Default::default() - }) + BootParams::default(), + ) } fn run_driver_test(test_rom: &'static FwId) { @@ -207,16 +207,16 @@ fn test_generate_doe_vectors_when_debug_not_locked() { #[test] fn test_doe_when_debug_not_locked() { let rom = caliptra_builder::build_firmware_rom(&firmware::driver_tests::DOE).unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: *SecurityState::from(0) .set_debug_locked(false) .set_device_lifecycle(DeviceLifecycle::Unprovisioned), ..default_init_params() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); let txn = model.wait_for_mailbox_receive().unwrap(); @@ -301,16 +301,16 @@ fn test_generate_doe_vectors_when_debug_locked() { #[test] fn test_doe_when_debug_locked() { let rom = caliptra_builder::build_firmware_rom(&firmware::driver_tests::DOE).unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: *SecurityState::from(0) .set_debug_locked(true) .set_device_lifecycle(DeviceLifecycle::Unprovisioned), ..default_init_params() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); let txn = model.wait_for_mailbox_receive().unwrap(); @@ -785,14 +785,14 @@ fn test_csrng_with_nibbles( ) { let rom = caliptra_builder::build_firmware_rom(fwid).unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, itrng_nibbles, ..default_init_params() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); model.step_until_exit_success().unwrap(); @@ -854,15 +854,17 @@ fn test_csrng_repetition_count() { .cycle() }); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, itrng_nibbles, ..default_init_params() }, - initial_repcnt_thresh_reg: soc_repcnt_threshold, - ..Default::default() - }) + BootParams { + initial_repcnt_thresh_reg: soc_repcnt_threshold, + ..Default::default() + }, + ) .unwrap(); model.step_until_exit_success().unwrap(); @@ -976,15 +978,17 @@ fn test_csrng_adaptive_proportion() { .high_threshold(HI_THRESHOLD) .low_threshold(LO_THRESHOLD); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, itrng_nibbles, ..default_init_params() }, - initial_adaptp_thresh_reg: Some(threshold_reg), - ..Default::default() - }) + BootParams { + initial_adaptp_thresh_reg: Some(threshold_reg), + ..Default::default() + }, + ) .unwrap(); model.step_until_exit_success().unwrap(); @@ -1016,15 +1020,15 @@ fn test_trng_in_itrng_mode() { let rom = caliptra_builder::build_firmware_rom(&firmware::driver_tests::TRNG_DRIVER_RESPONDER) .unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, itrng_nibbles: Box::new(trng_nibbles()), trng_mode: Some(TrngMode::Internal), ..default_init_params() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); let trng_block = model.mailbox_execute(0, &[]).unwrap(); @@ -1071,8 +1075,8 @@ fn test_trng_in_etrng_mode() { let rom = caliptra_builder::build_firmware_rom(&firmware::driver_tests::TRNG_DRIVER_RESPONDER) .unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, itrng_nibbles: Box::new([].iter().copied()), etrng_responses: Box::new( @@ -1091,8 +1095,8 @@ fn test_trng_in_etrng_mode() { trng_mode: Some(TrngMode::External), ..default_init_params() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); let trng_block = model.mailbox_execute(0, &[]).unwrap(); diff --git a/fmc/tests/fmc_integration_tests/test_hand_off.rs b/fmc/tests/fmc_integration_tests/test_hand_off.rs index c6407328aa..34b89930f8 100644 --- a/fmc/tests/fmc_integration_tests/test_hand_off.rs +++ b/fmc/tests/fmc_integration_tests/test_hand_off.rs @@ -13,14 +13,16 @@ fn test_hand_off() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); let mut output = vec![]; diff --git a/fmc/tests/fmc_integration_tests/test_rtalias.rs b/fmc/tests/fmc_integration_tests/test_rtalias.rs index f0454a96a9..a36abc35ab 100644 --- a/fmc/tests/fmc_integration_tests/test_rtalias.rs +++ b/fmc/tests/fmc_integration_tests/test_rtalias.rs @@ -45,14 +45,16 @@ fn test_boot_status_reporting() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(RT_ALIAS_MEASUREMENT_COMPLETE, true); @@ -74,14 +76,16 @@ fn test_fht_info() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); let data = hw.mailbox_execute(TEST_CMD_READ_FHT, &[]).unwrap().unwrap(); @@ -108,14 +112,16 @@ fn test_pcr_log() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image1.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image1.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); let data = hw.mailbox_execute(TEST_CMD_READ_FHT, &[]).unwrap().unwrap(); diff --git a/hw-model/src/lib.rs b/hw-model/src/lib.rs index abcbd3458f..6a7e05d454 100644 --- a/hw-model/src/lib.rs +++ b/hw-model/src/lib.rs @@ -103,8 +103,11 @@ pub fn new_unbooted(params: InitParams) -> Result /// (optionally) uploading firmware. Most test cases that need to construct a /// HwModel should use this function over [`HwModel::new()`] and /// [`crate::new_unbooted`]. -pub fn new(params: BootParams) -> Result> { - DefaultHwModel::new(params) +pub fn new( + init_params: InitParams, + boot_params: BootParams, +) -> Result> { + DefaultHwModel::new(init_params, boot_params) } #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -161,8 +164,6 @@ pub struct InitParams<'a> { // When None, use the itrng compile-time feature to decide which mode to use. pub trng_mode: Option, - pub wdt_timeout_cycles: u64, - // If true (and the HwModel supports it), initialize the SRAM with random // data. This will likely result in a ECC double-bit error if the CPU // attempts to read uninitialized memory. @@ -203,7 +204,6 @@ impl<'a> Default for InitParams<'a> { } else { TrngMode::External }), - wdt_timeout_cycles: EXPECTED_CALIPTRA_BOOT_TIME_IN_CYCLES, random_sram_puf: true, trace_path: None, } @@ -250,6 +250,7 @@ pub struct BootParams<'a> { pub initial_repcnt_thresh_reg: Option, pub initial_adaptp_thresh_reg: Option, pub valid_pauser: u32, + pub wdt_timeout_cycles: u64, } impl<'a> Default for BootParams<'a> { @@ -262,6 +263,7 @@ impl<'a> Default for BootParams<'a> { initial_repcnt_thresh_reg: Default::default(), initial_adaptp_thresh_reg: Default::default(), valid_pauser: 0x1, + wdt_timeout_cycles: EXPECTED_CALIPTRA_BOOT_TIME_IN_CYCLES, } } } @@ -476,15 +478,13 @@ pub trait HwModel { /// Create a model, and boot it to the point where CPU execution can /// occur. This includes programming the fuses, initializing the /// boot_fsm state machine, and (optionally) uploading firmware. - fn new(run_params: BootParams) -> Result> + fn new(init_params: InitParams, boot_params: BootParams) -> Result> where Self: Sized, { - let wdt_timeout_cycles = run_params.init_params.wdt_timeout_cycles; + let init_params_summary = init_params.summary(); - let init_params_summary = run_params.init_params.summary(); - - let mut hw: Self = HwModel::new_unbooted(run_params.init_params)?; + let mut hw: Self = HwModel::new_unbooted(init_params)?; let hw_rev_id = hw.soc_ifc().cptra_hw_rev_id().read(); println!( "Using hardware-model {} trng={:?} hw_rev_id={{cptra_generation=0x{:04x}, soc_stepping_id={:04x}}}", @@ -492,61 +492,74 @@ pub trait HwModel { ); println!("{init_params_summary:#?}"); - hw.init_fuses(&run_params.fuses); + hw.boot(boot_params)?; + + Ok(hw) + } + + fn boot(&mut self, boot_params: BootParams) -> Result<(), Box> + where + Self: Sized, + { + self.init_fuses(&boot_params.fuses); - hw.soc_ifc() + self.soc_ifc() .cptra_dbg_manuf_service_reg() - .write(|_| run_params.initial_dbg_manuf_service_reg); + .write(|_| boot_params.initial_dbg_manuf_service_reg); - hw.soc_ifc() + self.soc_ifc() .cptra_wdt_cfg() .at(0) - .write(|_| wdt_timeout_cycles as u32); + .write(|_| boot_params.wdt_timeout_cycles as u32); - hw.soc_ifc() + self.soc_ifc() .cptra_wdt_cfg() .at(1) - .write(|_| (wdt_timeout_cycles >> 32) as u32); + .write(|_| (boot_params.wdt_timeout_cycles >> 32) as u32); - if let Some(reg) = run_params.initial_repcnt_thresh_reg { - hw.soc_ifc().cptra_i_trng_entropy_config_1().write(|_| reg); + if let Some(reg) = boot_params.initial_repcnt_thresh_reg { + self.soc_ifc() + .cptra_i_trng_entropy_config_1() + .write(|_| reg); } - if let Some(reg) = run_params.initial_adaptp_thresh_reg { - hw.soc_ifc().cptra_i_trng_entropy_config_0().write(|_| reg); + if let Some(reg) = boot_params.initial_adaptp_thresh_reg { + self.soc_ifc() + .cptra_i_trng_entropy_config_0() + .write(|_| reg); } // Set up the PAUSER as valid for the mailbox (using index 0) - hw.soc_ifc() + self.soc_ifc() .cptra_mbox_valid_pauser() .at(0) - .write(|_| run_params.valid_pauser); - hw.soc_ifc() + .write(|_| boot_params.valid_pauser); + self.soc_ifc() .cptra_mbox_pauser_lock() .at(0) .write(|w| w.lock(true)); - writeln!(hw.output().logger(), "writing to cptra_bootfsm_go")?; - hw.soc_ifc().cptra_bootfsm_go().write(|w| w.go(true)); + writeln!(self.output().logger(), "writing to cptra_bootfsm_go")?; + self.soc_ifc().cptra_bootfsm_go().write(|w| w.go(true)); - hw.step(); + self.step(); - if let Some(fw_image) = run_params.fw_image { + if let Some(fw_image) = boot_params.fw_image { const MAX_WAIT_CYCLES: u32 = 20_000_000; let mut cycles = 0; - while !hw.ready_for_fw() { - hw.step(); + while !self.ready_for_fw() { + self.step(); cycles += 1; if cycles > MAX_WAIT_CYCLES { return Err(ModelError::ReadyForFirmwareTimeout { cycles }.into()); } } - writeln!(hw.output().logger(), "ready_for_fw is high")?; - hw.cover_fw_mage(fw_image); - hw.upload_firmware(fw_image)?; + writeln!(self.output().logger(), "ready_for_fw is high")?; + self.cover_fw_mage(fw_image); + self.upload_firmware(fw_image)?; } - Ok(hw) + Ok(()) } /// The type name of this model @@ -1330,26 +1343,26 @@ mod tests { #[test] fn test_execution() { - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &gen_image_hi(), ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); model.step_until_output("hii").unwrap(); } #[test] fn test_output_failure() { - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &gen_image_hi(), ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); if cfg!(feature = "fpga_realtime") { @@ -1375,13 +1388,13 @@ mod tests { caliptra_builder::build_firmware_rom(&firmware::hw_model_tests::MAILBOX_RESPONDER) .unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); // Send command that echoes the command and input message @@ -1430,13 +1443,13 @@ mod tests { let rom = caliptra_builder::build_firmware_rom(&firmware::hw_model_tests::MAILBOX_SENDER) .unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); // Test 8-byte request, respond-with-success @@ -1481,13 +1494,13 @@ mod tests { caliptra_builder::build_firmware_rom(&firmware::hw_model_tests::MAILBOX_RESPONDER) .unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); assert_eq!( @@ -1596,13 +1609,13 @@ mod tests { let rom = caliptra_builder::build_firmware_rom(&firmware::hw_model_tests::MAILBOX_RESPONDER) .unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); // Success diff --git a/hw-model/tests/model_tests.rs b/hw-model/tests/model_tests.rs index 637111654b..7405904311 100644 --- a/hw-model/tests/model_tests.rs +++ b/hw-model/tests/model_tests.rs @@ -7,27 +7,27 @@ use caliptra_test_harness_types as harness; fn run_fw_elf(elf: &[u8]) -> DefaultHwModel { let rom = caliptra_builder::elf2rom(elf).unwrap(); - let model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let model = caliptra_hw_model::new( + InitParams { rom: &rom, random_sram_puf: false, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); model } fn run_fw_elf_with_rand_puf(elf: &[u8]) -> DefaultHwModel { let rom = caliptra_builder::elf2rom(elf).unwrap(); - let model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let model = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); model } diff --git a/rom/dev/tests/rom_integration_tests/helpers.rs b/rom/dev/tests/rom_integration_tests/helpers.rs index d463773b16..f946b51bc1 100644 --- a/rom/dev/tests/rom_integration_tests/helpers.rs +++ b/rom/dev/tests/rom_integration_tests/helpers.rs @@ -17,15 +17,17 @@ pub fn build_hw_model_and_image_bundle( pub fn build_hw_model(fuses: Fuses) -> DefaultHwModel { let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - caliptra_hw_model::new(BootParams { - init_params: InitParams { + caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap() } diff --git a/rom/dev/tests/rom_integration_tests/rv32_unit_tests.rs b/rom/dev/tests/rom_integration_tests/rv32_unit_tests.rs index b4505cb106..cb181cc77d 100644 --- a/rom/dev/tests/rom_integration_tests/rv32_unit_tests.rs +++ b/rom/dev/tests/rom_integration_tests/rv32_unit_tests.rs @@ -6,15 +6,15 @@ use caliptra_hw_model::{BootParams, HwModel, InitParams}; #[test] fn test_asm() { let rom = caliptra_builder::build_firmware_rom(&firmware::rom_tests::ASM_TESTS).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, iccm: &vec![0x55u8; 128 * 1024], dccm: &vec![0x66u8; 128 * 1024], ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); let mut output = vec![]; diff --git a/rom/dev/tests/rom_integration_tests/test_cfi.rs b/rom/dev/tests/rom_integration_tests/test_cfi.rs index 7ee3832400..1641aac113 100644 --- a/rom/dev/tests/rom_integration_tests/test_cfi.rs +++ b/rom/dev/tests/rom_integration_tests/test_cfi.rs @@ -46,13 +46,13 @@ fn test_memcpy_not_called_before_cfi_init() { let rom = caliptra_builder::elf2rom(&elf_bytes).unwrap(); - let mut hw = caliptra_hw_model::ModelEmulated::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::ModelEmulated::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); hw.step_until_boot_status(RomBootStatus::CfiInitialized.into(), true); diff --git a/rom/dev/tests/rom_integration_tests/test_cpu_fault.rs b/rom/dev/tests/rom_integration_tests/test_cpu_fault.rs index 878eaa0901..0623b24207 100644 --- a/rom/dev/tests/rom_integration_tests/test_cpu_fault.rs +++ b/rom/dev/tests/rom_integration_tests/test_cpu_fault.rs @@ -27,13 +27,13 @@ fn test_cpu_fault() { rom[rom_entry_offset..rom_entry_offset + illegal_instruction.len()] .copy_from_slice(&illegal_instruction); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); hw.step_until(|m| m.soc_ifc().cptra_fw_error_fatal().read() == GLOBAL_EXCEPTION); diff --git a/rom/dev/tests/rom_integration_tests/test_dice_derivations.rs b/rom/dev/tests/rom_integration_tests/test_dice_derivations.rs index 1bc8e8bdc8..6339f4d955 100644 --- a/rom/dev/tests/rom_integration_tests/test_dice_derivations.rs +++ b/rom/dev/tests/rom_integration_tests/test_dice_derivations.rs @@ -98,14 +98,16 @@ fn test_cold_reset_success() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); @@ -123,15 +125,17 @@ fn test_cold_reset_no_rng() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - initial_dbg_manuf_service_reg: 0x2, // Disable RNG - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + initial_dbg_manuf_service_reg: 0x2, // Disable RNG + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); diff --git a/rom/dev/tests/rom_integration_tests/test_fake_rom.rs b/rom/dev/tests/rom_integration_tests/test_fake_rom.rs index b43fd711a2..230ca62702 100644 --- a/rom/dev/tests/rom_integration_tests/test_fake_rom.rs +++ b/rom/dev/tests/rom_integration_tests/test_fake_rom.rs @@ -28,13 +28,13 @@ const PUB_KEY_Y: [u8; 48] = [ #[test] fn test_skip_kats() { let rom = caliptra_builder::build_firmware_rom(&ROM_FAKE_WITH_UART).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); hw.step_until_boot_status(caliptra_common::RomBootStatus::CfiInitialized.into(), false); @@ -51,14 +51,14 @@ fn test_fake_rom_production_error() { *SecurityState::default().set_device_lifecycle(DeviceLifecycle::Production); let rom = caliptra_builder::build_firmware_rom(&ROM_FAKE_WITH_UART).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); // Let it run until a fatal error (should fail very early) @@ -78,15 +78,17 @@ fn test_fake_rom_production_enabled() { *SecurityState::default().set_device_lifecycle(DeviceLifecycle::Production); let rom = caliptra_builder::build_firmware_rom(&ROM_FAKE_WITH_UART).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state, ..Default::default() }, - initial_dbg_manuf_service_reg: DBG_MANUF_FAKE_ROM_PROD_EN, - ..Default::default() - }) + BootParams { + initial_dbg_manuf_service_reg: DBG_MANUF_FAKE_ROM_PROD_EN, + ..Default::default() + }, + ) .unwrap(); // Wait for ready for FW @@ -97,15 +99,17 @@ fn test_fake_rom_production_enabled() { fn test_fake_rom_fw_load() { let fuses = Fuses::default(); let rom = caliptra_builder::build_firmware_rom(&ROM_FAKE_WITH_UART).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); // Build the image we are going to send to ROM to load @@ -134,15 +138,17 @@ fn test_fake_rom_fw_load() { fn test_fake_rom_update_reset() { let fuses = Fuses::default(); let rom = caliptra_builder::build_firmware_rom(&ROM_FAKE_WITH_UART).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( @@ -185,16 +191,18 @@ fn test_image_verify() { const DBG_MANUF_FAKE_ROM_IMAGE_VERIFY: u32 = 0x1 << 31; // BIT 31 turns on image verify let fuses = Fuses::default(); let rom = caliptra_builder::build_firmware_rom(&ROM_FAKE_WITH_UART).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - initial_dbg_manuf_service_reg: DBG_MANUF_FAKE_ROM_IMAGE_VERIFY, - ..Default::default() - }) + BootParams { + fuses, + initial_dbg_manuf_service_reg: DBG_MANUF_FAKE_ROM_IMAGE_VERIFY, + ..Default::default() + }, + ) .unwrap(); let mut image_bundle = caliptra_builder::build_and_sign_image( @@ -233,13 +241,13 @@ fn test_fake_rom_version() { const FAKE_ROM_VERSION: u16 = 0xFFFF; let rom = caliptra_builder::build_firmware_rom(&ROM_FAKE_WITH_UART).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); // Wait for ready for FW diff --git a/rom/dev/tests/rom_integration_tests/test_fmcalias_derivation.rs b/rom/dev/tests/rom_integration_tests/test_fmcalias_derivation.rs index 56b3720421..92b852991a 100644 --- a/rom/dev/tests/rom_integration_tests/test_fmcalias_derivation.rs +++ b/rom/dev/tests/rom_integration_tests/test_fmcalias_derivation.rs @@ -145,15 +145,17 @@ fn test_pcr_log() { ..Default::default() }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); const FMC_SVN: u32 = 1; @@ -247,15 +249,17 @@ fn test_pcr_log_no_owner_key_digest_fuse() { ..Default::default() }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_options = ImageOptions { @@ -337,15 +341,17 @@ fn test_pcr_log_fmc_fuse_svn() { ..Default::default() }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_options = ImageOptions { @@ -476,15 +482,17 @@ fn test_pcr_log_across_update_reset() { ..Default::default() }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_options = ImageOptions { @@ -575,15 +583,17 @@ fn test_fuse_log() { }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_options = ImageOptions { @@ -706,14 +716,16 @@ fn test_fuse_log() { #[test] fn test_fht_info() { let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fuses: Fuses::default(), - ..Default::default() - }) + BootParams { + fuses: Fuses::default(), + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( @@ -745,15 +757,17 @@ fn test_check_no_lms_info_in_datavault_on_lms_unavailable() { ..Default::default() }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( @@ -791,15 +805,17 @@ fn test_check_rom_cold_boot_status_reg() { ..Default::default() }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( @@ -834,15 +850,17 @@ fn test_check_rom_cold_boot_status_reg() { fn test_upload_single_measurement() { let fuses = Fuses::default(); let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( @@ -900,15 +918,17 @@ fn test_upload_single_measurement() { fn test_upload_measurement_limit() { let fuses = Fuses::default(); let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( @@ -987,15 +1007,17 @@ fn test_upload_measurement_limit() { fn test_upload_no_measurement() { let fuses = Fuses::default(); let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( diff --git a/rom/dev/tests/rom_integration_tests/test_image_validation.rs b/rom/dev/tests/rom_integration_tests/test_image_validation.rs index 8b738bd750..6b9d9676dd 100644 --- a/rom/dev/tests/rom_integration_tests/test_image_validation.rs +++ b/rom/dev/tests/rom_integration_tests/test_image_validation.rs @@ -200,14 +200,16 @@ fn test_preamble_vendor_ecc_pubkey_revocation() { ..Default::default() }; - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = @@ -261,14 +263,16 @@ fn test_preamble_vendor_lms_pubkey_revocation() { ..Default::default() }; - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = @@ -316,14 +320,16 @@ fn test_preamble_vendor_lms_optional_no_pubkey_revocation_check() { ..Default::default() }; - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = @@ -807,15 +813,17 @@ fn test_header_verify_owner_sig_zero_fuses() { let fuses = caliptra_hw_model::Fuses::default(); let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); hw.upload_firmware(&image_bundle.to_bytes().unwrap()) @@ -852,15 +860,17 @@ fn test_header_verify_owner_ecc_sig_zero_pubkey_x() { }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); assert_eq!( @@ -905,15 +915,17 @@ fn test_header_verify_owner_ecc_sig_zero_pubkey_y() { }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); assert_eq!( @@ -949,15 +961,17 @@ fn test_header_verify_owner_ecc_sig_zero_signature_r() { }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); // Set owner_sig.r to zero. @@ -996,15 +1010,17 @@ fn test_header_verify_owner_ecc_sig_zero_signature_s() { }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); // Set owner_sig.s to zero. @@ -1043,15 +1059,17 @@ fn test_header_verify_owner_ecc_sig_invalid_signature_r() { }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); // Set an invalid owner_sig.r. @@ -1090,15 +1108,17 @@ fn test_header_verify_owner_ecc_sig_invalid_signature_s() { }; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); // Set an invalid owner_sig.s. @@ -1805,15 +1825,17 @@ fn test_runtime_svn_less_than_fuse_svn() { fn cert_test_with_custom_dates() { let fuses = Fuses::default(); let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let mut opts = ImageOptions::default(); @@ -1880,15 +1902,17 @@ fn cert_test_with_custom_dates() { fn cert_test() { let fuses = Fuses::default(); let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( @@ -1940,15 +1964,17 @@ fn cert_test_with_ueid() { fuses.idevid_cert_attr[IdevidCertAttr::UeidType as usize] = 1; let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let opts = ImageOptions::default(); @@ -2267,13 +2293,13 @@ fn fmcalias_cert(ldevid_cert: &X509, output: &str) -> X509 { #[test] fn test_max_fw_image() { let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( diff --git a/rom/dev/tests/rom_integration_tests/test_rom_integrity.rs b/rom/dev/tests/rom_integration_tests/test_rom_integrity.rs index 5784b84340..9369f1673c 100644 --- a/rom/dev/tests/rom_integration_tests/test_rom_integrity.rs +++ b/rom/dev/tests/rom_integration_tests/test_rom_integrity.rs @@ -29,13 +29,13 @@ fn test_rom_integrity_failure() { // location in the image as that might make the CPU crazy) rom[rom_info_offset + 9] ^= 1; - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - ..Default::default() - }) + BootParams::default(), + ) .unwrap(); loop { @@ -65,14 +65,16 @@ fn test_read_rom_info_from_fmc() { .to_bytes() .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle), + ..Default::default() + }, + ) .unwrap(); // 0x1000_0008 is test-fmc/read_rom_info() diff --git a/rom/dev/tests/rom_integration_tests/test_update_reset.rs b/rom/dev/tests/rom_integration_tests/test_update_reset.rs index 32ec9e6e93..4d8df2fdb3 100644 --- a/rom/dev/tests/rom_integration_tests/test_update_reset.rs +++ b/rom/dev/tests/rom_integration_tests/test_update_reset.rs @@ -33,14 +33,16 @@ fn test_update_reset_success() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); @@ -77,14 +79,16 @@ fn test_update_reset_no_mailbox_cmd() { ImageOptions::default(), ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); @@ -123,14 +127,16 @@ fn test_update_reset_non_fw_load_cmd() { ImageOptions::default(), ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); @@ -166,14 +172,16 @@ fn test_update_reset_verify_image_failure() { ImageOptions::default(), ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); @@ -215,14 +223,16 @@ fn test_update_reset_boot_status() { ImageOptions::default(), ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); @@ -276,14 +286,16 @@ fn test_update_reset_vendor_ecc_pub_key_idx_dv_mismatch() { image_options, ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); @@ -362,18 +374,20 @@ fn test_update_reset_vendor_lms_pub_key_idx_dv_mismatch() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fuses: caliptra_hw_model::Fuses { - lms_verify: true, + BootParams { + fuses: caliptra_hw_model::Fuses { + lms_verify: true, + ..Default::default() + }, + fw_image: Some(&image_bundle.to_bytes().unwrap()), ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); @@ -406,14 +420,16 @@ fn test_check_rom_update_reset_status_reg() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); @@ -510,14 +526,16 @@ fn test_update_reset_max_fw_image() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fw_image: Some(&image_bundle.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image_bundle.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); hw.step_until_boot_status(ColdResetComplete.into(), true); diff --git a/rom/dev/tests/rom_integration_tests/test_warm_reset.rs b/rom/dev/tests/rom_integration_tests/test_warm_reset.rs index 32cb818836..68bf3a9a33 100644 --- a/rom/dev/tests/rom_integration_tests/test_warm_reset.rs +++ b/rom/dev/tests/rom_integration_tests/test_warm_reset.rs @@ -41,21 +41,23 @@ fn test_warm_reset_success() { let owner_pk_hash = bytes_to_be_words_48(&sha384(image.manifest.preamble.owner_pub_keys.as_bytes())); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state, ..Default::default() }, - fuses: Fuses { - key_manifest_pk_hash: vendor_pk_hash, - owner_pk_hash, - fmc_key_manifest_svn: 0b1111111, + BootParams { + fuses: Fuses { + key_manifest_pk_hash: vendor_pk_hash, + owner_pk_hash, + fmc_key_manifest_svn: 0b1111111, + ..Default::default() + }, + fw_image: Some(&image.to_bytes().unwrap()), ..Default::default() }, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + ) .unwrap(); // Wait for boot diff --git a/rom/dev/tests/rom_integration_tests/test_wdt_activation_and_stoppage.rs b/rom/dev/tests/rom_integration_tests/test_wdt_activation_and_stoppage.rs index 85f8bdc2fe..ab7cf03df2 100644 --- a/rom/dev/tests/rom_integration_tests/test_wdt_activation_and_stoppage.rs +++ b/rom/dev/tests/rom_integration_tests/test_wdt_activation_and_stoppage.rs @@ -24,14 +24,14 @@ fn test_wdt_activation_and_stoppage() { let rom = caliptra_builder::build_firmware_rom(caliptra_builder::firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(caliptra_hw_model::BootParams { - init_params: caliptra_hw_model::InitParams { + let mut hw = caliptra_hw_model::new( + caliptra_hw_model::InitParams { rom: &rom, security_state, ..Default::default() }, - ..Default::default() - }) + caliptra_hw_model::BootParams::default(), + ) .unwrap(); if cfg!(feature = "fpga_realtime") { @@ -66,14 +66,14 @@ fn test_wdt_not_enabled_on_debug_part() { .set_device_lifecycle(DeviceLifecycle::Unprovisioned); let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(caliptra_hw_model::BootParams { - init_params: caliptra_hw_model::InitParams { + let mut hw = caliptra_hw_model::new( + caliptra_hw_model::InitParams { rom: &rom, security_state, ..Default::default() }, - ..Default::default() - }) + caliptra_hw_model::BootParams::default(), + ) .unwrap(); // Confirm security state is as expected. @@ -95,15 +95,17 @@ fn test_rom_wdt_timeout() { .set_device_lifecycle(DeviceLifecycle::Unprovisioned); let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(caliptra_hw_model::BootParams { - init_params: caliptra_hw_model::InitParams { + let mut hw = caliptra_hw_model::new( + caliptra_hw_model::InitParams { rom: &rom, security_state, + ..Default::default() + }, + caliptra_hw_model::BootParams { wdt_timeout_cycles: 1_000_000, ..Default::default() }, - ..Default::default() - }) + ) .unwrap(); hw.step_until(|m| m.soc_ifc().cptra_fw_error_fatal().read() == WDT_EXPIRED); diff --git a/runtime/tests/runtime_integration_tests/common.rs b/runtime/tests/runtime_integration_tests/common.rs index 1ef9551eac..b6da89b5f5 100644 --- a/runtime/tests/runtime_integration_tests/common.rs +++ b/runtime/tests/runtime_integration_tests/common.rs @@ -73,11 +73,13 @@ pub fn run_rt_test( let image = caliptra_builder::build_and_sign_image(&FMC_WITH_UART, runtime_fwid, image_options) .unwrap(); - let mut model = caliptra_hw_model::new(BootParams { + let mut model = caliptra_hw_model::new( init_params, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); model.step_until(|m| m.soc_ifc().cptra_flow_status().read().ready_for_fw()); diff --git a/runtime/tests/runtime_integration_tests/test_boot.rs b/runtime/tests/runtime_integration_tests/test_boot.rs index a0cb918664..c5f4bb818b 100644 --- a/runtime/tests/runtime_integration_tests/test_boot.rs +++ b/runtime/tests/runtime_integration_tests/test_boot.rs @@ -167,15 +167,17 @@ fn test_boot_tci_data() { fn test_measurement_in_measurement_log_added_to_dpe() { let fuses = Fuses::default(); let rom = caliptra_builder::rom_for_fw_integration_tests().unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( diff --git a/runtime/tests/runtime_integration_tests/test_info.rs b/runtime/tests/runtime_integration_tests/test_info.rs index b8edda7736..4b13cc6097 100644 --- a/runtime/tests/runtime_integration_tests/test_info.rs +++ b/runtime/tests/runtime_integration_tests/test_info.rs @@ -59,11 +59,13 @@ fn test_fw_info() { caliptra_builder::build_and_sign_image(&FMC_WITH_UART, &APP_WITH_UART, image_opts10) .unwrap(); - let mut model = caliptra_hw_model::new(BootParams { + let mut model = caliptra_hw_model::new( init_params, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fw_image: Some(&image.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); let rom_info = find_rom_info(&rom).unwrap(); diff --git a/runtime/tests/runtime_integration_tests/test_pauser_privilege_levels.rs b/runtime/tests/runtime_integration_tests/test_pauser_privilege_levels.rs index cc4d888af0..36d2a03828 100644 --- a/runtime/tests/runtime_integration_tests/test_pauser_privilege_levels.rs +++ b/runtime/tests/runtime_integration_tests/test_pauser_privilege_levels.rs @@ -404,15 +404,17 @@ fn test_stash_measurement_pl_context_thresholds() { fn test_measurement_log_pl_context_threshold() { let fuses = Fuses::default(); let rom = caliptra_builder::rom_for_fw_integration_tests().unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: SecurityState::from(fuses.life_cycle as u32), ..Default::default() }, - fuses, - ..Default::default() - }) + BootParams { + fuses, + ..Default::default() + }, + ) .unwrap(); let image_bundle = caliptra_builder::build_and_sign_image( diff --git a/runtime/tests/runtime_integration_tests/test_warm_reset.rs b/runtime/tests/runtime_integration_tests/test_warm_reset.rs index a74b5f416d..69d2637166 100644 --- a/runtime/tests/runtime_integration_tests/test_warm_reset.rs +++ b/runtime/tests/runtime_integration_tests/test_warm_reset.rs @@ -44,21 +44,23 @@ fn test_rt_journey_pcr_validation() { let owner_pk_hash = bytes_to_be_words_48(&sha384(image.manifest.preamble.owner_pub_keys.as_bytes())); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, security_state, ..Default::default() }, - fuses: Fuses { - key_manifest_pk_hash: vendor_pk_hash, - owner_pk_hash, - fmc_key_manifest_svn: 0b1111111, + BootParams { + fuses: Fuses { + key_manifest_pk_hash: vendor_pk_hash, + owner_pk_hash, + fmc_key_manifest_svn: 0b1111111, + ..Default::default() + }, + fw_image: Some(&image.to_bytes().unwrap()), ..Default::default() }, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + ) .unwrap(); // Wait for boot @@ -107,21 +109,23 @@ fn test_mbox_busy_during_warm_reset() { let owner_pk_hash = bytes_to_be_words_48(&sha384(image.manifest.preamble.owner_pub_keys.as_bytes())); - let mut model = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut model = caliptra_hw_model::new( + InitParams { rom: &rom, security_state, ..Default::default() }, - fuses: Fuses { - key_manifest_pk_hash: vendor_pk_hash, - owner_pk_hash, - fmc_key_manifest_svn: 0b1111111, + BootParams { + fuses: Fuses { + key_manifest_pk_hash: vendor_pk_hash, + owner_pk_hash, + fmc_key_manifest_svn: 0b1111111, + ..Default::default() + }, + fw_image: Some(&image.to_bytes().unwrap()), ..Default::default() }, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + ) .unwrap(); // Wait for boot diff --git a/test/src/lib.rs b/test/src/lib.rs index feff45adb5..54dd4c5ebe 100644 --- a/test/src/lib.rs +++ b/test/src/lib.rs @@ -33,6 +33,7 @@ pub fn run_test( test_fwid: Option<&'static FwId>, test_image_options: Option, init_params: Option, + boot_params: Option, ) -> DefaultHwModel { let runtime_fwid = test_fwid.unwrap_or(&APP_WITH_UART); @@ -55,13 +56,21 @@ pub fn run_test( let image = caliptra_builder::build_and_sign_image(&FMC_WITH_UART, runtime_fwid, image_options) .unwrap(); + let image_bytes = image.to_bytes().unwrap(); - let mut model = caliptra_hw_model::new(BootParams { - init_params, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) - .unwrap(); + let boot_params = boot_params.unwrap_or(BootParams::default()); + + // Use image in boot_params if provided + // Otherwise, add our newly built image + let boot_params = match boot_params.fw_image { + Some(_) => boot_params, + None => BootParams { + fw_image: Some(&image_bytes), + ..boot_params + }, + }; + + let mut model = caliptra_hw_model::new(init_params, boot_params).unwrap(); model.step_until(|m| m.soc_ifc().cptra_flow_status().read().ready_for_fw()); diff --git a/test/tests/caliptra_integration_tests/fake_collateral_boot_test.rs b/test/tests/caliptra_integration_tests/fake_collateral_boot_test.rs index 59c9e96c65..cfc5c4fd6a 100755 --- a/test/tests/caliptra_integration_tests/fake_collateral_boot_test.rs +++ b/test/tests/caliptra_integration_tests/fake_collateral_boot_test.rs @@ -65,20 +65,22 @@ fn fake_boot_test() { let owner_pk_hash = bytes_to_be_words_48(&sha384(image.manifest.preamble.owner_pub_keys.as_bytes())); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, ..Default::default() }, - fuses: Fuses { - key_manifest_pk_hash: vendor_pk_hash, - owner_pk_hash, - fmc_key_manifest_svn: 0b1111111, + BootParams { + fuses: Fuses { + key_manifest_pk_hash: vendor_pk_hash, + owner_pk_hash, + fmc_key_manifest_svn: 0b1111111, + ..Default::default() + }, + fw_image: Some(&image.to_bytes().unwrap()), ..Default::default() }, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + ) .unwrap(); let mut output = vec![]; diff --git a/test/tests/caliptra_integration_tests/jtag_test.rs b/test/tests/caliptra_integration_tests/jtag_test.rs index 27f3d6274a..91bcfa672f 100644 --- a/test/tests/caliptra_integration_tests/jtag_test.rs +++ b/test/tests/caliptra_integration_tests/jtag_test.rs @@ -106,16 +106,18 @@ fn gdb_test() { lms_verify: true, ..Default::default() }; - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state, ..Default::default() }, - fw_image: Some(&image.to_bytes().unwrap()), - fuses, - ..Default::default() - }) + BootParams { + fw_image: Some(&image.to_bytes().unwrap()), + fuses, + ..Default::default() + }, + ) .unwrap(); hw.step(); diff --git a/test/tests/caliptra_integration_tests/smoke_test.rs b/test/tests/caliptra_integration_tests/smoke_test.rs index 47952888e5..15fe05d5f0 100644 --- a/test/tests/caliptra_integration_tests/smoke_test.rs +++ b/test/tests/caliptra_integration_tests/smoke_test.rs @@ -34,15 +34,17 @@ fn assert_output_contains(haystack: &str, needle: &str) { fn retrieve_csr_test() { const GENERATE_IDEVID_CSR: u32 = 1; let rom = caliptra_builder::rom_for_fw_integration_tests().unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state: *SecurityState::default().set_debug_locked(true), ..Default::default() }, - initial_dbg_manuf_service_reg: GENERATE_IDEVID_CSR, - ..Default::default() - }) + BootParams { + initial_dbg_manuf_service_reg: GENERATE_IDEVID_CSR, + ..Default::default() + }, + ) .unwrap(); let mut txn = hw.wait_for_mailbox_receive().unwrap(); @@ -153,16 +155,18 @@ fn smoke_test() { lms_verify: true, ..Default::default() }; - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state, ..Default::default() }, - fuses, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + BootParams { + fuses, + fw_image: Some(&image.to_bytes().unwrap()), + ..Default::default() + }, + ) .unwrap(); if firmware::rom_from_env() == &firmware::ROM_WITH_UART { @@ -686,11 +690,7 @@ fn test_rt_wdt_timeout() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params, - ..Default::default() - }) - .unwrap(); + let mut hw = caliptra_hw_model::new(init_params, BootParams::default()).unwrap(); // WDT started shortly before KATs are started. hw.step_until_boot_status(u32::from(RomBootStatus::KatStarted), true); @@ -708,13 +708,17 @@ fn test_rt_wdt_timeout() { let init_params = caliptra_hw_model::InitParams { rom: &rom, security_state, - wdt_timeout_cycles: rt_wdt_timeout_cycles, itrng_nibbles: Box::new(RandomNibbles(StdRng::seed_from_u64(0))), etrng_responses: Box::new(RandomEtrngResponses(StdRng::seed_from_u64(0))), ..Default::default() }; - let mut hw = run_test(None, None, Some(init_params)); + let boot_params = caliptra_hw_model::BootParams { + wdt_timeout_cycles: rt_wdt_timeout_cycles, + ..Default::default() + }; + + let mut hw = run_test(None, None, Some(init_params), Some(boot_params)); hw.step_until(|m| m.soc_ifc().cptra_fw_error_fatal().read() != 0); assert_eq!( @@ -763,10 +767,12 @@ fn test_fmc_wdt_timeout() { ) .unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { + let mut hw = caliptra_hw_model::new( init_params, - ..Default::default() - }) + BootParams { + ..Default::default() + }, + ) .unwrap(); // WDT started shortly before KATs are started. @@ -785,13 +791,17 @@ fn test_fmc_wdt_timeout() { let init_params = caliptra_hw_model::InitParams { rom: &rom, security_state, - wdt_timeout_cycles: fmc_wdt_timeout_cycles, itrng_nibbles: Box::new(RandomNibbles(StdRng::seed_from_u64(0))), etrng_responses: Box::new(RandomEtrngResponses(StdRng::seed_from_u64(0))), ..Default::default() }; - let mut hw = caliptra_test::run_test(None, None, Some(init_params)); + let boot_params = caliptra_hw_model::BootParams { + wdt_timeout_cycles: fmc_wdt_timeout_cycles, + ..Default::default() + }; + + let mut hw = caliptra_test::run_test(None, None, Some(init_params), Some(boot_params)); hw.step_until(|m| m.soc_ifc().cptra_fw_error_fatal().read() != 0); assert_eq!( diff --git a/test/tests/caliptra_integration_tests/test_code_coverage.rs b/test/tests/caliptra_integration_tests/test_code_coverage.rs index 2145307e8c..a18a97b132 100644 --- a/test/tests/caliptra_integration_tests/test_code_coverage.rs +++ b/test/tests/caliptra_integration_tests/test_code_coverage.rs @@ -17,14 +17,16 @@ fn test_emu_coverage() { let coverage_from_bitmap = { let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap(); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, trace_path: Some(PathBuf::from(TRACE_PATH)), ..Default::default() }, - ..Default::default() - }) + BootParams { + ..Default::default() + }, + ) .unwrap(); // Upload FW hw.step_until(|m| m.soc_ifc().cptra_flow_status().read().ready_for_fw()); diff --git a/test/tests/caliptra_integration_tests/warm_reset.rs b/test/tests/caliptra_integration_tests/warm_reset.rs index 8180d4b4cf..c72427ac23 100644 --- a/test/tests/caliptra_integration_tests/warm_reset.rs +++ b/test/tests/caliptra_integration_tests/warm_reset.rs @@ -38,21 +38,23 @@ fn warm_reset_basic() { let owner_pk_hash = bytes_to_be_words_48(&sha384(image.manifest.preamble.owner_pub_keys.as_bytes())); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state, ..Default::default() }, - fuses: Fuses { - key_manifest_pk_hash: vendor_pk_hash, - owner_pk_hash, - fmc_key_manifest_svn: 0b1111111, + BootParams { + fuses: Fuses { + key_manifest_pk_hash: vendor_pk_hash, + owner_pk_hash, + fmc_key_manifest_svn: 0b1111111, + ..Default::default() + }, + fw_image: Some(&image.to_bytes().unwrap()), ..Default::default() }, - fw_image: Some(&image.to_bytes().unwrap()), - ..Default::default() - }) + ) .unwrap(); // Wait for boot @@ -95,21 +97,23 @@ fn warm_reset_during_fw_load() { let owner_pk_hash = bytes_to_be_words_48(&sha384(image.manifest.preamble.owner_pub_keys.as_bytes())); - let mut hw = caliptra_hw_model::new(BootParams { - init_params: InitParams { + let mut hw = caliptra_hw_model::new( + InitParams { rom: &rom, security_state, ..Default::default() }, - fuses: Fuses { - key_manifest_pk_hash: vendor_pk_hash, - owner_pk_hash, - fmc_key_manifest_svn: 0b1111111, + BootParams { + fuses: Fuses { + key_manifest_pk_hash: vendor_pk_hash, + owner_pk_hash, + fmc_key_manifest_svn: 0b1111111, + ..Default::default() + }, + fw_image: None, ..Default::default() }, - fw_image: None, - ..Default::default() - }) + ) .unwrap(); // Start the FW load diff --git a/test/tests/fips_test_suite/common.rs b/test/tests/fips_test_suite/common.rs index ab0e886caf..27872aaf10 100755 --- a/test/tests/fips_test_suite/common.rs +++ b/test/tests/fips_test_suite/common.rs @@ -3,7 +3,7 @@ use caliptra_builder::firmware::{APP_WITH_UART, FMC_WITH_UART}; use caliptra_builder::ImageOptions; use caliptra_common::mailbox_api::*; -use caliptra_hw_model::{BootParams, DefaultHwModel, HwModel, ModelError}; +use caliptra_hw_model::{BootParams, DefaultHwModel, HwModel, InitParams, ModelError}; use dpe::{ commands::*, response::{ @@ -123,15 +123,17 @@ impl RtExpVals { // Builds ROM, if not provided // HW Model will boot to runtime if image is provided fn fips_test_init_base( + init_params: Option, boot_params: Option, fw_image_override: Option<&[u8]>, ) -> DefaultHwModel { // Create params if not provided let mut boot_params = boot_params.unwrap_or(BootParams::default()); + let mut init_params = init_params.unwrap_or(InitParams::default()); // Check that ROM was not provided if the immutable_rom feature is set #[cfg(feature = "test_env_immutable_rom")] - if boot_params.init_params.rom != <&[u8]>::default() { + if init_params.rom != <&[u8]>::default() { panic!("FIPS_TEST_SUITE ERROR: ROM cannot be provided/changed when immutable_ROM feature is set") } @@ -148,8 +150,8 @@ fn fips_test_init_base( } }; - if boot_params.init_params.rom == <&[u8]>::default() { - boot_params.init_params.rom = &rom; + if init_params.rom == <&[u8]>::default() { + init_params.rom = &rom; } // Add fw image override to boot params if provided @@ -162,20 +164,23 @@ fn fips_test_init_base( } // Create the model - caliptra_hw_model::new(boot_params).unwrap() + caliptra_hw_model::new(init_params, boot_params).unwrap() } // Initializes caliptra to "ready_for_fw" // Builds and uses default ROM if not provided -pub fn fips_test_init_to_rom(boot_params: Option) -> DefaultHwModel { +pub fn fips_test_init_to_rom( + init_params: Option, + boot_params: Option, +) -> DefaultHwModel { // Check that no fw_image is in boot params - if let Some(ref params) = boot_params { - if params.fw_image.is_some() { + if let Some(ref boot_params) = boot_params { + if boot_params.fw_image.is_some() { panic!("No FW image should be provided when calling fips_test_init_to_rom") } } - let mut model = fips_test_init_base(boot_params, None); + let mut model = fips_test_init_base(init_params, boot_params, None); // Step to ready for FW in ROM model.step_until(|m| m.soc_ifc().cptra_flow_status().read().ready_for_fw()); @@ -185,11 +190,14 @@ pub fn fips_test_init_to_rom(boot_params: Option) -> DefaultHwModel // Initializes Caliptra to runtime // Builds and uses default ROM and FW if not provided -pub fn fips_test_init_to_rt(boot_params: Option) -> DefaultHwModel { +pub fn fips_test_init_to_rt( + init_params: Option, + boot_params: Option, +) -> DefaultHwModel { let mut build_fw = true; - if let Some(ref params) = boot_params { - if params.fw_image.is_some() { + if let Some(ref boot_params) = boot_params { + if boot_params.fw_image.is_some() { build_fw = false; } } @@ -198,9 +206,9 @@ pub fn fips_test_init_to_rt(boot_params: Option) -> DefaultHwModel { // If FW was not provided, build it or get it from the specified path let fw_image = fips_fw_image(); - fips_test_init_base(boot_params, Some(&fw_image)) + fips_test_init_base(init_params, boot_params, Some(&fw_image)) } else { - fips_test_init_base(boot_params, None) + fips_test_init_base(init_params, boot_params, None) } // HW model will complete FW upload cmd, nothing to wait for diff --git a/test/tests/fips_test_suite/jtag_locked.rs b/test/tests/fips_test_suite/jtag_locked.rs index 5d0ef00c58..523a543293 100644 --- a/test/tests/fips_test_suite/jtag_locked.rs +++ b/test/tests/fips_test_suite/jtag_locked.rs @@ -1,7 +1,7 @@ // Licensed under the Apache-2.0 license use crate::common::fips_test_init_to_rom; -use caliptra_hw_model::{BootParams, InitParams, SecurityState}; +use caliptra_hw_model::{InitParams, SecurityState}; use caliptra_hw_model_types::DeviceLifecycle; fn check_jtag_accessible( @@ -14,14 +14,14 @@ fn check_jtag_accessible( .set_debug_locked(debug_locked) .set_device_lifecycle(device_lifecycle); - let mut _hw = fips_test_init_to_rom(Some(BootParams { - init_params: InitParams { + let mut _hw = fips_test_init_to_rom( + Some(InitParams { rom, security_state, ..Default::default() - }, - ..Default::default() - })); + }), + None, + ); #[cfg(feature = "fpga_realtime")] match _hw.launch_openocd() { diff --git a/test/tests/fips_test_suite/services.rs b/test/tests/fips_test_suite/services.rs index e0ce6b0347..99c7a0edff 100755 --- a/test/tests/fips_test_suite/services.rs +++ b/test/tests/fips_test_suite/services.rs @@ -567,7 +567,7 @@ pub fn exec_cmd_shutdown(hw: &mut T) { #[test] pub fn check_version_rom() { - let mut hw = fips_test_init_to_rom(None); + let mut hw = fips_test_init_to_rom(None, None); // FMC and FW version should both be 0 before loading exec_cmd_version(&mut hw, 0x0, 0x0); @@ -575,7 +575,7 @@ pub fn check_version_rom() { #[test] pub fn check_version_rt() { - let mut hw = fips_test_init_to_rt(None); + let mut hw = fips_test_init_to_rt(None, None); exec_cmd_version( &mut hw, @@ -586,7 +586,7 @@ pub fn check_version_rt() { #[test] pub fn execute_all_services_rom() { - let mut hw = fips_test_init_to_rom(None); + let mut hw = fips_test_init_to_rom(None, None); // TODO: SHA accelerator engine @@ -614,10 +614,13 @@ pub fn execute_all_services_rom() { #[test] pub fn execute_all_services_rt() { let fw_image = fips_fw_image(); - let mut hw = fips_test_init_to_rt(Some(BootParams { - fw_image: Some(&fw_image), - ..Default::default() - })); + let mut hw = fips_test_init_to_rt( + None, + Some(BootParams { + fw_image: Some(&fw_image), + ..Default::default() + }), + ); // TODO: SHA accelerator engine