Skip to content

Commit

Permalink
Adding hw-model boot() function
Browse files Browse the repository at this point in the history
- separating InitParams from BootParams
- boot() can be used after a reset to boot without re-initializing the model
  • Loading branch information
nquarton committed Apr 10, 2024
1 parent b72c293 commit 193c319
Show file tree
Hide file tree
Showing 31 changed files with 674 additions and 511 deletions.
72 changes: 38 additions & 34 deletions drivers/tests/drivers_integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ fn default_init_params() -> InitParams<'static> {

fn start_driver_test(test_rom: &'static FwId) -> Result<DefaultHwModel, Box<dyn Error>> {
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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand All @@ -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();
Expand Down
12 changes: 7 additions & 5 deletions fmc/tests/fmc_integration_tests/test_hand_off.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand Down
36 changes: 21 additions & 15 deletions fmc/tests/fmc_integration_tests/test_rtalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 193c319

Please sign in to comment.