11 #include "sw/device/lib/testing/lc_ctrl_testutils.h"
12 #include "sw/device/lib/testing/otp_ctrl_testutils.h"
13 #include "sw/device/lib/testing/test_framework/check.h"
14 #include "sw/device/lib/testing/test_framework/ottf_test_config.h"
18 #define LC_TOKEN_SIZE 16
20 OTTF_DEFINE_TEST_CONFIG();
22 static dif_lc_ctrl_t lc;
23 static dif_otp_ctrl_t otp;
24 static dif_rstmgr_t rstmgr;
33 static volatile const uint8_t kOtpExitToken[LC_TOKEN_SIZE] = {
34 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
35 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
39 static volatile const uint8_t kOtpUnlockToken[LC_TOKEN_SIZE] = {
40 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
41 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
44 static void lock_otp_secret0_partition(
void) {
45 uint64_t otp_unlock_token_0 = 0;
46 uint64_t otp_unlock_token_1 = 0;
47 for (
int i = 0; i < LC_TOKEN_SIZE; i++) {
48 if (i < LC_TOKEN_SIZE / 2) {
49 otp_unlock_token_0 |= (uint64_t)kOtpUnlockToken[i] << (i * 8);
51 otp_unlock_token_1 |= (uint64_t)kOtpUnlockToken[i]
52 << ((i - LC_TOKEN_SIZE / 2) * 8);
56 uint64_t otp_exit_token_0 = 0;
57 uint64_t otp_exit_token_1 = 0;
58 for (
int i = 0; i < LC_TOKEN_SIZE; i++) {
59 if (i < LC_TOKEN_SIZE / 2) {
60 otp_exit_token_0 |= (uint64_t)kOtpExitToken[i] << (i * 8);
62 otp_exit_token_1 |= (uint64_t)kOtpExitToken[i]
63 << ((i - LC_TOKEN_SIZE / 2) * 8);
70 CHECK_STATUS_OK(otp_ctrl_testutils_wait_for_dai(&otp));
74 CHECK_STATUS_OK(otp_ctrl_testutils_wait_for_dai(&otp));
78 CHECK_STATUS_OK(otp_ctrl_testutils_wait_for_dai(&otp));
82 CHECK_STATUS_OK(otp_ctrl_testutils_wait_for_dai(&otp));
86 CHECK_STATUS_OK(otp_ctrl_testutils_wait_for_dai(&otp));
92 switch (*curr_state) {
126 LOG_FATAL(
"Unexpected state = %d", curr_state);
150 LOG_INFO(
"Start LC walkthrough testunlocks test.");
154 CHECK_DIF_OK(dif_lc_ctrl_init(lc_reg, &lc));
158 CHECK_DIF_OK(dif_otp_ctrl_init(otp_reg, &otp));
160 CHECK_DIF_OK(dif_rstmgr_init(
163 LOG_INFO(
"Read and check LC state and count.");
169 get_dest_state_and_cnt(&curr_state, &kDestState, &kExpCnt);
171 CHECK_STATUS_OK(lc_ctrl_testutils_check_transition_count(&lc, kExpCnt));
176 if (!secret0_locked) {
178 lock_otp_secret0_partition();
179 LOG_INFO(
"Wrote and locked OTP secret0 partition!");
189 for (
int i = 0; i < LC_TOKEN_SIZE; i++) {
199 bool use_ext_clock =
false;
201 "LC transition configuration failed!");
204 LOG_INFO(
"Waiting for LC transtition %d done and reboot.", kDestState);