From 85bb7a1428c0e1404b8f4c21fb3a32ab611f08a1 Mon Sep 17 00:00:00 2001 From: Sachin Parekh Date: Tue, 21 Apr 2020 02:53:49 +0530 Subject: [PATCH] esp32/mbedtls: Added in/out buffer allocation strategy "Internal IRAM" strategy allocates in/out buffers in IRAM thus saving memory in DRAM. --- .../espressif/boards/esp32/components/mbedtls/Kconfig | 11 +++++++++++ .../boards/esp32/components/mbedtls/port/esp_mem.c | 10 ++++++++++ vendors/espressif/esp-idf | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/vendors/espressif/boards/esp32/components/mbedtls/Kconfig b/vendors/espressif/boards/esp32/components/mbedtls/Kconfig index 42c5aeff162..e9d75794826 100644 --- a/vendors/espressif/boards/esp32/components/mbedtls/Kconfig +++ b/vendors/espressif/boards/esp32/components/mbedtls/Kconfig @@ -13,6 +13,7 @@ choice MBEDTLS_MEM_ALLOC_MODE behavior in ESP-IDF - Custom allocation mode, by overwriting calloc()/free() using mbedtls_platform_set_calloc_free() function + - Internal IRAM memory wherever applicable else internal DRAM Recommended mode here is always internal, since that is most preferred from security perspective. But if application requirement does not @@ -32,6 +33,16 @@ config MBEDTLS_DEFAULT_MEM_ALLOC config MBEDTLS_CUSTOM_MEM_ALLOC bool "Custom alloc mode" +config MBEDTLS_IRAM_8BIT_MEM_ALLOC + bool "Internal IRAM" + depends on ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY + help + Allows to use IRAM memory region as 8bit accessible region. + + TLS input and output buffers will be allocated in IRAM section which is 32bit aligned + memory. Every unaligned (8bit or 16bit) access will result in an exception + and incur penalty of certain clock cycles per unaligned read/write. + endchoice #MBEDTLS_MEM_ALLOC_MODE config MBEDTLS_SSL_MAX_CONTENT_LEN diff --git a/vendors/espressif/boards/esp32/components/mbedtls/port/esp_mem.c b/vendors/espressif/boards/esp32/components/mbedtls/port/esp_mem.c index c7b8e706f98..ef9392e25b4 100644 --- a/vendors/espressif/boards/esp32/components/mbedtls/port/esp_mem.c +++ b/vendors/espressif/boards/esp32/components/mbedtls/port/esp_mem.c @@ -25,6 +25,16 @@ IRAM_ATTR void *esp_mbedtls_mem_calloc(size_t n, size_t size) return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #elif CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); +#elif CONFIG_MBEDTLS_IRAM_8BIT_MEM_ALLOC +#ifdef CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN + if ((n*size) >= CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN || (n*size) >= CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN) { +#else + if ((n*size) >= CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN) { +#endif + return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + } else { + return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + } #else return calloc(n, size); #endif diff --git a/vendors/espressif/esp-idf b/vendors/espressif/esp-idf index e7e0ead31ea..09b15376213 160000 --- a/vendors/espressif/esp-idf +++ b/vendors/espressif/esp-idf @@ -1 +1 @@ -Subproject commit e7e0ead31eaa6dc07d5b133fb0dacb7c9a45b355 +Subproject commit 09b1537621338bd5518dae055d40cd986a3b5084