Software APIs
individualize_sw_cfg.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_MANUF_LIB_INDIVIDUALIZE_SW_CFG_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_MANUF_LIB_INDIVIDUALIZE_SW_CFG_H_
7 
8 #include "sw/device/lib/base/status.h"
11 #include "sw/device/silicon_creator/manuf/lib/otp_img_types.h"
12 
13 /**
14  * OTP Creator Software Configuration Partition.
15  */
16 extern const size_t kOtpKvCreatorSwCfgSize;
17 extern const otp_kv_t kOtpKvCreatorSwCfg[];
18 extern const uint32_t kCreatorSwCfgFlashDataDefaultCfgValue;
19 extern const uint32_t kCreatorSwCfgManufStateValue;
20 extern const uint32_t kCreatorSwCfgImmutableRomExtEnValue;
21 
22 /**
23  * OTP Owner Software Configuration Partition.
24  */
25 extern const size_t kOtpKvOwnerSwCfgSize;
26 extern const otp_kv_t kOtpKvOwnerSwCfg[];
27 extern const uint32_t kOwnerSwCfgRomBootstrapDisValue;
28 
29 /**
30  * OTP RoT Creator Auth Codesign Partition.
31  */
32 extern const size_t kOtpKvRotCreatorAuthCodesignSize;
33 extern const otp_kv_t kOtpKvRotCreatorAuthCodesign[];
34 
35 /**
36  * OTP RoT Creator Auth State Partition.
37  */
38 extern const size_t kOtpKvRotCreatorAuthStateSize;
39 extern const otp_kv_t kOtpKvRotCreatorAuthState[];
40 
41 /**
42  * Configures the CREATOR_SW_CFG OTP partition.
43  *
44  * The CREATOR_SW_CFG partition contains various settings for the ROM, e.g.,:
45  * - ROM execution enablement
46  * - ROM key enable/disable flags
47  * - AST and entropy complex configuration
48  * - Various ROM feature knobs
49  *
50  * Note:
51  * - The operation will fail if there are any pre-programmed words not equal
52  * to the expected test values.
53  * - This operation will explicitly NOT provision the FLASH_DATA_DEFAULT_CFG
54  * and MANUF_STATE fields in the CREATOR_SW_CFG partition. These fields must
55  * be explicitly configured after all other provisioning operations are done,
56  * but before the partition is locked, and the final transport image is loaded.
57  * - This function will NOT lock the partition either. This must be done after
58  * provisioning the final FLASH_DATA_DEFAULT_CFG and MANUF_STATE fields
59  * mentioned above.
60  * - The partition must be configured and the chip reset, before the ROM can be
61  * booted, thus enabling bootstrap.
62  *
63  * @param otp_ctrl OTP controller instance.
64  * @param flash_state Flash controller instance.
65  * @return OK_STATUS if the CREATOR_SW_CFG partition was provisioned.
66  */
68 status_t manuf_individualize_device_creator_sw_cfg(
69  const dif_otp_ctrl_t *otp_ctrl, dif_flash_ctrl_state_t *flash_state);
70 
71 /**
72  * This must be called before both
73  * `manuf_individualize_device_creator_sw_cfg_lock()` and
74  * `manuf_individualize_device_owner_sw_cfg_lock()` are called. The operation
75  * will fail if there are any pre-programmed words not equal to the expected
76  * test values.
77  *
78  */
80 status_t manuf_individualize_device_field_cfg(const dif_otp_ctrl_t *otp_ctrl,
81  uint32_t field_offset);
82 
83 /**
84  * Checks the FLASH_DATA_DEFAULT_CFG field in the CREATOR_SW_CFG OTP
85  * partition.
86  *
87  * @param otp_ctrl OTP controller instance.
88  * @return OK_STATUS if the FLASH_DATA_DEFAULT_CFG field is provisioned.
89  */
91 status_t manuf_individualize_device_flash_data_default_cfg_check(
92  const dif_otp_ctrl_t *otp_ctrl);
93 
94 /**
95  * Locks the CREATOR_SW_CFG OTP partition.
96  *
97  * This must be called after `manuf_individualize_device_field_cfg()`
98  * has been called.
99  *
100  * @param otp_ctrl OTP controller instance.
101  * @return OK_STATUS if the CREATOR_SW_CFG partition was locked.
102  */
104 status_t manuf_individualize_device_creator_sw_cfg_lock(
105  const dif_otp_ctrl_t *otp_ctrl);
106 
107 /**
108  * Checks the CREATOR_SW_CFG OTP partition end state.
109  *
110  * @param otp_ctrl OTP controller interface.
111  * @return OK_STATUS if the CREATOR_SW_CFG partition is locked.
112  */
113 status_t manuf_individualize_device_creator_sw_cfg_check(
114  const dif_otp_ctrl_t *otp_ctrl);
115 
116 /**
117  * Configures the OWNER_SW_CFG OTP partition.
118  *
119  * The OWNER_SW_CFG partition contains additional settings for the ROM and
120  * ROM_EXT, for example:
121  * - Alert handler configuration
122  * - ROM_EXT bootstrap enablement
123  *
124  * Note:
125  * - The operation will fail if there are any pre-programmed words not equal to
126  * the expected test values.
127  * - This operation will explicitly NOT provision the ROM_BOOTSTRAP_DIS
128  * field in the OWNER_SW_CFG partition. This field must be explicitly
129  * configured after all other provisioning operations are done, but before the
130  * partition is locked, and the final transport image is loaded.
131  *
132  * @param otp_ctrl OTP controller instance.
133  * @return OK_STATUS if the OWNER_SW_CFG partition is locked.
134  */
136 status_t manuf_individualize_device_owner_sw_cfg(
137  const dif_otp_ctrl_t *otp_ctrl);
138 
139 /**
140  * Locks the OWNER_SW_CFG OTP partition.
141  *
142  * This must be called after `manuf_individualize_device_field_cfg()`
143  * has been called.
144  *
145  * @param otp_ctrl OTP controller instance.
146  * @return OK_STATUS if the OWNER_SW_CFG partition was locked.
147  */
149 status_t manuf_individualize_device_owner_sw_cfg_lock(
150  const dif_otp_ctrl_t *otp_ctrl);
151 
152 /**
153  * Checks the OWNER_SW_CFG OTP partition end state.
154  *
155  * @param otp_ctrl OTP controller interface.
156  * @return OK_STATUS if the OWNER_SW_CFG partition is locked.
157  */
158 status_t manuf_individualize_device_owner_sw_cfg_check(
159  const dif_otp_ctrl_t *otp_ctrl);
160 
161 /**
162  * Overwrites unprovisioned fields with their expected final values in a buffer
163  * representing the provided partition.
164  *
165  * @param partition Target OTP partition.
166  * @param[out] buffer A buffer containing the entire target OTP partition.
167  * @return OK_STATUS if the expected partition values are successfully written
168  * to the `buffer`.
169  */
170 status_t manuf_individualize_device_partition_expected_read(
171  dif_otp_ctrl_partition_t partition, uint8_t *buffer);
172 
173 /**
174  * Configures and locks the ROT_CREATOR_AUTH_CODESIGN OTP partition.
175  *
176  * The ROT_CREATOR_AUTH_CODESIGN partition contains the first stage
177  * (ROM->ROM_EXT) secure boot public keys.
178  *
179  * @param otp_ctrl OTP controller instance.
180  * @return OK_STATUS if the ROT_CREATOR_AUTH_CODESIGN partition has been locked.
181  */
183 status_t manuf_individualize_device_rot_creator_auth_codesign(
184  const dif_otp_ctrl_t *otp_ctrl);
185 
186 /**
187  * Checks the ROT_CREATOR_AUTH_CODESIGN OTP partition end state.
188  *
189  * @param otp_ctrl OTP controller interface.
190  * @return OK_STATUS if the ROT_CREATOR_AUTH_CODESIGN partition is locked.
191  */
192 status_t manuf_individualize_device_rot_creator_auth_codesign_check(
193  const dif_otp_ctrl_t *otp_ctrl);
194 
195 /**
196  * Configures and locks the ROT_CREATOR_AUTH_STATE OTP partition.
197  *
198  * The ROT_CREATOR_AUTH_STATE partition contains the first stage
199  * (ROM->ROM_EXT) secure boot public key validity states.
200  *
201  * @param otp_ctrl OTP controller instance.
202  * @return OK_STATUS if the ROT_CREATOR_AUTH_STATE partition has been locked.
203  */
205 status_t manuf_individualize_device_rot_creator_auth_state(
206  const dif_otp_ctrl_t *otp_ctrl);
207 
208 /**
209  * Checks the ROT_CREATOR_AUTH_STATE OTP partition end state.
210  *
211  * @param otp_ctrl OTP controller interface.
212  * @return OK_STATUS if the ROT_CREATOR_AUTH_STATE partition is locked.
213  */
214 status_t manuf_individualize_device_rot_creator_auth_state_check(
215  const dif_otp_ctrl_t *otp_ctrl);
216 
217 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_MANUF_LIB_INDIVIDUALIZE_SW_CFG_H_