5 #include "sw/device/lib/base/status.h"
11 #include "sw/device/lib/testing/flash_ctrl_testutils.h"
12 #include "sw/device/lib/testing/otp_ctrl_testutils.h"
13 #include "sw/device/lib/testing/rstmgr_testutils.h"
14 #include "sw/device/lib/testing/test_framework/check.h"
16 #include "sw/device/silicon_creator/manuf/lib/flash_info_fields.h"
17 #include "sw/device/silicon_creator/manuf/lib/individualize_sw_cfg.h"
20 #include "otp_ctrl_regs.h"
22 OTTF_DEFINE_TEST_CONFIG();
29 static dif_otp_ctrl_t otp_ctrl;
31 static dif_rstmgr_t rstmgr;
34 .
ecc_en = kMultiBitBool4True,
35 .high_endurance_en = kMultiBitBool4False,
36 .erase_en = kMultiBitBool4True,
37 .prog_en = kMultiBitBool4True,
38 .rd_en = kMultiBitBool4True,
39 .scramble_en = kMultiBitBool4False};
44 static status_t peripheral_handles_init(
void) {
48 TRY(dif_otp_ctrl_init(
60 static status_t init_flash_info_page0(
void) {
61 uint32_t byte_address = 0;
62 TRY(flash_ctrl_testutils_info_region_setup_properties(
63 &flash_ctrl_state, kFlashInfoFieldAstCalibrationData.page,
64 kFlashInfoFieldAstCalibrationData.bank,
65 kFlashInfoFieldAstCalibrationData.partition, kFlashInfoPage0Permissions,
67 TRY(flash_ctrl_testutils_erase_page(
68 &flash_ctrl_state, byte_address,
69 kFlashInfoFieldAstCalibrationData.partition,
70 kDifFlashCtrlPartitionTypeInfo));
72 uint32_t ast_cfg_data[kFlashInfoAstCalibrationDataSizeIn32BitWords] = {0};
73 for (
size_t i = 0; i <
ARRAYSIZE(ast_cfg_data); ++i) {
76 TRY(flash_ctrl_testutils_write(
78 byte_address + kFlashInfoFieldAstCalibrationData.byte_offset,
79 kFlashInfoFieldAstCalibrationData.partition, ast_cfg_data,
80 kDifFlashCtrlPartitionTypeInfo,
81 kFlashInfoAstCalibrationDataSizeIn32BitWords));
88 static status_t check_otp_ast_cfg(
void) {
91 uint32_t relative_addr;
92 for (
size_t i = 0; i < kFlashInfoAstCalibrationDataSizeIn32BitWords; ++i) {
95 OTP_CTRL_PARAM_CREATOR_SW_CFG_AST_CFG_OFFSET + i *
sizeof(uint32_t),
97 TRY(otp_ctrl_testutils_dai_read32(
103 uint32_t ast_cfg_data[kFlashInfoAstCalibrationDataSizeIn32BitWords] = {0};
104 TRY(manuf_flash_info_field_read(
105 &flash_ctrl_state, kFlashInfoFieldAstCalibrationData, ast_cfg_data,
106 kFlashInfoAstCalibrationDataSizeIn32BitWords));
107 for (
size_t i = 0; i < kFlashInfoAstCalibrationDataSizeIn32BitWords; ++i) {
108 TRY_CHECK(ast_cfg_data[i] == UINT32_MAX);
117 static void sw_reset(
void) {
118 rstmgr_testutils_reason_clear();
124 CHECK_STATUS_OK(peripheral_handles_init());
127 if (!status_ok(manuf_individualize_device_creator_sw_cfg_check(&otp_ctrl))) {
128 CHECK_STATUS_OK(init_flash_info_page0());
129 CHECK_STATUS_OK(manuf_individualize_device_creator_sw_cfg(
130 &otp_ctrl, &flash_ctrl_state));
131 CHECK_STATUS_OK(manuf_individualize_device_field_cfg(
133 OTP_CTRL_PARAM_CREATOR_SW_CFG_FLASH_DATA_DEFAULT_CFG_OFFSET));
134 CHECK_STATUS_OK(manuf_individualize_device_field_cfg(
135 &otp_ctrl, OTP_CTRL_PARAM_CREATOR_SW_CFG_MANUF_STATE_OFFSET));
136 CHECK_STATUS_OK(manuf_individualize_device_field_cfg(
137 &otp_ctrl, OTP_CTRL_PARAM_CREATOR_SW_CFG_IMMUTABLE_ROM_EXT_EN_OFFSET));
138 CHECK_STATUS_OK(manuf_individualize_device_creator_sw_cfg_lock(&otp_ctrl));
139 CHECK_STATUS_OK(check_otp_ast_cfg());
140 LOG_INFO(
"Provisioned and locked CREATOR_SW_CFG OTP partition.");
147 bool perform_reset =
false;
150 if (!status_ok(manuf_individualize_device_owner_sw_cfg_check(&otp_ctrl))) {
151 CHECK_STATUS_OK(manuf_individualize_device_owner_sw_cfg(&otp_ctrl));
152 CHECK_STATUS_OK(manuf_individualize_device_field_cfg(
153 &otp_ctrl, OTP_CTRL_PARAM_OWNER_SW_CFG_ROM_BOOTSTRAP_DIS_OFFSET));
154 CHECK_STATUS_OK(manuf_individualize_device_owner_sw_cfg_lock(&otp_ctrl));
155 LOG_INFO(
"Provisioned and locked OWNER_SW_CFG OTP partition.");
156 perform_reset |=
true;
160 if (!status_ok(manuf_individualize_device_rot_creator_auth_codesign_check(
163 manuf_individualize_device_rot_creator_auth_codesign(&otp_ctrl));
164 LOG_INFO(
"Provisioned and locked ROT_CREATOR_AUTH_CODESIGN OTP partition.");
165 perform_reset |=
true;
170 manuf_individualize_device_rot_creator_auth_state_check(&otp_ctrl))) {
172 manuf_individualize_device_rot_creator_auth_state(&otp_ctrl));
173 LOG_INFO(
"Provisioned and locked ROT_CREATOR_AUTH_STATE OTP partition.");
174 perform_reset |=
true;
183 if (status_ok(manuf_individualize_device_creator_sw_cfg_check(&otp_ctrl)) &&
184 status_ok(manuf_individualize_device_owner_sw_cfg_check(&otp_ctrl)) &&
185 status_ok(manuf_individualize_device_rot_creator_auth_codesign_check(
188 manuf_individualize_device_rot_creator_auth_state_check(&otp_ctrl))) {