Repository: chipsalliance/caliptra-sw
Pull request #122 (2023-03-30 17:01:39)

[FMC][ROM] FHT.rt_fw_entry_point field should be the entry index into the DV
FMC specification is defining FHT.rt_fw_entry_point as the physical address of the entry point of Runtime FW Module in ICCM SRAM, however ROM is already making this information available in the data vault.

The proposal is to pass RT entry point field as the entry index instead of a physical address.


Patch:
diff --git a/common/src/hand_off.rs b/common/src/hand_off.rs
index 926f19ae..2e99836a 100644
--- a/common/src/hand_off.rs
+++ b/common/src/hand_off.rs
@@ -28,13 +28,13 @@ pub struct FirmwareHandoffTable {
 
     /// Physical base address of FIPS Module in ROM or ICCM SRAM.
     /// May be NULL if there is no discrete module.
-    pub fips_fw_load_addr: u32,
+    pub fips_fw_load_addr_idx: u8,
 
     /// Physical base address of Runtime FW Module in ICCM SRAM.
-    pub rt_fw_load_addr: u32,
+    pub rt_fw_load_addr_idx: u8,
 
     /// Entry point of Runtime FW Module in ICCM SRAM.
-    pub rt_fw_entry_point: u32,
+    pub rt_fw_entry_point_idx: u8,
 
     /// Index of FMC TCI value in the Data Vault.
     pub fmc_tci_dv_idx: u8,
@@ -85,7 +85,7 @@ pub struct FirmwareHandoffTable {
     pub rt_svn_dv_idx: u8,
 
     /// Reserved for future use.
-    pub reserved: [u8; 20],
+    pub reserved: [u8; 29],
 }
 
 impl Default for FirmwareHandoffTable {
@@ -95,9 +95,9 @@ impl Default for FirmwareHandoffTable {
             fht_major_ver: 0,
             fht_minor_ver: 0,
             manifest_load_addr: FHT_INVALID_ADDRESS,
-            fips_fw_load_addr: FHT_INVALID_ADDRESS,
-            rt_fw_load_addr: FHT_INVALID_ADDRESS,
-            rt_fw_entry_point: FHT_INVALID_ADDRESS,
+            fips_fw_load_addr_idx: FHT_INVALID_IDX,
+            rt_fw_load_addr_idx: FHT_INVALID_IDX,
+            rt_fw_entry_point_idx: FHT_INVALID_IDX,
             fmc_tci_dv_idx: FHT_INVALID_IDX,
             fmc_cdi_kv_idx: FHT_INVALID_IDX,
             fmc_priv_key_kv_idx: FHT_INVALID_IDX,
@@ -114,7 +114,7 @@ impl Default for FirmwareHandoffTable {
             rt_cert_sig_r_dv_idx: FHT_INVALID_IDX,
             rt_cert_sig_s_dv_idx: FHT_INVALID_IDX,
             rt_svn_dv_idx: FHT_INVALID_IDX,
-            reserved: [0; 20],
+            reserved: [0; 29],
         }
     }
 }
@@ -131,11 +131,11 @@ impl FirmwareHandoffTable {
             && self.fmc_pub_key_y_dv_idx != FHT_INVALID_IDX
             && self.fmc_cert_sig_r_dv_idx != FHT_INVALID_IDX
             && self.fmc_cert_sig_s_dv_idx != FHT_INVALID_IDX
-            && self.rt_fw_load_addr != FHT_INVALID_ADDRESS
+            && self.rt_fw_load_addr_idx != FHT_INVALID_IDX
             && self.rt_tci_dv_idx != FHT_INVALID_IDX
-            && self.rt_fw_entry_point != FHT_INVALID_ADDRESS
+            && self.rt_fw_entry_point_idx != FHT_INVALID_IDX
             // This is for Gen1 POR.
-            && self.fips_fw_load_addr == FHT_INVALID_ADDRESS
+            && self.fips_fw_load_addr_idx == FHT_INVALID_IDX
     }
     /// Load FHT from its fixed address and perform validity check of
     /// its data.
diff --git a/fmc/README.md b/fmc/README.md
index 243c9528..088537e4 100644
--- a/fmc/README.md
+++ b/fmc/README.md
@@ -112,9 +112,9 @@ fields may not be changed or removed). Table revisions with different Major Vers
 | fht_major_ver         | 2            | ROM        | Major version of FHT.                                                                                    |
 | fht_minor_ver         | 2            | ROM, FMC   | Minor version of FHT. Initially written by ROM but may be changed to a higher version by FMC.            |
 | manifest_load_addr    | 4            | ROM        | Physical base address of Manifest in DCCM SRAM.                                                          |
