Skip to content

Commit ea20827

Browse files
committed
[rom_ext] Run boot_svc after a wakeup according to owner config
Initial customers requested that boot services not run when the ROM_EXT detects a low-power wakeup. A new customer has requested the opposite behavior. 1. Add a configuration item to the ownership config to enable or disable boot_svc on low-power wakeups. Default to `False` (disabled). 2. Use a weak function to retrieve the ownership configuration value. This allows a down-stream ROM_EXT build to override this function with their preferred behavior (to account for chips that don't have the setting in their ownership config). Signed-off-by: Chris Frantz <[email protected]>
1 parent cf5a464 commit ea20827

File tree

9 files changed

+92
-9
lines changed

9 files changed

+92
-9
lines changed

sw/device/silicon_creator/lib/ownership/datatypes.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ typedef struct owner_block {
181181
uint32_t lock_constraint;
182182
/** The device ID to which this config applies */
183183
uint32_t device_id[8];
184+
/** Perform ROM_EXT boot services after wakeup (hardened_bool_t). */
185+
uint32_t boot_svc_after_wakeup;
184186
/** Reserved space for future use. */
185-
uint32_t reserved[16];
187+
uint32_t reserved[15];
186188
/** Owner public key. */
187189
owner_keydata_t owner_key;
188190
/** Owner's Activate public key. */
@@ -205,7 +207,8 @@ OT_ASSERT_MEMBER_OFFSET(owner_block_t, update_mode, 20);
205207
OT_ASSERT_MEMBER_OFFSET(owner_block_t, min_security_version_bl0, 24);
206208
OT_ASSERT_MEMBER_OFFSET(owner_block_t, lock_constraint, 28);
207209
OT_ASSERT_MEMBER_OFFSET(owner_block_t, device_id, 32);
208-
OT_ASSERT_MEMBER_OFFSET(owner_block_t, reserved, 64);
210+
OT_ASSERT_MEMBER_OFFSET(owner_block_t, boot_svc_after_wakeup, 64);
211+
OT_ASSERT_MEMBER_OFFSET(owner_block_t, reserved, 68);
209212
OT_ASSERT_MEMBER_OFFSET(owner_block_t, owner_key, 128);
210213
OT_ASSERT_MEMBER_OFFSET(owner_block_t, activate_key, 224);
211214
OT_ASSERT_MEMBER_OFFSET(owner_block_t, unlock_key, 320);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ void owner_config_default(owner_config_t *config) {
195195
config->rescue = (const owner_rescue_config_t *)kHardenedBoolFalse;
196196
config->isfb = (const owner_isfb_config_t *)kHardenedBoolFalse;
197197
config->sram_exec = kOwnerSramExecModeDisabledLocked;
198+
config->boot_svc_after_wakeup = kHardenedBoolFalse;
198199
}
199200

200201
rom_error_t owner_block_parse(const owner_block_t *block,
@@ -211,6 +212,7 @@ rom_error_t owner_block_parse(const owner_block_t *block,
211212
if (check_only == kHardenedBoolFalse) {
212213
owner_config_default(config);
213214
config->sram_exec = block->sram_exec_mode;
215+
config->boot_svc_after_wakeup = block->boot_svc_after_wakeup;
214216
}
215217

216218
uint32_t remain = sizeof(block->data);

sw/device/silicon_creator/lib/ownership/owner_block.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ extern owner_page_status_t owner_page_valid[2];
3939
typedef struct owner_config {
4040
/** The requested SRAM execution configuration. */
4141
owner_sram_exec_mode_t sram_exec;
42+
/** Allow boot_svc after wakeup. */
43+
hardened_bool_t boot_svc_after_wakeup;
4244
/** The requested flash configuration. */
4345
const owner_flash_config_t *flash;
4446
/** The requested flash INFO configuration. */

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@
108108
#define TEST_OWNER_SRAM_EXEC_MODE kOwnerSramExecModeDisabledLocked
109109
#endif
110110

111+
#ifndef TEST_OWNER_BOOT_SVC_AFTER_WAKEUP
112+
#define TEST_OWNER_BOOT_SVC_AFTER_WAKEUP kHardenedBoolFalse
113+
#endif
114+
111115
// The following preprocessor symbols are only relevant when
112116
// WITH_RESCUE_PROTOCOL is defined.
113117
#ifndef WITH_RESCUE_MISC_GPIO_PARAM
@@ -165,6 +169,7 @@ rom_error_t sku_creator_owner_init(boot_data_t *bootdata) {
165169
owner_page[0].header.version = (struct_version_t){0, 0};
166170
owner_page[0].config_version = TEST_OWNER_CONFIG_VERSION;
167171
owner_page[0].sram_exec_mode = TEST_OWNER_SRAM_EXEC_MODE;
172+
owner_page[0].boot_svc_after_wakeup = TEST_OWNER_BOOT_SVC_AFTER_WAKEUP;
168173
owner_page[0].ownership_key_alg = TEST_OWNER_KEY_ALG;
169174
owner_page[0].update_mode = TEST_OWNER_UPDATE_MODE;
170175
owner_page[0].min_security_version_bl0 = UINT32_MAX;

sw/device/silicon_creator/rom_ext/defs.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ SLOTS = [
3434
]
3535

3636
TEST_OWNER_CONFIGS = {
37+
"boot_svc_after_wakeup": {
38+
"owner_defines": ["TEST_OWNER_BOOT_SVC_AFTER_WAKEUP=kHardenedBoolTrue"],
39+
"rescue_module": ["//sw/device/silicon_creator/lib/rescue:rescue_xmodem"],
40+
},
3741
"hybrid_owner_keys": {
3842
# Enable hybrid ECDSA/SPX+ ownership.
3943
"owner_defines": ["TEST_OWNER_KEY_ALG_HYBRID_SPX_PURE=1"],

sw/device/silicon_creator/rom_ext/e2e/boot_svc/BUILD

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ opentitan_test(
119119
)
120120

121121
opentitan_test(
122-
name = "boot_svc_wakeup_test",
122+
name = "boot_svc_after_wakeup_disabled_test",
123123
srcs = ["boot_svc_wakeup_test.c"],
124+
defines = ["BOOT_SVC_AFTER_WAKEUP_ENABLED=0"],
124125
exec_env = {
125126
"//hw/top_earlgrey:fpga_hyper310_rom_ext": None,
126127
"//hw/top_earlgrey:fpga_cw340_rom_ext": None,
@@ -148,6 +149,45 @@ opentitan_test(
148149
],
149150
)
150151

152+
opentitan_test(
153+
name = "boot_svc_after_wakeup_enabled_test",
154+
srcs = ["boot_svc_wakeup_test.c"],
155+
defines = ["BOOT_SVC_AFTER_WAKEUP_ENABLED=1"],
156+
exec_env = {
157+
"//hw/top_earlgrey:fpga_hyper310_rom_ext": None,
158+
"//hw/top_earlgrey:fpga_cw340_rom_ext": None,
159+
# Not supported in QEMU whilst low power is not modelled
160+
},
161+
fpga = fpga_params(
162+
assemble = "{rom_ext}@{rom_ext_slot_a} {firmware}@{owner_slot_a}",
163+
changes_otp = True,
164+
rom_ext = "//sw/device/silicon_creator/rom_ext:rom_ext_boot_svc_after_wakeup",
165+
test_cmd = """
166+
--exec="transport init"
167+
--exec="fpga clear-bitstream"
168+
--exec="fpga load-bitstream {bitstream}"
169+
--exec="bootstrap --clear-uart=true {firmware}"
170+
--exec="console --non-interactive --exit-success='{exit_success}' --exit-failure='{exit_failure}'"
171+
no-op
172+
""",
173+
),
174+
linker_script = "//sw/device/lib/testing/test_framework:ottf_ld_silicon_owner_slot_virtual",
175+
deps = [
176+
":boot_svc_test_lib",
177+
"//sw/device/lib/base:status",
178+
"//sw/device/lib/dif:aon_timer",
179+
"//sw/device/lib/dif:pwrmgr",
180+
"//sw/device/lib/runtime:log",
181+
"//sw/device/lib/testing:pwrmgr_testutils",
182+
"//sw/device/lib/testing/test_framework:check",
183+
"//sw/device/lib/testing/test_framework:ottf_main",
184+
"//sw/device/silicon_creator/lib:boot_log",
185+
"//sw/device/silicon_creator/lib/boot_svc:boot_svc_empty",
186+
"//sw/device/silicon_creator/lib/drivers:retention_sram",
187+
"//sw/device/silicon_creator/lib/drivers:rstmgr",
188+
],
189+
)
190+
151191
NEXT_TEST_SEQUENCES = [
152192
"AAB",
153193
"ABA",

sw/device/silicon_creator/rom_ext/e2e/boot_svc/boot_svc_wakeup_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ static status_t check_empty(retention_sram_t *retram,
6767
}
6868
boot_svc_msg_t msg = retram->creator.boot_svc_msg;
6969
TRY(boot_svc_header_check(&msg.header));
70+
#if BOOT_SVC_AFTER_WAKEUP_ENABLED == 0
7071
// We expect the `EmptyReqType` here because the ROM_EXT should not process
7172
// boot_svc requests when waking from deep sleep.
7273
TRY_CHECK(msg.header.type == kBootSvcEmptyReqType);
74+
#else // WAKEUP_ENABLED == 1
75+
// We expect the `EmptyResType` here because the ROM_EXT should process
76+
// boot_svc requests when waking from deep sleep.
77+
TRY_CHECK(msg.header.type == kBootSvcEmptyResType);
78+
#endif
7379
state->state = kBootSvcTestStateFinal;
7480
return OK_STATUS();
7581
}

sw/device/silicon_creator/rom_ext/rom_ext.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,14 @@ static rom_error_t rom_ext_advance_secver(boot_data_t *boot_data,
484484
return kErrorOk;
485485
}
486486

487+
// This weak function allows downstream ROM_EXT builds to override whether or
488+
// not boot_svc runs after a low-power wakeup. This is a mitigation for a
489+
// late-added confiuration item to the owner configuration.
490+
OT_WEAK
491+
hardened_bool_t rom_ext_allow_boot_svc_after_wakeup(void) {
492+
return owner_config.boot_svc_after_wakeup;
493+
}
494+
487495
static rom_error_t rom_ext_start(boot_data_t *boot_data, boot_log_t *boot_log) {
488496
HARDENED_RETURN_IF_ERROR(rom_ext_init(boot_data));
489497
const manifest_t *self = rom_ext_manifest();
@@ -564,8 +572,13 @@ static rom_error_t rom_ext_start(boot_data_t *boot_data, boot_log_t *boot_log) {
564572
reset_reasons & (1 << kRstmgrReasonLowPowerExit) ? kHardenedBoolTrue
565573
: kHardenedBoolFalse;
566574

567-
// We don't want to execute boot_svc requests if this is a low-power wakeup.
568-
if (waking_from_low_power != kHardenedBoolTrue) {
575+
// Determine if we want to execute boot_svc requests if this is a low-power
576+
// wakeup.
577+
hardened_bool_t want_boot_svc = waking_from_low_power == kHardenedBoolTrue
578+
? rom_ext_allow_boot_svc_after_wakeup()
579+
: kHardenedBoolTrue;
580+
581+
if (want_boot_svc == kHardenedBoolTrue) {
569582
boot_svc_msg_t *boot_svc_msg = &retention_sram_get()->creator.boot_svc_msg;
570583
error =
571584
boot_svc_handler(boot_svc_msg, boot_data, boot_log, lc_state, &keyring,

sw/host/opentitanlib/src/ownership/owner.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use super::{
1616
DetachedSignature, OwnerApplicationKey, OwnerFlashConfig, OwnerFlashInfoConfig,
1717
OwnerIsfbConfig, OwnerRescueConfig,
1818
};
19+
use crate::chip::boolean::HardenedBool;
1920
use crate::crypto::Error as CryptoError;
2021
use crate::crypto::ecdsa::{EcdsaPrivateKey, EcdsaRawSignature};
2122
use crate::with_unknown;
@@ -72,9 +73,11 @@ pub struct OwnerBlock {
7273
)]
7374
#[annotate(format=hex)]
7475
pub device_id: [u32; 8],
76+
#[serde(default)]
77+
pub boot_svc_after_wakeup: HardenedBool,
7578
#[serde(default, skip_serializing_if = "GlobalFlags::not_debug")]
7679
#[annotate(format=hex)]
77-
pub reserved: [u32; 16],
80+
pub reserved: [u32; 15],
7881
/// The owner identity key.
7982
pub owner_key: KeyMaterial,
8083
/// The owner activation key.
@@ -105,7 +108,8 @@ impl Default for OwnerBlock {
105108
min_security_version_bl0: MinSecurityVersion::default(),
106109
lock_constraint: 0,
107110
device_id: Self::default_constraint(),
108-
reserved: [0u32; 16],
111+
boot_svc_after_wakeup: HardenedBool::default(),
112+
reserved: [0u32; 15],
109113
owner_key: KeyMaterial::default(),
110114
activate_key: KeyMaterial::default(),
111115
unlock_key: KeyMaterial::default(),
@@ -155,6 +159,7 @@ impl OwnerBlock {
155159
dest.write_u32::<LittleEndian>(*x)?;
156160
}
157161
}
162+
dest.write_u32::<LittleEndian>(u32::from(self.boot_svc_after_wakeup))?;
158163
for x in &self.reserved {
159164
dest.write_u32::<LittleEndian>(*x)?;
160165
}
@@ -186,7 +191,8 @@ impl OwnerBlock {
186191

187192
let mut device_id = [0u32; 8];
188193
src.read_u32_into::<LittleEndian>(&mut device_id)?;
189-
let mut reserved = [0u32; 16];
194+
let boot_svc_after_wakeup = HardenedBool(src.read_u32::<LittleEndian>()?);
195+
let mut reserved = [0u32; 15];
190196
src.read_u32_into::<LittleEndian>(&mut reserved)?;
191197
let owner_key = KeyMaterial::read_length(src, ownership_key_alg, 96)?;
192198
let activate_key = KeyMaterial::read_length(src, ownership_key_alg, 96)?;
@@ -213,6 +219,7 @@ impl OwnerBlock {
213219
min_security_version_bl0,
214220
lock_constraint,
215221
device_id,
222+
boot_svc_after_wakeup,
216223
reserved,
217224
owner_key,
218225
activate_key,
@@ -343,7 +350,7 @@ r#"00000000: 4f 57 4e 52 00 08 00 00 00 00 00 00 4c 4e 45 58 OWNR........LNEX
343350
00000010: 50 32 35 36 4f 50 45 4e ff ff ff ff 00 00 00 00 P256OPEN........
344351
00000020: 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e ~~~~~~~~~~~~~~~~
345352
00000030: 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e 7e ~~~~~~~~~~~~~~~~
346-
00000040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
353+
00000040: d4 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
347354
00000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
348355
00000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
349356
00000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
@@ -476,6 +483,7 @@ r#"00000000: 4f 57 4e 52 00 08 00 00 00 00 00 00 4c 4e 45 58 OWNR........LNEX
476483
update_mode: "Open",
477484
min_security_version_bl0: "NoChange",
478485
lock_constraint: 0,
486+
boot_svc_after_wakeup: "False",
479487
owner_key: {
480488
Ecdsa: {
481489
x: "1111111111111111111111111111111111111111111111111111111111111111",

0 commit comments

Comments
 (0)