Skip to content

Commit

Permalink
Tests must wait for ready_for_fw before sending commands
Browse files Browse the repository at this point in the history
At
https://github.com/chipsalliance/Caliptra/blob/main/doc/Caliptra.md#caliptra-fw-push-flow,
the Caliptra specification requires that the SoC wait for the
ready_for_fw signal before populating the mailbox. Today, the ROM
doesn't technically require this, but future changes may. In preparation
for such changes, update all the tests to wait.
  • Loading branch information
korran committed Jan 30, 2024
1 parent 5d901b3 commit 3fee80f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hw-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ pub trait HwModel {

/// Upload firmware to the mailbox.
fn upload_firmware(&mut self, firmware: &[u8]) -> Result<(), ModelError> {
self.step_until(|hw| hw.ready_for_fw());
let response = self.mailbox_execute(FW_LOAD_CMD_OPCODE, firmware)?;
if response.is_some() {
return Err(ModelError::UploadFirmwareUnexpectedResponse);
Expand Down Expand Up @@ -1101,6 +1102,7 @@ pub trait HwModel {

/// Upload measurement to the mailbox.
fn upload_measurement(&mut self, measurement: &[u8]) -> Result<(), ModelError> {
self.step_until(|hw| hw.ready_for_fw());
let response = self.mailbox_execute(STASH_MEASUREMENT_CMD_OPCODE, measurement)?;

// We expect a response
Expand Down
1 change: 1 addition & 0 deletions rom/dev/tests/rom_integration_tests/test_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::helpers;
fn test_capabilities() {
let (mut hw, _image_bundle) =
helpers::build_hw_model_and_image_bundle(Fuses::default(), ImageOptions::default());
hw.step_until(|hw| hw.ready_for_fw());

let payload = MailboxReqHeader {
chksum: caliptra_common::checksum::calc_checksum(u32::from(CommandId::CAPABILITIES), &[]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fn test_firmware_gt_max_size() {

let (mut hw, _image_bundle) =
helpers::build_hw_model_and_image_bundle(Fuses::default(), ImageOptions::default());
hw.step_until(|hw| hw.ready_for_fw());

// Manually put the oversize data in the mailbox because
// HwModel::upload_firmware won't let us.
Expand Down
5 changes: 5 additions & 0 deletions rom/dev/tests/rom_integration_tests/test_mailbox_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const MAX_WAIT_CYCLES: u32 = 30_000_000;
fn test_unknown_command_is_fatal() {
let (mut hw, _image_bundle) =
helpers::build_hw_model_and_image_bundle(Fuses::default(), ImageOptions::default());
hw.step_until(|hw| hw.soc_ifc().cptra_flow_status().read().ready_for_fw());

// This command does not exist
assert_eq!(
Expand Down Expand Up @@ -58,6 +59,7 @@ fn test_mailbox_command_aborted_after_handle_fatal_error() {
fn test_mailbox_invalid_checksum() {
let (mut hw, _image_bundle) =
helpers::build_hw_model_and_image_bundle(Fuses::default(), ImageOptions::default());
hw.step_until(|hw| hw.ready_for_fw());

// Upload measurement.
let payload = StashMeasurementReq {
Expand Down Expand Up @@ -94,6 +96,7 @@ fn test_mailbox_invalid_checksum() {
fn test_mailbox_invalid_req_size_large() {
let (mut hw, _image_bundle) =
helpers::build_hw_model_and_image_bundle(Fuses::default(), ImageOptions::default());
hw.step_until(|hw| hw.ready_for_fw());

// Upload measurement.
let payload = StashMeasurementReq {
Expand All @@ -117,6 +120,7 @@ fn test_mailbox_invalid_req_size_large() {
fn test_mailbox_invalid_req_size_small() {
let (mut hw, _image_bundle) =
helpers::build_hw_model_and_image_bundle(Fuses::default(), ImageOptions::default());
hw.step_until(|hw| hw.ready_for_fw());

// Upload measurement.
let payload = StashMeasurementReq {
Expand All @@ -143,6 +147,7 @@ fn test_mailbox_invalid_req_size_small() {
fn test_mailbox_invalid_req_size_zero() {
let (mut hw, _image_bundle) =
helpers::build_hw_model_and_image_bundle(Fuses::default(), ImageOptions::default());
hw.step_until(|hw| hw.ready_for_fw());

assert_eq!(
hw.mailbox_execute(CommandId::CAPABILITIES.into(), &[]),
Expand Down
1 change: 1 addition & 0 deletions rom/dev/tests/rom_integration_tests/test_warm_reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fn test_warm_reset_during_cold_boot_during_image_validation() {

let (mut hw, image_bundle) =
helpers::build_hw_model_and_image_bundle(fuses, ImageOptions::default());
hw.step_until(|hw| hw.ready_for_fw());

hw.start_mailbox_execute(
CommandId::FIRMWARE_LOAD.into(),
Expand Down

0 comments on commit 3fee80f

Please sign in to comment.