Skip to content

Commit 572f7cf

Browse files
sasdfcfrantz
authored andcommitted
[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 bdd735f commit 572f7cf

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-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
@@ -121,7 +125,7 @@ rom_error_t sku_creator_owner_init(boot_data_t *bootdata) {
121125
owner_page[0].header.length = 2048;
122126
owner_page[0].header.version = (struct_version_t){0, 0};
123127
owner_page[0].config_version = TEST_OWNER_CONFIG_VERSION;
124-
owner_page[0].sram_exec_mode = kOwnerSramExecModeDisabledLocked;
128+
owner_page[0].sram_exec_mode = TEST_OWNER_SRAM_EXEC_MODE;
125129
owner_page[0].ownership_key_alg = TEST_OWNER_KEY_ALG;
126130
owner_page[0].update_mode = TEST_OWNER_UPDATE_MODE;
127131
owner_page[0].min_security_version_bl0 = UINT32_MAX;

sw/device/silicon_creator/rom_ext/defs.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ 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+
],
59+
"rescue_module": ["//sw/device/silicon_creator/lib/rescue:rescue_xmodem"],
60+
},
61+
"owner_sram_exec_disabled": {
62+
"owner_defines": [
63+
"TEST_OWNER_SRAM_EXEC_MODE=kOwnerSramExecModeDisabled",
64+
],
65+
"rescue_module": ["//sw/device/silicon_creator/lib/rescue:rescue_xmodem"],
66+
},
5567
"usbdfu": {
5668
# Enable USB-DFU triggered by SW_STRAPS value 3.
5769
"owner_defines": [

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,57 @@ 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+
test_cmd = """
169+
--exec="transport init"
170+
--exec="fpga clear-bitstream"
171+
--exec="fpga load-bitstream {bitstream}"
172+
--exec="bootstrap --clear-uart=true {firmware}"
173+
--exec="console --non-interactive --exit-success='{exit_success}' --exit-failure='{exit_failure}'"
174+
no-op
175+
""",
176+
),
177+
linker_script = "//sw/device/lib/testing/test_framework:ottf_ld_silicon_owner_slot_virtual",
178+
deps = [
179+
"//hw/ip/sram_ctrl/data:sram_ctrl_c_regs",
180+
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
181+
"//sw/device/lib/base:abs_mmio",
182+
"//sw/device/lib/testing/test_framework:ottf_main",
183+
"//sw/device/silicon_creator/lib:dbg_print",
184+
],
185+
)
186+
for test in SRAM_EXEC_TESTCASES
187+
]
188+
138189
opentitan_test(
139190
name = "rom_ext_device_status_test",
140191
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)