Skip to content

Commit

Permalink
[test_rom] Change the way to get the manifest address
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pamaury committed Mar 5, 2025
1 parent 7a5b81b commit 52d57f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions sw/device/lib/testing/test_rom/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
18 changes: 6 additions & 12 deletions sw/device/lib/testing/test_rom/test_rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions sw/device/lib/testing/test_rom/test_rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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;
Expand Down

0 comments on commit 52d57f5

Please sign in to comment.