Skip to content

Commit f6be421

Browse files
committed
fix(bootloader_support): Enable pseudo round function in flash enc release mode for H2-ECO5
1 parent d75ca96 commit f6be421

File tree

13 files changed

+54
-27
lines changed

13 files changed

+54
-27
lines changed

components/bootloader_support/src/esp32h2/flash_encryption_secure_features.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <stdint.h>
78
#include <strings.h>
89
#include "esp_flash_encrypt.h"
910
#include "esp_secure_boot.h"
1011
#include "esp_efuse.h"
1112
#include "esp_efuse_table.h"
1213
#include "esp_log.h"
14+
#include "hal/spi_flash_encrypted_ll.h"
15+
#include "soc/soc_caps.h"
1316
#include "sdkconfig.h"
1417

1518
static __attribute__((unused)) const char *TAG = "flash_encrypt";
@@ -33,6 +36,14 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
3336

3437
esp_efuse_write_field_bit(ESP_EFUSE_DIS_DIRECT_BOOT);
3538

39+
#if defined(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE) && defined(SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND)
40+
if (spi_flash_encrypt_ll_is_pseudo_rounds_function_supported()) {
41+
ESP_LOGI(TAG, "Enable XTS-AES pseudo rounds function...");
42+
uint8_t xts_pseudo_level = CONFIG_SECURE_FLASH_PSEUDO_ROUND_FUNC_STRENGTH;
43+
esp_efuse_write_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
44+
}
45+
#endif
46+
3647
#if defined(CONFIG_SECURE_BOOT_V2_ENABLED) && !defined(CONFIG_SECURE_BOOT_V2_ALLOW_EFUSE_RD_DIS)
3748
// This bit is set when enabling Secure Boot V2, but we can't enable it until this later point in the first boot
3849
// otherwise the Flash Encryption key cannot be read protected

components/bootloader_support/src/flash_encrypt.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -12,6 +12,7 @@
1212
#include "esp_flash_encrypt.h"
1313
#include "esp_secure_boot.h"
1414
#include "hal/efuse_hal.h"
15+
#include "hal/spi_flash_encrypted_ll.h"
1516
#include "hal/spi_flash_encrypt_hal.h"
1617
#include "soc/soc_caps.h"
1718

@@ -210,8 +211,10 @@ void esp_flash_encryption_set_release_mode(void)
210211
#endif // !CONFIG_IDF_TARGET_ESP32
211212

212213
#ifdef SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND
213-
uint8_t xts_pseudo_level = ESP_XTS_AES_PSEUDO_ROUNDS_LOW;
214-
esp_efuse_write_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
214+
if (spi_flash_encrypt_ll_is_pseudo_rounds_function_supported()) {
215+
uint8_t xts_pseudo_level = ESP_XTS_AES_PSEUDO_ROUNDS_LOW;
216+
esp_efuse_write_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
217+
}
215218
#endif
216219

217220
#ifdef CONFIG_IDF_TARGET_ESP32
@@ -476,11 +479,13 @@ bool esp_flash_encryption_cfg_verify_release_mode(void)
476479
result &= secure;
477480

