Repository: chipsalliance/caliptra-sw
Pull request #460 (2023-07-06 16:37:53)

[feat] Add Memory Layout Module
This PR resolved the following:-

1. Makes the linker script simpler by removing the variables needed by the code. 
2. One place to have all the memory related variables. 
3. Added test cases such that invalid variables are caught as part of unit testing. 
4. At many occasions it was observed the data structure was bigger than the size of memory reserved for it. Since all the memory related variables are in single module, it is easier to catch these type of issues in unit test. 

Please note that with this PR I have moved the ROM to use the memory_layout module. I would also recommend other components [FMC and RT] to start using this.


rusty1968: Can this be merged now?

Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 9d6cf4f2..b7270dd2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -623,6 +623,7 @@ version = "0.1.0"
 dependencies = [
  "bitfield",
  "caliptra-drivers",
+ "caliptra-image-types",
  "caliptra-registers",
  "ufmt",
  "zerocopy",
diff --git a/common/Cargo.toml b/common/Cargo.toml
index fb5e746b..92e8532f 100644
--- a/common/Cargo.toml
+++ b/common/Cargo.toml
@@ -11,6 +11,7 @@ ufmt = "0.2.0"
 zerocopy = "0.6.1"
 caliptra-drivers = { path = "../drivers" }
 caliptra-registers = { path = "../registers" }
+caliptra-image-types = { path = "../image/types", default-features = false }
 bitfield = "0.14.0"
 
 
diff --git a/common/src/lib.rs b/common/src/lib.rs
index cd10aa6e..9fe38c7c 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -11,6 +11,7 @@ pub mod boot_status;
 pub mod checksum;
 pub mod fuse;
 pub mod helpers;
+pub mod memory_layout;
 pub mod pcr;
 
 ///merge imports
diff --git a/common/src/memory_layout.rs b/common/src/memory_layout.rs
new file mode 100644
index 00000000..be972df3
--- /dev/null
+++ b/common/src/memory_layout.rs
@@ -0,0 +1,100 @@
+/*++
+Licensed under the Apache-2.0 license.
+
+File Name:
+
+    memory_layout.rs
+
+Abstract:
+
+    The file contains the layout of memory. The constants defined
+    in this file define the memory layout.
+
+--*/
+
+#[cfg(test)]
+use crate::FirmwareHandoffTable;
+
+#[cfg(test)]
+use caliptra_image_types::ImageManifest;
+
+//
+// Memory Addresses
+//
+pub const ROM_ORG: u32 = 0x00000000;
+pub const MBOX_ORG: u32 = 0x30000000;
+pub const ICCM_ORG: u32 = 0x40000000;
+pub const DCCM_ORG: u32 = 0x50000000;
+pub const MAN1_ORG: u32 = 0x50000000;
+pub const MAN2_ORG: u32 = 0x50001400;
+pub const FHT_ORG: u32 = 0x50002800;
+pub const LDEVID_TBS_ORG: u32 = 0x50003000;
+pub const FMCALIAS_TBS_ORG: u32 = 0x50003400;
+pub const PCR_LOG_ORG: u32 = 0x50003800;
+pub const FUSE_LOG_ORG: u32 = 0x50003C00;
+pub const DATA_ORG: u32 = 0x50004000;
+pub const STACK_ORG: u32 = 0x5001C000;
+pub const ESTACK_ORG: u32 = 0x5001F800;
+pub const NSTACK_ORG: u32 = 0x5001FC00;
+
+//
+// Memory Sizes In Bytes
+//
+pub const ROM_RELAXATION_PADDING: u32 = 4 * 1024;
+pub const ROM_SIZE: u32 = 32 * 1024;
+pub const MBOX_SIZE: u32 = 128 * 1024;
+pub const ICCM_SIZE: u32 = 128 * 1024;
+pub const DCCM_SIZE: u32 = 128 * 1024;
+pub const MAN1_SIZE: u32 = 5 * 1024;
+pub const MAN2_SIZE: u32 = 5 * 1024;
+pub const FHT_SIZE: u32 = 2 * 1024;
+pub const LDEVID_TBS_SIZE: u32 = 1024;
+pub const FMCALIAS_TBS_SIZE: u32 = 1024;
+pub const PCR_LOG_SIZE: usize = 1024;
+pub const FUSE_LOG_SIZE: usize = 1024;
+pub const DATA_SIZE: u32 = 96 * 1024;
+pub const STACK_SIZE: u32 = 14 * 1024;
+pub const ESTACK_SIZE: u32 = 1024;
+pub const NSTACK_SIZE: u32 = 1024;
+
+#[test]
+#[allow(clippy::assertions_on_constants)]
+fn mem_layout_test_manifest() {
+    assert!(MAN1_SIZE as usize >= core::mem::size_of::<ImageManifest>());
+    assert!(MAN2_SIZE as usize >= core::mem::size_of::<ImageManifest>());
+    assert_eq!(MAN1_SIZE, MAN2_SIZE);
+    assert!((MAN2_ORG - MAN1_ORG) == MAN1_SIZE);
+    assert!((FHT_ORG - MAN2_ORG) as usize >= core::mem::size_of::<ImageManifest>());
+}
+
+#[test]
+#[allow(clippy::assertions_on_constants)]
+fn mem_layout_test_fht() {
+    assert!(FHT_SIZE as usize >= core::mem::size_of::<FirmwareHandoffTable>());
+    assert!((LDEVID_TBS_ORG - FHT_ORG) as usize >= core::mem::size_of::<FirmwareHandoffTable>());
+    assert!((LDEVID_TBS_ORG - FHT_ORG) == FHT_SIZE);
+}
+
+#[test]
+#[allow(clippy::assertions_on_constants)]
+fn mem_layout_test_ldevid() {
+    assert!((FMCALIAS_TBS_ORG - LDEVID_TBS_ORG) >= LDEVID_TBS_SIZE);
+}
+
+#[test]
+#[allow(clippy::assertions_on_constants)]
+fn mem_layout_test_fmcalias() {
+    assert!((PCR_LOG_ORG - FMCALIAS_TBS_ORG) >= FMCALIAS_TBS_SIZE);
+}
+
+#[test]
+#[allow(clippy::assertions_on_constants)]
+fn mem_layout_test_pcrlog() {
+    assert!((FUSE_LOG_ORG - PCR_LOG_ORG) as usize >= PCR_LOG_SIZE);
+}
+
+#[test]
+#[allow(clippy::assertions_on_constants)]
+fn mem_layout_test_fuselog() {
+    assert!((DATA_ORG - FUSE_LOG_ORG) as usize >= FUSE_LOG_SIZE);
+}
diff --git a/rom/dev/src/fht.rs b/rom/dev/src/fht.rs
index 85bc2f02..feb85ea6 100644
--- a/rom/dev/src/fht.rs
+++ b/rom/dev/src/fht.rs
@@ -13,6 +13,7 @@ Abstract:
 --*/
 
 use caliptra_common::{
+    memory_layout::{FHT_ORG, FMCALIAS_TBS_ORG, FUSE_LOG_ORG, LDEVID_TBS_ORG, PCR_LOG_ORG},
     DataVaultRegister, FirmwareHandoffTable, HandOffDataHandle, Vault, FHT_INVALID_HANDLE,
     FHT_MARKER,
 };
@@ -30,13 +31,6 @@ use crate::{
 const FHT_MAJOR_VERSION: u16 = 1;
 const FHT_MINOR_VERSION: u16 = 0;
 
-extern "C" {
-    static mut LDEVID_TBS_ORG: u8;
-    static mut FMCALIAS_TBS_ORG: u8;
-    static mut PCR_LOG_ORG: u8;
-    static mut FUSE_LOG_ORG: u8;
-}
-
 #[derive(Debug, Default)]
 pub struct FhtDataStore {
     /// LdevId TBS size
@@ -140,17 +134,10 @@ impl FhtDataStore {
 }
 
 pub fn make_fht(env: &RomEnv) -> FirmwareHandoffTable {
-    let ldevid_tbs_addr: u32;
-    let fmcalias_tbs_addr: u32;
-    let pcr_log_addr: u32;
-    let fuse_log_addr: u32;
-
-    unsafe {
-        ldevid_tbs_addr = &LDEVID_TBS_ORG as *const u8 as u32;
-        fmcalias_tbs_addr = &FMCALIAS_TBS_ORG as *const u8 as u32;
-        pcr_log_addr = &PCR_LOG_ORG as *const u8 as u32;
-        fuse_log_addr = &FUSE_LOG_ORG as *const u8 as u32;
-    }
+    let ldevid_tbs_addr: u32 = LDEVID_TBS_ORG;
+    let fmcalias_tbs_addr: u32 = FMCALIAS_TBS_ORG;
+    let pcr_log_addr: u32 = PCR_LOG_ORG;
+    let fuse_log_addr: u32 = FUSE_LOG_ORG;
 
     FirmwareHandoffTable {
         fht_marker: FHT_MARKER,
@@ -184,12 +171,8 @@ pub fn make_fht(env: &RomEnv) -> FirmwareHandoffTable {
 }
 
 pub fn store(fht: FirmwareHandoffTable) {
-    extern "C" {
-        static mut FHT_ORG: u8;
-    }
-
     let slice = unsafe {
-        let ptr = &mut FHT_ORG as *mut u8;
+        let ptr = FHT_ORG as *mut u8;
         cprintln!("[fht] Storing FHT @ 0x{:08X}", ptr as u32);
         core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<FirmwareHandoffTable>())
     };
diff --git a/rom/dev/src/flow/cold_reset/fw_processor.rs b/rom/dev/src/flow/cold_reset/fw_processor.rs
index 6faee6df..b11348a8 100644
--- a/rom/dev/src/flow/cold_reset/fw_processor.rs
+++ b/rom/dev/src/flow/cold_reset/fw_processor.rs
@@ -16,7 +16,7 @@ use crate::fuse::log_fuse_data;
 use crate::rom_env::RomEnv;
 use crate::{cprintln, verifier::RomImageVerificationEnv};
 use crate::{pcr, wdt};
-use caliptra_common::{cprint, FuseLogEntryId, RomBootStatus::*};
+use caliptra_common::{cprint, memory_layout::MAN1_ORG, FuseLogEntryId, RomBootStatus::*};
 use caliptra_drivers::*;
 use caliptra_image_types::{ImageManifest, IMAGE_BYTE_SIZE};
 use caliptra_image_verify::{ImageVerificationInfo, ImageVerificationLogInfo, ImageVerifier};
@@ -24,10 +24,6 @@ use caliptra_x509::{NotAfter, NotBefore};
 use core::mem::ManuallyDrop;
 use zerocopy::{AsBytes, FromBytes};
 
-extern "C" {
-    static mut MAN1_ORG: u32;
-}
-
 #[derive(Debug, Default)]
 pub struct FwProcInfo {
     pub fmc_cert_valid_not_before: NotBefore,
@@ -163,7 +159,7 @@ impl FirmwareProcessor {
     /// * `Manifest` - Caliptra Image Bundle Manifest
     fn load_manifest(txn: &mut MailboxRecvTxn) -> CaliptraResult<ImageManifest> {
         let slice = unsafe {
-            let ptr = &mut MAN1_ORG as *mut u32;
+            let ptr = MAN1_ORG as *mut u32;
             core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<ImageManifest>() / 4)
         };
 
@@ -328,8 +324,8 @@ impl FirmwareProcessor {
         data_vault.write_warm_reset_entry4(WarmResetEntry4::RtEntryPoint, info.runtime.entry_point);
 
         // TODO: Need a better way to get the Manifest address
-        let slice = unsafe {
-            let ptr = &MAN1_ORG as *const u32;
+        let slice = {
+            let ptr = MAN1_ORG as *const u32;
             ptr as u32
         };
 
diff --git a/rom/dev/src/flow/cold_reset/mod.rs b/rom/dev/src/flow/cold_reset/mod.rs
index 9399debd..c8ca6649 100644
--- a/rom/dev/src/flow/cold_reset/mod.rs
+++ b/rom/dev/src/flow/cold_reset/mod.rs
@@ -27,8 +27,11 @@ use crate::flow::cold_reset::fw_processor::FirmwareProcessor;
 use crate::flow::cold_reset::idev_id::InitDevIdLayer;
 use crate::flow::cold_reset::ldev_id::LocalDevIdLayer;
 use crate::{cprintln, rom_env::RomEnv};
-use caliptra_common::FirmwareHandoffTable;
 use caliptra_common::RomBootStatus::*;
+use caliptra_common::{
+    memory_layout::{FMCALIAS_TBS_ORG, FMCALIAS_TBS_SIZE, LDEVID_TBS_ORG, LDEVID_TBS_SIZE},
+    FirmwareHandoffTable,
+};
 use caliptra_drivers::*;
 
 pub const KEY_ID_UDS: KeyId = KeyId::KeyId0;
@@ -38,13 +41,6 @@ pub const KEY_ID_IDEVID_PRIV_KEY: KeyId = KeyId::KeyId7;
 pub const KEY_ID_LDEVID_PRIV_KEY: KeyId = KeyId::KeyId5;
 pub const KEY_ID_FMC_PRIV_KEY: KeyId = KeyId::KeyId7;
 
-extern "C" {
-    static mut LDEVID_TBS_ORG: u8;
-    static mut FMCALIAS_TBS_ORG: u8;
-    static mut LDEVID_TBS_SIZE: u8;
-    static mut FMCALIAS_TBS_SIZE: u8;
-}
-
 pub enum TbsType {
     LdevidTbs = 0,
     FmcaliasTbs = 1,
@@ -102,23 +98,23 @@ pub fn copy_tbs(tbs: &[u8], tbs_type: TbsType, env: &mut RomEnv) -> CaliptraResu
         TbsType::LdevidTbs => {
             env.fht_data_store.ldevid_tbs_size = tbs.len() as u16;
             unsafe {
-                let tbs_max_size = &LDEVID_TBS_SIZE as *const u8 as usize;
+                let tbs_max_size = LDEVID_TBS_SIZE as usize;
                 if tbs.len() > tbs_max_size {
                     return Err(CaliptraError::ROM_GLOBAL_UNSUPPORTED_LDEVID_TBS_SIZE);
                 }
-                let ptr = &mut LDEVID_TBS_ORG as *mut u8;
+                let ptr = LDEVID_TBS_ORG as *mut u8;
                 core::slice::from_raw_parts_mut(ptr, tbs.len())
             }
         }
         TbsType::FmcaliasTbs => {
             env.fht_data_store.fmcalias_tbs_size = tbs.len() as u16;
             unsafe {
-                let tbs_max_size = &FMCALIAS_TBS_SIZE as *const u8 as usize;
+                let tbs_max_size = FMCALIAS_TBS_SIZE as usize;
                 if tbs.len() > tbs_max_size {
                     return Err(CaliptraError::ROM_GLOBAL_UNSUPPORTED_FMCALIAS_TBS_SIZE);
                 }
 
-                let ptr = &mut FMCALIAS_TBS_ORG as *mut u8;
+                let ptr = FMCALIAS_TBS_ORG as *mut u8;
                 core::slice::from_raw_parts_mut(ptr, tbs.len())
             }
         }
diff --git a/rom/dev/src/flow/update_reset.rs b/rom/dev/src/flow/update_reset.rs
index 929f464c..fe2a745d 100644
--- a/rom/dev/src/flow/update_reset.rs
+++ b/rom/dev/src/flow/update_reset.rs
@@ -13,7 +13,9 @@ Abstract:
 --*/
 use crate::{cprintln, fht, rom_env::RomEnv, verifier::RomImageVerificationEnv, wdt};
 
+use caliptra_common::memory_layout::{MAN1_ORG, MAN2_ORG};
 use caliptra_common::FirmwareHandoffTable;
+
 use caliptra_common::RomBootStatus::*;
 use caliptra_drivers::{report_boot_status, MailboxRecvTxn, ResetReason};
 use caliptra_error::{CaliptraError, CaliptraResult};
@@ -21,11 +23,6 @@ use caliptra_image_types::ImageManifest;
 use caliptra_image_verify::{ImageVerificationInfo, ImageVerifier};
 use zerocopy::{AsBytes, FromBytes};
 
-extern "C" {
-    static mut MAN2_ORG: u32;
-    static mut MAN1_ORG: u32;
-}
-
 #[derive(Default)]
 pub struct UpdateResetFlow {}
 
@@ -119,15 +116,16 @@ impl UpdateResetFlow {
         cprintln!("[update-reset] Copying MAN_2 To MAN_1");
 
         let dst = unsafe {
-            let ptr = &mut MAN1_ORG as *mut u32;
+            let ptr = MAN1_ORG as *mut u32;
             core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<ImageManifest>())
         };
 
         let src = unsafe {
-            let ptr = &mut MAN2_ORG as *mut u32;
+            let ptr = MAN2_ORG as *mut u32;
 
             core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<ImageManifest>())
         };
+
         dst.clone_from_slice(src);
     }
 
@@ -169,7 +167,7 @@ impl UpdateResetFlow {
     /// * `Manifest` - Caliptra Image Bundle Manifest
     fn load_manifest(txn: &mut MailboxRecvTxn) -> CaliptraResult<ImageManifest> {
         let slice = unsafe {
-            let ptr = &mut MAN2_ORG as *mut u32;
+            let ptr = MAN2_ORG as *mut u32;
             core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<ImageManifest>() / 4)
         };
 
diff --git a/rom/dev/src/fuse.rs b/rom/dev/src/fuse.rs
index 49968a09..c5f07a34 100644
--- a/rom/dev/src/fuse.rs
+++ b/rom/dev/src/fuse.rs
@@ -10,17 +10,13 @@ Abstract:
     The file contains Fuse-related Implementations.
 
 --*/
-use caliptra_common::{FuseLogEntry, FuseLogEntryId};
+use caliptra_common::{
+    memory_layout::{FUSE_LOG_ORG, FUSE_LOG_SIZE},
+    FuseLogEntry, FuseLogEntryId,
+};
 use caliptra_drivers::{CaliptraError, CaliptraResult};
-use core::mem::size_of;
 use zerocopy::AsBytes;
 
-const FUSE_LOG_SIZE: usize = 1024;
-
-extern "C" {
-    static mut FUSE_LOG_ORG: [FuseLogEntry; FUSE_LOG_SIZE / size_of::<FuseLogEntry>()];
-}
-
 /// Log Fuse data
 ///
 /// # Arguments
@@ -48,8 +44,10 @@ pub fn log_fuse_data(entry_id: FuseLogEntryId, data: &[u8]) -> CaliptraResult<()
     };
     log_entry.log_data.as_bytes_mut()[..data.len()].copy_from_slice(data);
 
-    // Get a pointer to the FUSE log. This is a static array of FUSE log entries.
-    let dst = unsafe { &mut FUSE_LOG_ORG[..] };
+    let dst: &mut [FuseLogEntry] = unsafe {
+        let ptr = FUSE_LOG_ORG as *mut FuseLogEntry;
+        core::slice::from_raw_parts_mut(ptr, FUSE_LOG_SIZE / core::mem::size_of::<FuseLogEntry>())
+    };
 
     // Store the log entry.
     dst[entry_id as usize - 1] = log_entry;
diff --git a/rom/dev/src/pcr.rs b/rom/dev/src/pcr.rs
index eb369978..7666a7ee 100644
--- a/rom/dev/src/pcr.rs
+++ b/rom/dev/src/pcr.rs
@@ -22,17 +22,14 @@ Note:
 --*/
 
 use crate::verifier::RomImageVerificationEnv;
-use caliptra_common::{PcrLogEntry, PcrLogEntryId};
+use caliptra_common::{
+    memory_layout::{PCR_LOG_ORG, PCR_LOG_SIZE},
+    PcrLogEntry, PcrLogEntryId,
+};
 use caliptra_drivers::{Array4x12, CaliptraError, CaliptraResult, PcrBank, PcrId, Sha384};
 use caliptra_image_verify::ImageVerificationInfo;
-use core::mem::size_of;
-use zerocopy::AsBytes;
-
-const PCR_LOG_SIZE: usize = 1024;
 
-extern "C" {
-    static mut PCR_LOG_ORG: [PcrLogEntry; PCR_LOG_SIZE / size_of::<PcrLogEntry>()];
-}
+use zerocopy::AsBytes;
 
 struct PcrExtender<'a> {
     pcr_bank: &'a mut PcrBank,
@@ -128,8 +125,10 @@ pub fn log_pcr(pcr_entry_id: PcrLogEntryId, pcr_id: PcrId, data: &[u8]) -> Calip
     };
     pcr_log_entry.pcr_data.as_bytes_mut()[..data.len()].copy_from_slice(data);
 
-    // Get a pointer to the PCR log. This is a static array of PCR log entries.
-    let dst = unsafe { &mut PCR_LOG_ORG[..] };
+    let dst: &mut [PcrLogEntry] = unsafe {
+        let ptr = PCR_LOG_ORG as *mut PcrLogEntry;
+        core::slice::from_raw_parts_mut(ptr, PCR_LOG_SIZE / core::mem::size_of::<PcrLogEntry>())
+    };
 
     // Store the log entry.
     dst[pcr_entry_id as usize - 1] = pcr_log_entry;
diff --git a/rom/dev/src/rom.ld b/rom/dev/src/rom.ld
index 8e6343e2..120da500 100644
--- a/rom/dev/src/rom.ld
+++ b/rom/dev/src/rom.ld
@@ -17,16 +17,8 @@ OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv", "elf32-littleriscv")
 ENTRY(_start)
 
 ROM_ORG          = 0x00000000;
-MBOX_ORG         = 0x30000000;
 ICCM_ORG         = 0x40000000;
 DCCM_ORG         = 0x50000000;
-MAN1_ORG         = 0x50000000;
-MAN2_ORG         = 0x50001400;
-FHT_ORG          = 0x50002800;
-LDEVID_TBS_ORG   = 0x50003000;
-FMCALIAS_TBS_ORG = 0x50003400;
-PCR_LOG_ORG      = 0x50003800;
-FUSE_LOG_ORG     = 0x50003C00;
 DATA_ORG         = 0x50004000;
 STACK_ORG        = 0x5001C000;
 ESTACK_ORG       = 0x5001F800;
@@ -39,16 +31,8 @@ NSTACK_ORG       = 0x5001FC00;
  */
 ROM_RELAXATION_PADDING = 4k;
 ROM_SIZE          = 32K;
-MBOX_SIZE         = 128K;
 ICCM_SIZE         = 128K;
 DCCM_SIZE         = 128K;
-MAN1_SIZE         = 5K;
-MAN2_SIZE         = 5K;
-FHT_SIZE          = 2K;
-LDEVID_TBS_SIZE   = 1K;
-FMCALIAS_TBS_SIZE = 1K;
-PCR_LOG_SIZE      = 1K;
-FUSE_LOG_SIZE     = 1K;
 DATA_SIZE         = 96K;
 STACK_SIZE        = 14K;
 ESTACK_SIZE       = 1K;
@@ -57,15 +41,7 @@ NSTACK_SIZE       = 1K;
 MEMORY
 {
 	ROM          (rx) : ORIGIN = ROM_ORG,          LENGTH = ROM_SIZE + ROM_RELAXATION_PADDING
-	MBOX         (rw) : ORIGIN = MBOX_ORG,         LENGTH = MBOX_SIZE
 	ICCM         (rx) : ORIGIN = ICCM_ORG,         LENGTH = ICCM_SIZE
-	MAN1         (rw) : ORIGIN = MAN1_ORG,         LENGTH = MAN1_SIZE
-	MAN2         (rw) : ORIGIN = MAN2_ORG,         LENGTH = MAN2_SIZE
-	FHT          (rw) : ORIGIN = FHT_ORG,          LENGTH = FHT_SIZE
-	LDEVID_TBS   (rw) : ORIGIN = LDEVID_TBS_ORG,   LENGTH = LDEVID_TBS_SIZE
-	FMCALIAS_TBS (rw) : ORIGIN = FMCALIAS_TBS_ORG, LENGTH = FMCALIAS_TBS_SIZE
-	PCR_LOG      (rw) : ORIGIN = PCR_LOG_ORG,      LENGTH = PCR_LOG_SIZE
-	FUSE_LOG     (rw) : ORIGIN = FUSE_LOG_ORG,     LENGTH = FUSE_LOG_SIZE
 	DATA         (rw) : ORIGIN = DATA_ORG,         LENGTH = DATA_SIZE
 	STACK        (rw) : ORIGIN = STACK_ORG,        LENGTH = STACK_SIZE
 	ESTACK       (rw) : ORIGIN = ESTACK_ORG,       LENGTH = ESTACK_SIZE


Test patch:
diff --git a/rom/dev/tools/test-fmc/src/fmc.ld b/rom/dev/tools/test-fmc/src/fmc.ld
index c02995be..7332320b 100644
--- a/rom/dev/tools/test-fmc/src/fmc.ld
+++ b/rom/dev/tools/test-fmc/src/fmc.ld
@@ -16,31 +16,17 @@ OUTPUT_ARCH(riscv)
 OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv", "elf32-littleriscv")
 ENTRY(_start)
 
-MBOX_ORG         = 0x30000000;
+
 ICCM_ORG         = 0x40000000;
 DCCM_ORG         = 0x50000000;
-MAN1_ORG         = 0x50000000;
-MAN2_ORG         = 0x50001400;
-FHT_ORG          = 0x50002800;
-LDEVID_TBS_ORG   = 0x50003000;
-FMCALIAS_TBS_ORG = 0x50003400;
-PCR_LOG_ORG      = 0x50003800;
-FUSE_LOG_ORG     = 0x50003C00;
 DATA_ORG         = 0x50004000;
 STACK_ORG        = 0x5001C000;
 ESTACK_ORG       = 0x5001F800;
 NSTACK_ORG       = 0x5001FC00;
 
-MBOX_SIZE         = 128K;
+
 ICCM_SIZE         = 128K;
 DCCM_SIZE         = 128K;
-MAN1_SIZE         = 5K;
-MAN2_SIZE         = 5K;
-FHT_SIZE          = 2K;
-LDEVID_TBS_SIZE   = 1K;
-FMCALIAS_TBS_SIZE = 1K;
-PCR_LOG_SIZE      = 1K;
-FUSE_LOG_SIZE     = 1K;
 DATA_SIZE         = 96K;
 STACK_SIZE        = 14K;
 ESTACK_SIZE       = 1K;
@@ -48,15 +34,7 @@ NSTACK_SIZE       = 1K;
 
 MEMORY
 {
-	MBOX         (rw) : ORIGIN = MBOX_ORG,         LENGTH = MBOX_SIZE
 	ICCM         (rx) : ORIGIN = ICCM_ORG,         LENGTH = ICCM_SIZE
-	MAN1         (rw) : ORIGIN = MAN1_ORG,         LENGTH = MAN1_SIZE
-	MAN2         (rw) : ORIGIN = MAN2_ORG,         LENGTH = MAN2_SIZE
-	FHT          (rw) : ORIGIN = FHT_ORG,          LENGTH = FHT_SIZE
-	LDEVID_TBS   (rw) : ORIGIN = LDEVID_TBS_ORG,   LENGTH = LDEVID_TBS_SIZE
-	FMCALIAS_TBS (rw) : ORIGIN = FMCALIAS_TBS_ORG, LENGTH = FMCALIAS_TBS_SIZE
-	PCR_LOG      (rw) : ORIGIN = PCR_LOG_ORG,      LENGTH = PCR_LOG_SIZE
-	FUSE_LOG     (rw) : ORIGIN = FUSE_LOG_ORG,     LENGTH = FUSE_LOG_SIZE
 	DATA         (rw) : ORIGIN = DATA_ORG,         LENGTH = DATA_SIZE
 	STACK        (rw) : ORIGIN = STACK_ORG,        LENGTH = STACK_SIZE
 	ESTACK       (rw) : ORIGIN = ESTACK_ORG,       LENGTH = ESTACK_SIZE
diff --git a/rom/dev/tools/test-fmc/src/main.rs b/rom/dev/tools/test-fmc/src/main.rs
index ed42618a..59f40df9 100644
--- a/rom/dev/tools/test-fmc/src/main.rs
+++ b/rom/dev/tools/test-fmc/src/main.rs
@@ -14,22 +14,16 @@ Abstract:
 #![cfg_attr(not(feature = "std"), no_std)]
 #![cfg_attr(not(feature = "std"), no_main)]
 
-extern "C" {
-    static mut LDEVID_TBS_ORG: u8;
-    static mut FMCALIAS_TBS_ORG: u8;
-    static mut PCR_LOG_ORG: u8;
-    static mut FUSE_LOG_ORG: u8;
-    static mut FHT_ORG: u8;
-}
-
-use core::ptr;
-
+use caliptra_common::memory_layout::{
+    FHT_ORG, FMCALIAS_TBS_ORG, FUSE_LOG_ORG, LDEVID_TBS_ORG, PCR_LOG_ORG,
+};
 use caliptra_common::FirmwareHandoffTable;
 use caliptra_common::{FuseLogEntry, FuseLogEntryId};
 use caliptra_common::{PcrLogEntry, PcrLogEntryId};
 use caliptra_drivers::{DataVault, Mailbox};
 use caliptra_registers::dv::DvReg;
 use caliptra_x509::{Ecdsa384CertBuilder, Ecdsa384Signature, FmcAliasCertTbs, LocalDevIdCertTbs};
+use core::ptr;
 use ureg::RealMmioMut;
 use zerocopy::AsBytes;
 use zerocopy::FromBytes;
@@ -52,7 +46,7 @@ pub extern "C" fn fmc_entry() -> ! {
     cprintln!("{}", BANNER);
 
     let slice = unsafe {
-        let ptr = &mut FHT_ORG as *mut u8;
+        let ptr = FHT_ORG as *mut u8;
         cprintln!("[fmc] Loading FHT from 0x{:08X}", ptr as u32);
         core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<FirmwareHandoffTable>())
     };
@@ -174,12 +168,12 @@ fn copy_tbs(tbs: &mut [u8], ldevid_tbs: bool) {
     // Copy the tbs from DCCM
     let src = if ldevid_tbs {
         unsafe {
-            let ptr = &mut LDEVID_TBS_ORG as *mut u8;
+            let ptr = LDEVID_TBS_ORG as *mut u8;
             core::slice::from_raw_parts_mut(ptr, tbs.len())
         }
     } else {
         unsafe {
-            let ptr = &mut FMCALIAS_TBS_ORG as *mut u8;
+            let ptr = FMCALIAS_TBS_ORG as *mut u8;
             core::slice::from_raw_parts_mut(ptr, tbs.len())
         }
     };
@@ -193,7 +187,7 @@ fn get_pcr_entry(entry_index: usize) -> PcrLogEntry {
 
     let src = unsafe {
         let offset = core::mem::size_of::<PcrLogEntry>() * entry_index;
-        let ptr = (&mut PCR_LOG_ORG as *mut u8).add(offset);
+        let ptr = (PCR_LOG_ORG as *mut u8).add(offset);
         core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<PcrLogEntry>())
     };
 
@@ -282,7 +276,7 @@ fn get_fuse_entry(entry_index: usize) -> FuseLogEntry {
 
     let src = unsafe {
         let offset = core::mem::size_of::<FuseLogEntry>() * entry_index;
-        let ptr = (&mut FUSE_LOG_ORG as *mut u8).add(offset);
+        let ptr = (FUSE_LOG_ORG as *mut u8).add(offset);
         core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<FuseLogEntry>())
     };
 
@@ -296,7 +290,7 @@ fn read_fht(mbox: &caliptra_registers::mbox::RegisterBlock<RealMmioMut>) {
         [0u8; core::mem::size_of::<FirmwareHandoffTable>()];
 
     let src = unsafe {
-        let ptr = &mut FHT_ORG as *mut u8;
+        let ptr = FHT_ORG as *mut u8;
         core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<FirmwareHandoffTable>())
     };
 
diff --git a/rom/dev/tools/test-rt/src/rt.ld b/rom/dev/tools/test-rt/src/rt.ld
index 963e0aa3..5d8f18a2 100644
--- a/rom/dev/tools/test-rt/src/rt.ld
+++ b/rom/dev/tools/test-rt/src/rt.ld
@@ -16,23 +16,16 @@ OUTPUT_ARCH(riscv)
 OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv", "elf32-littleriscv")
 ENTRY(_start)
 
-MBOX_ORG    = 0x30000000;
+
 ICCM_ORG    = 0x40004000; /* Range [0x40000000 - 0x40003FFF] is reserved for FMC */
 DCCM_ORG    = 0x50000000;
-MAN1_ORG    = 0x50000000;
-MAN2_ORG    = 0x50001400;
-FHT_ORG     = 0x50002800;
 DATA_ORG    = 0x50003000;
 STACK_ORG   = 0x5001C000;
 ESTACK_ORG  = 0x5001F800;
 NSTACK_ORG  = 0x5001FC00;
 
-MBOX_SIZE   = 128K;
 ICCM_SIZE   = 112K;
 DCCM_SIZE   = 128K;
-MAN1_SIZE   = 5K;
-MAN2_SIZE   = 5K;
-FHT_SIZE    = 2K;
 DATA_SIZE   = 100K;
 STACK_SIZE  = 14K;
 ESTACK_SIZE = 1K;
@@ -40,11 +33,7 @@ NSTACK_SIZE = 1K;
 
 MEMORY
 {
-	MBOX   (rw) : ORIGIN = MBOX_ORG,   LENGTH = MBOX_SIZE
 	ICCM   (rx) : ORIGIN = ICCM_ORG,   LENGTH = ICCM_SIZE
-	MAN1   (rw) : ORIGIN = MAN1_ORG,   LENGTH = MAN1_SIZE
-	MAN2   (rw) : ORIGIN = MAN2_ORG,   LENGTH = MAN2_SIZE
-	FHT    (rw) : ORIGIN = FHT_ORG,    LENGTH = FHT_SIZE
 	DATA   (rw) : ORIGIN = DATA_ORG,   LENGTH = DATA_SIZE
 	STACK  (rw) : ORIGIN = STACK_ORG,  LENGTH = STACK_SIZE
 	ESTACK (rw) : ORIGIN = ESTACK_ORG, LENGTH = ESTACK_SIZE