14 #include "sw/device/lib/testing/otp_ctrl_testutils.h"
15 #include "sw/device/lib/testing/rstmgr_testutils.h"
16 #include "sw/device/lib/testing/test_framework/check.h"
20 #include "otp_ctrl_regs.h"
22 static dif_otp_ctrl_t otp;
23 static dif_rstmgr_t rstmgr;
26 kLastWriteValue = 0x77778888,
29 static const uint32_t kTestData[] = {
36 OTTF_DEFINE_TEST_CONFIG();
46 .size = OTP_CTRL_PARAM_VENDOR_TEST_SIZE /
sizeof(uint32_t),
50 .size = OTP_CTRL_PARAM_CREATOR_SW_CFG_SIZE /
sizeof(uint32_t),
54 .size = OTP_CTRL_PARAM_OWNER_SW_CFG_SIZE /
sizeof(uint32_t),
57 .partition = kDifOtpCtrlPartitionRotCreatorAuthCodesign,
59 OTP_CTRL_PARAM_ROT_CREATOR_AUTH_CODESIGN_SIZE /
sizeof(uint32_t),
62 .partition = kDifOtpCtrlPartitionRotCreatorAuthState,
63 .size = OTP_CTRL_PARAM_ROT_CREATOR_AUTH_STATE_SIZE /
sizeof(uint32_t),
67 static void peripheral_handles_init(
void) {
68 CHECK_DIF_OK(dif_otp_ctrl_init(
70 CHECK_DIF_OK(dif_rstmgr_init(
74 static void otp_ctrl_dai_write_test(
bool expect_eq) {
75 for (uint32_t i = 0; i <
ARRAYSIZE(kTestData); ++i) {
76 LOG_INFO(
"Programming word kTestData[%d] = 0x%08x.", i, kTestData[i]);
77 CHECK_STATUS_OK(otp_ctrl_testutils_wait_for_dai(&otp));
79 uint32_t address = 0x10 + i *
sizeof(uint32_t);
82 address, kTestData[i]),
83 "Failed to program word kTestData[%d] = 0x%08x.", i, kTestData[i]);
85 CHECK_STATUS_OK(otp_ctrl_testutils_wait_for_dai(&otp));
87 uint32_t readout[
ARRAYSIZE(kTestData)] = {0};
88 CHECK_STATUS_OK(otp_ctrl_testutils_dai_read32_array(
92 CHECK_ARRAYS_EQ(readout, kTestData,
ARRAYSIZE(kTestData));
94 CHECK_ARRAYS_NE(readout, kTestData,
ARRAYSIZE(kTestData));
98 static void dai_disable(
void) {
104 CHECK_STATUS_OK(otp_ctrl_testutils_wait_for_dai(&otp));
107 static void otp_ctrl_dai_disable_test(uint32_t last_dai_value) {
109 LOG_INFO(
"Checking that the DAI is disabled.");
110 for (uint32_t i = 0; i <
ARRAYSIZE(kPartitions); ++i) {
112 LOG_INFO(
"Checking partition %d.", partition->partition);
113 uint32_t readout[partition->size];
114 CHECK_STATUS_OK(otp_ctrl_testutils_dai_read32_array(
115 &otp, partition->partition, 0, readout,
ARRAYSIZE(readout)));
126 for (uint32_t j = 0; j <
ARRAYSIZE(readout); ++j) {
127 CHECK(readout[j] == last_dai_value,
128 "Partition %d, word %d: expected 0x%08x, got 0x%08x.",
129 partition->partition, j, last_dai_value, readout[j]);
135 peripheral_handles_init();
139 .check_timeout = 100000,
140 .integrity_period_mask = 0x3ffff,
141 .consistency_period_mask = 0x3ffffff,
145 rstmgr_testutils_reason_get();
147 LOG_INFO(
"Power-on reset detected.");
149 otp_ctrl_dai_write_test(
false);
151 rstmgr_testutils_reason_clear();
163 LOG_INFO(
"Software reset detected.");
165 otp_ctrl_dai_write_test(
true);
166 otp_ctrl_dai_disable_test(kLastWriteValue);