Skip to content

Commit a3232e4

Browse files
bootloader: Adds an option to leave DIS_CACHE writeable
1 parent 199e5ab commit a3232e4

File tree

8 files changed

+48
-7
lines changed

8 files changed

+48
-7
lines changed

components/bootloader/Kconfig.projbuild

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,10 @@ menu "Security features"
829829

830830
endchoice
831831

832+
config SECURE_FLASH_HAS_WRITE_PROTECTION_CACHE
833+
bool
834+
default y if (SOC_EFUSE_DIS_ICACHE || IDF_TARGET_ESP32) && SECURE_FLASH_ENC_ENABLED
835+
832836
menu "Potentially insecure options"
833837
visible if SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT || SECURE_BOOT_INSECURE || SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT # NOERROR
834838

@@ -855,6 +859,7 @@ menu "Security features"
855859
config SECURE_BOOT_ALLOW_JTAG
856860
bool "Allow JTAG Debugging"
857861
depends on SECURE_BOOT_INSECURE || SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
862+
select SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE if SECURE_FLASH_HAS_WRITE_PROTECTION_CACHE
858863
default N
859864
help
860865
If not set (default), the bootloader will permanently disable JTAG (across entire chip) on first boot
@@ -912,6 +917,7 @@ menu "Security features"
912917
config SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC
913918
bool "Leave UART bootloader encryption enabled"
914919
depends on SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
920+
select SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE if SECURE_FLASH_HAS_WRITE_PROTECTION_CACHE
915921
default N
916922
help
917923
If not set (default), the bootloader will permanently disable UART bootloader encryption access on
@@ -934,6 +940,7 @@ menu "Security features"
934940
bool "Leave UART bootloader flash cache enabled"
935941
depends on SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT && (IDF_TARGET_ESP32 || SOC_EFUSE_DIS_DOWNLOAD_ICACHE || SOC_EFUSE_DIS_DOWNLOAD_DCACHE) # NOERROR
936942
default N
943+
select SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE if SECURE_FLASH_HAS_WRITE_PROTECTION_CACHE
937944
help
938945
If not set (default), the bootloader will permanently disable UART bootloader flash cache access on
939946
first boot. If set, the UART bootloader will still be able to access the flash cache.
@@ -954,6 +961,40 @@ menu "Security features"
954961
Only use this option in testing environments, to avoid accidentally enabling flash encryption on
955962
the wrong device. The device needs to have flash encryption already enabled using espefuse.py.
956963

964+
config SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE
965+
bool "Skip write-protection of DIS_CACHE (DIS_ICACHE, DIS_DCACHE)"
966+
default n
967+
depends on SECURE_FLASH_HAS_WRITE_PROTECTION_CACHE
968+
help
969+
If not set (default, recommended), on the first boot the bootloader will burn the write-protection of
970+
DIS_CACHE(for ESP32) or DIS_ICACHE/DIS_DCACHE(for other chips) eFuse when Flash Encryption is enabled.
971+
Write protection for cache disable efuse prevents the chip from being blocked if it is set by accident.
972+
App and bootloader use cache so disabling it makes the chip useless for IDF.
973+
Due to other eFuses are linked with the same write protection bit (see the list below) then
974+
write-protection will not be done if these SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC,
975+
SECURE_BOOT_ALLOW_JTAG or SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE options are selected
976+
to give a chance to turn on the chip into the release mode later.
977+
978+
List of eFuses with the same write protection bit:
979+
ESP32: MAC, MAC_CRC, DISABLE_APP_CPU, DISABLE_BT, DIS_CACHE, VOL_LEVEL_HP_INV.
980+
981+
ESP32-C3: DIS_ICACHE, DIS_USB_JTAG, DIS_DOWNLOAD_ICACHE, DIS_USB_SERIAL_JTAG,
982+
DIS_FORCE_DOWNLOAD, DIS_TWAI, JTAG_SEL_ENABLE, DIS_PAD_JTAG, DIS_DOWNLOAD_MANUAL_ENCRYPT.
983+
984+
ESP32-C6: SWAP_UART_SDIO_EN, DIS_ICACHE, DIS_USB_JTAG, DIS_DOWNLOAD_ICACHE,
985+
DIS_USB_SERIAL_JTAG, DIS_FORCE_DOWNLOAD, DIS_TWAI, JTAG_SEL_ENABLE,
986+
DIS_PAD_JTAG, DIS_DOWNLOAD_MANUAL_ENCRYPT.
987+
988+
ESP32-H2: DIS_ICACHE, DIS_USB_JTAG, POWERGLITCH_EN, DIS_FORCE_DOWNLOAD, SPI_DOWNLOAD_MSPI_DIS,
989+
DIS_TWAI, JTAG_SEL_ENABLE, DIS_PAD_JTAG, DIS_DOWNLOAD_MANUAL_ENCRYPT.
990+
991+
ESP32-S2: DIS_ICACHE, DIS_DCACHE, DIS_DOWNLOAD_ICACHE, DIS_DOWNLOAD_DCACHE,
992+
DIS_FORCE_DOWNLOAD, DIS_USB, DIS_TWAI, DIS_BOOT_REMAP, SOFT_DIS_JTAG,
993+
HARD_DIS_JTAG, DIS_DOWNLOAD_MANUAL_ENCRYPT.
994+
995+
ESP32-S3: DIS_ICACHE, DIS_DCACHE, DIS_DOWNLOAD_ICACHE, DIS_DOWNLOAD_DCACHE,
996+
DIS_FORCE_DOWNLOAD, DIS_USB_OTG, DIS_TWAI, DIS_APP_CPU, DIS_PAD_JTAG,
997+
DIS_DOWNLOAD_MANUAL_ENCRYPT, DIS_USB_JTAG, DIS_USB_SERIAL_JTAG, STRAP_JTAG_SEL, USB_PHY_SEL.
957998
endmenu # Potentially Insecure
958999

