esp_efuse.h 4.3 KB

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