esp_efuse.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _ESP_EFUSE_H
  14. #define _ESP_EFUSE_H
  15. #include "soc/efuse_reg.h"
  16. #include "esp_err.h"
  17. #include "stdbool.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /* @brief Permanently update values written to the efuse write registers
  22. *
  23. * After updating EFUSE_BLKx_WDATAx_REG registers with new values to
  24. * write, call this function to permanently write them to efuse.
  25. *
  26. * @note Setting bits in efuse is permanent, they cannot be unset.
  27. *
  28. * @note Due to this restriction you don't need to copy values to
  29. * Efuse write registers from the matching read registers, bits which
  30. * are set in the read register but unset in the matching write
  31. * register will be unchanged when new values are burned.
  32. *
  33. * @note This function is not threadsafe, if calling code updates
  34. * efuse values from multiple tasks then this is caller's
  35. * responsibility to serialise.
  36. *
  37. * After burning new efuses, the read registers are updated to match
  38. * the new efuse values.
  39. */
  40. void esp_efuse_burn_new_values(void);
  41. /* @brief Reset efuse write registers
  42. *
  43. * Efuse write registers are written to zero, to negate
  44. * any changes that have been staged here.
  45. */
  46. void esp_efuse_reset(void);
  47. /* @brief Disable BASIC ROM Console via efuse
  48. *
  49. * By default, if booting from flash fails the ESP32 will boot a
  50. * BASIC console in ROM.
  51. *
  52. * Call this function (from bootloader or app) to permanently
  53. * disable the console on this chip.
  54. */
  55. void esp_efuse_disable_basic_rom_console(void);
  56. /* @brief Encode one or more sets of 6 byte sequences into
  57. * 8 bytes suitable for 3/4 Coding Scheme.
  58. *
  59. * This function is only useful if the CODING_SCHEME efuse
  60. * is set to value 1 for 3/4 Coding Scheme.
  61. *
  62. * @param[in] in_bytes Pointer to a sequence of bytes to encode for 3/4 Coding Scheme. Must have length in_bytes_len. After being written to hardware, these bytes will read back as little-endian words.
  63. * @param[out] out_words Pointer to array of words suitable for writing to efuse write registers. Array must contain 2 words (8 bytes) for every 6 bytes in in_bytes_len. Can be a pointer to efuse write registers.
  64. * @param in_bytes_len. Length of array pointed to by in_bytes, in bytes. Must be a multiple of 6.
  65. *
  66. * @return ESP_ERR_INVALID_ARG if either pointer is null or in_bytes_len is not a multiple of 6. ESP_OK otherwise.
  67. */
  68. esp_err_t esp_efuse_apply_34_encoding(const uint8_t *in_bytes, uint32_t *out_words, size_t in_bytes_len);
  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. * @param blk_wdata0_reg Address of the first data write register
  83. * in the block
  84. */
  85. void esp_efuse_write_random_key(uint32_t blk_wdata0_reg);
  86. /* @brief Return secure_version from efuse field.
  87. * @return Secure version from efuse field
  88. */
  89. uint32_t esp_efuse_read_secure_version();
  90. /* @brief Check secure_version from app and secure_version and from efuse field.
  91. *
  92. * @param secure_version Secure version from app.
  93. * @return
  94. * - True: If version of app is equal or more then secure_version from efuse.
  95. */
  96. bool esp_efuse_check_secure_version(uint32_t secure_version);
  97. /* @brief Write efuse field by secure_version value.
  98. *
  99. * Update the secure_version value is available if the coding scheme is None.
  100. * Note: Do not use this function in your applications. This function is called as part of the other API.
  101. *
  102. * @param[in] secure_version Secure version from app.
  103. * @return
  104. * - ESP_OK: Successful.
  105. * - ESP_FAIL: secure version of app cannot be set to efuse field.
  106. * - ESP_ERR_NOT_SUPPORTED: Anti rollback is not supported with the 3/4 and Repeat coding scheme.
  107. */
  108. esp_err_t esp_efuse_update_secure_version(uint32_t secure_version);
  109. /* @brief Initializes variables: offset and size to simulate the work of an eFuse.
  110. *
  111. * Note: To simulate the work of an eFuse need to set CONFIG_EFUSE_SECURE_VERSION_EMULATE option
  112. * and to add in the partition.csv file a line `efuse_em, data, efuse, , 0x2000,`.
  113. *
  114. * @param[in] offset The starting address of the partition where the eFuse data will be located.
  115. * @param[in] size The size of the partition.
  116. */
  117. void esp_efuse_init(uint32_t offset, uint32_t size);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif /* __ESP_EFUSE_H */