[test_rom] enable address translation
This commit:
1. enables address translation in the test ROM (if the manifest
requests it, defaulting to no address translation), and
2. align test ROM manifest symbols with ROM's.
This partially addresses #10712.
Signed-off-by: Timothy Trippel <ttrippel@google.com>
diff --git a/sw/device/lib/base/BUILD b/sw/device/lib/base/BUILD
index 6a82bec..4d2b73f 100644
--- a/sw/device/lib/base/BUILD
+++ b/sw/device/lib/base/BUILD
@@ -2,16 +2,15 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
-package(default_visibility = ["//visibility:public"])
-
load("//rules:cross_platform.bzl", "dual_cc_library", "dual_inputs")
-load("//rules:opentitan.bzl", "OPENTITAN_CPU")
load(
"//rules:opentitan_test.bzl",
"cw310_params",
"opentitan_functest",
)
+package(default_visibility = ["//visibility:public"])
+
cc_library(
name = "global_mock",
hdrs = ["global_mock.h"],
@@ -94,7 +93,6 @@
name = "memory_perftest",
srcs = ["memory_perftest.c"],
cw310 = cw310_params(
- bitstream = "//hw/bitstream:test_rom",
tags = [
"flaky",
"manual",
diff --git a/sw/device/lib/testing/test_rom/test_rom.c b/sw/device/lib/testing/test_rom/test_rom.c
index 7fa4ef6..3f7cab8 100644
--- a/sw/device/lib/testing/test_rom/test_rom.c
+++ b/sw/device/lib/testing/test_rom/test_rom.c
@@ -31,15 +31,12 @@
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
#include "otp_ctrl_regs.h"
-/**
- * This symbol is defined in `sw/device/lib/testing/test_rom/test_rom.ld`,
- * and describes the location of the flash header.
- *
- * The actual contents are not defined by the ROM, but rather
- * by the flash binary: see `sw/device/lib/testing/test_framework/ottf.ld`
- * for that.
+/* These symbols are defined in
+ * `opentitan/sw/device/lib/testing/test_rom/test_rom.ld`, and describes the
+ * location of the flash header.
*/
-extern const char _manifest[];
+extern char _rom_ext_virtual_start_address[];
+extern char _rom_ext_virtual_size[];
/**
* Type alias for the OTTF entry point.
@@ -47,7 +44,7 @@
* The entry point address obtained from the OTTF manifest must be cast to a
* pointer to this type before being called.
*/
-typedef void ottf_entry(void);
+typedef void ottf_entry_point(void);
static dif_clkmgr_t clkmgr;
static dif_flash_ctrl_state_t flash_ctrl;
@@ -56,6 +53,19 @@
static dif_uart_t uart0;
static dif_rv_core_ibex_t ibex;
+/**
+ * Compute the virtual address corresponding to the physical address `lma_addr`.
+ *
+ * @param manifest Pointer to the current manifest.
+ * @param lma_addr Load address or physical address.
+ * @return the computed virtual address.
+ */
+static inline uintptr_t rom_ext_vma_get(const manifest_t *manifest,
+ uintptr_t lma_addr) {
+ return (lma_addr - (uintptr_t)manifest +
+ (uintptr_t)_rom_ext_virtual_start_address);
+}
+
// `test_in_rom = True` tests can override this symbol to provide their own
// rom tests. By default, it simply jumps into the OTTF's flash.
OT_WEAK
@@ -171,14 +181,35 @@
CHECK_DIF_OK(
dif_flash_ctrl_set_exec_enablement(&flash_ctrl, kDifToggleEnabled));
- // TODO(lowrisc/opentitan:#10712): setup Ibex address translation
+ // Always select slot a and enable address translation if manifest says to.
+ const manifest_t *manifest =
+ (const manifest_t *)TOP_EARLGREY_EFLASH_BASE_ADDR;
+ uintptr_t entry_point = manifest_entry_point_get(manifest);
+ if (manifest->address_translation == kHardenedBoolTrue) {
+ dif_rv_core_ibex_addr_translation_mapping_t addr_map = {
+ .matching_addr = (uintptr_t)_rom_ext_virtual_start_address,
+ .remap_addr = (uintptr_t)manifest,
+ .size = (size_t)_rom_ext_virtual_size,
+ };
+ CHECK_DIF_OK(dif_rv_core_ibex_configure_addr_translation(
+ &ibex, kDifRvCoreIbexAddrTranslationSlot_0,
+ kDifRvCoreIbexAddrTranslationDBus, addr_map));
+ CHECK_DIF_OK(dif_rv_core_ibex_configure_addr_translation(
+ &ibex, kDifRvCoreIbexAddrTranslationSlot_0,
+ kDifRvCoreIbexAddrTranslationIBus, addr_map));
+ CHECK_DIF_OK(dif_rv_core_ibex_enable_addr_translation(
+ &ibex, kDifRvCoreIbexAddrTranslationSlot_0,
+ kDifRvCoreIbexAddrTranslationDBus));
+ CHECK_DIF_OK(dif_rv_core_ibex_enable_addr_translation(
+ &ibex, kDifRvCoreIbexAddrTranslationSlot_0,
+ kDifRvCoreIbexAddrTranslationIBus));
+ entry_point = rom_ext_vma_get(manifest, entry_point);
+ }
- // Jump to the OTTF in flash. Within the flash binary, it is the responsibily
- // of the OTTF to set up its own stack, and to never return.
- uintptr_t entry_point =
- manifest_entry_point_get((const manifest_t *)_manifest);
- LOG_INFO("Test ROM complete, jumping to flash!");
- ((ottf_entry *)entry_point)();
+ // Jump to the OTTF in flash. Within the flash binary, it is the
+ // responsibily of the OTTF to set up its own stack, and to never return.
+ LOG_INFO("Test ROM complete, jumping to flash (addr: %x)!", entry_point);
+ ((ottf_entry_point *)entry_point)();
// If the flash image returns, we should abort anyway.
abort();
diff --git a/sw/device/lib/testing/test_rom/test_rom.ld b/sw/device/lib/testing/test_rom/test_rom.ld
index b19c545..290ce54 100644
--- a/sw/device/lib/testing/test_rom/test_rom.ld
+++ b/sw/device/lib/testing/test_rom/test_rom.ld
@@ -23,24 +23,13 @@
*/
_boot_address = ORIGIN(rom);
-_heap_size = 0xe000;
-_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);
-
/**
- * TODO(lowrisc/opentitan:#10712): setup Ibex address translation
+ * Symbols to be used in the setup of the address translation for ROM_EXT.
*/
-
-/**
- * This symbol points at the manifest of the OTTF + test binary, which contains
- * loading and signing information.
- *
- * See `sw/device/lib/testing/test_framework/ottf.ld`, under the
- * .manifest section, which populates it.
- */
-_manifest = _flash_start;
+_rom_ext_virtual_start_address = ORIGIN(rom_ext_virtual);
+_rom_ext_virtual_size = LENGTH(rom_ext_virtual);
+ASSERT((_rom_ext_virtual_size <= (LENGTH(eflash) / 2)),
+ "Error: rom ext flash is bigger than slot.");
_rom_digest_size = 32;
_chip_info_start = ORIGIN(rom) + LENGTH(rom) - _rom_digest_size - _chip_info_size;
@@ -145,7 +134,7 @@
* Immutable chip_info data, containing build-time-recorded information.
*/
.chip_info _chip_info_start : ALIGN(4) {
- *(.chip_info)
+ KEEP(*(.chip_info))
} > rom
/**
diff --git a/sw/device/silicon_creator/rom/rom.ld b/sw/device/silicon_creator/rom/rom.ld
index 363dd7f..c324363 100644
--- a/sw/device/silicon_creator/rom/rom.ld
+++ b/sw/device/silicon_creator/rom/rom.ld
@@ -28,7 +28,8 @@
*/
_rom_ext_virtual_start_address = ORIGIN(rom_ext_virtual);
_rom_ext_virtual_size = LENGTH(rom_ext_virtual);
-ASSERT((_rom_ext_virtual_size <= (LENGTH(eflash) / 2)), "Error: rom ext flash is bigger than slot");
+ASSERT((_rom_ext_virtual_size <= (LENGTH(eflash) / 2)),
+ "Error: rom ext flash is bigger than slot.");
/* DV Log offset (has to be different to other boot stages). */
_dv_log_offset = 0x0;