secure_boot_secure_features.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <strings.h>
  7. #include "esp_flash_encrypt.h"
  8. #include "esp_secure_boot.h"
  9. #include "esp_efuse.h"
  10. #include "esp_efuse_table.h"
  11. #include "esp_log.h"
  12. #include "sdkconfig.h"
  13. static __attribute__((unused)) const char *TAG = "secure_boot";
  14. esp_err_t esp_secure_boot_enable_secure_features(void)
  15. {
  16. esp_efuse_write_field_bit(ESP_EFUSE_DIS_BOOT_REMAP);
  17. esp_efuse_write_field_bit(ESP_EFUSE_DIS_LEGACY_SPI_BOOT);
  18. #ifdef CONFIG_SECURE_ENABLE_SECURE_ROM_DL_MODE
  19. ESP_LOGI(TAG, "Enabling Security download mode...");
  20. esp_efuse_write_field_bit(ESP_EFUSE_ENABLE_SECURITY_DOWNLOAD);
  21. #else
  22. ESP_LOGW(TAG, "Not enabling Security download mode - SECURITY COMPROMISED");
  23. #endif
  24. #ifndef CONFIG_SECURE_BOOT_ALLOW_JTAG
  25. ESP_LOGI(TAG, "Disable hardware & software JTAG...");
  26. esp_efuse_write_field_bit(ESP_EFUSE_HARD_DIS_JTAG);
  27. esp_efuse_write_field_bit(ESP_EFUSE_SOFT_DIS_JTAG);
  28. #else
  29. ESP_LOGW(TAG, "Not disabling JTAG - SECURITY COMPROMISED");
  30. #endif
  31. #ifdef CONFIG_SECURE_BOOT_ENABLE_AGGRESSIVE_KEY_REVOKE
  32. esp_efuse_write_field_bit(ESP_EFUSE_SECURE_BOOT_AGGRESSIVE_REVOKE);
  33. #endif
  34. esp_efuse_write_field_bit(ESP_EFUSE_SECURE_BOOT_EN);
  35. #ifndef CONFIG_SECURE_BOOT_V2_ALLOW_EFUSE_RD_DIS
  36. bool rd_dis_now = true;
  37. #ifdef CONFIG_SECURE_FLASH_ENC_ENABLED
  38. /* If flash encryption is not enabled yet then don't read-disable efuses yet, do it later in the boot
  39. when Flash Encryption is being enabled */
  40. rd_dis_now = esp_flash_encryption_enabled();
  41. #endif
  42. if (rd_dis_now) {
  43. ESP_LOGI(TAG, "Prevent read disabling of additional efuses...");
  44. esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_RD_DIS);
  45. }
  46. #else
  47. ESP_LOGW(TAG, "Allowing read disabling of additional efuses - SECURITY COMPROMISED");
  48. #endif
  49. return ESP_OK;
  50. }