forked from lowRISC/opentitan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rom_ext_e2e] Test the
MinBl0SecVer
request
1. Verify the manifests of both slots to determine a maximum `min_sec_ver`. We prevent advancing the `min_sec_ver` beyond the value associated with any valid firmware in flash. 2. Test the `MinBl0SecVer` request by advancing the minimum security version forward. Attempt to go beyond the maximum allowed value and confirm that the request is rejected. Attempt to go backwards and confirm that the request is rejected. This addresses lowRISC#23259. Signed-off-by: Chris Frantz <[email protected]> (cherry picked from commit 49bbeb2)
- Loading branch information
Showing
5 changed files
with
234 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
sw/device/silicon_creator/rom_ext/e2e/boot_svc/boot_svc_min_sec_ver_test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "sw/device/lib/base/status.h" | ||
#include "sw/device/lib/runtime/log.h" | ||
#include "sw/device/lib/testing/test_framework/check.h" | ||
#include "sw/device/lib/testing/test_framework/ottf_main.h" | ||
#include "sw/device/silicon_creator/lib/boot_svc/boot_svc_min_bl0_sec_ver.h" | ||
#include "sw/device/silicon_creator/lib/drivers/retention_sram.h" | ||
#include "sw/device/silicon_creator/lib/drivers/rstmgr.h" | ||
#include "sw/device/silicon_creator/rom_ext/e2e/boot_svc/boot_svc_test_lib.h" | ||
|
||
OTTF_DEFINE_TEST_CONFIG(); | ||
|
||
#define MANIFEST_SEC_VER 4 | ||
|
||
static status_t initialize(retention_sram_t *retram, boot_svc_retram_t *state) { | ||
boot_svc_msg_t msg = {0}; | ||
boot_svc_empty_init(&msg.empty); | ||
boot_svc_min_bl0_sec_ver_req_init(2, &msg.min_bl0_sec_ver_req); | ||
retram->creator.boot_svc_msg = msg; | ||
state->state = kBootSvcTestStateMinSecAdvance; | ||
rstmgr_reset(); | ||
return INTERNAL(); | ||
} | ||
|
||
static status_t advance(retention_sram_t *retram, boot_svc_retram_t *state) { | ||
boot_svc_msg_t msg = retram->creator.boot_svc_msg; | ||
TRY(boot_svc_header_check(&msg.header)); | ||
TRY_CHECK(msg.header.type == kBootSvcMinBl0SecVerResType); | ||
LOG_INFO("Response: status=%08x min_bl0_sec_ver=%d", | ||
msg.min_bl0_sec_ver_res.status, | ||
msg.min_bl0_sec_ver_res.min_bl0_sec_ver); | ||
|
||
TRY_CHECK(msg.min_bl0_sec_ver_res.status == kErrorOk); | ||
|
||
if (msg.min_bl0_sec_ver_res.min_bl0_sec_ver < MANIFEST_SEC_VER) { | ||
// Advance by one and check again for success | ||
boot_svc_min_bl0_sec_ver_req_init( | ||
msg.min_bl0_sec_ver_res.min_bl0_sec_ver + 1, &msg.min_bl0_sec_ver_req); | ||
retram->creator.boot_svc_msg = msg; | ||
rstmgr_reset(); | ||
} | ||
|
||
if (msg.min_bl0_sec_ver_res.min_bl0_sec_ver == MANIFEST_SEC_VER) { | ||
// Advance by one and check for failure | ||
state->state = kBootSvcTestStateMinSecTooFar; | ||
boot_svc_min_bl0_sec_ver_req_init( | ||
msg.min_bl0_sec_ver_res.min_bl0_sec_ver + 1, &msg.min_bl0_sec_ver_req); | ||
retram->creator.boot_svc_msg = msg; | ||
rstmgr_reset(); | ||
} | ||
return INTERNAL(); | ||
} | ||
|
||
static status_t too_far(retention_sram_t *retram, boot_svc_retram_t *state) { | ||
boot_svc_msg_t msg = retram->creator.boot_svc_msg; | ||
TRY(boot_svc_header_check(&msg.header)); | ||
TRY_CHECK(msg.header.type == kBootSvcMinBl0SecVerResType); | ||
LOG_INFO("Response: status=%08x min_bl0_sec_ver=%d", | ||
msg.min_bl0_sec_ver_res.status, | ||
msg.min_bl0_sec_ver_res.min_bl0_sec_ver); | ||
TRY_CHECK(msg.min_bl0_sec_ver_res.status == kErrorBootSvcBadSecVer); | ||
TRY_CHECK(msg.min_bl0_sec_ver_res.min_bl0_sec_ver == MANIFEST_SEC_VER); | ||
|
||
// Try to go back | ||
state->state = kBootSvcTestStateMinSecGoBack; | ||
boot_svc_min_bl0_sec_ver_req_init(msg.min_bl0_sec_ver_res.min_bl0_sec_ver - 1, | ||
&msg.min_bl0_sec_ver_req); | ||
retram->creator.boot_svc_msg = msg; | ||
rstmgr_reset(); | ||
return INTERNAL(); | ||
} | ||
|
||
static status_t go_back(retention_sram_t *retram, boot_svc_retram_t *state) { | ||
boot_svc_msg_t msg = retram->creator.boot_svc_msg; | ||
TRY(boot_svc_header_check(&msg.header)); | ||
TRY_CHECK(msg.header.type == kBootSvcMinBl0SecVerResType); | ||
LOG_INFO("Response: status=%08x min_bl0_sec_ver=%d", | ||
msg.min_bl0_sec_ver_res.status, | ||
msg.min_bl0_sec_ver_res.min_bl0_sec_ver); | ||
TRY_CHECK(msg.min_bl0_sec_ver_res.status == kErrorBootSvcBadSecVer); | ||
TRY_CHECK(msg.min_bl0_sec_ver_res.min_bl0_sec_ver == MANIFEST_SEC_VER); | ||
|
||
// End of test sequence. | ||
state->state = kBootSvcTestStateFinal; | ||
return OK_STATUS(); | ||
} | ||
|
||
static status_t min_sec_ver_test(void) { | ||
retention_sram_t *retram = retention_sram_get(); | ||
TRY(boot_svc_test_init(retram, kBootSvcTestBl0MinSecVer)); | ||
boot_svc_retram_t *state = (boot_svc_retram_t *)&retram->owner; | ||
|
||
for (;;) { | ||
LOG_INFO("Test state = %d", state->state); | ||
switch (state->state) { | ||
case kBootSvcTestStateInit: | ||
TRY(initialize(retram, state)); | ||
break; | ||
case kBootSvcTestStateMinSecAdvance: | ||
TRY(advance(retram, state)); | ||
break; | ||
case kBootSvcTestStateMinSecTooFar: | ||
TRY(too_far(retram, state)); | ||
break; | ||
case kBootSvcTestStateMinSecGoBack: | ||
TRY(go_back(retram, state)); | ||
break; | ||
case kBootSvcTestStateFinal: | ||
LOG_INFO("FinalBootLog: %d:%s", state->boots, state->partition); | ||
return OK_STATUS(); | ||
default: | ||
return UNKNOWN(); | ||
} | ||
} | ||
} | ||
|
||
bool test_main(void) { | ||
status_t sts = min_sec_ver_test(); | ||
if (status_err(sts)) { | ||
LOG_ERROR("min_sec_ver_test: %r", sts); | ||
} | ||
return status_ok(sts); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters