Repository: chipsalliance/caliptra-sw
Pull request #464 (2023-07-08 05:04:07)

Generate linker.x and memory.x using build scripts
The purpose of this commit is to generate linker.x and memory.x files for mutable code based on a single source of truth, the memory layout description in the common crate.


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index b7270dd2..6e88986b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -288,6 +288,7 @@ dependencies = [
  "caliptra-cpu",
  "caliptra-drivers",
  "caliptra-error",
+ "caliptra-gen-linker-scripts",
  "caliptra-hw-model",
  "caliptra-image-types",
  "caliptra-registers",
@@ -311,6 +312,13 @@ dependencies = [
  "zerocopy",
 ]
 
+[[package]]
+name = "caliptra-gen-linker-scripts"
+version = "0.1.0"
+dependencies = [
+ "caliptra_common",
+]
+
 [[package]]
 name = "caliptra-hw-model"
 version = "0.1.0"
@@ -531,6 +539,7 @@ dependencies = [
  "caliptra-builder",
  "caliptra-cpu",
  "caliptra-drivers",
+ "caliptra-gen-linker-scripts",
  "caliptra-hw-model",
  "caliptra-image-elf",
  "caliptra-image-fake-keys",
@@ -553,6 +562,7 @@ version = "0.1.0"
 dependencies = [
  "caliptra-cpu",
  "caliptra-drivers",
+ "caliptra-gen-linker-scripts",
  "caliptra-registers",
  "caliptra-runtime",
  "caliptra-test-harness",
diff --git a/common/src/hand_off.rs b/common/src/hand_off.rs
index fc6e882c..a338c5df 100644
--- a/common/src/hand_off.rs
+++ b/common/src/hand_off.rs
@@ -1,5 +1,5 @@
 // Licensed under the Apache-2.0 license.
-use crate::helpers::*;
+use crate::{helpers::*, FHT_ORG};
 use bitfield::{bitfield_bitrange, bitfield_fields};
 use caliptra_drivers::{
     report_fw_error_non_fatal, ColdResetEntry4, ColdResetEntry48, Ecc384PubKey, Ecc384Signature,
@@ -413,11 +413,8 @@ impl FirmwareHandoffTable {
     /// Load FHT from its fixed address and perform validity check of
     /// its data.
     pub fn try_load() -> Option<FirmwareHandoffTable> {
-        extern "C" {
-            static mut FHT_ORG: u32;
-        }
         let slice = unsafe {
-            let ptr = &mut FHT_ORG as *mut u32;
+            let ptr = FHT_ORG as *mut u32;
             core::slice::from_raw_parts_mut(
                 ptr,
                 core::mem::size_of::<FirmwareHandoffTable>() / core::mem::size_of::<u32>(),
@@ -434,12 +431,8 @@ impl FirmwareHandoffTable {
     }
 
     pub fn save(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;
             crate::cprintln!("[fht] Saving FHT @ 0x{:08X}", ptr as u32);
             core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<FirmwareHandoffTable>())
         };
diff --git a/common/src/lib.rs b/common/src/lib.rs
index acc15427..3e6e0a65 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -26,3 +26,10 @@ pub use fuse::{FuseLogEntry, FuseLogEntryId};
 pub use pcr::{PcrLogEntry, PcrLogEntryId};
 pub use printer::HexBytes;
 pub use printer::MutablePrinter;
+
+pub const FMC_ORG: u32 = 0x40000000;
+pub const FMC_SIZE: u32 = 16 * 1024;
+pub const RUNTIME_ORG: u32 = FMC_ORG + FMC_SIZE;
+pub const RUNTIME_SIZE: u32 = 96 * 1024;
+
+pub use memory_layout::{FHT_ORG, FHT_SIZE};
diff --git a/cpu/build.rs b/cpu/build.rs
index 887f1507..16a75685 100644
--- a/cpu/build.rs
+++ b/cpu/build.rs
@@ -8,7 +8,120 @@ fn main() {
     let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
 
     // Put the linker script somewhere the linker can find it.
-    fs::write(out_dir.join("link.x"), include_bytes!("link.x")).unwrap();
+    fs::write(
+        out_dir.join("link.x"),
+        r#"SECTIONS 
+    {
+        .text : ALIGN(4)
+        {
+            _stext = .;
+    
+            KEEP(*(.init .init.*));
+            *(.text .text.*);
+            KEEP(*(.vectors))
+    
+            . = ALIGN(4);
+            _etext = .;
+        } > REGION_TEXT
+    
+        .rodata : ALIGN(4)
+        {
+            _srodata = .;
+            
+            *(.srodata .srodata.*);
+            *(.rodata .rodata.*);
+    
+            . = ALIGN(4);
+            _erodata = .;
+        } > REGION_RODATA
+    
+        .data : AT (_erodata) ALIGN(4) 
+        {
+            _sidata = LOADADDR(.data);
+            _sdata = .;
+            
+            /* Must be called __global_pointer$ for linker relaxations to work. */
+            PROVIDE(__global_pointer$ = . + 0x800);
+       
+            *(.sdata .sdata.* .sdata2 .sdata2.*);
+            *(.data .data.*);
+            
+            . = ALIGN(4);
+            _edata = .;
+        } > REGION_DATA 
+    
+     
+        .bss (NOLOAD) : ALIGN(4) 
+        {
+            _sbss = .;
+    
+            *(.bss*)
+            *(.sbss*)
+            *(COMMON)
+            . = ALIGN(4);
+            
+            _ebss = .;
+        } > REGION_BSS
+    
+        .stack (NOLOAD): ALIGN(4)
+        {
+            _estack = .;
+            
+            . = . + STACK_SIZE;
+    
+            . = ALIGN(4);
+            _sstack = .;
+        } > REGION_STACK
+    
+        .estack (NOLOAD): ALIGN(4)
+        {
+            _eestack = .;
+            
+            . = . + ESTACK_SIZE;
+    
+            . = ALIGN(4);
+            _sestack = .;
+        } > REGION_ESTACK
+    
+        .nstack (NOLOAD): ALIGN(4)
+        {
+            _enstack = .;
+            
+            . = . + NSTACK_SIZE;
+    
+            . = ALIGN(4);
+            _snstack = .;
+        } > REGION_NSTACK
+    
+    
+        .got (INFO) :
+        {
+            KEEP(*(.got .got.*));
+        }
+    
+        .eh_frame (INFO) : 
+        { 
+            KEEP(*(.eh_frame))
+        }
+        
+        .eh_frame_hdr (INFO) :
+        {
+            *(.eh_frame_hdr) 
+        }
+    }
+    
+    _bss_len  = SIZEOF(.bss);
+    _data_len = SIZEOF(.data);
+    
+    ASSERT(SIZEOF(.got) == 0, ".got section detected");
+    ASSERT(SIZEOF(.data) == 0, ".data section detected");
+    ASSERT(SIZEOF(.bss) == 0, ".bss section detected");
+    ASSERT(SIZEOF(.stack) == STACK_SIZE, ".stack section overflow");
+    ASSERT(SIZEOF(.estack) == ESTACK_SIZE, ".estack section overflow");
+    ASSERT(SIZEOF(.nstack) == NSTACK_SIZE, ".nstack section overflow");"#
+            .as_bytes(),
+    )
+    .unwrap();
     println!("cargo:rustc-link-search={}", out_dir.display());
 
     println!("cargo:rerun-if-changed=link.x");
diff --git a/cpu/gen/Cargo.toml b/cpu/gen/Cargo.toml
new file mode 100644
index 00000000..048486c7
--- /dev/null
+++ b/cpu/gen/Cargo.toml
@@ -0,0 +1,11 @@
+# Licensed under the Apache-2.0 license
+
+[package]
+name = "caliptra-gen-linker-scripts"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+caliptra_common = { path = "../../common", default-features = false }
\ No newline at end of file
diff --git a/cpu/gen/src/lib.rs b/cpu/gen/src/lib.rs
new file mode 100644
index 00000000..8e50db30
--- /dev/null
+++ b/cpu/gen/src/lib.rs
@@ -0,0 +1,46 @@
+// Licensed under the Apache-2.0 license
+use caliptra_common::memory_layout::{FMCALIAS_TBS_ORG, LDEVID_TBS_ORG};
+pub fn gen_memory_x(iccm_org: u32, iccm_size: u32) -> String {
+    format!(
+        r#"
+        ICCM_ORG  		 = 0x{:08X};
+        DCCM_ORG  		 = 0x50000000;
+        DATA_ORG  		 = 0x50004400;
+        STACK_ORG 		 = 0x5001C000;
+        ESTACK_ORG  	 = 0x5001F800;
+        NSTACK_ORG       = 0x5001FC00;
+        LDEVID_TBS_ORG   = 0x{:08X};;
+        FMCALIAS_TBS_ORG = 0x{:08X};;
+        RTALIAS_TBS_ORG  = 0x50004000;
+        
+        LDEVID_TBS_SIZE   = 1K;
+        FMCALIAS_TBS_SIZE = 1K;
+        RTALIAS_TBS_SIZE  = 1K;
+              
+        ICCM_SIZE   = 0x{:08X};
+        DCCM_SIZE   = 128K;
+        DATA_SIZE   = 95K;
+        STACK_SIZE  = 14K;
+        ESTACK_SIZE = 1K;
+        NSTACK_SIZE = 1K;
+        
+        
+        MEMORY
+        {{
+            ICCM 		 (rx) : ORIGIN = ICCM_ORG, 		   LENGTH = ICCM_SIZE
+            RTALIAS_TBS  (rw) : ORIGIN = RTALIAS_TBS_ORG,  LENGTH = RTALIAS_TBS_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
+            NSTACK       (rw) : ORIGIN = NSTACK_ORG,       LENGTH = NSTACK_SIZE
+        }} 
+        REGION_ALIAS("REGION_TEXT", ICCM);     
+        REGION_ALIAS("REGION_RODATA", ICCM);  
+        REGION_ALIAS("REGION_DATA", DATA);     
+        REGION_ALIAS("REGION_BSS", DATA);      
+        REGION_ALIAS("REGION_STACK", STACK);     
+        REGION_ALIAS("REGION_ESTACK", ESTACK);     
+        REGION_ALIAS("REGION_NSTACK", NSTACK);"#,
+        iccm_org, LDEVID_TBS_ORG, FMCALIAS_TBS_ORG, iccm_size,
+    )
+}
diff --git a/cpu/link.x b/cpu/link.x
deleted file mode 100644
index cf87dbbc..00000000
--- a/cpu/link.x
+++ /dev/null
@@ -1,109 +0,0 @@
-SECTIONS 
-{
-	.text : ALIGN(4)
-	{
-        _stext = .;
-
-		KEEP(*(.init .init.*));
-        *(.text .text.*);
-        KEEP(*(.vectors))
-
-    	. = ALIGN(4);
-        _etext = .;
-  	} > REGION_TEXT
-
-	.rodata : ALIGN(4)
-	{
-        _srodata = .;
-		
-		*(.srodata .srodata.*);
-    	*(.rodata .rodata.*);
-
-    	. = ALIGN(4);
-        _erodata = .;
-	} > REGION_RODATA
-
-	.data : AT (_erodata) ALIGN(4) 
-	{
-		_sidata = LOADADDR(.data);
-	    _sdata = .;
-		
-	    /* Must be called __global_pointer$ for linker relaxations to work. */
-	    PROVIDE(__global_pointer$ = . + 0x800);
-   
-		*(.sdata .sdata.* .sdata2 .sdata2.*);
-	    *(.data .data.*);
-	    
-		. = ALIGN(4);
-	    _edata = .;
-	} > REGION_DATA 
-
- 
-	.bss (NOLOAD) : ALIGN(4) 
-    {
-		_sbss = .;
-
-        *(.bss*)
-        *(.sbss*)
-        *(COMMON)
-        . = ALIGN(4);
-		
-		_ebss = .;
-    } > REGION_BSS
-
-    .stack (NOLOAD): ALIGN(4)
-    {
-    	_estack = .;
-		
-        . = . + STACK_SIZE;
-
-        . = ALIGN(4);
-    	_sstack = .;
-    } > REGION_STACK
-
-	.estack (NOLOAD): ALIGN(4)
-    {
-    	_eestack = .;
-		
-        . = . + ESTACK_SIZE;
-
-        . = ALIGN(4);
-    	_sestack = .;
-    } > REGION_ESTACK
-
-	.nstack (NOLOAD): ALIGN(4)
-    {
-    	_enstack = .;
-		
-        . = . + NSTACK_SIZE;
-
-        . = ALIGN(4);
-    	_snstack = .;
-    } > REGION_NSTACK
-
-
-	.got (INFO) :
-  	{
-    	KEEP(*(.got .got.*));
-  	}
-
-  	.eh_frame (INFO) : 
-	{ 
-		KEEP(*(.eh_frame))
-	}
-	
-  	.eh_frame_hdr (INFO) :
-	{
-		*(.eh_frame_hdr) 
-	}
-}
-
-_bss_len  = SIZEOF(.bss);
-_data_len = SIZEOF(.data);
-
-ASSERT(SIZEOF(.got) == 0, ".got section detected");
-ASSERT(SIZEOF(.data) == 0, ".data section detected");
-ASSERT(SIZEOF(.bss) == 0, ".bss section detected");
-ASSERT(SIZEOF(.stack) == STACK_SIZE, ".stack section overflow");
-ASSERT(SIZEOF(.estack) == ESTACK_SIZE, ".estack section overflow");
-ASSERT(SIZEOF(.nstack) == NSTACK_SIZE, ".nstack section overflow");
diff --git a/fmc/Cargo.toml b/fmc/Cargo.toml
index 05d01617..1670ab83 100644
--- a/fmc/Cargo.toml
+++ b/fmc/Cargo.toml
@@ -18,6 +18,8 @@ zerocopy = "0.6.1"
 
 [build-dependencies]
 cfg-if = "1.0.0"
+caliptra-gen-linker-scripts = { version = "0.1.0", path = "../cpu/gen" }
+caliptra_common = { path = "../common", default-features = false }
 
 [dev-dependencies]
 caliptra-builder = { path = "../builder" }
diff --git a/fmc/build.rs b/fmc/build.rs
index 2bf690e3..fc5058e0 100644
--- a/fmc/build.rs
+++ b/fmc/build.rs
@@ -8,7 +8,7 @@ File Name:
 
 Abstract:
 
-    Build script for Caliptra ROM Test FMC.
+    Build script for Caliptra FMC
 
 --*/
 
@@ -18,11 +18,15 @@ fn main() {
             use std::env;
             use std::fs;
             use std::path::PathBuf;
+            use caliptra_gen_linker_scripts::gen_memory_x;
 
             let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
 
-            // Put the linker script somewhere the linker can find it.
-            fs::write(out_dir.join("memory.x"), include_bytes!("memory.x")).unwrap();
+            fs::write(out_dir.join("memory.x"),gen_memory_x(caliptra_common::FMC_ORG, caliptra_common::FMC_SIZE)
+            .as_bytes())
+            .expect("Unable to generate memory.x");
+
+
             println!("cargo:rustc-link-search={}", out_dir.display());
 
             println!("cargo:rerun-if-changed=memory.x");
diff --git a/fmc/memory.x b/fmc/memory.x
deleted file mode 100644
index 2075332d..00000000
--- a/fmc/memory.x
+++ /dev/null
@@ -1,62 +0,0 @@
-
-
-ROM_ORG   	     = 0x00000000;
-META_ORG  		 = ROM_SIZE;
-ICCM_ORG  		 = 0x40000000;
-DCCM_ORG  		 = 0x50000000;
-FHT_ORG   		 = 0x50002800;
-DATA_ORG  		 = 0x50004400;
-STACK_ORG 		 = 0x5001C000;
-ESTACK_ORG  	 = 0x5001F800;
-NSTACK_ORG       = 0x5001FC00;
-LDEVID_TBS_ORG   = 0x50003000;
-FMCALIAS_TBS_ORG = 0x50003400;
-PCR_LOG_ORG      = 0x50003800;
-FUSE_LOG_ORG     = 0x50003C00;
-RTALIAS_TBS_ORG  = 0x50004000;
-
-LDEVID_TBS_SIZE   = 1K;
-FMCALIAS_TBS_SIZE = 1K;
-RTALIAS_TBS_SIZE  = 1K;
-PCR_LOG_SIZE      = 1K;
-FUSE_LOG_SIZE     = 1K;
-
-
-
-ROM_SIZE    = 32K;
-MBOX_SIZE   = 128K;
-ICCM_SIZE   = 128K;
-DCCM_SIZE   = 128K;
-MAN1_SIZE   = 5K;
-MAN2_SIZE   = 5K;
-FHT_SIZE    = 2K;
-DATA_SIZE   = 95K;
-STACK_SIZE  = 14K;
-ESTACK_SIZE = 1K;
-NSTACK_SIZE = 1K;
-
-
-MEMORY
-{
-	ROM  		 (rx) : ORIGIN = ROM_ORG,  		   LENGTH = ROM_SIZE
-	META 		 (r)  : ORIGIN = META_ORG, 		   LENGTH = META_SIZE
-	ICCM 		 (rx) : ORIGIN = ICCM_ORG, 		   LENGTH = ICCM_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
-	RTALIAS_TBS  (rw) : ORIGIN = RTALIAS_TBS_ORG,  LENGTH = RTALIAS_TBS_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
-	NSTACK       (rw) : ORIGIN = NSTACK_ORG,       LENGTH = NSTACK_SIZE
-} 
-/* https://sourceware.org/binutils/docs/ld/REGION_005fALIAS.html#REGION_005fALIAS */
-REGION_ALIAS("REGION_TEXT", ICCM);     
-REGION_ALIAS("REGION_RODATA", ICCM);  
-REGION_ALIAS("REGION_DATA", DATA);     
-REGION_ALIAS("REGION_BSS", DATA);      
-REGION_ALIAS("REGION_STACK", STACK);     
-REGION_ALIAS("REGION_ESTACK", ESTACK);     
-REGION_ALIAS("REGION_NSTACK", NSTACK);     
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml
index 603e4d5e..2d0556c3 100644
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -16,6 +16,8 @@ zerocopy = "0.6.1"
 
 [build-dependencies]
 cfg-if = "1.0.0"
+caliptra_common = { path = "../common", default-features = false }
+caliptra-gen-linker-scripts = { version = "0.1.0", path = "../cpu/gen" }
 
 [dev-dependencies]
 caliptra-hw-model = { path = "../hw-model" }
diff --git a/runtime/build.rs b/runtime/build.rs
index c5173e05..dc1c5989 100644
--- a/runtime/build.rs
+++ b/runtime/build.rs
@@ -1,4 +1,16 @@
-// Licensed under the Apache-2.0 license
+/*++
+
+Licensed under the Apache-2.0 license.
+
+File Name:
+
+    build.rs
+
+Abstract:
+
+    Build script for Caliptra Runtime.
+
+--*/
 
 fn main() {
     cfg_if::cfg_if! {
@@ -6,18 +18,21 @@ fn main() {
             use std::env;
             use std::fs;
             use std::path::PathBuf;
+            use caliptra_gen_linker_scripts::gen_memory_x;
 
             let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
 
-            // Put the linker script somewhere the linker can find it.
-            fs::write(out_dir.join("memory.x"), include_bytes!("memory.x")).unwrap();
+            fs::write(out_dir.join("memory.x"),gen_memory_x(caliptra_common::RUNTIME_ORG, caliptra_common::RUNTIME_SIZE)
+            .as_bytes())
+            .expect("Unable to generate memory.x");
+
+
             println!("cargo:rustc-link-search={}", out_dir.display());
 
             println!("cargo:rerun-if-changed=memory.x");
             println!("cargo:rustc-link-arg=-Tmemory.x");
 
             println!("cargo:rustc-link-arg=-Tlink.x");
-
             println!("cargo:rerun-if-changed=build.rs");
         }
     }
diff --git a/runtime/memory.x b/runtime/memory.x
deleted file mode 100644
index 79925453..00000000
--- a/runtime/memory.x
+++ /dev/null
@@ -1,62 +0,0 @@
-
-
-ROM_ORG   = 0x00000000;
-META_ORG  = ROM_SIZE;
-ICCM_ORG  = 0x40004000; /* Range [0x40000000 - 0x40003FFF] is reserved for FMC */
-DCCM_ORG  = 0x50000000;
-FHT_ORG   = 0x50002800;
-LDEVID_TBS_ORG   = 0x50003000;
-FMCALIAS_TBS_ORG = 0x50003400;
-RTALIAS_TBS_ORG  = 0x50004000;
-PCR_LOG_ORG      = 0x50003800;
-FUSE_LOG_ORG     = 0x50003C00;
-DATA_ORG    = 0x50004400;
-STACK_ORG   = 0x5001C000;
-ESTACK_ORG  = 0x5001F800;
-NSTACK_ORG  = 0x5001FC00;
-
-
-ROM_SIZE    = 32K;
-MBOX_SIZE   = 128K;
-ICCM_SIZE   = 112K;
-DCCM_SIZE   = 128K;
-MAN1_SIZE   = 5K;
-MAN2_SIZE   = 5K;
-FHT_SIZE    = 2K;
-LDEVID_TBS_SIZE   = 1K;
-FMCALIAS_TBS_SIZE = 1K;
-RTALIAS_TBS_SIZE  = 1K;
-PCR_LOG_SIZE      = 1K;
-FUSE_LOG_SIZE     = 1K;
-
-DATA_SIZE   = 95K;
-STACK_SIZE  = 14K;
-ESTACK_SIZE = 1K;
-NSTACK_SIZE = 1K;
-
-
-MEMORY
-{
-	ROM  (rx) : ORIGIN = ROM_ORG,  LENGTH = ROM_SIZE
-	META (r)  : ORIGIN = META_ORG, LENGTH = META_SIZE
-	ICCM (rx) : ORIGIN = ICCM_ORG, LENGTH = ICCM_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
-	RTALIAS_TBS  (rw) : ORIGIN = RTALIAS_TBS_ORG,  LENGTH = RTALIAS_TBS_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
-	NSTACK (rw) : ORIGIN = NSTACK_ORG, LENGTH = NSTACK_SIZE
-} 
-/* https://sourceware.org/binutils/docs/ld/REGION_005fALIAS.html#REGION_005fALIAS */
-REGION_ALIAS("REGION_TEXT", ICCM);     
-REGION_ALIAS("REGION_RODATA", ICCM);  
-REGION_ALIAS("REGION_DATA", DATA);     
-REGION_ALIAS("REGION_BSS", DATA);      
-REGION_ALIAS("REGION_STACK", STACK);     
-REGION_ALIAS("REGION_ESTACK", ESTACK);     
-REGION_ALIAS("REGION_NSTACK", NSTACK);     


Test patch:
diff --git a/runtime/test-fw/Cargo.toml b/runtime/test-fw/Cargo.toml
index ab2a0195..8f0ad37e 100644
--- a/runtime/test-fw/Cargo.toml
+++ b/runtime/test-fw/Cargo.toml
@@ -35,6 +35,8 @@ required-features = ["riscv"]
 
 [build-dependencies]
 cfg-if = "1.0.0"
+caliptra_common = { path = "../../common", default-features = false }
+caliptra-gen-linker-scripts = { version = "0.1.0", path = "../../cpu/gen" }
 
 [dependencies]
 caliptra-test-harness = { path = "../../test-harness" }
diff --git a/runtime/test-fw/build.rs b/runtime/test-fw/build.rs
index 0cc8a621..ca00d4f6 100644
--- a/runtime/test-fw/build.rs
+++ b/runtime/test-fw/build.rs
@@ -8,10 +8,13 @@ fn main() {
                     use std::env;
                     use std::fs;
                     use std::path::PathBuf;
+                    use caliptra_gen_linker_scripts::gen_memory_x;
 
                     let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
                     // Put the linker script somewhere the linker can find it.
-                    fs::write(out_dir.join("memory.x"), include_bytes!("../memory.x")).unwrap();
+                    fs::write(out_dir.join("memory.x"),gen_memory_x(caliptra_common::RUNTIME_ORG, caliptra_common::RUNTIME_SIZE)
+                    .as_bytes())
+                    .expect("Unable to generate memory.x");
                     println!("cargo:rustc-link-search={}", out_dir.display());
 
                     println!("cargo:rerun-if-changed=memory.x");