secure_boot_secure_features.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_LEGACY_SPI_BOOT);
  17. #ifdef CONFIG_SECURE_ENABLE_SECURE_ROM_DL_MODE
  18. ESP_LOGI(TAG, "Enabling Security download mode...");
  19. esp_efuse_write_field_bit(ESP_EFUSE_ENABLE_SECURITY_DOWNLOAD);
  20. #else
  21. ESP_LOGW(TAG, "Not enabling Security download mode - SECURITY COMPROMISED");
  22. #endif
  23. #ifndef CONFIG_SECURE_BOOT_ALLOW_JTAG
  24. ESP_LOGI(TAG, "Disable hardware & software JTAG...");
  25. esp_efuse_write_field_bit(ESP_EFUSE_DIS_PAD_JTAG);
  26. esp_efuse_write_field_bit(ESP_EFUSE_DIS_USB_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. return ESP_OK;
  36. }