1 /** 2 * @file hi_efuse.h 3 * 4 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /** 19 * @defgroup iot_efuse Efuse 20 * @ingroup drivers 21 */ 22 #ifndef __HI_EFUSE_H__ 23 #define __HI_EFUSE_H__ 24 #include <hi_types_base.h> 25 26 #ifdef __cplusplus 27 #if __cplusplus 28 extern "C" { 29 #endif 30 #endif /* __cplusplus */ 31 32 typedef enum { 33 HI_EFUSE_CHIP_RW_ID = 0, 34 HI_EFUSE_DIE_RW_ID = 1, 35 HI_EFUSE_PMU_FUSE1_RW_ID = 2, 36 HI_EFUSE_PMU_FUSE2_RW_ID = 3, 37 HI_EFUSE_FLASH_ENCPY_CNT3_RW_ID = 4, 38 HI_EFUSE_FLASH_ENCPY_CNT4_RW_ID = 5, 39 HI_EFUSE_FLASH_ENCPY_CNT5_RW_ID = 6, 40 HI_EFUSE_DSLEEP_FLAG_RW_ID = 7, 41 HI_EFUSE_ROOT_PUBKEY_RW_ID = 8, 42 HI_EFUSE_ROOT_KEY_WO_ID = 9, 43 HI_EFUSE_CUSTOMER_RSVD0_RW_ID = 10, 44 HI_EFUSE_SUBKEY_CAT_RW_ID = 11, 45 HI_EFUSE_ENCRYPT_FLAG_RW_ID = 12, 46 HI_EFUSE_SUBKEY_RSIM_RW_ID = 13, 47 HI_EFUSE_START_TYPE_RW_ID = 14, 48 HI_EFUSE_JTM_RW_ID = 15, 49 HI_EFUSE_UTM0_RW_ID = 16, 50 HI_EFUSE_UTM1_RW_ID = 17, 51 HI_EFUSE_UTM2_RW_ID = 18, 52 HI_EFUSE_SDC_RW_ID = 19, 53 HI_EFUSE_RSVD0_RW_ID = 20, 54 HI_EFUSE_KDF2ECC_HUK_DISABLE_RW_ID = 21, 55 HI_EFUSE_SSS_CORNER_RW_ID = 22, 56 HI_EFUSE_UART_HALT_INTERVAL_RW_ID = 23, 57 HI_EFUSE_TSENSOR_RIM_RW_ID = 24, 58 HI_EFUSE_CHIP_BK_RW_ID = 25, 59 HI_EFUSE_IPV4_MAC_ADDR_RW_ID = 26, 60 HI_EFUSE_IPV6_MAC_ADDR_RW_ID = 27, 61 HI_EFUSE_PG2GCCKA0_TRIM0_RW_ID = 28, 62 HI_EFUSE_PG2GCCKA1_TRIM0_RW_ID = 29, 63 HI_EFUSE_NVRAM_PA2GA0_TRIM0_RW_ID = 30, 64 HI_EFUSE_NVRAM_PA2GA1_TRIM0_RW_ID = 31, 65 HI_EFUSE_PG2GCCKA0_TRIM1_RW_ID = 32, 66 HI_EFUSE_PG2GCCKA1_TRIM1_RW_ID = 33, 67 HI_EFUSE_NVRAM_PA2GA0_TRIM1_RW_ID = 34, 68 HI_EFUSE_NVRAM_PA2GA1_TRIM1_RW_ID = 35, 69 HI_EFUSE_PG2GCCKA0_TRIM2_RW_ID = 36, 70 HI_EFUSE_PG2GCCKA1_TRIM2_RW_ID = 37, 71 HI_EFUSE_NVRAM_PA2GA0_TRIM2_RW_ID = 38, 72 HI_EFUSE_NVRAM_PA2GA1_TRIM2_RW_ID = 39, 73 HI_EFUSE_TEE_BOOT_VER_RW_ID = 40, 74 HI_EFUSE_TEE_KERNEL_VER_RW_ID = 41, 75 HI_EFUSE_TEE_SALT_RW_ID = 42, 76 HI_EFUSE_FLASH_ENCPY_CNT0_RW_ID = 43, 77 HI_EFUSE_FLASH_ENCPY_CNT1_RW_ID = 44, 78 HI_EFUSE_FLASH_ENCPY_CNT2_RW_ID = 45, 79 HI_EFUSE_FLASH_ENCPY_CFG_RW_ID = 46, 80 HI_EFUSE_FLASH_SCRAMBLE_EN_RW_ID = 47, 81 HI_EFUSE_USER_FLASH_IND_RW_ID = 48, 82 HI_EFUSE_RF_PDBUFFER_GCAL_RW_ID = 49, 83 HI_EFUSE_CUSTOMER_RSVD1_RW_ID = 50, 84 HI_EFUSE_DIE_2_RW_ID = 51, 85 HI_EFUSE_SEC_BOOT_RW_ID = 52, 86 HI_EFUSE_IDX_MAX, 87 } hi_efuse_idx; 88 89 typedef enum { 90 HI_EFUSE_LOCK_CHIP_ID = 0, 91 HI_EFUSE_LOCK_DIE_ID = 1, 92 HI_EFUSE_LOCK_PMU_FUSE1_FUSE2_START_TYPE_TSENSOR_ID = 2, 93 HI_EFUSE_LOCK_ROOT_PUBKEY_ID = 3, 94 HI_EFUSE_LOCK_ROOT_KEY_ID = 4, 95 HI_EFUSE_LOCK_CUSTOMER_RSVD0_ID = 5, 96 HI_EFUSE_LOCK_SUBKEY_CAT_ID = 6, 97 HI_EFUSE_LOCK_ENCRYPT_RSIM_ID = 7, 98 HI_EFUSE_LOCK_JTM_ID = 8, 99 HI_EFUSE_LOCK_UTM0_ID = 9, 100 HI_EFUSE_LOCK_UTM1_ID = 10, 101 HI_EFUSE_LOCK_UTM2_ID = 11, 102 HI_EFUSE_LOCK_SDC_ID = 12, 103 HI_EFUSE_LOCK_RSVD0_ID = 13, 104 HI_EFUSE_LOCK_SSS_CORNER_ID = 14, 105 HI_EFUSE_LOCK_UART_HALT_INTERVAL_ID = 15, 106 HI_EFUSE_LOCK_CHIP_BK_ID = 16, 107 HI_EFUSE_LOCK_IPV4_IPV6_MAC_ADDR_ID = 17, 108 HI_EFUSE_LOCK_PG2GCCKA0_PG2GCCKA1_TRIM0_ID = 18, 109 HI_EFUSE_LOCK_NVRAM_PA2GA0_PA2GA1_TRIM0_ID = 19, 110 HI_EFUSE_LOCK_PG2GCCKA0_PG2GCCKA1_TRIM1_ID = 20, 111 HI_EFUSE_LOCK_NVRAM_PA2GA0_PA2GA1_TRIM1_ID = 21, 112 HI_EFUSE_LOCK_PG2GCCKA0_PG2GCCKA1_TRIM2_ID = 22, 113 HI_EFUSE_LOCK_NVRAM_PA2GA0_PA2GA1_TRIM2_ID = 23, 114 HI_EFUSE_LOCK_TEE_BOOT_VER_ID = 24, 115 HI_EFUSE_LOCK_TEE_KERNEL_VER_ID = 25, 116 HI_EFUSE_LOCK_TEE_SALT_ID = 26, 117 HI_EFUSE_LOCK_FLASH_ENCPY_CNT0_ID = 27, 118 HI_EFUSE_LOCK_FLASH_ENCPY_CNT1_ID = 28, 119 HI_EFUSE_LOCK_FLASH_ENCPY_CNT2_ID = 29, 120 HI_EFUSE_LOCK_FLASH_ENCPY_CFG_ID = 30, 121 HI_EFUSE_LOCK_FLASH_SCRAMBLE_EN_FLASH_IND_ID = 31, 122 HI_EFUSE_LOCK_RF_PDBUFFER_GCAL_ID = 32, 123 HI_EFUSE_LOCK_CUSTOMER_RSVD1_ID = 33, 124 HI_EFUSE_LOCK_DIE_2_ID = 34, 125 HI_EFUSE_LOCK_KDF2ECC_HUK_DISABLE_ID = 35, 126 HI_EFUSE_LOCK_FLASH_ENCPY_CNT3_ID = 36, 127 HI_EFUSE_LOCK_FLASH_ENCPY_CNT4_ID = 37, 128 HI_EFUSE_LOCK_FLASH_ENCPY_CNT5_ID = 38, 129 HI_EFUSE_LOCK_SEC_BOOT_ID = 39, 130 HI_EFUSE_LOCK_DSLEEP_FLAG_ID = 40, 131 HI_EFUSE_LOCK_MAX, 132 } hi_efuse_lock_id; 133 134 /** 135 * @ingroup iot_efuse 136 * @brief Obtains the preset length of each eFUSE area.CNcomment:根据EFUSE ID号获取该EFUSE数据长度。CNend 137 * 138 * @par 描述: 139 * Obtains the preset length of each eFUSE area.CNcomment:获取EFUSE数据长度。CNend 140 * 141 * @attention None 142 * @param efuse_id [IN] type #hi_efuse_idx,EFUSE ID 143 * 144 * @retval #HI_ERR_EFUSE_INVALIDATE_ID Invalid ID.CNcomment: 无效EFUSE ID。CNend 145 * @retval #Other Length of EFUSE data.(Unit bytes).CNcomment: EFUSE数据长度(单位为bit)。CNend 146 * @par 依赖: 147 * @li hi_efuse.h:Describes the encryption and decryption APIs. 148 CNcomment:文件用于描述efuse字段操作相关接口。CNend 149 * @see hi_efuse_get_id_size。 150 */ 151 hi_u32 hi_efuse_get_id_size(hi_efuse_idx efuse_id); 152 153 /** 154 * @ingroup iot_efuse 155 * @brief Reads the eFUSE.CNcomment:EFUSE读取数据。CNend 156 * 157 * @par 描述: 158 * Reads the eFUSE.CNcomment:从EFUSE中读取数据。CNend 159 * 160 * @attention Ensure that the value of (data_len*8) is not less than efuse_id and the length of the efuse field is 8bit 161 * aligned.CNcomment:需保证(data_len*8)不小于efuse_id对应efuse字段的长度向上8bit对齐。CNend 162 * 163 * @param efuse_id [IN] type #hi_efuse_idx,EFUSE ID 164 * @param data [OUT] type #hi_u8*,Address for saving the read data.CNcomment:读到的数据放到该地址。CNend 165 * @param data_len [IN] type #hi_u8 Space allocated to data, in bytes.CNcomment:给data分配的空间,单位byte。CNend 166 * 167 * @retval #0 Success 168 * @retval #Other Failure. For details, see hi_errno.h. 169 * @par 依赖: 170 * @li hi_efuse.h:Describes the encryption and decryption APIs. 171 CNcomment:文件用于描述efuse字段操作相关接口。CNend 172 * @see hi_efuse_write。 173 */ 174 hi_u32 hi_efuse_read(hi_efuse_idx efuse_id, hi_u8 *data, hi_u8 data_len); 175 176 /** 177 * @ingroup iot_efuse 178 * @brief Writes the eFUSE.CNcomment:写数据到EFUSE。CNend 179 * 180 * @par 描述: 181 * Writes the eFUSE.CNcomment:写数据到EFUSE。CNend 182 * 183 * @attention None 184 * @param efuse_id [IN] type #hi_efuse_idx,EFUSE ID 185 * @param data [IN] type #const hi_u8*,Data to be written to the eFUSE.CNcomment:写该数据到EFUSE中。CNend 186 * 187 * @retval #0 Success 188 * @retval #Other Failure. For details, see hi_errno.h. 189 * @par 依赖: 190 * @li hi_efuse.h:Describes the encryption and decryption APIs. 191 CNcomment:文件用于描述efuse字段操作相关接口。CNend 192 * @see hi_efuse_read。 193 */ 194 hi_u32 hi_efuse_write(hi_efuse_idx efuse_id, const hi_u8 *data); 195 196 /** 197 * @ingroup iot_efuse 198 * @brief Locks an area in the eFUSE. After the lock takes effect upon reboot, the area cannot be written. 199 CNcomment:加锁EFUSE中的某个区域,加锁后重启单板生效,该区域无法再写入。CNend 200 * 201 * @par 描述: 202 * Locks an area in the eFUSE. After the lock takes effect upon reboot, the area cannot be written. 203 CNcomment:加锁EFUSE中的某个区域,加锁后重启单板生效,该区域无法再写入。CNend 204 * 205 * @attention None 206 * @param lock_id [IN] type #hi_efuse_lock_id,eFUSE ID to be locked.CNcomment:待加锁的EFUSE ID项。CNend 207 * 208 * @retval #0 Success 209 * @retval #Other Failure. For details, see hi_errno.h. 210 * @par 依赖: 211 * @li hi_efuse.h:Describes the encryption and decryption APIs. 212 CNcomment:文件用于描述efuse字段操作相关接口。CNend 213 * @see hi_efuse_write。 214 */ 215 hi_u32 hi_efuse_lock(hi_efuse_lock_id lock_id); 216 217 /** 218 * @ingroup iot_efuse 219 * @brief Obtains the lock status of the eFUSE and queries which areas are locked. 220 CNcomment:获取EFUSE的锁状态,查询哪些区域已锁定。CNend 221 * 222 * @par 描述: 223 * Obtains the lock status of the eFUSE and queries which areas are locked. 224 CNcomment:获取EFUSE的锁状态,查询哪些区域已锁定。CNend 225 * 226 * @attention None 227 * @param lock_stat [OUT] type #hi_u64*,Lock status of the eFUSE.CNcomment:获取EFUSE的锁状态。CNend 228 * 229 * @retval #0 Success 230 * @retval #Other Failure. For details, see hi_errno.h. 231 * @par 依赖: 232 * @li hi_efuse.h:Describes the encryption and decryption APIs. 233 CNcomment:文件用于描述efuse字段操作相关接口。CNend 234 * @see hi_efuse_write。 235 */ 236 hi_u32 hi_efuse_get_lockstat(hi_u64 *lock_stat); 237 238 /** 239 * @ingroup iot_efuse 240 * @brief Reads the user eFUSE.CNcomment:EFUSE用户读取数据。CNend 241 * 242 * @par 描述: 243 * Reads a reserved area in the eFUSE.CNcomment:用户从EFUSE中读取数据。CNend 244 * 245 * @attention None 246 * @param start_bit [IN] type #hi_u16,Start bit. The address must be 8-bit aligned. 247 CNcomment:起始bit位,该地址必须8bit对齐。CNend 248 * @param size [IN] type #hi_u16,Number of bits to be read. If the input is not 8-bit aligned, 249 * the function performs 8-bit alignment internally. The user needs to process the read data before using it. 250 CNcomment:待读取的bit位数,如果输入不是8bit对齐则函数内部会处理为8bit对齐,用户读取数据后需处理后使用。CNend 251 * @param key_data [OUT] type #hi_u8*,Address for saving the read data. 252 CNcommnet:读到的数据放到该地址。CNend 253 * 254 * @retval #0 Success 255 * @retval #Other Failure. For details, see hi_errno.h. 256 * @par 依赖: 257 * @li hi_efuse.h:Describes the encryption and decryption APIs. 258 CNcomment:文件用于描述efuse字段操作相关接口。CNend 259 * @see hi_efuse_usr_write。 260 */ 261 hi_u32 hi_efuse_usr_read(hi_u16 start_bit, hi_u16 size, hi_u8 *key_data); 262 263 /** 264 * @ingroup iot_efuse 265 * @brief Writes data to reserved area of the eFUSE.CNcomment:EFUSE用户区写入数据。CNend 266 * 267 * @par 描述: 268 * Writes data to reserved area of the eFUSE.CNcomment:用户往EFUSE写入数据。CNend 269 * 270 * @attention Generally, this API is used to write a reserved area. To write other pre-allocated areas, 271 * should check the design spec to avoid conflict.CNcomment:支持用户写入任意地址数据, 272 建议用户使用用户预留区,其他区域的写入需要结合方案文档评估是否有冲突。CNend 273 * 274 * @param start_bit [IN] type #hi_u16,Start bit.CNcomment:起始bit位。CNend 275 * @param size [IN] type #hi_u16,Number of bits to be written. 1-to-256-bit write is supported. 276 CNcomment:待写入bit数,支持单bit写入,最大值为256bit数。CNend 277 * @param key_data [IN] type #const hi_u8*,Address for the data to be written. The maximum length is 32 bytes. 278 CNcomment:待写入的数据放到该地址,最长为32byte。CNend 279 * 280 * @retval #0 Success 281 * @retval #Other Failure. For details, see hi_errno.h. 282 * @par 依赖: 283 * @li hi_efuse.h:Describes the encryption and decryption APIs. 284 CNcomment:文件用于描述efuse字段操作相关接口。CNend 285 * @see hi_efuse_usr_read。 286 */ 287 hi_u32 hi_efuse_usr_write(hi_u16 start_bit, hi_u16 size, const hi_u8 *key_data); 288 289 #ifdef __cplusplus 290 #if __cplusplus 291 } 292 #endif 293 #endif /* __cplusplus */ 294 295 #endif /* __HI_EFUSE_H__ */ 296