summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2023-07-28 12:16:05 +1000
committerDamien George <damien@micropython.org>2023-08-15 10:49:33 +1000
commit98fd78437c56efeebe2e38c944f5af0a1a59fe8a (patch)
treea1d6df3baae870047baf453a378c1c8b47012484
parent519c24dd48764f28593112dbeac7e30b8b2a6240 (diff)
esp32: Allow malloc() to allocate from SPIRAM.
Also shrinks the "prefer internal" threshold to 8KB, any allocation larger than this will try PSRAM first. Change the mbedTLS config to use regular malloc() as well, instead of internal only. The default is set to internal-only due to to potential physical security issue of readout via PSRAM on the original ESP32. However, as MicroPython runs from plaintext flash and all other context is in the MP heap of PSRAM then it's hard to see how worsens physical security for MP. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
-rw-r--r--ports/esp32/boards/sdkconfig.base9
-rw-r--r--ports/esp32/boards/sdkconfig.spiram6
-rw-r--r--ports/esp32/boards/sdkconfig.spiram_sx6
3 files changed, 19 insertions, 2 deletions
diff --git a/ports/esp32/boards/sdkconfig.base b/ports/esp32/boards/sdkconfig.base
index bf6c3f45c..b98d5d067 100644
--- a/ports/esp32/boards/sdkconfig.base
+++ b/ports/esp32/boards/sdkconfig.base
@@ -49,6 +49,15 @@ CONFIG_LWIP_PPP_CHAP_SUPPORT=y
# Use 4kiB output buffer instead of default 16kiB
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
+# Allow mbedTLS to allocate from PSRAM or internal memory
+#
+# (The ESP-IDF default is internal-only, partly for physical security to prevent
+# possible information leakage from unencrypted PSRAM contents on the original
+# ESP32 - no PSRAM encryption on that chip. MicroPython doesn't support flash
+# encryption and is already storing the Python heap in PSRAM so this isn't a
+# significant factor in overall physical security.)
+CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
+
# ULP coprocessor support
# Only on: ESP32, ESP32S2, ESP32S3
CONFIG_ULP_COPROC_ENABLED=y
diff --git a/ports/esp32/boards/sdkconfig.spiram b/ports/esp32/boards/sdkconfig.spiram
index 74d35f7b4..4dfc63624 100644
--- a/ports/esp32/boards/sdkconfig.spiram
+++ b/ports/esp32/boards/sdkconfig.spiram
@@ -3,7 +3,11 @@
CONFIG_SPIRAM=y
CONFIG_SPIRAM_CACHE_WORKAROUND=y
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
-CONFIG_SPIRAM_USE_CAPS_ALLOC=y
+CONFIG_SPIRAM_USE_MALLOC=y
+
+# This is the threshold for preferring small allocations from internal memory
+# first, before failing over to PSRAM.
+CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=8192
# SPIRAM increases the size of the firmware and overflows iram0_0_seg, due
# to PSRAM bug workarounds. Apply some options to reduce the firmware size.
diff --git a/ports/esp32/boards/sdkconfig.spiram_sx b/ports/esp32/boards/sdkconfig.spiram_sx
index 329a50733..efe53ada4 100644
--- a/ports/esp32/boards/sdkconfig.spiram_sx
+++ b/ports/esp32/boards/sdkconfig.spiram_sx
@@ -7,4 +7,8 @@ CONFIG_SPIRAM_SPEED_80M=y
CONFIG_SPIRAM=y
CONFIG_SPIRAM_BOOT_INIT=y
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
-CONFIG_SPIRAM_USE_CAPS_ALLOC=y
+CONFIG_SPIRAM_USE_MALLOC=y
+
+# This is the threshold for preferring small allocations from internal memory
+# first, before failing over to PSRAM.
+CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=8192