8000 esp32: Allow malloc() to allocate from SPIRAM. · jimmo/micropython@98fd784 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98fd784

Browse files
projectgusdpgeorge
authored andcommitted
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>
1 parent 519c24d commit 98fd784

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

ports/esp32/boards/sdkconfig.base

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ CONFIG_LWIP_PPP_CHAP_SUPPORT=y
4949
# Use 4kiB output buffer instead of default 16kiB
5050
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
5151

52+
# Allow mbedTLS to allocate from PSRAM or internal memory
53+
#
54+
# (The ESP-IDF default is internal-only, partly for physical security to prevent
55+
# possible information leakage from unencrypted PSRAM contents on the original
56+
# ESP32 - no PSRAM encryption on that chip. MicroPython doesn't support flash
57+
# encryption and is already storing the Python heap in PSRAM so this isn't a
58+
# significant factor in overall physical security.)
59+
CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
60+
5261
# ULP coprocessor support
5362
# Only on: ESP32, ESP32S2, ESP32S3
5463
CONFIG_ULP_COPROC_ENABLED=y

ports/esp32/boards/sdkconfig.spiram

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
CONFIG_SPIRAM=y
44
CONFIG_SPIRAM_CACHE_WORKAROUND=y
55
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
6-
CONFIG_SPIRAM_USE_CAPS_ALLOC=y
6+
CONFIG_SPIRAM_USE_MALLOC=y
7+
8+
# This is the threshold for preferring small allocations from internal memory
9+
# first, before failing over to PSRAM.
10+
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=8192
711

812
# SPIRAM increases the size of the firmware and overflows iram0_0_seg, due
913
# to PSRAM bug workarounds. Apply some options to reduce the firmware size.

ports/esp32/boards/sdkconfig.spiram_sx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ CONFIG_SPIRAM_SPEED_80M=y
77
CONFIG_SPIRAM=y
88
CONFIG_SPIRAM_BOOT_INIT=y
99
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
10-
CONFIG_SPIRAM_USE_CAPS_ALLOC=y
10+
CONFIG_SPIRAM_USE_MALLOC=y
11+
12+
# This is the threshold for preferring small allocations from internal memory
13+
# first, before failing over to PSRAM.
14+
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=8192

0 commit comments

Comments
 (0)
0