478481
#if SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND
479-
uint8_t xts_pseudo_level = 0;
480-
esp_efuse_read_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
481-
if (!xts_pseudo_level) {
482-
result &= false;
483-
ESP_LOGW(TAG, "Not enabled XTS-AES pseudo rounds function (set XTS_DPA_PSEUDO_LEVEL->1 or more)");
482+
if (spi_flash_encrypt_ll_is_pseudo_rounds_function_supported()) {
483+
uint8_t xts_pseudo_level = 0;
484+
esp_efuse_read_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
485+
if (!xts_pseudo_level) {
486+
result &= false;
487+
ESP_LOGW(TAG, "Not enabled XTS-AES pseudo rounds function (set XTS_DPA_PSEUDO_LEVEL->1 or more)");
488+
}
484489
}
485490
#endif
486491

components/hal/esp32/include/hal/spi_flash_encrypted_ll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212

1313
// The Lowlevel layer for SPI Flash Encryption.
14+
#pragma once
1415

1516
#include "soc/dport_reg.h"
1617
#include "soc/flash_encryption_reg.h"

components/hal/esp32c2/include/hal/spi_flash_encrypted_ll.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212

1313
// The Lowlevel layer for SPI Flash Encryption.
14+
#pragma once
1415

1516
#include <stdbool.h>
1617
#include <string.h>
@@ -24,7 +25,7 @@
2425
extern "C" {
2526
#endif
2627

27-
/// Choose type of chip you want to encrypt manully
28+
/// Choose type of chip you want to encrypt manually
2829
typedef enum
2930
{
3031
FLASH_ENCRYPTION_MANU = 0, ///!< Manually encrypt the flash chip.
@@ -51,7 +52,7 @@ static inline void spi_flash_encrypt_ll_disable(void)
5152
}
5253

5354
/**
54-
* Choose type of chip you want to encrypt manully
55+
* Choose type of chip you want to encrypt manually
5556
*
5657
* @param type The type of chip to be encrypted
5758
*

components/hal/esp32c3/include/hal/spi_flash_encrypted_ll.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212

1313
// The Lowlevel layer for SPI Flash Encryption.
14+
#pragma once
1415

1516
#include <stdbool.h>
1617
#include <string.h>
@@ -24,7 +25,7 @@
2425
extern "C" {
2526
#endif
2627

27-
/// Choose type of chip you want to encrypt manully
28+
/// Choose type of chip you want to encrypt manually
2829
typedef enum
2930
{
3031
FLASH_ENCRYPTION_MANU = 0, ///!< Manually encrypt the flash chip.
@@ -51,7 +52,7 @@ static inline void spi_flash_encrypt_ll_disable(void)
5152
}
5253

5354
/**
54-
* Choose type of chip you want to encrypt manully
55+
* Choose type of chip you want to encrypt manually
5556
*
5657
* @param type The type of chip to be encrypted
5758
*

components/hal/esp32c5/include/hal/spi_flash_encrypted_ll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212

1313
// The Lowlevel layer for SPI Flash Encryption.
14+
#pragma once
1415

1516
#include <stdbool.h>
1617
#include <string.h>

components/hal/esp32c6/include/hal/spi_flash_encrypted_ll.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212

1313
// The Lowlevel layer for SPI Flash Encryption.
14+
#pragma once
1415

1516
#include <stdbool.h>
1617
#include <string.h>
@@ -24,7 +25,7 @@
2425
extern "C" {
2526
#endif
2627

27-
/// Choose type of chip you want to encrypt manully
28+
/// Choose type of chip you want to encrypt manually
2829
typedef enum
2930
{
3031
FLASH_ENCRYPTION_MANU = 0, ///!< Manually encrypt the flash chip.
@@ -51,7 +52,7 @@ static inline void spi_flash_encrypt_ll_disable(void)
5152
}
5253

5354
/**
54-
* Choose type of chip you want to encrypt manully
55+
* Choose type of chip you want to encrypt manually
5556
*
5657
* @param type The type of chip to be encrypted
5758
*

components/hal/esp32c61/include/hal/spi_flash_encrypted_ll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212

1313
// The Lowlevel layer for SPI Flash Encryption.
14+
#pragma once
1415

1516
#include <stdbool.h>
1617
#include <string.h>

components/hal/esp32h2/include/hal/spi_flash_encrypted_ll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212

1313
// The Lowlevel layer for SPI Flash Encryption.
14+
#pragma once
1415

1516
#include <stdbool.h>
1617
#include <string.h>

components/hal/esp32h21/include/hal/spi_flash_encrypted_ll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
******************************************************************************/
1212

1313
// The Lowlevel layer for SPI Flash Encryption.
14+
#pragma once
1415

1516
#include <stdbool.h>
1617
#include <string.h>

0 commit comments

Comments
 (0)