1 /* 2 * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #include <esp_types.h> 10 #include <esp_err.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** 17 * @brief Type of eFuse blocks for ESP32 18 */ 19 typedef enum { 20 EFUSE_BLK0 = 0, /**< Number of eFuse block. Reserved. */ 21 22 EFUSE_BLK1 = 1, /**< Number of eFuse block. Used for Flash Encryption. If not using that Flash Encryption feature, they can be used for another purpose. */ 23 EFUSE_BLK_KEY0 = 1, /**< Number of eFuse block. Used for Flash Encryption. If not using that Flash Encryption feature, they can be used for another purpose. */ 24 EFUSE_BLK_ENCRYPT_FLASH = 1, /**< Number of eFuse block. Used for Flash Encryption. If not using that Flash Encryption feature, they can be used for another purpose. */ 25 26 EFUSE_BLK2 = 2, /**< Number of eFuse block. Used for Secure Boot. If not using that Secure Boot feature, they can be used for another purpose. */ 27 EFUSE_BLK_KEY1 = 2, /**< Number of eFuse block. Used for Secure Boot. If not using that Secure Boot feature, they can be used for another purpose. */ 28 EFUSE_BLK_SECURE_BOOT = 2, /**< Number of eFuse block. Used for Secure Boot. If not using that Secure Boot feature, they can be used for another purpose. */ 29 30 EFUSE_BLK3 = 3, /**< Number of eFuse block. Uses for the purpose of the user. */ 31 EFUSE_BLK_KEY2 = 3, /**< Number of eFuse block. Uses for the purpose of the user. */ 32 EFUSE_BLK_KEY_MAX = 4, 33 34 EFUSE_BLK_MAX = 4, 35 } esp_efuse_block_t; 36 37 /** 38 * @brief Type of coding scheme 39 */ 40 typedef enum { 41 EFUSE_CODING_SCHEME_NONE = 0, /**< None */ 42 EFUSE_CODING_SCHEME_3_4 = 1, /**< 3/4 coding */ 43 EFUSE_CODING_SCHEME_REPEAT = 2, /**< Repeat coding */ 44 } esp_efuse_coding_scheme_t; 45 46 /** 47 * @brief Type of key purpose (virtual because ESP32 has only fixed purposes for blocks) 48 */ 49 typedef enum { 50 ESP_EFUSE_KEY_PURPOSE_USER = 0, /**< BLOCK3 */ 51 ESP_EFUSE_KEY_PURPOSE_SYSTEM = 1, /**< BLOCK0 */ 52 ESP_EFUSE_KEY_PURPOSE_FLASH_ENCRYPTION = 2, /**< BLOCK1 */ 53 ESP_EFUSE_KEY_PURPOSE_SECURE_BOOT_V2 = 3, /**< BLOCK2 */ 54 ESP_EFUSE_KEY_PURPOSE_MAX, /**< MAX PURPOSE*/ 55 } esp_efuse_purpose_t; 56 57 58 /** 59 * @brief Permanently update values written to the efuse write registers 60 * 61 * After updating EFUSE_BLKx_WDATAx_REG registers with new values to 62 * write, call this function to permanently write them to efuse. 63 * 64 * @note Setting bits in efuse is permanent, they cannot be unset. 65 * 66 * @note Due to this restriction you don't need to copy values to 67 * Efuse write registers from the matching read registers, bits which 68 * are set in the read register but unset in the matching write 69 * register will be unchanged when new values are burned. 70 * 71 * @note This function is not threadsafe, if calling code updates 72 * efuse values from multiple tasks then this is caller's 73 * responsibility to serialise. 74 * 75 * @deprecated Use the batch mode instead of directly call the burn command. 76 * 77 * After burning new efuses, the read registers are updated to match 78 * the new efuse values. 79 */ 80 void esp_efuse_burn_new_values(void) __attribute__ ((deprecated)); 81 82 /* @brief Write random data to efuse key block write registers 83 * 84 * @note Caller is responsible for ensuring efuse 85 * block is empty and not write protected, before calling. 86 * 87 * @note Behaviour depends on coding scheme: a 256-bit key is 88 * generated and written for Coding Scheme "None", a 192-bit key 89 * is generated, extended to 256-bits by the Coding Scheme, 90 * and then writtten for 3/4 Coding Scheme. 91 * 92 * @note This function does not burn the new values, caller should 93 * call esp_efuse_burn_new_values() when ready to do this. 94 * 95 * @deprecated Use the code below instead of this function: 96 * 97 * @code{c} 98 * uint32_t key[8]; 99 * size_t key_size = 256; 100 * if (coding_scheme == EFUSE_CODING_SCHEME_3_4) { 101 * key_size = 192; 102 * } 103 * bootloader_fill_random(key, key_size / 8); 104 * esp_efuse_write_block(EFUSE_BLK1, key, 0, key_size); 105 * @endcode 106 * 107 * @param blk_wdata0_reg Address of the first data write register 108 * in the block 109 */ 110 void esp_efuse_write_random_key(uint32_t blk_wdata0_reg) __attribute__ ((deprecated)); 111 112 #ifdef __cplusplus 113 } 114 #endif 115