@@ -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+ )
0 commit comments