1 /* 2 * @file hi_flashboot.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 /** @defgroup iot_flashboot Flash Boot */ 19 #ifndef _HI_FLASHBOOT_H_ 20 #define _HI_FLASHBOOT_H_ 21 22 #include <hi_types.h> 23 #include <hi_boot_rom.h> 24 25 /** @defgroup iot_nv NV Management APIs 26 * @ingroup iot_flashboot 27 */ 28 /** 29 * @ingroup iot_nv 30 * Maximum length of an NV item (unit: byte). CNcomment:NV项最大长度(单位:byte)。CNend 31 */ 32 #define HNV_ITEM_MAXLEN (256 - 4) 33 34 /** 35 * @ingroup iot_nv 36 */ 37 #define PRODUCT_CFG_NV_REG_NUM_MAX 20 38 39 /** 40 * @ingroup iot_nv 41 */ 42 #define HI_FNV_DEFAULT_ADDR 0x8000 43 44 /** 45 * @ingroup iot_nv 46 */ 47 #define HI_NV_DEFAULT_TOTAL_SIZE 0x2000 48 49 /** 50 * @ingroup iot_nv 51 */ 52 #define HI_NV_DEFAULT_BLOCK_SIZE 0x1000 53 54 /** 55 * @ingroup iot_nv 56 * 57 * Factory NV area user area end ID. CNcomment:工厂区NV结束ID。CNend 58 */ 59 #define HI_NV_FACTORY_USR_ID_END 0x20 60 61 /** 62 * @ingroup iot_nv 63 */ 64 #define HI_NV_FTM_FLASH_PARTIRION_TABLE_ID 0x02 65 66 /** 67 * @ingroup iot_nv 68 * @brief Initializes NV management in the factory partition.CNcomment:工厂区NV初始化。CNend 69 * 70 * @par 描述: 71 * Initializes NV management in the factory partition.CNcomment: 工厂区NV管理初始化。CNend 72 * 73 * @attention The parameters cannot be set randomly and must match the product delivery plan. 74 CNcomment:参数不能随意配置,需要与产品出厂规划匹配。CNend 75 * @param addr [IN] type #hi_u32,Start address of the NV factory partition in the flash. The address is planned by 76 * the factory and set by the boot macro #FACTORY_NV_ADDR. 77 CNcomment:设置工厂区NV FLASH首地址,由出厂规划,boot宏定义FACTORY_NV_ADDR 统一设置。CNend 78 * @param total_size [IN] type #hi_u32,total size of factory NV. 79 CNcomment:工厂区NV的总大小。CNend 80 * @param block_size [IN] type #hi_u32,block size of factory NV. 81 CNcomment:工厂区NV的块大小。CNend 82 * 83 * @retval #0 Success. 84 * @retval #Other Failure. For details, see hi_errno.h. 85 * @par 依赖: 86 * @li hi_flashboot.h:Describes NV APIs.CNcomment:文件用于描述NV相关接口。CNend 87 * @see hi_factory_nv_write | hi_factory_nv_read。 88 */ 89 hi_u32 hi_factory_nv_init(hi_u32 addr, hi_u32 total_size, hi_u32 block_size); 90 91 /** 92 * @ingroup iot_nv 93 * @brief Sets the NV value in the factory partition. CNcomment:设置工厂区NV值。CNend 94 * 95 * @par 描述: 96 * Sets the NV value in the factory partition.CNcomment:设置工厂区NV值。CNend 97 * 98 * @attention None 99 * @param id [IN] type #hi_u8,NV item ID, ranging from #HI_NV_FACTORY_ID_START to #HI_NV_FACTORY_USR_ID_END. 100 CNcomment:NV项ID,范围从#HI_NV_FACTORY_ID_START到#HI_NV_FACTORY_USR_ID_END。CNend 101 * @param pdata [IN] type #hi_pvoid,NV item data.CNcomment:NV项数据。CNend 102 * @param len [IN] type #hi_u8,Length of an NV item (unit: byte). The maximum value is #HNV_ITEM_MAXLEN. 103 CNcomment:NV项长度(单位:byte),最大不允许超过HNV_ITEM_MAXLEN。CNend 104 * @param flag [IN] type #hi_u32,Reserve.CNcomment:保留参数。CNend 105 * 106 * @retval #0 Success. 107 * @retval #Other Failure. For details, see hi_errno.h. 108 * @par 依赖: 109 * @li hi_flashboot.h:Describes NV APIs.CNcomment:文件用于描述NV相关接口。CNend 110 * @see hi_factory_nv_read。 111 */ 112 hi_u32 hi_factory_nv_write(hi_u8 id, hi_pvoid pdata, hi_u8 len, hi_u32 flag); 113 114 /** 115 * @ingroup iot_nv 116 * @brief Reads the NV value in the factory partition.CNcomment:读取工厂区NV值。CNend 117 * 118 * @par 描述: 119 * Reads the NV value in the factory partition.读取工厂区NV值。CNend 120 * 121 * @attention None 122 * 123 * @param id [IN] type #hi_u8,NV item ID, ranging from #HI_NV_NORMAL_ID_START to #HI_NV_NORMAL_USR_ID_END. 124 CNcomment:NV项ID,范围从#HI_NV_NORMAL_ID_START到#HI_NV_NORMAL_USR_ID_END。CNend 125 * @param pdata [IN] type #hi_pvoid,NV item data.CNcomment:NV项数据。CNend 126 * @param len [IN] type #hi_u8,Length of an NV item (unit: byte). The maximum value is HNV_ITEM_MAXLEN. 127 CNcomment:NV项长度(单位:byte),最大不允许超过HNV_ITEM_MAXLEN。CNend 128 * @param flag [IN] type #hi_u32,Reserve.CNcomment:保留参数。CNend 129 * 130 * @retval #0 Success. 131 * @retval #Other Failure. For details, see hi_errno.h. 132 * @par 依赖: 133 * @li hi_flashboot.h:Describes NV APIs.CNcomment:文件用于描述NV相关接口。CNend 134 * @see hi_factory_nv_write。 135 */ 136 hi_u32 hi_factory_nv_read(hi_u8 id, hi_pvoid pdata, hi_u8 len, hi_u32 flag); 137 138 /** @defgroup iot_flash_partiton Partition Table APIs 139 * @ingroup iot_flashboot 140 */ 141 /** 142 * @ingroup iot_flash_partiton 143 * 144 * partition number. 145 */ 146 #define HI_FLASH_PARTITON_MAX 12 147 148 /** 149 * @ingroup iot_flash_partiton 150 * 151 * partition ID. 152 */ 153 typedef enum { 154 HI_FLASH_PARTITON_BOOT = 0, /**< Boot partition ID.CNcomment:BOOT分区ID.CNend */ 155 HI_FLASH_PARTITON_FACTORY_NV, /**< Factory NV working partition ID.CNcomment:工厂NV分区ID.CNend */ 156 HI_FLASH_PARTITON_NORMAL_NV, /**< NORMAL NV partition ID.CNcomment:非工厂NV分区ID.CNend */ 157 HI_FLASH_PARTITON_NORMAL_NV_BACKUP, /**< NORMAL backup NV partition ID.CNcomment:非工厂NV备份分区ID,必须和非工厂区连续.CNend */ 158 HI_FLASH_PARTITON_KERNEL_A, /**< Kernel A running partition ID.CNcomment:内核A区ID.CNend */ 159 HI_FLASH_PARTITON_KERNEL_B, /**< Kernel B runing partition ID.CNcomment:内核B区ID.CNend */ 160 HI_FLASH_PARTITON_HILINK, /**< HILINK partition ID.CNcomment:HILINK分区ID(未使用HILINK可不需要).CNend */ 161 HI_FLASH_PARTITON_FILE_SYSTEM, /**< File system partition ID.CNcomment:文件系统区ID.CNend */ 162 HI_FLASH_PARTITON_USR_RESERVE, /**< User Reserved partition.CNcomment:用户保留区ID.CNend */ 163 HI_FLASH_PARTITON_HILINK_PKI, /**< HiLink PKI partition.CNcomment: HILINK PKI证书ID(未使用HILINK可不需要). CNend */ 164 HI_FLASH_PARTITON_CRASH_INFO, /**< Crash log partition.CNcomment:死机存储区ID.CNend */ 165 HI_FLASH_PARTITON_BOOT_BACK, /**< Boot backup partition.CNcomment:备份boot区ID. CNend */ 166 } hi_flash_partition_table_id; 167 168 /** 169 * @ingroup iot_flash_partiton 170 * 171 * Flash partition management. CNcomment:Flash分区表项。CNend 172 */ 173 typedef struct { 174 hi_u32 addr : 24; /* Flash partition address. The value is 16 MB. If the address is in reverse order, 175 the value is the end low address. CNcomment:Flash分区地址,限制为16MB, 176 如果为倒序,存放为结束的低地址值 CNend */ 177 hi_u32 id : 7; /* Flash partition ID. CNcomment:Flash区ID.CNend */ 178 hi_u32 dir : 1; /* Flash area storage direction. 0:regular. 1: reversed.CNcomment:Flash区存放方向。 179 0:分区内容正序;1:倒序末地址 CNend */ 180 181 hi_u32 size : 24; /* Size of the parition(Unit:byte). CNcomment:Flash分区大小(单位:byte)CNend */ 182 hi_u32 reserve : 8; /* Reserved. CNcomment:保留区CNend */ 183 184 hi_u32 addition; /* Supplementary information about the flash partition, such as the address of the Ram. 185 CNcomment:Flash分区补充信息,如Ram对应地址等 CNend */ 186 } hi_flash_partition_info; 187 188 /** 189 * @ingroup iot_flash_partiton 190 * Flash partiton table. 191 */ 192 typedef struct { 193 hi_flash_partition_info table[HI_FLASH_PARTITON_MAX]; /**< Flash分区表项描述 */ 194 } hi_flash_partition_table; 195 196 /** 197 * @ingroup iot_flash_partiton 198 * @brief Initialize flash partition table. CNcomment:初始化Flash分区表。CNend 199 * 200 * @par 描述: 201 * Initialize flash partition table. CNcomment:初始化Flash分区表。CNend 202 * 203 * @attention None. 204 * @param None. 205 * 206 * @retval #HI_ERR_FAILURE Failure. 207 * @retval #HI_ERR_SUCCESS Success. 208 * @par 依赖: 209 * @li hi_flashboot.h:Describes FlashBoot APIs.CNcomment:文件用于描述Boot模块接口。CNend 210 * @see hi_get_partition_table。 211 */ 212 hi_u32 hi_flash_partition_init(hi_void); 213 214 /** 215 * @ingroup iot_flash_partiton 216 * @brief Get flash partition table. CNcomment:获取Flash分区表。CNend 217 * 218 * @par 描述: 219 * Get flash partition table. CNcomment:获取Flash分区表。CNend 220 * 221 * @attention None. 222 * @param None. 223 * 224 * @retval #HI_NULL Failure. 225 * @retval #Other Success. 226 * @par 依赖: 227 * @li hi_flashboot.h:Describes FlashBoot APIs.CNcomment:文件用于描述Boot模块接口。CNend 228 * @see hi_flash_partition_init。 229 */ 230 hi_flash_partition_table* hi_get_partition_table(hi_void); 231 232 /** @defgroup iot_efuse eFuse APIs 233 * @ingroup iot_flashboot 234 */ 235 /** 236 * @ingroup iot_efuse 237 * 238 * Efuse ID. 239 */ 240 typedef enum { 241 HI_EFUSE_CHIP_RW_ID = 0, 242 HI_EFUSE_DIE_RW_ID = 1, 243 HI_EFUSE_PMU_FUSE1_RW_ID = 2, 244 HI_EFUSE_PMU_FUSE2_RW_ID = 3, 245 HI_EFUSE_FLASH_ENCPY_CNT3_RW_ID = 4, 246 HI_EFUSE_FLASH_ENCPY_CNT4_RW_ID = 5, 247 HI_EFUSE_FLASH_ENCPY_CNT5_RW_ID = 6, 248 HI_EFUSE_DSLEEP_FLAG_RW_ID = 7, 249 HI_EFUSE_ROOT_PUBKEY_RW_ID = 8, 250 HI_EFUSE_ROOT_KEY_WO_ID = 9, 251 HI_EFUSE_CUSTOMER_RSVD0_RW_ID = 10, 252 HI_EFUSE_SUBKEY_CAT_RW_ID = 11, 253 HI_EFUSE_ENCRYPT_FLAG_RW_ID = 12, 254 HI_EFUSE_SUBKEY_RSIM_RW_ID = 13, 255 HI_EFUSE_START_TYPE_RW_ID = 14, 256 HI_EFUSE_JTM_RW_ID = 15, 257 HI_EFUSE_UTM0_RW_ID = 16, 258 HI_EFUSE_UTM1_RW_ID = 17, 259 HI_EFUSE_UTM2_RW_ID = 18, 260 HI_EFUSE_SDC_RW_ID = 19, 261 HI_EFUSE_RSVD0_RW_ID = 20, 262 HI_EFUSE_KDF2ECC_HUK_DISABLE_RW_ID = 21, 263 HI_EFUSE_SSS_CORNER_RW_ID = 22, 264 HI_EFUSE_UART_HALT_INTERVAL_RW_ID = 23, 265 HI_EFUSE_TSENSOR_RIM_RW_ID = 24, 266 HI_EFUSE_CHIP_BK_RW_ID = 25, 267 HI_EFUSE_IPV4_MAC_ADDR_RW_ID = 26, 268 HI_EFUSE_IPV6_MAC_ADDR_RW_ID = 27, 269 HI_EFUSE_PG2GCCKA0_TRIM0_RW_ID = 28, 270 HI_EFUSE_PG2GCCKA1_TRIM0_RW_ID = 29, 271 HI_EFUSE_NVRAM_PA2GA0_TRIM0_RW_ID = 30, 272 HI_EFUSE_NVRAM_PA2GA1_TRIM0_RW_ID = 31, 273 HI_EFUSE_PG2GCCKA0_TRIM1_RW_ID = 32, 274 HI_EFUSE_PG2GCCKA1_TRIM1_RW_ID = 33, 275 HI_EFUSE_NVRAM_PA2GA0_TRIM1_RW_ID = 34, 276 HI_EFUSE_NVRAM_PA2GA1_TRIM1_RW_ID = 35, 277 HI_EFUSE_PG2GCCKA0_TRIM2_RW_ID = 36, 278 HI_EFUSE_PG2GCCKA1_TRIM2_RW_ID = 37, 279 HI_EFUSE_NVRAM_PA2GA0_TRIM2_RW_ID = 38, 280 HI_EFUSE_NVRAM_PA2GA1_TRIM2_RW_ID = 39, 281 HI_EFUSE_TEE_BOOT_VER_RW_ID = 40, 282 HI_EFUSE_TEE_KERNEL_VER_RW_ID = 41, 283 HI_EFUSE_TEE_SALT_RW_ID = 42, 284 HI_EFUSE_FLASH_ENCPY_CNT0_RW_ID = 43, 285 HI_EFUSE_FLASH_ENCPY_CNT1_RW_ID = 44, 286 HI_EFUSE_FLASH_ENCPY_CNT2_RW_ID = 45, 287 HI_EFUSE_FLASH_ENCPY_CFG_RW_ID = 46, 288 HI_EFUSE_FLASH_SCRAMBLE_EN_RW_ID = 47, 289 HI_EFUSE_USER_FLASH_IND_RW_ID = 48, 290 HI_EFUSE_RF_PDBUFFER_GCAL_RW_ID = 49, 291 HI_EFUSE_CUSTOMER_RSVD1_RW_ID = 50, 292 HI_EFUSE_DIE_2_RW_ID = 51, 293 HI_EFUSE_SEC_BOOT_RW_ID = 52, 294 HI_EFUSE_IDX_MAX, 295 } hi_efuse_idx; 296 297 /** 298 * @ingroup iot_efuse 299 * 300 * Efuse Lock ID. 301 */ 302 typedef enum { 303 HI_EFUSE_LOCK_CHIP_ID = 0, 304 HI_EFUSE_LOCK_DIE_ID = 1, 305 HI_EFUSE_LOCK_PMU_FUSE1_FUSE2_START_TYPE_TSENSOR_ID = 2, 306 HI_EFUSE_LOCK_ROOT_PUBKEY_ID = 3, 307 HI_EFUSE_LOCK_ROOT_KEY_ID = 4, 308 HI_EFUSE_LOCK_CUSTOMER_RSVD0_ID = 5, 309 HI_EFUSE_LOCK_SUBKEY_CAT_ID = 6, 310 HI_EFUSE_LOCK_ENCRYPT_RSIM_ID = 7, 311 HI_EFUSE_LOCK_JTM_ID = 8, 312 HI_EFUSE_LOCK_UTM0_ID = 9, 313 HI_EFUSE_LOCK_UTM1_ID = 10, 314 HI_EFUSE_LOCK_UTM2_ID = 11, 315 HI_EFUSE_LOCK_SDC_ID = 12, 316 HI_EFUSE_LOCK_RSVD0_ID = 13, 317 HI_EFUSE_LOCK_SSS_CORNER_ID = 14, 318 HI_EFUSE_LOCK_UART_HALT_INTERVAL_ID = 15, 319 HI_EFUSE_LOCK_CHIP_BK_ID = 16, 320 HI_EFUSE_LOCK_IPV4_IPV6_MAC_ADDR_ID = 17, 321 HI_EFUSE_LOCK_PG2GCCKA0_PG2GCCKA1_TRIM0_ID = 18, 322 HI_EFUSE_LOCK_NVRAM_PA2GA0_PA2GA1_TRIM0_ID = 19, 323 HI_EFUSE_LOCK_PG2GCCKA0_PG2GCCKA1_TRIM1_ID = 20, 324 HI_EFUSE_LOCK_NVRAM_PA2GA0_PA2GA1_TRIM1_ID = 21, 325 HI_EFUSE_LOCK_PG2GCCKA0_PG2GCCKA1_TRIM2_ID = 22, 326 HI_EFUSE_LOCK_NVRAM_PA2GA0_PA2GA1_TRIM2_ID = 23, 327 HI_EFUSE_LOCK_TEE_BOOT_VER_ID = 24, 328 HI_EFUSE_LOCK_TEE_KERNEL_VER_ID = 25, 329 HI_EFUSE_LOCK_TEE_SALT_ID = 26, 330 HI_EFUSE_LOCK_FLASH_ENCPY_CNT0_ID = 27, 331 HI_EFUSE_LOCK_FLASH_ENCPY_CNT1_ID = 28, 332 HI_EFUSE_LOCK_FLASH_ENCPY_CNT2_ID = 29, 333 HI_EFUSE_LOCK_FLASH_ENCPY_CFG_ID = 30, 334 HI_EFUSE_LOCK_FLASH_SCRAMBLE_EN_FLASH_IND_ID = 31, 335 HI_EFUSE_LOCK_RF_PDBUFFER_GCAL_ID = 32, 336 HI_EFUSE_LOCK_CUSTOMER_RSVD1_ID = 33, 337 HI_EFUSE_LOCK_DIE_2_ID = 34, 338 HI_EFUSE_LOCK_KDF2ECC_HUK_DISABLE_ID = 35, 339 HI_EFUSE_LOCK_FLASH_ENCPY_CNT3_ID = 36, 340 HI_EFUSE_LOCK_FLASH_ENCPY_CNT4_ID = 37, 341 HI_EFUSE_LOCK_FLASH_ENCPY_CNT5_ID = 38, 342 HI_EFUSE_LOCK_SEC_BOOT_ID = 39, 343 HI_EFUSE_LOCK_DSLEEP_FLAG_ID = 40, 344 HI_EFUSE_LOCK_MAX, 345 } hi_efuse_lock_id; 346 347 /** 348 * @ingroup iot_efuse 349 * @brief Reads the eFUSE.CNcomment:EFUSE读取数据。CNend 350 * 351 * @par 描述: 352 * Reads the eFUSE.CNcomment:从EFUSE中读取数据。CNend 353 * 354 * @attention Ensure that the value of (data_len*8) is not less than efuse_id and the length of the efuse field is 8bit 355 * aligned.CNcomment:需保证(data_len*8)不小于efuse_id对应efuse字段的长度向上8bit对齐。CNend 356 * 357 * @param efuse_id [IN] type #hi_efuse_idx,EFUSE ID 358 * @param data [OUT] type #hi_u8*,Address for saving the read data.CNcomment:读到的数据放到该地址。CNend 359 * @param data_len [IN] type #hi_u8 Space allocated to data, in bytes.CNcomment:给data分配的空间,单位byte。CNend 360 * 361 * @retval #HI_ERR_SUCCESS Success 362 * @retval #Other Failure. For details, see hi_boot_err.h. 363 * @par 依赖: 364 * @li hi_boot_rom.h:Describes the encryption and decryption APIs. 365 CNcomment:文件用于描述efuse字段操作相关接口。CNend 366 * @see hi_efuse_write。 367 */ 368 hi_u32 hi_efuse_read(hi_efuse_idx efuse_id, hi_u8 *data, hi_u8 data_len); 369 370 /** 371 * @ingroup iot_efuse 372 * @brief Writes the eFUSE.CNcomment:写数据到EFUSE。CNend 373 * 374 * @par 描述: 375 * Writes the eFUSE.CNcomment:写数据到EFUSE。CNend 376 * 377 * @attention None 378 * @param efuse_id [IN] type #hi_efuse_idx,EFUSE ID 379 * @param data [IN] type #const hi_u8*,Data to be written to the eFUSE.CNcomment:写该数据到EFUSE中。CNend 380 * 381 * @retval #HI_ERR_SUCCESS Success 382 * @retval #Other Failure. For details, see hi_boot_err.h. 383 * @par 依赖: 384 * @li hi_boot_rom.h:Describes the encryption and decryption APIs. 385 CNcomment:文件用于描述efuse字段操作相关接口。CNend 386 * @see hi_efuse_read。 387 */ 388 hi_u32 hi_efuse_write(hi_efuse_idx efuse_id, const hi_u8 *data); 389 390 /** 391 * @ingroup iot_efuse 392 * @brief Locks an area in the eFUSE. After the lock takes effect upon reboot, the area cannot be written. 393 CNcomment:加锁EFUSE中的某个区域,加锁后重启单板生效,该区域无法再写入。CNend 394 * 395 * @par 描述: 396 * Locks an area in the eFUSE. After the lock takes effect upon reboot, the area cannot be written. 397 CNcomment:加锁EFUSE中的某个区域,加锁后重启单板生效,该区域无法再写入。CNend 398 * 399 * @attention None 400 * @param lock_id [IN] type #hi_efuse_lock_id,eFUSE ID to be locked.CNcomment:待加锁的EFUSE ID项。CNend 401 * 402 * @retval #HI_ERR_SUCCESS Success 403 * @retval #Other Failure. For details, see hi_boot_err.h. 404 * @par 依赖: 405 * @li hi_boot_rom.h:Describes the encryption and decryption APIs. 406 CNcomment:文件用于描述efuse字段操作相关接口。CNend 407 * @see hi_efuse_write。 408 */ 409 hi_u32 hi_efuse_lock(hi_efuse_lock_id efuse_lock_id); 410 411 /** 412 * @ingroup iot_efuse 413 * @brief Obtains the lock status of the eFUSE and queries which areas are locked. 414 CNcomment:获取EFUSE的锁状态,查询哪些区域已锁定。CNend 415 * 416 * @par 描述: 417 * Obtains the lock status of the eFUSE and queries which areas are locked. 418 CNcomment:获取EFUSE的锁状态,查询哪些区域已锁定。CNend 419 * 420 * @attention None 421 * @param lock_stat [OUT] type #hi_u64*,Lock status of the eFUSE.CNcomment:获取EFUSE的锁状态。CNend 422 * 423 * @retval #HI_ERR_SUCCESS Success 424 * @retval #Other Failure. For details, see hi_boot_err.h. 425 * @par 依赖: 426 * @li hi_boot_rom.h:Describes the encryption and decryption APIs. 427 CNcomment:文件用于描述efuse字段操作相关接口。CNend 428 * @see hi_efuse_write。 429 */ 430 hi_u32 hi_efuse_get_lockstat(hi_u64 *lock_stat); 431 432 /** 433 * @ingroup iot_efuse 434 * @brief Reads the user eFUSE.CNcomment:EFUSE用户读取数据。CNend 435 * 436 * @par 描述: 437 * Reads a reserved area in the eFUSE.CNcomment:用户从EFUSE中读取数据。CNend 438 * 439 * @attention None 440 * @param start_bit [IN] type #hi_u16,Start bit. The address must be 8-bit aligned. 441 CNcomment:起始bit位,该地址必须8bit对齐。CNend 442 * @param size [IN] type #hi_u16,Number of bits to be read. If the input is not 8-bit aligned, 443 * the function performs 8-bit alignment internally. The user needs to process the read data before using it. 444 CNcomment:待读取的bit位数,如果输入不是8bit对齐则函数内部会处理为8bit对齐,用户读取数据后需处理后使用。CNend 445 * @param key_data [OUT] type #hi_u8*,Address for saving the read data. 446 CNcomment:读到的数据放到该地址。CNend 447 * 448 * @retval #HI_ERR_SUCCESS Success 449 * @retval #Other Failure. For details, see hi_boot_err.h. 450 * @par 依赖: 451 * @li hi_boot_rom.h:Describes the encryption and decryption APIs. 452 CNcomment:文件用于描述efuse字段操作相关接口。CNend 453 * @see hi_efuse_usr_write。 454 */ 455 hi_u32 hi_efuse_usr_read(hi_u16 start_bit, hi_u16 size, hi_u8 *key_data); 456 457 /** 458 * @ingroup iot_efuse 459 * @brief Writes data to reserved area of the eFUSE.CNcomment:EFUSE用户区写入数据。CNend 460 * 461 * @par 描述: 462 * Writes data to reserved area of the eFUSE.CNcomment:用户往EFUSE写入数据。CNend 463 * 464 * @attention Generally, this API is used to write a reserved area. To write other pre-allocated areas, 465 * should check the design spec to avoid conflict.CNcomment:支持用户写入任意地址数据, 466 建议用户使用用户预留区,其他区域的写入需要结合方案文档评估是否有冲突。CNend 467 * 468 * @param start_bit [IN] type #hi_u16,Start bit.CNcomment:起始bit位。CNend 469 * @param size [IN] type #hi_u16,Number of bits to be written. 1-to-256-bit write is supported. 470 CNcomment:待写入bit数,支持单bit写入,最大值为256bit数。CNend 471 * @param key_data [IN] type #const hi_u8*,Address for the data to be written. The maximum length is 32 bytes. 472 CNcomment:待写入的数据放到该地址,最长为32byte。CNend 473 * 474 * @retval #HI_ERR_SUCCESS Success 475 * @retval #Other Failure. For details, see hi_boot_err.h. 476 * @par 依赖: 477 * @li hi_boot_rom.h:Describes the encryption and decryption APIs. 478 CNcomment:文件用于描述efuse字段操作相关接口。CNend 479 * @see hi_efuse_usr_read。 480 */ 481 hi_u32 hi_efuse_usr_write(hi_u16 start_bit, hi_u16 size, const hi_u8 *key_data); 482 483 /** @defgroup iot_flash Flash Driver APIs 484 * @ingroup iot_flashboot 485 */ 486 /** 487 * @ingroup iot_flash 488 * @brief Initializes the flash device. CNcomment:初始化Flash设备。CNend 489 * 490 * @par 描述: 491 * Initializes the flash device. CNcomment:初始化Flash设备。CNend 492 * 493 * @attention Initialize the flash module during system boot. 494 CNcomment:Flash模块初始化,一般在系统启动时调用。CNend 495 * @param None 496 * 497 * @retval #HI_ERR_SUCCESS Success. 498 * @retval #Other Failure. For details, see hi_errno.h. 499 * @par 依赖: 500 * @li hi_flashboot.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend 501 * @see None 502 */ 503 hi_u32 hi_flash_init(hi_void); 504 505 /** 506 * @ingroup iot_flash 507 * @brief Erases the data in the specified flash partition.CNcomment:把指定的Flash区域数据擦除。CNend 508 * 509 * @par 描述: 510 * Erases the data in the specified flash partition.CNcomment:把指定的Flash区域数据擦除。CNend 511 * 512 * @attention 513 * @li Restriction protection for the relative address of the flash memory. 514 CNcomment:Flash相对地址的限制保护。CNend 515 * @li The number of flash erase times must comply with the device data sheet. 516 CNcomment:Flash擦写次数限制。CNend 517 * 518 * @param flash_offset [IN] type #hi_u32,Address offset of the flash memory to be erased. 519 CNcomment:指定要擦除Flash的地址偏移。CNend 520 * @param size [IN] type #hi_u32,Length of the data to be erased (unit: byte). 521 * The value must be a multiple of 4 KB. 522 CNcomment:需要擦除的长度(单位:byte),必须是4K的倍数。CNend 523 * 524 * @retval #HI_ERR_SUCCESS Success. 525 * @retval #Other Failure. For details, see hi_errno.h. 526 * @par 依赖: 527 * @li hi_flashboot.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend 528 * @see None 529 */ 530 hi_u32 hi_flash_erase(const hi_u32 flash_addr, hi_u32 flash_erase_size); 531 532 /** 533 * @ingroup iot_flash 534 * @brief Writes data to the specified flash partition.CNcomment:把数据写入指定的Flash区。CNend 535 * 536 * @par 描述: 537 * Writes data to the specified flash partition.CNcomment:把数据写入指定的Flash区域。CNend 538 * 539 * @attention 540 * @li Restriction protection for the relative address of the flash memory. 541 CNcomment:Flash相对地址的限制保护。CNend 542 * @li The number of flash erase times must comply with the device data sheet. 543 CNcomment:Flash擦写次数限制。CNend 544 * @li Determine whether to erase the flash before the write based on the actual control scenario. 545 CNcomment:根据用户实际控制场景决定是否先擦后写。CNend 546 * @param flash_offset [IN] type #hi_u32,Offset address for writing data to the flash memory. 547 CNcomment:指定写入Flash偏移地址。CNend 548 * @param size [IN] type #hi_u32,Length of the data to be written (unit: byte). 549 CNcomment:需要写入的长度(单位:byte)。CNend 550 * @param ram_data [IN] type #hi_u8*,Cache address of the data to be written. 551 CNcomment:需要写入的数据的缓存地址。CNend 552 * @param do_erase [IN] type #hi_bool,HI_FALSE: Write data to the flash memory directly. 553 * HI_TRUE: Erase the sector space before write. The user data is written 554 * to the user operation space and the historical data is written back to other spaces. 555 CNcomment:表示是否自动擦除并覆盖写入。HI_TRUE:本接口中先擦后写。HI_FALSE:用户已经擦除本接口,可直接写入。CNend 556 * 557 * @retval #HI_ERR_SUCCESS Success. 558 * @retval #Other Failure. For details, see hi_errno.h. 559 * @par 依赖: 560 * @li hi_flashboot.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend 561 * @see None 562 */ 563 hi_u32 hi_flash_write(hi_u32 flash_addr, hi_u32 flash_write_size, const hi_u8 *p_flash_write_data, hi_bool do_erase); 564 565 /** 566 * @ingroup iot_flash 567 * @brief Reads the flash data to the specified cache. CNcomment:读出Flash数据到指定缓存区域。CNend 568 * 569 * @par 描述: 570 * Reads the flash data to the specified cache. CNcomment:读出Flash数据到指定缓存区域。CNend 571 * 572 * @attention None 573 * @param flash_offset [IN] type #hi_u32,Offset of the flash address.CNcomment:指定的Flash地址偏移。CNend 574 * @param size [IN] type #hi_u32,Read length (unit: byte). 575 CNcomment:指定读取的长度(单位:byte)。CNend 576 * @param ram_data [IN] type #hi_u8*,Destination cache address.CNcomment:目的缓存地址。CNend 577 * 578 * @retval #HI_ERR_SUCCESS Success. 579 * @retval #Other Failure. For details, see hi_errno.h. 580 * @par 依赖: 581 * @li hi_flashboot.h:FLASH driver APIs.CNcomment:该接口声明所在的头文件。CNend 582 * @see None 583 */ 584 hi_u32 hi_flash_read(hi_u32 flash_addr, hi_u32 flash_read_size, hi_u8 *p_flash_read_data); 585 586 /** @defgroup iot_crc32 CRC32 APIs 587 * @ingroup iot_flashboot 588 */ 589 /** 590 * @ingroup iot_crc32 591 * @brief Generates a 32-bit CRC value.CNcomment:生成32位CRC校验值。CNend 592 * 593 * @par 描述: 594 * Generates a 32-bit CRC value.CNcomment:生成32位CRC校验值。CNend 595 * 596 * @attention None 597 * @param crc [IN] type #hi_u32,The CRC initial value.CNcomment:CRC初始值。CNend 598 * @param p [IN] type #const hi_u8*,Pointer to the buffer to be verified. 599 CNcomment:被校验Buffer指针。CNend 600 * @param len [IN] type #hi_u32,Length of the buffer to be verified (unit: Byte). 601 CNcomment:被校验Buffer长度(单位:byte)。CNend 602 * 603 * @retval #HI_ERR_SUCCESS Success 604 * @retval #Other Failure. For details, see hi_boot_err.h. 605 * 606 * @par 依赖: 607 * @li hi_flashboot.h:Describes CRC APIs.CNcomment:文件包含CRC校验接口。CNend 608 * @see None 609 */ 610 hi_u32 hi_crc32 (hi_u32 crc, const hi_u8 *p, hi_u32 len); 611 612 #endif 613 614