-| fips_fw_load_addr     | 4            | ROM        | Physical base address of FIPS Module in ROM or ICCM SRAM. May be 0xFFFF_FFFF if there is no discrete module.    |
-| rt_fw_load_addr       | 4            | ROM        | Physical base address of Runtime FW Module in ICCM SRAM.                                                 |
-| rt_fw_entry_point     | 4            | ROM        | Entry point of Runtime FW Module in ICCM SRAM.                                                           |
+| fips_fw_load_addr_idx | 4            | ROM        | Index of base address of FIPS Module in ROM or ICCM SRAM. May be 0xFF if there is no discrete module.    |
+| rt_fw_load_addr_idx   | 4            | ROM        | Index of load address of Runtime FW Module value in data vault.SRAM.                                                 |
+| rt_fw_entry_point_idx | 4            | ROM        | Index of entry point of Runtime FW Module value in data vault. SRAM.                                                           |
 | fmc_tci_dv_idx        | 1            | ROM        | Index of FMC TCI value in the Data Vault.                                                                |
 | fmc_cdi_kv_idx        | 1            | ROM        | Index of FMC CDI value in the Key Vault. Value of 0xFF indicates not present.                            |
 | fmc_priv_key_kv_idx   | 1            | ROM        | Index of FMC Private Alias Key in the Key Vault.                                                         |
@@ -155,19 +155,19 @@ additional data to the first 4 bytes of the reserved space at the end of the FHT
 This is the physical address of the location in SRAM where ROM has placed a complete copy of the Firmware Manifest. This must remain resident such that firmware
 is able to re-run firmware integrity checks on-demand (required by FIPS 140-3).
 
-### fips_fw_load_addr
+### fips_fw_load_addr_idx
 
-*Future feature, not currently supported.* This is the physical address of the location in ROM or SRAM where a discrete FIPS Crypto module resides. If a
-discrete FIPS module does not exist, then this field shall be 0xFFFF_FFFF and ROM, FMC, and RT FW must all carry their own code for accessing crypto resources and
+*Future feature, not currently supported.* This field provides the index of the DV entry that stores the physical address of the location in ROM or SRAM where a discrete FIPS Crypto module resides. If a
+discrete FIPS module does not exist, then this field shall be 0xFF and ROM, FMC, and RT FW must all carry their own code for accessing crypto resources and
 keys.
 
-### rt_fw_load_addr
+### rt_fw_load_addr_idx
 
-This is the physical address of the location in ICCM SRAM where ROM has placed the authenticated Runtime Firmware module.
+This field provides the index of the DV entry that stores the physical address of the location in ICCM SRAM where ROM has placed the authenticated Runtime Firmware module.
 
-### rt_fw_entry_point
+### rt_fw_entry_point_idx
 
-This is the physical address of the Entry Point of Runtime FW Module in ICCM SRAM.
+This field provides the index of the DV entry that stores the physical address of the Entry Point of Runtime FW Module in ICCM SRAM.
 
 ### fmc_tci_dv_idx
 
diff --git a/fmc/src/main.rs b/fmc/src/main.rs
index 151365ea..1bd8cbd2 100644
--- a/fmc/src/main.rs
+++ b/fmc/src/main.rs
@@ -45,8 +45,14 @@ pub extern "C" fn entry_point() -> ! {
             "[fmc] FHT FMC PrivKey KV KeyID: {}",
             fht.fmc_priv_key_kv_idx
         );
