Skip to content

Commit 2f8f6ec

Browse files
cfrantzpamaury
authored andcommitted
[rom_ext_e2e] Test rescue with a restricted command set
Test that the rescue protocol is functional when the `RescueFirmware` mode is not in the list of allowed commands. Signed-off-by: Chris Frantz <[email protected]> (cherry picked from commit 23b5b87)
1 parent ab879fb commit 2f8f6ec

File tree

3 files changed

+110
-16
lines changed

3 files changed

+110
-16
lines changed

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
(owner_keydata_t) { .ecdsa = UNLOCK_ECDSA_P256 }
7272
#endif
7373

74+
// The following preprocessor symbols are only relevant when
75+
// WITH_RESCUE_PROTOCOL is defined.
7476
#ifndef WITH_RESCUE_GPIO_PARAM
7577
#define WITH_RESCUE_GPIO_PARAM 0
7678
#endif
@@ -83,6 +85,15 @@
8385
#ifndef WITH_RESCUE_TRIGGER
8486
#define WITH_RESCUE_TRIGGER 1 /* default to UartBreak */
8587
#endif
88+
#ifndef WITH_RESCUE_COMMAND_ALLOW
89+
#define WITH_RESCUE_COMMAND_ALLOW \
90+
kRescueModeBootLog, kRescueModeBootSvcRsp, kRescueModeBootSvcReq, \
91+
kRescueModeOwnerBlock, kRescueModeOwnerPage0, kRescueModeOwnerPage1, \
92+
kRescueModeOpenTitanID, kRescueModeFirmware, kRescueModeFirmwareSlotB, \
93+
kBootSvcEmptyReqType, kBootSvcNextBl0SlotReqType, \
94+
kBootSvcMinBl0SecVerReqType, kBootSvcOwnershipActivateReqType, \
95+
kBootSvcOwnershipUnlockReqType,
96+
#endif
8697

8798
rom_error_t sku_creator_owner_init(boot_data_t *bootdata) {
8899
owner_keydata_t owner = OWNER_KEYDATA;
@@ -231,22 +242,7 @@ rom_error_t sku_creator_owner_init(boot_data_t *bootdata) {
231242
.start = 32,
232243
.size = 224,
233244
};
234-
const uint32_t commands[] = {
235-
kRescueModeBootLog,
236-
kRescueModeBootSvcRsp,
237-
kRescueModeBootSvcReq,
238-
kRescueModeOwnerBlock,
239-
kRescueModeOwnerPage0,
240-
kRescueModeOwnerPage1,
241-
kRescueModeOpenTitanID,
242-
kRescueModeFirmware,
243-
kRescueModeFirmwareSlotB,
244-
kBootSvcEmptyReqType,
245-
kBootSvcNextBl0SlotReqType,
246-
kBootSvcMinBl0SecVerReqType,
247-
kBootSvcOwnershipActivateReqType,
248-
kBootSvcOwnershipUnlockReqType,
249-
};
245+
const uint32_t commands[] = {WITH_RESCUE_COMMAND_ALLOW};
250246
memcpy(&rescue->command_allow, commands, sizeof(commands));
251247
rescue->header.length += sizeof(commands);
252248
end = (uintptr_t)rescue + rescue->header.length;

sw/device/silicon_creator/rom_ext/defs.bzl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,34 @@ TEST_OWNER_CONFIGS = {
8686
],
8787
"rescue_module": ["//sw/device/silicon_creator/lib/rescue:rescue_xmodem"],
8888
},
89+
"xmodem_restricted_commands": {
90+
# Enable Xmodem rescue with enter-on-fail and a timeout.
91+
"owner_defines": [
92+
# 0x58 is 'X'modem.
93+
"WITH_RESCUE_PROTOCOL=0x58",
94+
# Restrict rescue to only one command
95+
"WITH_RESCUE_COMMAND_ALLOW=kRescueModeOpenTitanID",
96+
],
97+
"rescue_module": ["//sw/device/silicon_creator/lib/rescue:rescue_xmodem"],
98+
},
99+
"spidfu_restricted_commands": {
100+
# Enable USB-DFU triggered by SW_STRAPS value 3.
101+
"owner_defines": [
102+
# 0x53 is 'S'pi.
103+
"WITH_RESCUE_PROTOCOL=0x53",
104+
# Trigger 3 is GPIO pin.
105+
"WITH_RESCUE_TRIGGER=3",
106+
# When the trigger is GPIO, the index is the MuxedPad to us as the sense
107+
# input. Index 2 is kTopEarlgreyMuxedPadsIoa2.
108+
"WITH_RESCUE_INDEX=2",
109+
# GPIO param 3 means enable the internal pull resistor and trigger
110+
# rescue when the GPIO is high.
111+
"WITH_RESCUE_GPIO_PARAM=3",
112+
# Timeout: 0x80=enter_on_fail, 0x00 = No timeout.
113+
"WITH_RESCUE_TIMEOUT=0x80",
114+
# Restrict rescue to only one command
115+
"WITH_RESCUE_COMMAND_ALLOW=kRescueModeOpenTitanID",
116+
],
117+
"rescue_module": ["//sw/device/silicon_creator/lib/rescue:rescue_spidfu"],
118+
},
89119
}

