Skip to content

Commit 2041523

Browse files
authored
[TB] Add smoke_test_fc_filter_rule_write_zer_id for fuse_ctrl_filter coverage (#1056)
* Add smoke_test_fc_filter_rule_write_zer_id for fuse_ctrl_filter coverage Add a new integration test targeting four uncovered paths in the fuse_ctrl_filter FSM (FUSE_ADDR_AXI_WR_ST and FUSE_CMD_AXI_ADDR_ST states): Scenario 1 - trigger_table_check in FUSE_ADDR_AXI_WR_ST: Writing DIRECT_ACCESS_ADDRESS twice in succession causes the FSM to see trigger_table_check while already in FUSE_ADDR_AXI_WR_ST, exercising the re-latch-and-loop-back path to FUSE_ADDR_AXI_ADDR_ST. Issuing a DaiWrite from the MCU user to a secret partition address (SECRET_MANUF_PARTITION). The MCU user is not in the access_control_table for the secret range [0x48,0xF0], so wr_req_allowed evaluates to false and the filter asserts discard_fuse_write. Writing WDATA_0 and WDATA_1 with MCU user, then switching to Caliptra core user for ADDRESS and CMD. The command is authorized (Caliptra core matches entry[0]), but the latched data IDs (MCU) differ from the address/command IDs (Caliptra core), making all_same_id false. The filter discards the write. Writing DIRECT_ACCESS_ADDRESS with MCU user, then switching to Caliptra core user for the DaiZeroize CMD. A non-secret partition (SW_MANUF_PARTITION at 0xF8) is targeted so the FIPS zeroization check passes, and the command is authorized, but addr_and_cmd_same_id is false because the address writer differs from the command writer. The filter discards the zeroize. * removed hard-coded line numbers * added new fc cov test to the regression list * Cover the false-branch of line 172 in mci_lcc_st_trans.sv where │ │ │ │ lcc_volatile_raw_unlock_success_i is HIGH but state_error is also HIGH, │ │ │ │ keeping the FSM in TRANSLATOR_NON_DEBUG instead of transitioning to │ │ │ │ TRANSLATOR_UNPROV_DEBUG. This is a security-critical guard that prevents │ │ │ │ debug unlock when a fatal state error is active. │ │ │ │ │ │ │ │ Changes: │ │ │ │ - Add CMD_MCI_FORCE_STATE_ERROR/CMD_MCI_RELEASE_STATE_ERROR BFM commands │ │ │ │ to caliptra_ss_tb_cmd_list.svh, caliptra_ss_lib.h, and │ │ │ │ fc_lcc_tb_services.sv (force/release state_error on │ │ │ │ MCI_PATH.LCC_state_translator) │ │ │ │ - Add caliptra_ss_lcc_volatile_unlock_with_state_error test that boots │ │ │ │ to RAW, forces state_error, performs volatile raw unlock, and verifies │ │ │ │ the MCI translator stays locked │ │ │ │ - Fix UnProvSIGNAL_with_Volatile_Decoding_A assertion to disable when │ │ │ │ state_error is active (the assertion incorrectly fired when state_error │ │ │ │ legitimately blocks the volatile unlock promotion) │ │ │ │ - Register test in master test list and regenerate regression YAMLs │ │ * removed the hard-coded line number * removed assertion change on RTL * MICROSOFT AUTOMATED PIPELINE: Stamp 'user/ekarabulut/fc-filter-write-zeroize-id-coverage' with updated timestamp and hash after successful run * updated assertion label * MICROSOFT AUTOMATED PIPELINE: Stamp 'user/ekarabulut/fc-filter-write-zeroize-id-coverage' with updated timestamp and hash after successful run
1 parent 305d71f commit 2041523

13 files changed

Lines changed: 521 additions & 2 deletions

.github/workflow_metadata/pr_hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b43efcc44f38d7e048d4f47a2897277c0c10e25765a3f3f66182742b7339f6baf3f651c7ffb1d72804e96c509eef92f2
1+
cd3d5d50511f98172c9d0920f3827b80c106fbb6146a243ae75579ec82c49382ab99374d2148e9406b82673ffc178e20
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1769035735
1+
1771639896

src/integration/stimulus/L1_Nightly_Directed_Strict_caliptra_ss_top_tb_regression.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,5 @@ contents:
101101
- ../test_suites/smoke_test_fc_cptra_zeroization/smoke_test_fc_cptra_zeroization.yml
102102
- ../test_suites/smoke_test_fc_ratchet_seed_lock_en/smoke_test_fc_ratchet_seed_lock_en.yml
103103
- ../test_suites/smoke_test_fc_secret_prog_in_dbg/smoke_test_fc_secret_prog_in_dbg.yml
104+
- ../test_suites/smoke_test_fc_filter_rule_write_zer_id/smoke_test_fc_filter_rule_write_zer_id.yml
105+
- ../test_suites/caliptra_ss_lcc_volatile_unlock_with_state_error/caliptra_ss_lcc_volatile_unlock_with_state_error.yml

src/integration/stimulus/L1_Nightly_Directed_caliptra_ss_top_tb_regression.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,5 @@ contents:
108108
$CALIPTRA_SS_ROOT/src/integration/test_suites/smoke_test_fc_cptra_zeroization/smoke_test_fc_cptra_zeroization: { weight: 10 }
109109
$CALIPTRA_SS_ROOT/src/integration/test_suites/smoke_test_fc_ratchet_seed_lock_en/smoke_test_fc_ratchet_seed_lock_en: { weight: 10 }
110110
$CALIPTRA_SS_ROOT/src/integration/test_suites/smoke_test_fc_secret_prog_in_dbg/smoke_test_fc_secret_prog_in_dbg: { weight: 100 }
111+
$CALIPTRA_SS_ROOT/src/integration/test_suites/smoke_test_fc_filter_rule_write_zer_id/smoke_test_fc_filter_rule_write_zer_id: { weight: 100 }
112+
$CALIPTRA_SS_ROOT/src/integration/test_suites/caliptra_ss_lcc_volatile_unlock_with_state_error/caliptra_ss_lcc_volatile_unlock_with_state_error: { weight: 100 }

src/integration/stimulus/testsuites/caliptra_ss_master_test_list.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,5 @@ $CALIPTRA_SS_ROOT/src/integration/test_suites/smoke_test_fc_mcu_uds_fe_zeroizati
128128
$CALIPTRA_SS_ROOT/src/integration/test_suites/smoke_test_fc_cptra_zeroization/smoke_test_fc_cptra_zeroization , Directed , Nightly , None, L1 , caliptra_ss_top_tb, None , None , 10
129129
$CALIPTRA_SS_ROOT/src/integration/test_suites/smoke_test_fc_ratchet_seed_lock_en/smoke_test_fc_ratchet_seed_lock_en , Directed , Nightly , None, L1 , caliptra_ss_top_tb, None , None , 10
130130
$CALIPTRA_SS_ROOT/src/integration/test_suites/smoke_test_fc_secret_prog_in_dbg/smoke_test_fc_secret_prog_in_dbg , Directed , Nightly , None, L1 , caliptra_ss_top_tb, None , None , 100
131+
$CALIPTRA_SS_ROOT/src/integration/test_suites/smoke_test_fc_filter_rule_write_zer_id/smoke_test_fc_filter_rule_write_zer_id , Directed , Nightly , None, L1 , caliptra_ss_top_tb, None , None , 100
132+
$CALIPTRA_SS_ROOT/src/integration/test_suites/caliptra_ss_lcc_volatile_unlock_with_state_error/caliptra_ss_lcc_volatile_unlock_with_state_error , Directed , Nightly , None, L1 , caliptra_ss_top_tb, None , None , 100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//********************************************************************************
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//********************************************************************************
17+
#include <string.h>
18+
#include <stdint.h>
19+
#include <time.h>
20+
#include <stdlib.h>
21+
22+
#include "soc_address_map.h"
23+
#include "printf.h"
24+
#include "riscv_hw_if.h"
25+
#include "soc_ifc.h"
26+
#include "caliptra_ss_lc_ctrl_address_map.h"
27+
#include "caliptra_ss_lib.h"
28+
#include "fuse_ctrl.h"
29+
#include "lc_ctrl.h"
30+
31+
// Coverage test for mci_lcc_st_trans.sv line:
32+
// if (lcc_volatile_raw_unlock_success_i && !(lcc_valid_SCRAP_req || state_error))
33+
//
34+
// This test hits the FALSE branch by forcing state_error HIGH via BFM
35+
// while performing a volatile raw unlock. The MCI translator FSM should
36+
// stay in TRANSLATOR_NON_DEBUG despite the successful volatile unlock,
37+
// keeping security_state_o = {DEVICE_PRODUCTION, debug_locked=1}.
38+
39+
volatile char* stdout = (char *)SOC_MCI_TOP_MCI_REG_DEBUG_OUT;
40+
#ifdef CPT_VERBOSITY
41+
enum printf_verbosity verbosity_g = CPT_VERBOSITY;
42+
#else
43+
enum printf_verbosity verbosity_g = LOW;
44+
#endif
45+
46+
void main (void) {
47+
VPRINTF(LOW, "=================\nMCU Caliptra Boot Go\n=================\n\n");
48+
49+
mcu_cptra_init_d();
50+
wait_dai_op_idle(0);
51+
52+
lcc_initialization();
53+
grant_mcu_for_fc_writes();
54+
55+
// Verify initial state is RAW (FSM is in TRANSLATOR_NON_DEBUG)
56+
if (!check_lc_state("RAW", RAW)) {
57+
handle_error("ERROR: lcc is not in RAW state\n");
58+
}
59+
60+
// Force state_error HIGH via BFM before initiating volatile unlock
61+
VPRINTF(LOW, "Forcing state_error HIGH via BFM\n");
62+
lsu_write_32(SOC_MCI_TOP_MCI_REG_DEBUG_OUT, CMD_MCI_FORCE_STATE_ERROR);
63+
mcu_sleep(100);
64+
65+
// In volatile raw unlock mode the token has to be passed in hashed form.
66+
const uint32_t hashed_raw_unlock_token[4] = {
67+
0xf0930a4d, 0xde8a30e6, 0xd1c8cbba, 0x896e4a11
68+
};
69+
70+
// Obtain mutex to be able to write to the LCC CSRs.
71+
const uint32_t claim_trans_val = 0x96;
72+
uint32_t reg_value, loop_ctrl = 0;
73+
while (loop_ctrl != claim_trans_val) {
74+
lsu_write_32(LC_CTRL_CLAIM_TRANSITION_IF_OFFSET, claim_trans_val);
75+
reg_value = lsu_read_32(LC_CTRL_CLAIM_TRANSITION_IF_OFFSET);
76+
loop_ctrl = reg_value & claim_trans_val;
77+
}
78+
79+
// Activate volatile raw unlock mode.
80+
lsu_write_32(SOC_LC_CTRL_TRANSITION_CTRL, 0x2);
81+
82+
// Submit the volatile raw unlock transition to TEST_UNLOCKED0.
83+
// LCC will pulse lcc_volatile_raw_unlock_success_i, but since
84+
// state_error is forced HIGH, the MCI translator FSM condition
85+
// evaluates FALSE and the FSM stays in TRANSLATOR_NON_DEBUG.
86+
if (!start_state_transition(TEST_UNLOCKED0, hashed_raw_unlock_token, false)) {
87+
// Release state_error before failing
88+
lsu_write_32(SOC_MCI_TOP_MCI_REG_DEBUG_OUT, CMD_MCI_RELEASE_STATE_ERROR);
89+
handle_error("ERROR: Unexpected failure when starting state transition.\n");
90+
}
91+
92+
// At the LCC level, the volatile unlock succeeded and the LC state
93+
// reports TEST_UNLOCKED0. But the MCI translator blocked the debug
94+
// unlock due to state_error.
95+
if (!check_lc_state("TEST_UNLOCKED0", TEST_UNLOCKED0)) {
96+
lsu_write_32(SOC_MCI_TOP_MCI_REG_DEBUG_OUT, CMD_MCI_RELEASE_STATE_ERROR);
97+
handle_error("ERROR: LC state is not TEST_UNLOCKED0 after volatile unlock\n");
98+
}
99+
100+
VPRINTF(LOW, "Volatile unlock succeeded at LCC level but MCI translator stayed locked (state_error active)\n");
101+
102+
// Release state_error
103+
VPRINTF(LOW, "Releasing state_error via BFM\n");
104+
lsu_write_32(SOC_MCI_TOP_MCI_REG_DEBUG_OUT, CMD_MCI_RELEASE_STATE_ERROR);
105+
mcu_sleep(100);
106+
107+
// Reset FC/LCC and verify we return to RAW (volatile = no OTP write)
108+
reset_fc_lcc_rtl();
109+
lcc_initialization();
110+
if (!check_lc_state("RAW", RAW)) {
111+
handle_error("ERROR: LC state did not revert to RAW after reset\n");
112+
}
113+
114+
mcu_sleep(160);
115+
116+
SEND_STDOUT_CTRL(0xff);
117+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
seed: 1
3+
testname: caliptra_ss_lcc_volatile_unlock_with_state_error
4+
pre-exec: |
5+
echo "Running pre_exec for [caliptra_ss_lcc_volatile_unlock_with_state_error]"
6+
CALIPTRA_ROOT=$CALIPTRA_SS_ROOT/third_party/caliptra-rtl make -f $CALIPTRA_SS_ROOT/third_party/caliptra-rtl/tools/scripts/Makefile CALIPTRA_INTERNAL_TRNG=0 TESTNAME=smoke_test_mbox program.hex
7+
make -f $CALIPTRA_SS_ROOT/tools/scripts/Makefile TESTNAME=caliptra_ss_lcc_volatile_unlock_with_state_error mcu_program.hex

src/integration/test_suites/libs/caliptra_ss_lib/caliptra_ss_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
#define CMD_FC_RELEASE_FUSE_UNZEROIZ FC_LCC_CMD_OFFSET + 0x22
6565
#define CMD_FC_ALL_ONES_DISABLE_SVA FC_LCC_CMD_OFFSET + 0x23
6666
#define CMD_FC_ALL_ONES_ENABLE_SVA FC_LCC_CMD_OFFSET + 0x24
67+
#define CMD_MCI_FORCE_STATE_ERROR FC_LCC_CMD_OFFSET + 0x25
68+
#define CMD_MCI_RELEASE_STATE_ERROR FC_LCC_CMD_OFFSET + 0x26
6769

6870

6971
#define TB_CMD_DISABLE_MCU_SRAM_PROT_ASSERTS 0xC0

0 commit comments

Comments
 (0)