esp_efuse_fields.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "esp_efuse.h"
  7. #include "esp_efuse_utility.h"
  8. #include "esp_efuse_table.h"
  9. #include "stdlib.h"
  10. #include "esp_types.h"
  11. #include "assert.h"
  12. #include "esp_err.h"
  13. #include "esp_log.h"
  14. #include "soc/efuse_periph.h"
  15. #include "bootloader_random.h"
  16. #include "sys/param.h"
  17. static __attribute__((unused)) const char *TAG = "efuse";
  18. // Contains functions that provide access to efuse fields which are often used in IDF.
  19. // Returns chip version from efuse
  20. uint8_t esp_efuse_get_chip_ver(void)
  21. {
  22. // should return the same value as bootloader_common_get_chip_revision()
  23. uint32_t chip_ver = 0;
  24. // TODO: ESP32S2 does not have this field
  25. return chip_ver;
  26. }
  27. // Returns chip package from efuse
  28. uint32_t esp_efuse_get_pkg_ver(void)
  29. {
  30. uint32_t pkg_ver = 0;
  31. esp_efuse_read_field_blob(ESP_EFUSE_PKG_VERSION, &pkg_ver, ESP_EFUSE_PKG_VERSION[0]->bit_count);
  32. return pkg_ver;
  33. }
  34. esp_err_t esp_efuse_disable_rom_download_mode(void)
  35. {
  36. return esp_efuse_write_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE);
  37. }
  38. esp_err_t esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme)
  39. {
  40. int cur_log_scheme = 0;
  41. esp_efuse_read_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &cur_log_scheme, ESP_EFUSE_UART_PRINT_CONTROL[0]->bit_count);
  42. if (!cur_log_scheme) { // not burned yet
  43. return esp_efuse_write_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &log_scheme, ESP_EFUSE_UART_PRINT_CONTROL[0]->bit_count);
  44. } else {
  45. return ESP_ERR_INVALID_STATE;
  46. }
  47. }
  48. esp_err_t esp_efuse_enable_rom_secure_download_mode(void)
  49. {
  50. if (esp_efuse_read_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE)) {
  51. return ESP_ERR_INVALID_STATE;
  52. }
  53. return esp_efuse_write_field_bit(ESP_EFUSE_ENABLE_SECURITY_DOWNLOAD);
  54. }