[test_rom] Add .static_critical section for consistency with silicon_creator code

Signed-off-by: Alphan Ulusoy <alphan@google.com>
diff --git a/sw/device/lib/testing/test_rom/BUILD b/sw/device/lib/testing/test_rom/BUILD
index bea9ccc..8f59bbd 100644
--- a/sw/device/lib/testing/test_rom/BUILD
+++ b/sw/device/lib/testing/test_rom/BUILD
@@ -21,6 +21,7 @@
     deps = [
         "//hw/top_earlgrey/sw/autogen:top_earlgrey_memory",
         "//sw/device:info_sections",
+        "//sw/device/silicon_creator/lib/base:static_critical_sections",
     ],
 )
 
@@ -145,6 +146,9 @@
         "//sw/device/lib/testing:pinmux_testutils",
         "//sw/device/lib/testing/test_framework:check",
         "//sw/device/lib/testing/test_framework:status",
+        "//sw/device/silicon_creator/lib/base:sec_mmio",
+        "//sw/device/silicon_creator/lib/base:static_critical_boot_measurements",
+        "//sw/device/silicon_creator/lib/base:static_critical_sec_mmio",
         "//sw/device/silicon_creator/lib/drivers:retention_sram",
     ],
 )
diff --git a/sw/device/lib/testing/test_rom/test_rom.c b/sw/device/lib/testing/test_rom/test_rom.c
index 7a21aae..f2e823e 100644
--- a/sw/device/lib/testing/test_rom/test_rom.c
+++ b/sw/device/lib/testing/test_rom/test_rom.c
@@ -20,6 +20,7 @@
 #include "sw/device/lib/testing/test_framework/check.h"
 #include "sw/device/lib/testing/test_framework/status.h"
 #include "sw/device/lib/testing/test_rom/chip_info.h"  // Generated.
+#include "sw/device/silicon_creator/lib/base/sec_mmio.h"
 #include "sw/device/silicon_creator/lib/drivers/retention_sram.h"
 #include "sw/device/silicon_creator/lib/manifest.h"
 #include "sw/device/silicon_creator/rom/bootstrap.h"
@@ -55,6 +56,9 @@
 // rom tests. By default, it simply jumps into the OTTF's flash.
 OT_WEAK
 bool rom_test_main(void) {
+  // Initial sec_mmio, required by bootstrap and its dependencies.
+  sec_mmio_init();
+
   // Configure the pinmux.
   CHECK_DIF_OK(dif_pinmux_init(
       mmio_region_from_addr(TOP_EARLGREY_PINMUX_AON_BASE_ADDR), &pinmux));
diff --git a/sw/device/lib/testing/test_rom/test_rom.ld b/sw/device/lib/testing/test_rom/test_rom.ld
index 1e0ec30..c8c38b4 100644
--- a/sw/device/lib/testing/test_rom/test_rom.ld
+++ b/sw/device/lib/testing/test_rom/test_rom.ld
@@ -24,7 +24,7 @@
 _boot_address = ORIGIN(rom);
 
 _heap_size = 0xe000;
-_stack_size = LENGTH(ram_main) - _heap_size;
+_stack_size = LENGTH(ram_main) - _heap_size - _static_critical_size;
 _stack_end = ORIGIN(ram_main) + LENGTH(ram_main);
 _stack_start = _stack_end - _stack_size;
 _flash_start = ORIGIN(eflash);
@@ -100,19 +100,24 @@
   } > rom
 
   /**
-   * "Intitial data" section, the initial values of the mutable data section
-   * initialized at runtime.
+   * Critical static data that is accessible by both the ROM and the ROM
+   * extension.
    */
-  .idata : ALIGN(4) {
-    _data_init_start = .;
-  } > rom
+  INCLUDE sw/device/silicon_creator/lib/base/static_critical.ld
 
   /**
    * Standard mutable data section, at the bottom of RAM. This will be
    * initialized from the .idata section at runtime by the CRT.
    */
-  .data ORIGIN(ram_main): AT(_data_init_start) ALIGN(4) {
+  .data : ALIGN(4) {
     _data_start = .;
+    _data_init_start = LOADADDR(.data);
+
+    /* This will get loaded into `gp`, and the linker will use that register for
+     * accessing data within [-2048,2047] of `__global_pointer$`.
+     *
+     * This is much cheaper (for small data) than materializing the
+     * address and loading from that (which will take one extra instruction). */
     __global_pointer$ = . + 2048;
 
     /* Small data should come before larger data. This helps to ensure small
@@ -126,9 +131,16 @@
      */
     *(.data)
     *(.data.*)
+
+    /* Ensure section end is word-aligned. */
     . = ALIGN(4);
     _data_end = .;
-  } > ram_main
+    _data_init_end = LOADADDR(.data) + SIZEOF(.data);
+
+    /* This puts it in ram_main at runtime (for the VMA), but puts the section
+     * into rom for load time (for the LMA). This is why `_data_init_*` uses
+     * `LOADADDR`. */
+  } > ram_main AT> rom
 
   /**
    * Immutable chip_info data, containing build-time-recorded information.