From 068adfba70f969cfa0baf0c023dd5653755f380e Mon Sep 17 00:00:00 2001 From: morris Date: Fri, 6 May 2022 19:20:05 +0800 Subject: [PATCH] heap: use ROM implementation for heap tlsf on esp32c2 --- components/esp_rom/CMakeLists.txt | 2 +- components/esp_rom/esp32c2/Kconfig.soc_caps.in | 4 ++++ components/esp_rom/esp32c2/esp_rom_caps.h | 1 + components/heap/CMakeLists.txt | 2 +- components/heap/Kconfig | 11 +++-------- components/heap/heap_caps_init.c | 2 +- components/heap/linker.lf | 2 +- components/heap/multi_heap.c | 6 +++--- components/heap/multi_heap_poisoning.c | 2 +- docs/en/api-guides/performance/size.rst | 8 ++++++++ 10 files changed, 24 insertions(+), 16 deletions(-) diff --git a/components/esp_rom/CMakeLists.txt b/components/esp_rom/CMakeLists.txt index 17eecab140..44d9365029 100644 --- a/components/esp_rom/CMakeLists.txt +++ b/components/esp_rom/CMakeLists.txt @@ -200,7 +200,7 @@ else() # Regular app build rom_linker_script("newlib-nano") endif() - if(CONFIG_HEAP_ROM_IMPL) + if(CONFIG_HEAP_TLSF_USE_ROM_IMPL) rom_linker_script("heap") endif() endif() diff --git a/components/esp_rom/esp32c2/Kconfig.soc_caps.in b/components/esp_rom/esp32c2/Kconfig.soc_caps.in index 0eebf6d89a..b6e13da822 100644 --- a/components/esp_rom/esp32c2/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32c2/Kconfig.soc_caps.in @@ -34,3 +34,7 @@ config ESP_ROM_HAS_HAL_WDT config ESP_ROM_HAS_HAL_SYSTIMER bool default y + +config ESP_ROM_HAS_HEAP_TLSF + bool + default y diff --git a/components/esp_rom/esp32c2/esp_rom_caps.h b/components/esp_rom/esp32c2/esp_rom_caps.h index dfc376b77d..eee69daaaa 100644 --- a/components/esp_rom/esp32c2/esp_rom_caps.h +++ b/components/esp_rom/esp32c2/esp_rom_caps.h @@ -14,3 +14,4 @@ #define ESP_ROM_HAS_RVFPLIB (1) // ROM has the rvfplib #define ESP_ROM_HAS_HAL_WDT (1) // ROM has the implementation of Watchdog HAL driver #define ESP_ROM_HAS_HAL_SYSTIMER (1) // ROM has the implementation of Systimer HAL driver +#define ESP_ROM_HAS_HEAP_TLSF (1) // ROM has the implementation of the tlsf and multi-heap library diff --git a/components/heap/CMakeLists.txt b/components/heap/CMakeLists.txt index ceedec32e7..66e32e9cee 100644 --- a/components/heap/CMakeLists.txt +++ b/components/heap/CMakeLists.txt @@ -3,7 +3,7 @@ set(srcs "heap_caps_init.c" "multi_heap.c") -if(NOT CONFIG_HEAP_ROM_IMPL) +if(NOT CONFIG_HEAP_TLSF_USE_ROM_IMPL) list(APPEND srcs "heap_tlsf.c") endif() diff --git a/components/heap/Kconfig b/components/heap/Kconfig index 67720aa3ca..f19574a691 100644 --- a/components/heap/Kconfig +++ b/components/heap/Kconfig @@ -71,14 +71,9 @@ menu "Heap memory debugging" help When enabled, if a memory allocation operation fails it will cause a system abort. - config HEAP_HAS_ROM_IMPL - bool - depends on IDF_TARGET_ESP32C2 - default y if IDF_TARGET_ESP32C2 - - config HEAP_ROM_IMPL - bool "Use heap implementation in ROM" - depends on HEAP_HAS_ROM_IMPL + config HEAP_TLSF_USE_ROM_IMPL + bool "Use ROM implementation of heap tlsf library" + depends on ESP_ROM_HAS_HEAP_TLSF default y help Enable this flag to use heap functions from ROM instead of ESP-IDF. diff --git a/components/heap/heap_caps_init.c b/components/heap/heap_caps_init.c index bbefa0482a..75556dd155 100644 --- a/components/heap/heap_caps_init.c +++ b/components/heap/heap_caps_init.c @@ -49,7 +49,7 @@ void heap_caps_enable_nonos_stack_heaps(void) */ void heap_caps_init(void) { -#ifdef CONFIG_HEAP_ROM_IMPL +#ifdef CONFIG_HEAP_TLSF_USE_ROM_IMPL extern void multi_heap_in_rom_init(void); multi_heap_in_rom_init(); #endif diff --git a/components/heap/linker.lf b/components/heap/linker.lf index 31cf88aa9e..55b6465205 100644 --- a/components/heap/linker.lf +++ b/components/heap/linker.lf @@ -1,7 +1,7 @@ [mapping:heap] archive: libheap.a entries: - if HEAP_HAS_ROM_IMPL = n || HEAP_ROM_IMPL = n: + if HEAP_TLSF_USE_ROM_IMPL = n: heap_tlsf (noflash) multi_heap (noflash) if HEAP_POISONING_DISABLED = n: diff --git a/components/heap/multi_heap.c b/components/heap/multi_heap.c index a4b3997620..2f28b0c574 100644 --- a/components/heap/multi_heap.c +++ b/components/heap/multi_heap.c @@ -22,7 +22,7 @@ /* Defines compile-time configuration macros */ #include "multi_heap_config.h" -#if (!defined MULTI_HEAP_POISONING) && (!defined CONFIG_HEAP_ROM_IMPL) +#if (!defined MULTI_HEAP_POISONING) && (!defined CONFIG_HEAP_TLSF_USE_ROM_IMPL) /* if no heap poisoning, public API aliases directly to these implementations */ void *multi_heap_malloc(multi_heap_handle_t heap, size_t size) __attribute__((alias("multi_heap_malloc_impl"))); @@ -77,7 +77,7 @@ typedef struct multi_heap_info { tlsf_t heap_data; } heap_t; -#ifdef CONFIG_HEAP_ROM_IMPL +#ifdef CONFIG_HEAP_TLSF_USE_ROM_IMPL void _multi_heap_lock(void *lock) { @@ -99,7 +99,7 @@ void multi_heap_in_rom_init(void) multi_heap_os_funcs_init(&multi_heap_os_funcs); } -#else //#ifndef CONFIG_HEAP_ROM_IMPL +#else //#ifndef CONFIG_HEAP_TLSF_USE_ROM_IMPL /* Return true if this block is free. */ static inline bool is_free(const block_header_t *block) diff --git a/components/heap/multi_heap_poisoning.c b/components/heap/multi_heap_poisoning.c index 31dfc69452..45f95cde7c 100644 --- a/components/heap/multi_heap_poisoning.c +++ b/components/heap/multi_heap_poisoning.c @@ -334,7 +334,7 @@ multi_heap_handle_t multi_heap_register(void *start, size_t size) memset(start, FREE_FILL_PATTERN, size); } #endif -#ifdef CONFIG_HEAP_ROM_IMPL +#ifdef CONFIG_HEAP_TLSF_USE_ROM_IMPL tlsf_poison_fill_pfunc_set(multi_heap_internal_poison_fill_region); #endif return multi_heap_register_impl(start, size); diff --git a/docs/en/api-guides/performance/size.rst b/docs/en/api-guides/performance/size.rst index adebc8f23b..fae92c0cd5 100644 --- a/docs/en/api-guides/performance/size.rst +++ b/docs/en/api-guides/performance/size.rst @@ -421,6 +421,14 @@ VFS :CONFIG_ESP_ROM_HAS_HAL_SYSTIMER: * Enabling :ref:`CONFIG_HAL_SYSTIMER_USE_ROM_IMPL` can reduce the IRAM usage and binary size by linking in the systimer HAL driver of ROM implementation. :CONFIG_ESP_ROM_HAS_HAL_WDT: * Enabling :ref:`CONFIG_HAL_WDT_USE_ROM_IMPL` can reduce the IRAM usage and binary size by linking in the watchdog HAL driver of ROM implementation. +.. only:: esp32c2 + + Heap + @@@@ + + .. list:: + + :CONFIG_ESP_ROM_HAS_HEAP_TLSF: * Enabling :ref:`CONFIG_HEAP_TLSF_USE_ROM_IMPL` can reduce the IRAM usage and binary size by linking in the TLSF library of ROM implementation. Bootloader Size ---------------