5 #include "sw/device/lib/base/status.h"
10 #include "sw/device/lib/testing/json/provisioning_data.h"
11 #include "sw/device/lib/testing/rstmgr_testutils.h"
12 #include "sw/device/lib/testing/test_framework/check.h"
14 #include "sw/device/lib/testing/test_framework/ujson_ottf.h"
15 #include "sw/device/lib/ujson/ujson.h"
16 #include "sw/device/silicon_creator/lib/attestation.h"
17 #include "sw/device/silicon_creator/lib/drivers/retention_sram.h"
18 #include "sw/device/silicon_creator/manuf/lib/flash_info_fields.h"
19 #include "sw/device/silicon_creator/manuf/lib/personalize.h"
23 OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control =
true);
31 static dif_lc_ctrl_t lc_ctrl;
32 static dif_otp_ctrl_t otp_ctrl;
33 static dif_rstmgr_t rstmgr;
38 static status_t peripheral_handles_init(
void) {
44 TRY(dif_otp_ctrl_init(
54 static void sw_reset(
void) {
55 rstmgr_testutils_reason_clear();
60 static status_t check_array_non_zero(uint32_t *array,
size_t num_words) {
61 for (
size_t i = 0; i < num_words; ++i) {
70 ujson_t uj = ujson_ottf_console();
71 CHECK_STATUS_OK(peripheral_handles_init());
80 LOG_INFO(
"Now in RMA state, spinning for host to connect over JTAG.");
90 if (!status_ok(manuf_personalize_device_secret1_check(&otp_ctrl))) {
91 LOG_INFO(
"Provisioning OTP SECRET1 ...");
92 CHECK_STATUS_OK(manuf_personalize_device_secret1(&lc_ctrl, &otp_ctrl));
97 LOG_INFO(
"Provisioning OTP SECRET1 Done ...");
102 if (!status_ok(manuf_personalize_device_secrets_check(&otp_ctrl))) {
103 lc_token_hash_t token_hash;
106 LOG_INFO(
"Waiting For RMA Unlock Token Hash ...");
109 UJSON_WITH_CRC(ujson_deserialize_lc_token_hash_t, &uj, &token_hash));
112 CHECK_STATUS_OK(manuf_personalize_device_secrets(&flash_state, &lc_ctrl,
113 &otp_ctrl, &token_hash));
114 LOG_INFO(
"Provisioning flash info asymmetric keygen seeds ...");
115 CHECK_STATUS_OK(manuf_personalize_flash_asymm_key_seed(
116 &flash_state, kFlashInfoFieldUdsAttestationKeySeed,
117 kAttestationSeedWords));
118 CHECK_STATUS_OK(manuf_personalize_flash_asymm_key_seed(
119 &flash_state, kFlashInfoFieldCdi0AttestationKeySeed,
120 kAttestationSeedWords));
121 CHECK_STATUS_OK(manuf_personalize_flash_asymm_key_seed(
122 &flash_state, kFlashInfoFieldCdi1AttestationKeySeed,
123 kAttestationSeedWords));
126 uint32_t uds_attestation_key_seed[kAttestationSeedWords];
127 uint32_t cdi_0_attestation_key_seed[kAttestationSeedWords];
128 uint32_t cdi_1_attestation_key_seed[kAttestationSeedWords];
129 CHECK_STATUS_OK(manuf_flash_info_field_read(
130 &flash_state, kFlashInfoFieldUdsAttestationKeySeed,
131 uds_attestation_key_seed, kAttestationSeedWords));
132 CHECK_STATUS_OK(check_array_non_zero(uds_attestation_key_seed,
133 kAttestationSeedWords));
134 CHECK_STATUS_OK(manuf_flash_info_field_read(
135 &flash_state, kFlashInfoFieldCdi0AttestationKeySeed,
136 cdi_0_attestation_key_seed, kAttestationSeedWords));
137 CHECK_STATUS_OK(check_array_non_zero(cdi_0_attestation_key_seed,
138 kAttestationSeedWords));
139 CHECK_STATUS_OK(manuf_flash_info_field_read(
140 &flash_state, kFlashInfoFieldCdi1AttestationKeySeed,
141 cdi_1_attestation_key_seed, kAttestationSeedWords));
142 CHECK_STATUS_OK(check_array_non_zero(cdi_1_attestation_key_seed,
143 kAttestationSeedWords));
145 "Finished provisioning OTP SECRET2 and keymgr flash info pages ...");
153 LOG_INFO(
"Spinning for host to connect over JTAG.");
156 LOG_FATAL(
"Unexpected reset reason: %08x", info);