9591000
config SECURE_FLASH_CHECK_ENC_EN_IN_APP

components/bootloader_support/src/esp32/flash_encryption_secure_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
7979
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_EFUSE_RD_DISABLE);
8080
#endif
8181

82-
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
82+
#ifndef CONFIG_SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE
8383
// Set write-protection for DIS_ICACHE to prevent bricking chip in case it will be set accidentally.
8484
// esp32 has DIS_ICACHE. Write-protection bit = 3.
8585
// List of eFuses with the same write protection bit:

components/bootloader_support/src/esp32c3/flash_encryption_secure_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
4646
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_RD_DIS);
4747
#endif
4848

49-
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
49+
#ifndef CONFIG_SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE
5050
// Set write-protection for DIS_ICACHE to prevent bricking chip in case it will be set accidentally.
5151
// esp32c3 has DIS_ICACHE. Write-protection bit = 2.
5252
// List of eFuses with the same write protection bit:

components/bootloader_support/src/esp32c6/flash_encryption_secure_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
4646
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_RD_DIS);
4747
#endif
4848

49-
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
49+
#ifndef CONFIG_SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE
5050
// Set write-protection for DIS_ICACHE to prevent bricking chip in case it will be set accidentally.
5151
// esp32c6 has DIS_ICACHE. Write-protection bit = 2.
5252
// List of eFuses with the same write protection bit:

components/bootloader_support/src/esp32h2/flash_encryption_secure_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
3939
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_RD_DIS);
4040
#endif
4141

42-
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
42+
#ifndef CONFIG_SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE
4343
// Set write-protection for DIS_ICACHE to prevent bricking chip in case it will be set accidentally.
4444
// esp32h2 has DIS_ICACHE. Write-protection bit = 2.
4545
// List of eFuses with the same write protection bit:

components/bootloader_support/src/esp32h4/flash_encryption_secure_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
4646
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_RD_DIS);
4747
#endif
4848

49-
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
49+
#ifndef CONFIG_SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE
5050
// Set write-protection for DIS_ICACHE to prevent bricking chip in case it will be set accidentally.
5151
// esp32h4 has DIS_ICACHE. Write-protection bit = 2.
5252
// List of eFuses with the same write protection bit:

components/bootloader_support/src/esp32s2/flash_encryption_secure_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
4747
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_RD_DIS);
4848
#endif
4949

50-
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
50+
#ifndef CONFIG_SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE
5151
// Set write-protection for DIS_ICACHE and DIS_DCACHE to prevent bricking chip in case it will be set accidentally.
5252
// esp32s2 has DIS_ICACHE and DIS_DCACHE. Write-protection bit = 2 for both.
5353
// List of eFuses with the same write protection bit:

components/bootloader_support/src/esp32s3/flash_encryption_secure_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
4747
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_RD_DIS);
4848
#endif
4949

50-
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
50+
#ifndef CONFIG_SECURE_FLASH_SKIP_WRITE_PROTECTION_CACHE
5151
// Set write-protection for DIS_ICACHE and DIS_DCACHE to prevent bricking chip in case it will be set accidentally.
5252
// esp32s3 has DIS_ICACHE and DIS_DCACHE. Write-protection bit = 2 for both.
5353
// List of eFuses with the same write protection bit:

0 commit comments

Comments
 (0)