Skip to content

Commit 5fa0347

Browse files
committed
fix(bootloader_support): Allow pre-programmed XTS-AES psuedo round level efuses
- The API esp_flash_encryption_set_release_mode() by defualt programs the XTS-AES pseudo round level efuse to level low but did not considered any existing value that would have been programmed in the efuse bit.
1 parent 8d9f366 commit 5fa0347

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

components/bootloader_support/include/esp_flash_encrypt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ bool esp_flash_encryption_cfg_verify_release_mode(void);
215215
* It burns:
216216
* - "disable encrypt in dl mode"
217217
* - set FLASH_CRYPT_CNT efuse to max
218+
*
219+
* In case of the targets that support the XTS-AES peripheral's pseudo rounds function,
220+
* this API would configure the pseudo rounds level efuse bit to level low if the efuse bit
221+
* is not set already.
218222
*/
219223
void esp_flash_encryption_set_release_mode(void);
220224

components/bootloader_support/src/esp32h2/flash_encryption_secure_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
3636

3737
esp_efuse_write_field_bit(ESP_EFUSE_DIS_DIRECT_BOOT);
3838

39-
#if defined(CONFIG_SECURE_FLASH_PSEUDO_ROUND_FUNC)
39+
#if CONFIG_SECURE_FLASH_PSEUDO_ROUND_FUNC
4040
if (spi_flash_encrypt_ll_is_pseudo_rounds_function_supported()) {
4141
ESP_LOGI(TAG, "Enable XTS-AES pseudo rounds function...");
4242
uint8_t xts_pseudo_level = CONFIG_SECURE_FLASH_PSEUDO_ROUND_FUNC_STRENGTH;

components/bootloader_support/src/flash_encrypt.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ void esp_flash_encryption_set_release_mode(void)
210210
#endif // CONFIG_SOC_FLASH_ENCRYPTION_XTS_AES_128_DERIVED
211211
#endif // !CONFIG_IDF_TARGET_ESP32
212212

213+
#ifdef SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND
214+
if (spi_flash_encrypt_ll_is_pseudo_rounds_function_supported()) {
215+
uint8_t xts_pseudo_level = 0;
216+
esp_efuse_read_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
217+
218+
if (xts_pseudo_level == ESP_XTS_AES_PSEUDO_ROUNDS_DISABLE) {
219+
xts_pseudo_level = ESP_XTS_AES_PSEUDO_ROUNDS_LOW;
220+
esp_efuse_write_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
221+
}
222+
}
223+
#endif
224+
213225
#ifdef CONFIG_IDF_TARGET_ESP32
214226
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_DIS_CACHE);
215227
#else

0 commit comments

Comments
 (0)