Repository: chipsalliance/caliptra-sw
Pull request #766 (2023-09-13 16:27:35)

Log measurement context and SVN.
Also massage a bit of test code.


Patch:
diff --git a/drivers/src/lib.rs b/drivers/src/lib.rs
index 442c6391..a6b9b5a9 100644
--- a/drivers/src/lib.rs
+++ b/drivers/src/lib.rs
@@ -81,7 +81,7 @@ pub use okref::okref;
 pub use pcr_bank::{PcrBank, PcrId};
 pub use persistent::{
     FuseLogArray, PcrLogArray, PersistentData, PersistentDataAccessor, StashMeasurementArray,
-    MEASUREMENT_MAX_COUNT,
+    FUSE_LOG_MAX_COUNT, MEASUREMENT_MAX_COUNT, PCR_LOG_MAX_COUNT,
 };
 pub use sha1::{Sha1, Sha1Digest, Sha1DigestOp};
 pub use sha256::{Sha256, Sha256DigestOp};
diff --git a/drivers/src/memory_layout.rs b/drivers/src/memory_layout.rs
index fb2b0db6..b73da8d8 100644
--- a/drivers/src/memory_layout.rs
+++ b/drivers/src/memory_layout.rs
@@ -60,9 +60,9 @@ pub const FHT_SIZE: u32 = 2 * 1024;
 pub const LDEVID_TBS_SIZE: u32 = 1024;
 pub const FMCALIAS_TBS_SIZE: u32 = 1024;
 pub const RTALIAS_TBS_SIZE: u32 = 1024;
-pub const PCR_LOG_SIZE: usize = 1024;
-pub const MEASUREMENT_LOG_SIZE: usize = 1024;
-pub const FUSE_LOG_SIZE: usize = 1024;
+pub const PCR_LOG_SIZE: u32 = 1024;
+pub const MEASUREMENT_LOG_SIZE: u32 = 1024;
+pub const FUSE_LOG_SIZE: u32 = 1024;
 pub const DATA_SIZE: u32 = 83 * 1024;
 pub const STACK_SIZE: u32 = 22 * 1024;
 pub const ESTACK_SIZE: u32 = 1024;