sw/device/silicon_creator/rom_ext/e2e/rescue/BUILD

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,74 @@ opentitan_test(
328328
],
329329
)
330330

331+
# Check that xmodem rescue is functional when the `RESQ` mode is disabled.
332+
opentitan_test(
333+
name = "xmodem_restricted_commands",
334+
srcs = [
335+
"//sw/device/silicon_creator/rom_ext/e2e/verified_boot:boot_test",
336+
],
337+
exec_env = {
338+
"//hw/top_earlgrey:fpga_cw310_rom_ext": None,
339+
},
340+
fpga = fpga_params(
341+
changes_otp = True,
342+
exit_failure = "ok: ",
343+
exit_success = "error: mode not allowed",
344+
rom_ext = "//sw/device/silicon_creator/rom_ext:rom_ext_xmodem_restricted_commands",
345+
test_cmd = """
346+
--exec="transport init"
347+
--exec="fpga clear-bitstream"
348+
--exec="fpga load-bitstream {bitstream}"
349+
--exec="bootstrap --clear-uart=true {firmware}"
350+
# Trigger rescue and make sure we can get the device ID.
351+
--exec="rescue get-device-id --reboot=false"
352+
# Try the `RESQ` mode and make sure we get an error message.
353+
--exec="console --non-interactive --send='RESQ\r' --exit-success='{exit_success}' --exit-failure='{exit_failure}'"
354+
no-op
355+
""",
356+
),
357+
deps = [
358+
"//sw/device/lib/base:status",
359+
"//sw/device/lib/testing/test_framework:ottf_main",
360+
"//sw/device/silicon_creator/lib:boot_log",
361+
"//sw/device/silicon_creator/lib/drivers:retention_sram",
362+
],
363+
)
364+
365+
# Check that DFU rescue is functional when the `RESQ` mode is disabled.
366+
# TODO: Add a test to try to perform a firmware rescue and ensure that it fails.
367+
opentitan_test(
368+
name = "spidfu_restricted_commands",
369+
srcs = [
370+
"//sw/device/silicon_creator/rom_ext/e2e/verified_boot:boot_test",
371+
],
372+
exec_env = {
373+
"//hw/top_earlgrey:fpga_cw310_rom_ext": None,
374+
},
375+
fpga = fpga_params(
376+
changes_otp = True,
377+
params = "-p spi-dfu -t gpio -v +Ioa2",
378+
rom_ext = "//sw/device/silicon_creator/rom_ext:rom_ext_spidfu_restricted_commands",
379+
setup = "--exec=\"gpio set --mode OpenDrain Ioa2\"",
380+
test_cmd = """
381+
--exec="transport init"
382+
--exec="fpga clear-bitstream"
383+
--exec="fpga load-bitstream {bitstream}"
384+
{setup}
385+
--exec="bootstrap --clear-uart=true {firmware}"
386+
# Trigger rescue and make sure we can get the device ID.
387+
--exec="rescue {params} get-device-id --reboot=false"
388+
no-op
389+
""",
390+
),
391+
deps = [
392+
"//sw/device/lib/base:status",
393+
"//sw/device/lib/testing/test_framework:ottf_main",
394+
"//sw/device/silicon_creator/lib:boot_log",
395+
"//sw/device/silicon_creator/lib/drivers:retention_sram",
396+
],
397+
)
398+
331399
[
332400
opentitan_test(
333401
name = "rescue_enter_on_fail_{}".format(name),

0 commit comments

Comments
 (0)