refactor(flash_enc): move esp_flash_encryption_enabled() to efuse component

This commit is contained in:
Chen Jichang
2026-01-21 15:11:59 +08:00
committed by Chen Ji Chang
parent 0ac402217c
commit b8c527a87c
53 changed files with 139 additions and 131 deletions
+8 -1
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -823,6 +823,13 @@ esp_err_t esp_efuse_check_errors(void);
*/
esp_err_t esp_efuse_destroy_block(esp_efuse_block_t block);
/**
* @brief Checks if flash encryption is enabled.
*
* This function checks if the current eFuse configuration supports flash encryption.
*/
bool esp_efuse_is_flash_encryption_enabled(void);
#if SOC_ECDSA_SUPPORTED
/**
* @brief Checks if 192-bit ECDSA curve operations are supported.
+24 -1
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -187,3 +187,26 @@ esp_err_t esp_efuse_set_recovery_bootloader_offset(const uint32_t offset)
return ESP_OK;
}
#endif // SOC_RECOVERY_BOOTLOADER_SUPPORTED
bool IRAM_ATTR esp_efuse_is_flash_encryption_enabled(void)
{
#ifndef CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
return efuse_hal_flash_encryption_enabled();
#else
uint32_t flash_crypt_cnt = 0;
#if CONFIG_IDF_TARGET_ESP32
esp_efuse_read_field_blob(ESP_EFUSE_FLASH_CRYPT_CNT, &flash_crypt_cnt, ESP_EFUSE_FLASH_CRYPT_CNT[0]->bit_count);
#else
esp_efuse_read_field_blob(ESP_EFUSE_SPI_BOOT_CRYPT_CNT, &flash_crypt_cnt, ESP_EFUSE_SPI_BOOT_CRYPT_CNT[0]->bit_count);
#endif
/* __builtin_parity is in flash, so we calculate parity inline */
bool enabled = false;
while (flash_crypt_cnt) {
if (flash_crypt_cnt & 1) {
enabled = !enabled;
}
flash_crypt_cnt >>= 1;
}
return enabled;
#endif // CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH
}