Skip to content

Commit d0508aa

Browse files
cfrantzpamaury
authored andcommitted
[rom_e2e] Add tests for a bad immutable section
Add tests that check if a valid signed ROM_EXT with an invalid immutable section can boot. The correct behavior is that the ROM should determine that the immutable section is invalid and try the other slot. Signed-off-by: Chris Frantz <[email protected]> (cherry picked from commit f17d30f)
1 parent 1f7db17 commit d0508aa

File tree

2 files changed

+109
-3
lines changed

2 files changed

+109
-3
lines changed

sw/device/silicon_creator/rom/e2e/immutable_rom_ext_section/BUILD

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,25 @@ ROM_EXT_SLOTS = [
3636
"name": "a",
3737
"slot": "a",
3838
"offset": SLOTS["a"],
39+
"linker_script": "//sw/device/lib/testing/test_framework:ottf_ld_silicon_creator_slot_a",
3940
},
4041
{
4142
"name": "virtual_a",
4243
"slot": "a",
4344
"offset": SLOTS["a"],
45+
"linker_script": "//sw/device/lib/testing/test_framework:ottf_ld_silicon_creator_slot_virtual",
4446
},
4547
{
4648
"name": "b",
4749
"slot": "b",
4850
"offset": SLOTS["b"],
51+
"linker_script": "//sw/device/lib/testing/test_framework:ottf_ld_silicon_creator_slot_b",
4952
},
5053
{
5154
"name": "virtual_b",
5255
"slot": "b",
5356
"offset": SLOTS["b"],
57+
"linker_script": "//sw/device/lib/testing/test_framework:ottf_ld_silicon_creator_slot_virtual",
5458
},
5559
]
5660

@@ -195,7 +199,7 @@ IMMUTABLE_PARTITION_TEST_CASES = [
195199
exec_env = [
196200
"//hw/top_earlgrey:fpga_cw310_sival",
197201
],
198-
linker_script = "//sw/device/lib/testing/test_framework:ottf_ld_silicon_creator_slot_{}".format(s["slot"]),
202+
linker_script = s["linker_script"],
199203
deps = [
200204
"//hw/top:otp_ctrl_c_regs",
201205
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
@@ -249,3 +253,101 @@ test_suite(
249253
for t in IMMUTABLE_PARTITION_TEST_CASES
250254
],
251255
)
256+
257+
BAD_SECTION_BINS = {
258+
"invalid": {
259+
# l b a t u m m i
260+
"message": "0x6c626174756d6d69",
261+
},
262+
"valid": {
263+
# l b a t u m m I
264+
"message": "0x6c626174756d6d49",
265+
},
266+
}
267+
268+
# Both `imm_section_{valid,invalid}` are valid signed ROM_EXTs. There is a
269+
# single bit difference in the immutable section ("Immutable" vs "immutable").
270+
# The former produces an immutable section with a valid hash, whereas the
271+
# later produces an invalid hash.
272+
[
273+
opentitan_binary(
274+
name = "imm_section_{}".format(name),
275+
testonly = True,
276+
srcs = ["immutable_rom_ext_section_test.c"],
277+
defines = [
278+
"IMMUTABLE_MESSAGE={}".format(param["message"]),
279+
],
280+
exec_env = [
281+
"//hw/top_earlgrey:fpga_cw310_sival",
282+
],
283+
linker_script = "//sw/device/lib/testing/test_framework:ottf_ld_silicon_creator_slot_virtual",
284+
manifest = ":manifest",
285+
deps = [
286+
"//hw/top:otp_ctrl_c_regs",
287+
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
288+
"//sw/device/lib/base:hardened",
289+
"//sw/device/lib/base:status",
290+
"//sw/device/lib/testing/test_framework:ottf_main",
291+
"//sw/device/silicon_creator/lib/drivers:otp",
292+
"//sw/device/silicon_creator/lib/drivers:retention_sram",
293+
"//sw/device/silicon_creator/lib/drivers:uart",
294+
],
295+
)
296+
for name, param in BAD_SECTION_BINS.items()
297+
]
298+
299+
# Tests that "imm_section_invalid" is functional when OTP disabled the immutable
300+
# section. This test proves that `imm_section_invalid` is a valid signed
301+
# ROM_EXT stage.
302+
opentitan_test(
303+
name = "immutable_section_invalid_ok_when_disabled",
304+
exec_env = {
305+
"//hw/top_earlgrey:fpga_cw310_sival": None,
306+
},
307+
fpga = fpga_params(
308+
assemble = "{invalid}@0",
309+
binaries = {
310+
":imm_section_invalid": "invalid",
311+
},
312+
otp = ":otp_img_immutable_rom_ext_exec_disabled_hash_valid_virtual_a",
313+
),
314+
)
315+
316+
# Tests that we can boot "imm_section_valid" when there is a valid signed
317+
# ROM_EXT with an invalid immutable section in the primary slot.
318+
# The ROM should skip the primary slot and boot the secondary slot.
319+
opentitan_test(
320+
name = "immutable_section_a_bad_b_good",
321+
exec_env = {
322+
"//hw/top_earlgrey:fpga_cw310_sival": None,
323+
},
324+
fpga = fpga_params(
325+
assemble = "{invalid}@0 {valid}@0x80000",
326+
binaries = {
327+
":imm_section_invalid": "invalid",
328+
":imm_section_valid": "valid",
329+
},
330+
exit_failure = DEFAULT_TEST_FAILURE_MSG,
331+
exit_success = "(?msR)Immutable$.*PASS!$",
332+
otp = ":otp_img_immutable_rom_ext_exec_enabled_hash_valid_virtual_a",
333+
),
334+
)
335+
336+
# Test that the ROM fails to boot when both slots have valid signatures
337+
# and invalid immutable sections.
338+
opentitan_test(
339+
name = "immutable_section_a_bad_b_bad",
340+
exec_env = {
341+
"//hw/top_earlgrey:fpga_cw310_sival": None,
342+
},
343+
fpga = fpga_params(
344+
assemble = "{invalid}@0 {invalid}@0x80000",
345+
binaries = {
346+
":imm_section_invalid": "invalid",
347+
},
348+
exit_failure = DEFAULT_TEST_SUCCESS_MSG,
349+
# This fault code is kErrorRomImmSection.
350+
exit_success = "BFV:034d5203$",
351+
otp = ":otp_img_immutable_rom_ext_exec_enabled_hash_valid_virtual_a",
352+
),
353+
)

sw/device/silicon_creator/rom/e2e/immutable_rom_ext_section/immutable_rom_ext_section_test.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
OTTF_DEFINE_TEST_CONFIG();
1919

20+
#ifndef IMMUTABLE_MESSAGE
21+
// l b a t u m m I
22+
#define IMMUTABLE_MESSAGE 0x6c626174756d6d49;
23+
#endif
24+
2025
enum {
2126
kImmutableRomExtSectionHashSizeIn32BitWords =
2227
OTP_CTRL_PARAM_CREATOR_SW_CFG_IMMUTABLE_ROM_EXT_SHA256_HASH_SIZE /
@@ -26,8 +31,7 @@ enum {
2631

2732
OT_USED OT_SECTION(".rom_ext_immutable") void rom_ext_non_mutable(void) {
2833
// Print "Immutable" to the UART console.
29-
// l b a t u m m I
30-
const uint64_t kStr1 = 0x6c626174756d6d49;
34+
const uint64_t kStr1 = IMMUTABLE_MESSAGE;
3135
// e
3236
const uint32_t kStr2 = 0x65;
3337
const uint32_t kNewline = 0x0a0d;

0 commit comments

Comments
 (0)