@@ -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,100 @@ 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+ deps = [
285+ "//hw/top:otp_ctrl_c_regs" ,
286+ "//hw/top_earlgrey/sw/autogen:top_earlgrey" ,
287+ "//sw/device/lib/base:hardened" ,
288+ "//sw/device/lib/base:status" ,
289+ "//sw/device/lib/testing/test_framework:ottf_main" ,
290+ "//sw/device/silicon_creator/lib/drivers:otp" ,
291+ "//sw/device/silicon_creator/lib/drivers:retention_sram" ,
292+ "//sw/device/silicon_creator/lib/drivers:uart" ,
293+ ],
294+ )
295+ for name , param in BAD_SECTION_BINS .items ()
296+ ]
297+
298+ # Tests that "imm_section_invalid" is functional when OTP disabled the immutable
299+ # section. This test proves that `imm_section_invalid` is a valid signed
300+ # ROM_EXT stage.
301+ opentitan_test (
302+ name = "immutable_section_invalid_ok_when_disabled" ,
303+ exec_env = {
304+ "//hw/top_earlgrey:fpga_cw310_sival" : None ,
305+ },
306+ fpga = fpga_params (
307+ assemble = "{invalid}@0" ,
308+ binaries = {
309+ ":imm_section_invalid" : "invalid" ,
310+ },
311+ otp = ":otp_img_immutable_rom_ext_exec_disabled_hash_valid_virtual_a" ,
312+ ),
313+ )
314+
315+ # Tests that we can boot "imm_section_valid" when there is a valid signed
316+ # ROM_EXT with an invalid immutable section in the primary slot.
317+ # The ROM should skip the primary slot and boot the secondary slot.
318+ opentitan_test (
319+ name = "immutable_section_a_bad_b_good" ,
320+ exec_env = {
321+ "//hw/top_earlgrey:fpga_cw310_sival" : None ,
322+ },
323+ fpga = fpga_params (
324+ assemble = "{invalid}@0 {valid}@0x80000" ,
325+ binaries = {
326+ ":imm_section_invalid" : "invalid" ,
327+ ":imm_section_valid" : "valid" ,
328+ },
329+ exit_failure = DEFAULT_TEST_FAILURE_MSG ,
330+ exit_success = "(?msR)Immutable$.*PASS!$" ,
331+ otp = ":otp_img_immutable_rom_ext_exec_enabled_hash_valid_virtual_a" ,
332+ ),
333+ )
334+
335+ # Test that the ROM fails to boot when both slots have valid signatures
336+ # and invalid immutable sections.
337+ opentitan_test (
338+ name = "immutable_section_a_bad_b_bad" ,
339+ exec_env = {
340+ "//hw/top_earlgrey:fpga_cw310_sival" : None ,
341+ },
342+ fpga = fpga_params (
343+ assemble = "{invalid}@0 {invalid}@0x80000" ,
344+ binaries = {
345+ ":imm_section_invalid" : "invalid" ,
346+ },
347+ exit_failure = DEFAULT_TEST_SUCCESS_MSG ,
348+ # This fault code is kErrorRomImmSection.
349+ exit_success = "BFV:034d5203$" ,
350+ otp = ":otp_img_immutable_rom_ext_exec_enabled_hash_valid_virtual_a" ,
351+ ),
352+ )
0 commit comments