-        cprintln!("[fmc] FHT RT Load Address: 0x{:08x}", fht.rt_fw_load_addr);
-        cprintln!("[fmc] FHT RT Entry Point: 0x{:08x}", fht.rt_fw_load_addr);
+        cprintln!(
+            "[fmc] FHT RT Load Address: 0x{:08x}",
+            fht.rt_fw_load_addr_idx
+        );
+        cprintln!(
+            "[fmc] FHT RT Entry Point: 0x{:08x}",
+            fht.rt_fw_load_addr_idx
+        );
 
         let env = fmc_env::FmcEnv::default();
         launch_rt(&env)
diff --git a/rom/dev/src/fht.rs b/rom/dev/src/fht.rs
index 0026edb8..771533ee 100644
--- a/rom/dev/src/fht.rs
+++ b/rom/dev/src/fht.rs
@@ -31,9 +31,9 @@ pub fn make_fht(env: &RomEnv) -> FirmwareHandoffTable {
         fht_major_ver: FHT_MAJOR_VERSION,
         fht_minor_ver: FHT_MINOR_VERSION,
         manifest_load_addr: env.data_vault().map(|d| d.manifest_addr()),
-        fips_fw_load_addr: u32::MAX,
-        rt_fw_load_addr: env.data_vault().map(|d| d.rt_load_addr()),
-        rt_fw_entry_point: env.data_vault().map(|d| d.rt_entry_point()),
+        fips_fw_load_addr_idx: u8::MAX,
+        rt_fw_load_addr_idx: WarmResetEntry4::RtEntryPoint.into(),
+        rt_fw_entry_point_idx: WarmResetEntry4::RtEntryPoint.into(),
         fmc_cdi_kv_idx: KEY_ID_CDI.into(),
         fmc_priv_key_kv_idx: KEY_ID_PRIV_KEY.into(),
         fmc_pub_key_x_dv_idx: ColdResetEntry48::FmcPubKeyX.into(),
diff --git a/runtime/src/main.rs b/runtime/src/main.rs
index 6c56351c..843e2ad9 100644
--- a/runtime/src/main.rs
+++ b/runtime/src/main.rs
@@ -40,8 +40,11 @@ pub extern "C" fn entry_point() -> ! {
         cprintln!("[rt] FHT Manifest Addr: 0x{:08X}", fht.manifest_load_addr);
         cprintln!("[rt] FHT FMC CDI KV KeyID: {}", fht.fmc_cdi_kv_idx);
         cprintln!("[rt] FHT FMC PrivKey KV KeyID: {}", fht.fmc_priv_key_kv_idx);
-        cprintln!("[rt] FHT RT Load Address: 0x{:08x}", fht.rt_fw_load_addr);
-        cprintln!("[rt] FHT RT Entry Point: 0x{:08x}", fht.rt_fw_load_addr);
+        cprintln!(
+            "[rt] FHT RT Load Address: 0x{:08x}",
+            fht.rt_fw_load_addr_idx
+        );
+        cprintln!("[rt] FHT RT Entry Point: 0x{:08x}", fht.rt_fw_load_addr_idx);
         caliptra_drivers::ExitCtrl::exit(0)
     } else {
         caliptra_drivers::ExitCtrl::exit(0xff)


Test patch:
diff --git a/rom/dev/tools/test-fmc/src/main.rs b/rom/dev/tools/test-fmc/src/main.rs
index 7aade6b4..064eec98 100644
--- a/rom/dev/tools/test-fmc/src/main.rs
+++ b/rom/dev/tools/test-fmc/src/main.rs
@@ -55,8 +55,14 @@ pub extern "C" fn fmc_entry() -> ! {
         "[fmc] FHT FMC PrivKey KV KeyID: {}",
         fht.fmc_priv_key_kv_idx
     );
-    cprintln!("[fmc] FHT RT Load Address: 0x{:08x}", fht.rt_fw_load_addr);
-    cprintln!("[fmc] FHT RT Entry Point: 0x{:08x}", fht.rt_fw_load_addr);
+    cprintln!(
+        "[fmc] FHT RT Load Address: 0x{:08x}",
+        fht.rt_fw_load_addr_idx
+    );
+    cprintln!(
+        "[fmc] FHT RT Entry Point: 0x{:08x}",
+        fht.rt_fw_load_addr_idx
+    );
 
     caliptra_drivers::ExitCtrl::exit(0)
 }