Skip to content

Commit 4f8f974

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'bugfix/psram_enc_workaround_v5.5' into 'release/v5.5'
fix(psram): provide boot warning about PSRAM encryption issue on C5/C61 (v5.5) See merge request espressif/esp-idf!41163
2 parents 0f07209 + 29df728 commit 4f8f974

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

components/esp_psram/Kconfig.spiram.common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ choice SPIRAM_USE
6969
return SPI RAM pointers.
7070

7171
config SPIRAM_USE_MEMMAP
72+
depends on IDF_TARGET_ESP32
7273
bool "Integrate RAM into memory map"
7374
config SPIRAM_USE_CAPS_ALLOC
7475
bool "Make RAM allocatable using heap_caps_malloc(..., MALLOC_CAP_SPIRAM)"

components/esp_psram/system_layer/esp_psram.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ static const DRAM_ATTR char TAG[] = "esp_psram";
114114
ESP_SYSTEM_INIT_FN(add_psram_to_heap, CORE, BIT(0), 103)
115115
{
116116
#if CONFIG_SPIRAM_BOOT_INIT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC)
117+
118+
#if (CONFIG_IDF_TARGET_ESP32C5 && CONFIG_ESP32C5_REV_MIN_FULL <= 100) || (CONFIG_IDF_TARGET_ESP32C61 && CONFIG_ESP32C61_REV_MIN_FULL <= 100)
119+
ESP_EARLY_LOGW(TAG, "Due to hardware issue on ESP32-C5/C61 (Rev v1.0), PSRAM contents won't be encrypted (for flash encryption enabled case)");
120+
ESP_EARLY_LOGW(TAG, "Please avoid using PSRAM for security sensitive data e.g., TLS stack allocations (CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC)");
121+
#endif
117122
if (esp_psram_is_initialized()) {
118123
esp_err_t r = esp_psram_extram_add_to_heap_allocator();
119124
if (r != ESP_OK) {
@@ -383,6 +388,10 @@ esp_err_t esp_psram_init(void)
383388
__attribute__((unused)) uint32_t start_page = 0;
384389

385390
#if CONFIG_SPIRAM_FETCH_INSTRUCTIONS || CONFIG_SPIRAM_RODATA
391+
#if (CONFIG_IDF_TARGET_ESP32C5 && CONFIG_ESP32C5_REV_MIN_FULL <= 100) || (CONFIG_IDF_TARGET_ESP32C61 && CONFIG_ESP32C61_REV_MIN_FULL <= 100)
392+
ESP_EARLY_LOGW(TAG, "Due to hardware issue on ESP32-C5/C61 (Rev v1.0), PSRAM contents won't be encrypted (for flash encryption enabled case)");
393+
ESP_EARLY_LOGW(TAG, "Please avoid using PSRAM for execution as the code/rodata shall be copied as plaintext and this could pose a security risk.");
394+
#endif
386395
s_xip_psram_placement(&psram_available_size, &start_page);
387396
#endif
388397

components/hal/esp32c5/include/hal/mmu_ll.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "hal/mmu_types.h"
1818
#if SOC_EFUSE_SUPPORTED
1919
#include "hal/efuse_ll.h"
20+
#include "hal/efuse_hal.h"
2021
#endif
2122

2223

@@ -214,7 +215,10 @@ __attribute__((always_inline)) static inline void mmu_ll_write_entry(uint32_t mm
214215
{
215216
uint32_t mmu_raw_value;
216217
if (mmu_ll_cache_encryption_enabled()) {
217-
mmu_val |= SOC_MMU_SENSITIVE;
218+
// For PSRAM case, avoid encryption due to a bug in the hardware
219+
if (!(target == MMU_TARGET_PSRAM0 && efuse_hal_chip_revision() <= 100)) {
220+
mmu_val |= SOC_MMU_SENSITIVE;
221+
}
218222
}
219223
mmu_val |= (target == MMU_TARGET_FLASH0) ? SOC_MMU_ACCESS_FLASH : SOC_MMU_ACCESS_SPIRAM;
220224

components/hal/esp32c61/include/hal/mmu_ll.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "hal/assert.h"
1414
#include "hal/mmu_types.h"
1515
#include "hal/efuse_ll.h"
16+
#include "hal/efuse_hal.h"
1617

1718
// TODO: [ESP32C61] IDF-9265, inherit from c6
1819

@@ -216,7 +217,10 @@ __attribute__((always_inline)) static inline void mmu_ll_write_entry(uint32_t mm
216217
(void)mmu_id;
217218
uint32_t mmu_raw_value;
218219
if (mmu_ll_cache_encryption_enabled()) {
219-
mmu_val |= SOC_MMU_SENSITIVE;
220+
// For PSRAM case, avoid encryption due to a bug in the hardware
221+
if (!(target == MMU_TARGET_PSRAM0 && efuse_hal_chip_revision() <= 100)) {
222+
mmu_val |= SOC_MMU_SENSITIVE;
223+
}
220224
}
221225
mmu_val |= (target == MMU_TARGET_FLASH0) ? SOC_MMU_ACCESS_FLASH : SOC_MMU_ACCESS_SPIRAM;
222226

0 commit comments

Comments
 (0)