From 52d57f5cf7bfd33bcf60b173aa9a7f20370f6267 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Wed, 5 Mar 2025 17:09:17 +0000 Subject: [PATCH] [test_rom] Change the way to get the manifest address Instead of duplicating the logic to find the manifest, rely on the fact that the OTTF already needs to know the address to link. Therefore we can reuse the OTTF top config to create a symbol for the manifest address. Signed-off-by: Amaury Pouly --- sw/device/lib/testing/test_rom/BUILD | 1 + sw/device/lib/testing/test_rom/test_rom.c | 18 ++++++------------ sw/device/lib/testing/test_rom/test_rom.ld | 11 ++++++++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sw/device/lib/testing/test_rom/BUILD b/sw/device/lib/testing/test_rom/BUILD index adc81d9dcd4b2..8a57178e95cdd 100644 --- a/sw/device/lib/testing/test_rom/BUILD +++ b/sw/device/lib/testing/test_rom/BUILD @@ -23,6 +23,7 @@ ld_library( "//hw/top:top_ld", "//sw/device:info_sections", "//sw/device/silicon_creator/lib/base:static_critical_sections", + "//sw/device/lib/testing/test_framework:ottf_ld_top_config", ], ) diff --git a/sw/device/lib/testing/test_rom/test_rom.c b/sw/device/lib/testing/test_rom/test_rom.c index 931e53e1631ce..827f458905c0d 100644 --- a/sw/device/lib/testing/test_rom/test_rom.c +++ b/sw/device/lib/testing/test_rom/test_rom.c @@ -68,10 +68,11 @@ static const dt_otp_ctrl_t kOtpCtrlDt = kDtOtpCtrl; /* These symbols are defined in * `opentitan/sw/device/lib/testing/test_rom/test_rom.ld`, and describes the - * location of the flash header. + * location of the flash header and manifest. */ extern char _rom_ext_virtual_start_address[]; extern char _rom_ext_virtual_size[]; +extern char _manifest_address[]; /** * Type alias for the OTTF entry point. @@ -231,22 +232,15 @@ bool rom_test_main(void) { } #endif -#if defined(HAS_FLASH_CTRL) +#ifdef OPENTITAN_IS_EARLGREY CHECK_DIF_OK( dif_flash_ctrl_set_exec_enablement(&flash_ctrl, kDifToggleEnabled)); - - // Always select slot a and enable address translation if manifest says to. - const manifest_t *manifest = (const manifest_t *)dt_flash_ctrl_reg_block( - kFlashCtrlDt, kDtFlashCtrlRegBlockMem); -#elif defined(OPENTITAN_IS_DARJEELING) - // Always select slot a and enable address translation if manifest says to. - const manifest_t *manifest = (const manifest_t *)dt_soc_proxy_reg_block( - kDtSocProxy, kDtSocProxyRegBlockCtn); -#else -#error I don't know how to find the test code on this platform! #endif + const manifest_t *manifest = (const manifest_t *)_manifest_address; + uintptr_t entry_point = manifest_entry_point_get(manifest); + // Enable address translation if manifest says to if (manifest->address_translation == kHardenedBoolTrue) { dif_rv_core_ibex_addr_translation_mapping_t addr_map = { .matching_addr = (uintptr_t)_rom_ext_virtual_start_address, diff --git a/sw/device/lib/testing/test_rom/test_rom.ld b/sw/device/lib/testing/test_rom/test_rom.ld index 44efa3d28ce91..3406f3a880a60 100644 --- a/sw/device/lib/testing/test_rom/test_rom.ld +++ b/sw/device/lib/testing/test_rom/test_rom.ld @@ -17,15 +17,15 @@ __DYNAMIC = 0; INCLUDE OPENTITAN_TOP_MEMORY_LD +#include "ottf_ld_top_config.ld" + /** * Region aliases. */ #ifdef OPENTITAN_IS_DARJEELING REGION_ALIAS("test_rom", rom0) -REGION_ALIAS("test_code_region", ctn) #else REGION_ALIAS("test_rom", rom) -REGION_ALIAS("test_code_region", eflash) #endif /** @@ -34,12 +34,17 @@ REGION_ALIAS("test_code_region", eflash) */ _boot_address = ORIGIN(test_rom); +/** + * Location of the manifest. + */ +_manifest_address = ORIGIN(ottf_storage); + /** * Symbols to be used in the setup of the address translation for ROM_EXT. */ _rom_ext_virtual_start_address = ORIGIN(rom_ext_virtual); _rom_ext_virtual_size = LENGTH(rom_ext_virtual); -ASSERT((_rom_ext_virtual_size <= (LENGTH(test_code_region) / 2)), +ASSERT((_rom_ext_virtual_size <= (LENGTH(ottf_storage) / 2)), "Error: rom ext flash is bigger than slot."); _rom_digest_size = 32;