@@ -111,22 +111,19 @@ fn mem_layout_test_rtalias() {
 #[test]
 #[allow(clippy::assertions_on_constants)]
 fn mem_layout_test_pcr_log() {
-    assert_eq!((MEASUREMENT_LOG_ORG - PCR_LOG_ORG), PCR_LOG_SIZE as u32);
+    assert_eq!((MEASUREMENT_LOG_ORG - PCR_LOG_ORG), PCR_LOG_SIZE);
 }
 
 #[test]
 #[allow(clippy::assertions_on_constants)]
 fn mem_layout_test_measurement_log() {
-    assert_eq!(
-        (FUSE_LOG_ORG - MEASUREMENT_LOG_ORG),
-        MEASUREMENT_LOG_SIZE as u32
-    );
+    assert_eq!((FUSE_LOG_ORG - MEASUREMENT_LOG_ORG), MEASUREMENT_LOG_SIZE);
 }
 
 #[test]
 #[allow(clippy::assertions_on_constants)]
 fn mem_layout_test_fuselog() {
-    assert_eq!((BOOT_STATUS_ORG - FUSE_LOG_ORG), FUSE_LOG_SIZE as u32);
+    assert_eq!((BOOT_STATUS_ORG - FUSE_LOG_ORG), FUSE_LOG_SIZE);
 }
 
 #[test]
diff --git a/drivers/src/pcr_log.rs b/drivers/src/pcr_log.rs
index dc14d65b..9624d2b5 100644
--- a/drivers/src/pcr_log.rs
+++ b/drivers/src/pcr_log.rs
@@ -73,9 +73,6 @@ pub struct PcrLogEntry {
 
     // PCR data
     pub pcr_data: [u32; 12],
-
-    // PCR Metadata
-    pub metadata: [u8; 4],
 }
 
 impl PcrLogEntry {
@@ -100,5 +97,16 @@ impl PcrLogEntry {
     }
 }
 
+/// Measurement log entry
+#[repr(C)]
+#[derive(AsBytes, Clone, Copy, Debug, Default, FromBytes)]
+pub struct MeasurementLogEntry {
+    pub pcr_entry: PcrLogEntry,
+    pub metadata: [u8; 4],
+    pub context: [u32; 12],
+    pub svn: u32,
+    pub reserved0: [u8; 4],
+}
+
 pub const RT_FW_CURRENT_PCR: PcrId = PcrId::PcrId2;
 pub const RT_FW_JOURNEY_PCR: PcrId = PcrId::PcrId3;
diff --git a/drivers/src/persistent.rs b/drivers/src/persistent.rs
index a7b92c3f..d0a16570 100644
--- a/drivers/src/persistent.rs
+++ b/drivers/src/persistent.rs
@@ -5,13 +5,20 @@ use core::{marker::PhantomData, mem::size_of, ptr::addr_of};
 use caliptra_image_types::ImageManifest;
 use zerocopy::{AsBytes, FromBytes};
 
-use crate::{fuse_log::FuseLogEntry, memory_layout, pcr_log::PcrLogEntry, FirmwareHandoffTable};
+use crate::{
+    fuse_log::FuseLogEntry,
+    memory_layout,
+    pcr_log::{MeasurementLogEntry, PcrLogEntry},
+    FirmwareHandoffTable,
+};
 
-pub const MEASUREMENT_MAX_COUNT: u32 = 8;
+pub const PCR_LOG_MAX_COUNT: usize = 17;
+pub const FUSE_LOG_MAX_COUNT: usize = 62;
+pub const MEASUREMENT_MAX_COUNT: usize = 8;
 
-pub type PcrLogArray = [PcrLogEntry; 17];
-pub type FuseLogArray = [FuseLogEntry; 62];
-pub type StashMeasurementArray = [PcrLogEntry; MEASUREMENT_MAX_COUNT as usize];
+pub type PcrLogArray = [PcrLogEntry; PCR_LOG_MAX_COUNT];
+pub type FuseLogArray = [FuseLogEntry; FUSE_LOG_MAX_COUNT];
+pub type StashMeasurementArray = [MeasurementLogEntry; MEASUREMENT_MAX_COUNT];
 
 #[derive(FromBytes, AsBytes)]
 #[repr(C)]
@@ -32,13 +39,14 @@ pub struct PersistentData {
     pub rtalias_tbs: [u8; memory_layout::RTALIAS_TBS_SIZE as usize],
 
     pub pcr_log: PcrLogArray,
-    reserved3: [u8; 4],
+    reserved3: [u8; memory_layout::PCR_LOG_SIZE as usize - size_of::<PcrLogArray>()],
 
     pub measurement_log: StashMeasurementArray,
-    reserved4: [u8; 544],
+    reserved4:
+        [u8; memory_layout::MEASUREMENT_LOG_SIZE as usize - size_of::<StashMeasurementArray>()],
 
     pub fuse_log: FuseLogArray,
-    reserved5: [u8; 32],
+    reserved5: [u8; memory_layout::FUSE_LOG_SIZE as usize - size_of::<FuseLogArray>()],
 }
 impl PersistentData {
     pub fn assert_matches_layout() {
diff --git a/rom/dev/src/flow/cold_reset/fw_processor.rs b/rom/dev/src/flow/cold_reset/fw_processor.rs
index 3ea1ca58..7ab316cc 100644
--- a/rom/dev/src/flow/cold_reset/fw_processor.rs
+++ b/rom/dev/src/flow/cold_reset/fw_processor.rs
@@ -30,6 +30,7 @@ use caliptra_common::verifier::FirmwareImageVerificationEnv;
 use caliptra_common::PcrLogEntry;
 use caliptra_common::PcrLogEntryId;
 use caliptra_common::{FuseLogEntryId, RomBootStatus::*};
+use caliptra_drivers::pcr_log::MeasurementLogEntry;
 use caliptra_drivers::*;
 use caliptra_image_types::{ImageManifest, IMAGE_BYTE_SIZE};
 use caliptra_image_verify::{ImageVerificationInfo, ImageVerificationLogInfo, ImageVerifier};
@@ -580,7 +581,7 @@ impl FirmwareProcessor {
         sha384: &mut Sha384,
         measurement_log: &mut StashMeasurementArray,
         txn: &mut MailboxRecvTxn,
-        log_index: u32,
+        log_index: usize,
     ) -> CaliptraResult<()> {
         let mut measurement = StashMeasurementReq::default();
         if txn.dlen() as usize != measurement.as_bytes().len() {
@@ -589,13 +590,7 @@ impl FirmwareProcessor {
         txn.copy_request(measurement.as_bytes_mut())?;
 
         // Extend measurement into PCR31.
-        Self::extend_measurement(
-            pcr_bank,
-            sha384,
-            measurement_log,
-            &measurement,
-            log_index as usize,
-        )?;
+        Self::extend_measurement(pcr_bank, sha384, measurement_log, &measurement, log_index)?;
 
         Ok(())
     }
@@ -652,18 +647,19 @@ impl FirmwareProcessor {
         return Err(CaliptraError::ROM_GLOBAL_MEASUREMENT_LOG_EXHAUSTED);
     };
 
-        // Create a PCR log entry
-        let pcr_log_entry = PcrLogEntry {
-            id: PcrLogEntryId::StashMeasurement as u16,
-            pcr_ids: 1 << (PCR_ID_STASH_MEASUREMENT as u8),
-            pcr_data: zerocopy::transmute!(stash_measurement.measurement),
+        *dst = MeasurementLogEntry {
+            pcr_entry: PcrLogEntry {
+                id: PcrLogEntryId::StashMeasurement as u16,
+                reserved0: [0u8; 2],
+                pcr_ids: 1 << (PCR_ID_STASH_MEASUREMENT as u8),
+                pcr_data: zerocopy::transmute!(stash_measurement.measurement),
+            },
             metadata: stash_measurement.metadata,
-            ..Default::default()
+            context: zerocopy::transmute!(stash_measurement.context),
+            svn: stash_measurement.svn,
+            reserved0: [0u8; 4],
         };
 
-        // Store the log entry.
-        *dst = pcr_log_entry;
-
         Ok(())
     }
 }


Test patch:
diff --git a/rom/dev/tests/test_fmcalias_derivation.rs b/rom/dev/tests/test_fmcalias_derivation.rs
index a45b0bf9..9bb0e1a5 100644
--- a/rom/dev/tests/test_fmcalias_derivation.rs
+++ b/rom/dev/tests/test_fmcalias_derivation.rs
@@ -7,6 +7,7 @@ use caliptra_common::RomBootStatus::ColdResetComplete;
 use caliptra_common::RomBootStatus::*;
 use caliptra_common::{FirmwareHandoffTable, FuseLogEntry, FuseLogEntryId};
 use caliptra_common::{PcrLogEntry, PcrLogEntryId};
+use caliptra_drivers::pcr_log::MeasurementLogEntry;
 use caliptra_drivers::{ColdResetEntry4, PcrId, RomVerifyConfig};
 use caliptra_error::CaliptraError;
 use caliptra_hw_model::{BootParams, Fuses, HwModel, InitParams, ModelError, SecurityState};
@@ -76,16 +77,16 @@ fn test_firmware_gt_max_size() {
 
 const PCR_COUNT: usize = 32;
 const PCR_ENTRY_SIZE: usize = core::mem::size_of::<PcrLogEntry>();
+const MEASUREMENT_ENTRY_SIZE: usize = core::mem::size_of::<MeasurementLogEntry>();
 const MEASUREMENT_MAX_COUNT: usize = 8;
 
-// Checks entries for both PCR0 and PCR1. Skips checking `data` if empty.
+// Skips checking `data` if empty.
 fn check_pcr_log_entry(
     pcr_entry_arr: &[u8],
     pcr_entry_index: usize,
     entry_id: PcrLogEntryId,
-    pcr_data: &[u8],
-    metadata: &[u8],
     pcr_ids: u32,
+    pcr_data: &[u8],
 ) {
     let offset = pcr_entry_index * PCR_ENTRY_SIZE;
     let entry = PcrLogEntry::read_from_prefix(pcr_entry_arr[offset..].as_bytes()).unwrap();
@@ -96,8 +97,26 @@ fn check_pcr_log_entry(
     if !pcr_data.is_empty() {
         assert_eq!(entry.measured_data(), pcr_data);
     }
+}
+
+fn check_measurement_log_entry(
+    measurement_entry_arr: &[u8],
+    measurement_entry_index: usize,
+    measurement_req: &StashMeasurementReq,
+) {
+    let offset = measurement_entry_index * MEASUREMENT_ENTRY_SIZE;
+    let entry =
+        MeasurementLogEntry::read_from_prefix(measurement_entry_arr[offset..].as_bytes()).unwrap();
 
-    assert_eq!(entry.metadata, metadata);
+    assert_eq!(entry.pcr_entry.id, PcrLogEntryId::StashMeasurement as u16);
+    assert_eq!(entry.pcr_entry.pcr_ids, PCR31_EXTENDED_ID);
+    assert_eq!(
+        entry.pcr_entry.measured_data(),
+        &measurement_req.measurement
+    );
+    assert_eq!(entry.metadata, measurement_req.metadata);
+    assert_eq!(entry.context.as_bytes(), &measurement_req.context);
+    assert_eq!(entry.svn, measurement_req.svn);
 }
 
 #[test]
@@ -149,9 +168,8 @@ fn test_pcr_log() {
         caliptra_builder::build_and_sign_image(&TEST_FMC_WITH_UART, &APP_WITH_UART, image_options)
             .unwrap();
 
-    assert!(hw
-        .upload_firmware(&image_bundle.to_bytes().unwrap())
-        .is_ok());
+    hw.upload_firmware(&image_bundle.to_bytes().unwrap())
+        .unwrap();
 
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
@@ -167,9 +185,8 @@ fn test_pcr_log() {
         &pcr_entry_arr,
         0,
         PcrLogEntryId::DeviceLifecycle,
-        &[device_lifecycle as u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[device_lifecycle as u8],
     );
 
     let debug_locked = hw.soc_ifc().cptra_security_state().read().debug_locked();
@@ -178,9 +195,8 @@ fn test_pcr_log() {
         &pcr_entry_arr,
         1,
         PcrLogEntryId::DebugLocked,
-        &[debug_locked as u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[debug_locked as u8],
     );
 
     let anti_rollback_disable = hw.soc_ifc().fuse_anti_rollback_disable().read().dis();
@@ -189,9 +205,8 @@ fn test_pcr_log() {
         &pcr_entry_arr,
         2,
         PcrLogEntryId::AntiRollbackDisabled,
-        &[anti_rollback_disable as u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[anti_rollback_disable as u8],
     );
 
     helpers::change_dword_endianess(vendor_pubkey_digest.as_bytes_mut());
@@ -200,9 +215,8 @@ fn test_pcr_log() {
         &pcr_entry_arr,
         3,
         PcrLogEntryId::VendorPubKeyHash,
-        vendor_pubkey_digest.as_bytes(),
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        vendor_pubkey_digest.as_bytes(),
     );
 
     helpers::change_dword_endianess(owner_pubkey_digest.as_bytes_mut());
@@ -211,63 +225,56 @@ fn test_pcr_log() {
         &pcr_entry_arr,
         4,
         PcrLogEntryId::OwnerPubKeyHash,
-        owner_pubkey_digest.as_bytes(),
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        owner_pubkey_digest.as_bytes(),
     );
 
     check_pcr_log_entry(
         &pcr_entry_arr,
         5,
         PcrLogEntryId::EccVendorPubKeyIndex,
-        &[VENDOR_CONFIG_KEY_1.ecc_key_idx as u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[VENDOR_CONFIG_KEY_1.ecc_key_idx as u8],
     );
 
     check_pcr_log_entry(
         &pcr_entry_arr,
         6,
         PcrLogEntryId::FmcTci,
-        &[],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[],
     );
 
     check_pcr_log_entry(
         &pcr_entry_arr,
         7,
         PcrLogEntryId::FmcSvn,
-        &[FMC_SVN as u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[FMC_SVN as u8],
     );
 
     check_pcr_log_entry(
         &pcr_entry_arr,
         8,
         PcrLogEntryId::FmcFuseSvn,
-        &[0_u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[0_u8],
     );
 
     check_pcr_log_entry(
         &pcr_entry_arr,
         9,
         PcrLogEntryId::LmsVendorPubKeyIndex,
-        &[VENDOR_CONFIG_KEY_1.lms_key_idx as u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[VENDOR_CONFIG_KEY_1.lms_key_idx as u8],
     );
 
     check_pcr_log_entry(
         &pcr_entry_arr,
         10,
         PcrLogEntryId::RomVerifyConfig,
-        &[RomVerifyConfig::EcdsaAndLms as u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[RomVerifyConfig::EcdsaAndLms as u8],
     );
 }
 
@@ -322,9 +329,8 @@ fn test_pcr_log_fmc_fuse_svn() {
         caliptra_builder::build_and_sign_image(&TEST_FMC_WITH_UART, &APP_WITH_UART, image_options)
             .unwrap();
 
-    assert!(hw
-        .upload_firmware(&image_bundle.to_bytes().unwrap())
-        .is_ok());
+    hw.upload_firmware(&image_bundle.to_bytes().unwrap())
+        .unwrap();
 
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
@@ -334,18 +340,16 @@ fn test_pcr_log_fmc_fuse_svn() {
         &pcr_entry_arr,
         7,
         PcrLogEntryId::FmcSvn,
-        &[FMC_SVN as u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[FMC_SVN as u8],
     );
 
     check_pcr_log_entry(
         &pcr_entry_arr,
         8,
         PcrLogEntryId::FmcFuseSvn,
-        &[FMC_FUSE_SVN as u8],
-        &[0u8; 4],
         PCR0_AND_PCR1_EXTENDED_ID,
+        &[FMC_FUSE_SVN as u8],
     );
 }
 
@@ -430,9 +434,8 @@ fn test_pcr_log_across_update_reset() {
         caliptra_builder::build_and_sign_image(&TEST_FMC_WITH_UART, &APP_WITH_UART, image_options)
             .unwrap();
 
-    assert!(hw
-        .upload_firmware(&image_bundle.to_bytes().unwrap())
-        .is_ok());
+    hw.upload_firmware(&image_bundle.to_bytes().unwrap())
+        .unwrap();
 
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
@@ -542,16 +545,12 @@ fn test_fuse_log() {
         caliptra_builder::build_and_sign_image(&TEST_FMC_WITH_UART, &APP_WITH_UART, image_options)
             .unwrap();
 
-    assert!(hw
-        .upload_firmware(&image_bundle.to_bytes().unwrap())
-        .is_ok());
+    hw.upload_firmware(&image_bundle.to_bytes().unwrap())
+        .unwrap();
 
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
-    let result = hw.mailbox_execute(0x1000_0002, &[]);
-    assert!(result.is_ok());
-
-    let fuse_entry_arr = result.unwrap().unwrap();
+    let fuse_entry_arr = hw.mailbox_execute(0x1000_0002, &[]).unwrap().unwrap();
 
     let mut fuse_log_entry_offset = 0;
 
@@ -676,16 +675,12 @@ fn test_fht_info() {
         ImageOptions::default(),
     )
     .unwrap();
-    assert!(hw
-        .upload_firmware(&image_bundle.to_bytes().unwrap())
-        .is_ok());
+    hw.upload_firmware(&image_bundle.to_bytes().unwrap())
+        .unwrap();
 
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
-    let result = hw.mailbox_execute(0x1000_0003, &[]);
-    assert!(result.is_ok());
-
-    let data = result.unwrap().unwrap();
+    let data = hw.mailbox_execute(0x1000_0003, &[]).unwrap().unwrap();
     let fht = FirmwareHandoffTable::read_from_prefix(data.as_bytes()).unwrap();
     assert_eq!(fht.ldevid_tbs_size, 533);
     assert_eq!(fht.fmcalias_tbs_size, 745);
@@ -732,16 +727,12 @@ fn test_check_no_lms_info_in_datavault_on_lms_unavailable() {
     )
     .unwrap();
 
-    assert!(hw
-        .upload_firmware(&image_bundle.to_bytes().unwrap())
-        .is_ok());
+    hw.upload_firmware(&image_bundle.to_bytes().unwrap())
+        .unwrap();
 
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
-    let result = hw.mailbox_execute(0x1000_0005, &[]);
-    assert!(result.is_ok());
-
-    let coldresetentry4_array = result.unwrap().unwrap();
+    let coldresetentry4_array = hw.mailbox_execute(0x1000_0005, &[]).unwrap().unwrap();
     let mut coldresetentry4_offset = core::mem::size_of::<u32>() * 8; // Skip first 4 entries
 
     // Check LmsVendorPubKeyIndex datavault value.
@@ -792,16 +783,12 @@ fn test_check_rom_cold_boot_status_reg() {
     )
     .unwrap();
 
-    assert!(hw
-        .upload_firmware(&image_bundle.to_bytes().unwrap())
-        .is_ok());
+    hw.upload_firmware(&image_bundle.to_bytes().unwrap())
+        .unwrap();
 
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
-    let result = hw.mailbox_execute(0x1000_0005, &[]);
-    assert!(result.is_ok());
-
-    let coldresetentry4_array = result.unwrap().unwrap();
+    let coldresetentry4_array = hw.mailbox_execute(0x1000_0005, &[]).unwrap().unwrap();
     let mut coldresetentry4_offset = core::mem::size_of::<u32>() * 2; // Skip first entry
 
     // Check RomColdBootStatus datavault value.
@@ -850,12 +837,11 @@ fn test_upload_single_measurement() {
     let measurement = StashMeasurementReq {
         measurement: [0xdeadbeef_u32; 12].as_bytes().try_into().unwrap(),
         hdr: MailboxReqHeader { chksum: 0 },
-        metadata: [0xBA; 4],
-        context: [0u8; 48],
-        svn: 0,
+        metadata: [0xAB; 4],
+        context: [0xCD; 48],
+        svn: 0xEF01,
     };
-    let result = hw.upload_measurement(measurement.as_bytes());
-    assert!(result.is_ok());
+    hw.upload_measurement(measurement.as_bytes()).unwrap();
 
     hw.upload_firmware(&image_bundle.to_bytes().unwrap())
         .unwrap();
@@ -863,9 +849,7 @@ fn test_upload_single_measurement() {
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
     // Get PCR31
-    let result = hw.mailbox_execute(0x1000_0009, &[]);
-    assert!(result.is_ok());
-    let pcr31 = result.unwrap().unwrap();
+    let pcr31 = hw.mailbox_execute(0x1000_0009, &[]).unwrap().unwrap();
 
     // Check that the measurement was extended to PCR31.
     let mut data: [u8; 96] = [0u8; 96];
@@ -874,16 +858,10 @@ fn test_upload_single_measurement() {
     assert_eq!(pcr31.as_bytes(), out);
 
     // Check if the measurement was present in the measurement log.
-    let pcr_entry_arr = hw.mailbox_execute(0x1000_000A, &[]).unwrap().unwrap();
+    let measurement_log = hw.mailbox_execute(0x1000_000A, &[]).unwrap().unwrap();
 
-    check_pcr_log_entry(
-        &pcr_entry_arr,
-        0,
-        PcrLogEntryId::StashMeasurement,
-        measurement.measurement.as_bytes(),
-        &[0xBA; 4],
-        PCR31_EXTENDED_ID,
-    );
+    assert_eq!(measurement_log.len(), MEASUREMENT_ENTRY_SIZE);
+    check_measurement_log_entry(&measurement_log, 0, &measurement);
 }
 
 #[test]
@@ -926,8 +904,9 @@ fn test_upload_measurement_limit() {
     // Upload 8 measurements.
     for idx in 0..8 {
         measurement.measurement[0] = idx;
-        let result = hw.upload_measurement(measurement.as_bytes());
-        assert!(result.is_ok());
+        measurement.context[1] = idx;
+        measurement.svn = idx as u32;
+        hw.upload_measurement(measurement.as_bytes()).unwrap();
     }
 
     // Upload a 9th measurement, which should fail.
@@ -943,9 +922,7 @@ fn test_upload_measurement_limit() {
 
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
-    let result = hw.mailbox_execute(0x1000_0009, &[]);
-    assert!(result.is_ok());
-    let pcr31 = result.unwrap().unwrap();
+    let pcr31 = hw.mailbox_execute(0x1000_0009, &[]).unwrap().unwrap();
 
     // Check that only 8 measurements were extended to PCR31
     let mut out: [u8; 48] = [0u8; 48];
@@ -959,23 +936,16 @@ fn test_upload_measurement_limit() {
     assert_eq!(pcr31.as_bytes(), out);
 
     // Check the Mesaurement log.
-    let result = hw.mailbox_execute(0x1000_000A, &[]);
-    assert!(result.is_ok());
-    let measurement_log = result.unwrap().unwrap();
+    let measurement_log = hw.mailbox_execute(0x1000_000A, &[]).unwrap().unwrap();
     assert_eq!(
         measurement_log.len(),
-        PCR_ENTRY_SIZE * MEASUREMENT_MAX_COUNT
+        MEASUREMENT_ENTRY_SIZE * MEASUREMENT_MAX_COUNT
     );
     for idx in 0..8 {
         measurement.measurement[0] = idx;
-        check_pcr_log_entry(
-            &measurement_log,
-            idx as usize,
-            PcrLogEntryId::StashMeasurement,
-            measurement.measurement.as_bytes(),
-            &[0u8; 4],
-            PCR31_EXTENDED_ID,
-        );
+        measurement.context[1] = idx;
+        measurement.svn = idx as u32;
+        check_measurement_log_entry(&measurement_log, idx as usize, &measurement);
     }
 }
 
@@ -1014,9 +984,7 @@ fn test_upload_no_measurement() {
     hw.step_until_boot_status(ColdResetComplete.into(), true);
 
     // Check whether the fake measurement was extended to PCR31.
-    let result = hw.mailbox_execute(0x1000_0009, &[]);
-    assert!(result.is_ok());
-    let pcr31 = result.unwrap().unwrap();
+    let pcr31 = hw.mailbox_execute(0x1000_0009, &[]).unwrap().unwrap();
 
     let mut out: [u8; 48] = [0u8; 48];
     let mut data: [u8; 96] = [0u8; 96];
@@ -1026,14 +994,18 @@ fn test_upload_no_measurement() {
     assert_eq!(pcr31.as_bytes(), out);
 
     // Check whether the fake measurement is in the measurement log.
-    let pcr_entry_arr = hw.mailbox_execute(0x1000_000A, &[]).unwrap().unwrap();
+    let measurement_log = hw.mailbox_execute(0x1000_000A, &[]).unwrap().unwrap();
+    assert_eq!(measurement_log.len(), MEASUREMENT_ENTRY_SIZE);
 
-    check_pcr_log_entry(
-        &pcr_entry_arr,
+    check_measurement_log_entry(
+        &measurement_log,
         0,
-        PcrLogEntryId::StashMeasurement,
-        &[0xFFu8; 48],
-        &[0u8; 4],
-        PCR31_EXTENDED_ID,
+        &StashMeasurementReq {
+            measurement: [0xFFu8; 48],
+            metadata: [0u8; 4],
+            context: [0u8; 48],
+            svn: 0,
+            ..Default::default()
+        },
     );
 }
diff --git a/rom/dev/tools/test-fmc/src/main.rs b/rom/dev/tools/test-fmc/src/main.rs
index ef881a05..a7d7a942 100644
--- a/rom/dev/tools/test-fmc/src/main.rs
+++ b/rom/dev/tools/test-fmc/src/main.rs
@@ -17,9 +17,10 @@ Abstract:
 use caliptra_common::pcr::PCR_ID_STASH_MEASUREMENT;
 use caliptra_common::{FuseLogEntry, FuseLogEntryId};
 use caliptra_common::{PcrLogEntry, PcrLogEntryId};
+use caliptra_drivers::pcr_log::MeasurementLogEntry;
 use caliptra_drivers::{
     ColdResetEntry4::*, DataVault, Mailbox, PcrBank, PcrId, PersistentDataAccessor,
-    MEASUREMENT_MAX_COUNT,
+    MEASUREMENT_MAX_COUNT, PCR_LOG_MAX_COUNT,
 };
 use caliptra_registers::dv::DvReg;
 use caliptra_registers::pv::PvReg;
@@ -166,14 +167,14 @@ fn copy_tbs(tbs: &mut [u8], ldevid_tbs: bool) {
     tbs.copy_from_slice(&src[..tbs.len()]);
 }
 
-fn get_pcr_entry(entry_index: usize, read_measurement_log: bool) -> PcrLogEntry {
+fn get_pcr_entry(entry_index: usize) -> PcrLogEntry {
     let persistent_data = unsafe { PersistentDataAccessor::new() };
+    persistent_data.get().pcr_log[entry_index]
+}
 
-    if read_measurement_log {
-        persistent_data.get().measurement_log[entry_index]
-    } else {
-        persistent_data.get().pcr_log[entry_index]
-    }
+fn get_measurement_entry(entry_index: usize) -> MeasurementLogEntry {
+    let persistent_data = unsafe { PersistentDataAccessor::new() };
+    persistent_data.get().measurement_log[entry_index]
 }
 
 fn process_mailbox_command(mbox: &caliptra_registers::mbox::RegisterBlock<RealMmioMut>) {
@@ -272,7 +273,12 @@ fn trigger_update_reset(mbox: &caliptra_registers::mbox::RegisterBlock<RealMmioM
 fn read_pcr_log(mbox: &caliptra_registers::mbox::RegisterBlock<RealMmioMut>) {
     let mut pcr_entry_count = 0;
     loop {
-        let pcr_entry = get_pcr_entry(pcr_entry_count, false);
+        if pcr_entry_count == PCR_LOG_MAX_COUNT {
+            break;
+        }
+
+        let pcr_entry = get_pcr_entry(pcr_entry_count);
+
         if PcrLogEntryId::from(pcr_entry.id) == PcrLogEntryId::Invalid {
             break;
         }
@@ -292,17 +298,22 @@ fn read_pcr_log(mbox: &caliptra_registers::mbox::RegisterBlock<RealMmioMut>) {
 fn read_measurement_log(mbox: &caliptra_registers::mbox::RegisterBlock<RealMmioMut>) {
     let mut measurement_entry_count = 0;
     loop {
-        let measurement_entry = get_pcr_entry(measurement_entry_count, true);
-        measurement_entry_count += 1;
-        send_to_mailbox(mbox, measurement_entry.as_bytes(), false);
+        if measurement_entry_count == MEASUREMENT_MAX_COUNT {
+            break;
+        }
 
-        if measurement_entry_count == MEASUREMENT_MAX_COUNT as usize {
+        let measurement_entry = get_measurement_entry(measurement_entry_count);
+
+        if PcrLogEntryId::from(measurement_entry.pcr_entry.id) == PcrLogEntryId::Invalid {
             break;
         }
+
+        measurement_entry_count += 1;
+        send_to_mailbox(mbox, measurement_entry.as_bytes(), false);
     }
 
     mbox.dlen().write(|_| {
-        (core::mem::size_of::<PcrLogEntry>() * measurement_entry_count)
+        (core::mem::size_of::<MeasurementLogEntry>() * measurement_entry_count)
             .try_into()
             .unwrap()
     });