Skip to content

Commit 6e6c081

Browse files
committed
[sw,e2e] Add SRAM execution owner config testcases
This change adds an end-to-end test for SRAM execution mode owner config switches. The test verifies that the SRAM execution mode can be enabled, disabled, and disabled+locked. Change-Id: I5a98e91586ae4be6a9362adaa9b1a983c1082bf9 Signed-off-by: Yi-Hsuan Deng <[email protected]>
1 parent 1ec3ed4 commit 6e6c081

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

sw/device/silicon_creator/lib/ownership/test_owner.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
(owner_keydata_t) { .ecdsa = UNLOCK_ECDSA_P256 }
7272
#endif
7373

74+
#ifndef TEST_OWNER_SRAM_EXEC_MODE
75+
#define TEST_OWNER_SRAM_EXEC_MODE kOwnerSramExecModeDisabledLocked
76+
#endif
77+
7478
// The following preprocessor symbols are only relevant when
7579
// WITH_RESCUE_PROTOCOL is defined.
7680
#ifndef WITH_RESCUE_GPIO_PARAM
@@ -123,7 +127,7 @@ rom_error_t sku_creator_owner_init(boot_data_t *bootdata) {
123127
owner_page[0].header.length = 2048;
124128
owner_page[0].header.version = (struct_version_t){0, 0};
125129
owner_page[0].config_version = TEST_OWNER_CONFIG_VERSION;
126-
owner_page[0].sram_exec_mode = kOwnerSramExecModeDisabledLocked;
130+
owner_page[0].sram_exec_mode = TEST_OWNER_SRAM_EXEC_MODE;
127131
owner_page[0].ownership_key_alg = TEST_OWNER_KEY_ALG;
128132
owner_page[0].update_mode = TEST_OWNER_UPDATE_MODE;
129133
owner_page[0].min_security_version_bl0 = UINT32_MAX;

sw/device/silicon_creator/rom_ext/defs.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ TEST_OWNER_CONFIGS = {
5252
"owner_defines": ["TEST_OWNER_UPDATE_MODE=kOwnershipUpdateModeNewVersion"],
5353
"rescue_module": ["//sw/device/silicon_creator/lib/rescue:rescue_xmodem"],
5454
},
55+
"owner_sram_exec_enabled": {
56+
"owner_defines": [
57+
"TEST_OWNER_SRAM_EXEC_MODE=kOwnerSramExecModeEnabled",
58+
"TEST_OWNER_FORCE_UPDATE=1",
59+
],
60+
"rescue_module": ["//sw/device/silicon_creator/lib/rescue:rescue_xmodem"],
61+
},
62+
"owner_sram_exec_disabled": {
63+
"owner_defines": [
64+
"TEST_OWNER_SRAM_EXEC_MODE=kOwnerSramExecModeDisabled",
65+
"TEST_OWNER_FORCE_UPDATE=1",
66+
],
67+
"rescue_module": ["//sw/device/silicon_creator/lib/rescue:rescue_xmodem"],
68+
},
5569
"usbdfu": {
5670
# Enable USB-DFU triggered by SW_STRAPS value 3.
5771
"owner_defines": [

sw/device/silicon_creator/rom_ext/e2e/handoff/BUILD

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,49 @@ opentitan_test(
135135
],
136136
)
137137

138+
SRAM_EXEC_TESTCASES = [
139+
{
140+
"name": "enabled",
141+
"rom_ext": "//sw/device/silicon_creator/rom_ext:rom_ext_owner_sram_exec_enabled",
142+
"exit_success": "value = 00000006, 00000006, 00000001[\\s\\S]*PASS!",
143+
},
144+
{
145+
"name": "disabled",
146+
"rom_ext": "//sw/device/silicon_creator/rom_ext:rom_ext_owner_sram_exec_disabled",
147+
"exit_success": "value = 00000009, 00000006, 00000001[\\s\\S]*PASS!",
148+
},
149+
{
150+
"name": "disabled_locked",
151+
"rom_ext": "//sw/device/silicon_creator/rom_ext:rom_ext_dice_x509_slot_virtual",
152+
"exit_success": "value = 00000009, 00000009, 00000000[\\s\\S]*MCAUSE=00000001",
153+
},
154+
]
155+
156+
[
157+
opentitan_test(
158+
name = "sram_exec_{}_test".format(test["name"]),
159+
srcs = ["sram_exec_test.c"],
160+
exec_env = {
161+
"//hw/top_earlgrey:fpga_hyper310_rom_ext": None,
162+
"//hw/top_earlgrey:fpga_cw340_rom_ext": None,
163+
},
164+
fpga = fpga_params(
165+
changes_otp = True,
166+
exit_success = test["exit_success"],
167+
rom_ext = test["rom_ext"],
168+
),
169+
linker_script = "//sw/device/lib/testing/test_framework:ottf_ld_silicon_owner_slot_virtual",
170+
deps = [
171+
"//hw/ip/sram_ctrl/data:sram_ctrl_c_regs",
172+
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
173+
"//sw/device/lib/base:abs_mmio",
174+
"//sw/device/lib/testing/test_framework:ottf_main",
175+
"//sw/device/silicon_creator/lib:dbg_print",
176+
],
177+
)
178+
for test in SRAM_EXEC_TESTCASES
179+
]
180+
138181
opentitan_test(
139182
name = "rom_ext_device_status_test",
140183
srcs = ["//sw/device/silicon_creator/rom_ext/e2e/verified_boot:boot_test"],
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright lowRISC contributors (OpenTitan project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include "sw/device/lib/base/abs_mmio.h"
6+
#include "sw/device/lib/testing/test_framework/ottf_main.h"
7+
#include "sw/device/silicon_creator/lib/dbg_print.h"
8+
9+
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.
10+
#include "sram_ctrl_regs.h" // Generated.
11+
12+
OTTF_DEFINE_TEST_CONFIG();
13+
14+
enum {
15+
kBase = TOP_EARLGREY_SRAM_CTRL_MAIN_REGS_BASE_ADDR,
16+
};
17+
18+
int test_stub(void) { return 0x42; }
19+
20+
// SRAM copy of `test_stub` bytecodes.
21+
uint32_t test_stub_sram[32];
22+
23+
bool test_main(void) {
24+
// Try to enable SRAM_EXEC
25+
uint32_t reg_before = abs_mmio_read32(kBase + SRAM_CTRL_EXEC_REG_OFFSET);
26+
uint32_t reg_wen = abs_mmio_read32(kBase + SRAM_CTRL_EXEC_REGWEN_REG_OFFSET);
27+
abs_mmio_write32(kBase + SRAM_CTRL_EXEC_REG_OFFSET, kMultiBitBool4True);
28+
uint32_t reg_after = abs_mmio_read32(kBase + SRAM_CTRL_EXEC_REG_OFFSET);
29+
dbg_printf("value = %x, %x, %x\r\n", reg_before, reg_after, reg_wen);
30+
31+
// Try to execute code on SRAM.
32+
memcpy(test_stub_sram, test_stub, sizeof(test_stub_sram));
33+
int result = ((int (*)(void))test_stub_sram)();
34+
35+
return result == 0x42;
36+
}

0 commit comments

Comments
 (0)