diff --git a/components/esp_rom/CMakeLists.txt b/components/esp_rom/CMakeLists.txt index 5bdf6c77570..9f9c3bfbcf9 100644 --- a/components/esp_rom/CMakeLists.txt +++ b/components/esp_rom/CMakeLists.txt @@ -24,18 +24,6 @@ else() "patches/esp_rom_efuse.c" "patches/esp_rom_gpio.c") - if(NOT BOOTLOADER_BUILD) - if(CONFIG_HEAP_TLSF_USE_ROM_IMPL AND CONFIG_ESP_ROM_TLSF_CHECK_PATCH) - # This file shall be included in the build if TLSF in ROM is activated - list(APPEND sources "patches/esp_rom_tlsf.c") - endif() - - if(CONFIG_HEAP_TLSF_USE_ROM_IMPL AND CONFIG_ESP_ROM_MULTI_HEAP_WALK_PATCH) - # This file shall be included in the build if TLSF in ROM is activated - list(APPEND sources "patches/esp_rom_multi_heap.c") - endif() - endif() - list(APPEND private_required_comp soc hal esp_hal_uart) endif() @@ -119,7 +107,6 @@ if(CONFIG_ESP_ROM_HAS_VERSION) endif() if(ESP_TEE_BUILD) - rom_linker_script("heap") if(CONFIG_LIBC_NEWLIB AND CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT) rom_linker_script("newlib-nano") endif() @@ -347,22 +334,6 @@ else() # Regular app build endif() endif() - if(CONFIG_HEAP_TLSF_USE_ROM_IMPL) - # After registering the component, set the tlsf_set_rom_patches symbol as undefined - # to force the linker to integrate the whole `esp_rom_tlsf.c` object file inside the - # final binary. This is necessary because tlsf_set_rom_patches is a constructor, thus, - # there as no explicit reference/call to it in IDF. - if((CONFIG_ESP_ROM_TLSF_CHECK_PATCH OR CONFIG_HEAP_TLSF_CHECK_PATCH)) - target_link_libraries(${COMPONENT_LIB} PRIVATE "-u tlsf_set_rom_patches") - endif() - - if((CONFIG_ESP_ROM_TLSF_CHECK_PATCH OR CONFIG_ESP_ROM_MULTI_HEAP_WALK_PATCH)) - target_link_libraries(${COMPONENT_LIB} PRIVATE "-u esp_rom_include_multi_heap_patch") - endif() - - rom_linker_script("heap") - endif() - if(CONFIG_SPI_FLASH_ROM_IMPL) # Older targets do not have a separate ld file for spiflash if(NOT target STREQUAL "esp32c3" AND NOT target STREQUAL "esp32s3" AND NOT target STREQUAL "esp32c2") diff --git a/components/esp_tee/subproject/main/CMakeLists.txt b/components/esp_tee/subproject/main/CMakeLists.txt index 1e6396a0049..9c0f7e3f366 100644 --- a/components/esp_tee/subproject/main/CMakeLists.txt +++ b/components/esp_tee/subproject/main/CMakeLists.txt @@ -58,6 +58,7 @@ list(APPEND srcs "common/multi_heap.c") # TLSF implementation for heap list(APPEND include "${heap_dir}/tlsf") +list(APPEND include "${heap_dir}/rom_patches/include") # esp_app_desc_t configuration structure for TEE list(APPEND srcs "common/esp_app_desc_tee.c") diff --git a/components/esp_tee/subproject/main/common/multi_heap.c b/components/esp_tee/subproject/main/common/multi_heap.c index ec0b1975155..536a4ae5cec 100644 --- a/components/esp_tee/subproject/main/common/multi_heap.c +++ b/components/esp_tee/subproject/main/common/multi_heap.c @@ -6,7 +6,7 @@ #include #include #include -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #include "esp_rom_sys.h" #include "tlsf_block_functions.h" #include "multi_heap.h" diff --git a/components/esp_tee/subproject/main/ld/esp_tee_ld.cmake b/components/esp_tee/subproject/main/ld/esp_tee_ld.cmake index e7569ed498f..f780497f062 100644 --- a/components/esp_tee/subproject/main/ld/esp_tee_ld.cmake +++ b/components/esp_tee/subproject/main/ld/esp_tee_ld.cmake @@ -13,6 +13,9 @@ set(ld_output "${CMAKE_CURRENT_BINARY_DIR}/ld/esp_tee.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "${ld_output}") +idf_component_get_property(heap_dir heap COMPONENT_DIR) +target_linker_script(${COMPONENT_LIB} INTERFACE "${heap_dir}/port/${target}/ld/${target}.rom.heap.ld") + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ld") # Preprocess esp_tee.ld.in linker script to include configuration, becomes esp_tee.ld diff --git a/components/esp_tee/test_apps/tee_test_fw/components/test_sec_srv/src/test_heap.c b/components/esp_tee/test_apps/tee_test_fw/components/test_sec_srv/src/test_heap.c index 457cb31e235..efdb03241a8 100644 --- a/components/esp_tee/test_apps/tee_test_fw/components/test_sec_srv/src/test_heap.c +++ b/components/esp_tee/test_apps/tee_test_fw/components/test_sec_srv/src/test_heap.c @@ -5,7 +5,7 @@ */ #include "esp_rom_sys.h" #include "multi_heap.h" -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" typedef struct { int *ptr; diff --git a/components/heap/CMakeLists.txt b/components/heap/CMakeLists.txt index af111087661..23b8563df27 100644 --- a/components/heap/CMakeLists.txt +++ b/components/heap/CMakeLists.txt @@ -13,7 +13,7 @@ set(srcs "heap_caps_base.c" "multi_heap.c") # the root dir of TLSF submodule contains headers with static inline -# functions used in the esp_rom component for TLSF patches. Therefore, +# functions used in the heap ROM patches. Therefore, # the tlsf/ dir must be included in the list of public includes. set(includes "include" "tlsf") @@ -49,6 +49,21 @@ endif() if(NOT BOOTLOADER_BUILD) list(APPEND srcs "port/memory_layout_utils.c") list(APPEND srcs "port/${target}/memory_layout.c") + + if(CONFIG_HEAP_TLSF_USE_ROM_IMPL) + list(APPEND includes "rom_patches/include" + "rom_patches/${target}") + + if(CONFIG_ESP_ROM_TLSF_CHECK_PATCH) + # This file shall be included in the build if TLSF in ROM is activated + list(APPEND srcs "rom_patches/rom_patch_tlsf.c") + endif() + + if(CONFIG_ESP_ROM_MULTI_HEAP_WALK_PATCH) + # This file shall be included in the build if TLSF in ROM is activated + list(APPEND srcs "rom_patches/rom_patch_multi_heap.c") + endif() + endif() endif() idf_component_register(SRCS "${srcs}" @@ -57,6 +72,22 @@ idf_component_register(SRCS "${srcs}" LDFRAGMENTS linker.lf PRIV_REQUIRES soc) +if(CONFIG_HEAP_TLSF_USE_ROM_IMPL AND NOT BOOTLOADER_BUILD) + # After registering the component, set the tlsf_set_rom_patches symbol as undefined + # to force the linker to integrate the whole rom_patch_tlsf.c object file inside the + # final binary. This is necessary because tlsf_set_rom_patches is a constructor, thus, + # there is no explicit reference/call to it in IDF. + if(CONFIG_ESP_ROM_TLSF_CHECK_PATCH) + target_link_libraries(${COMPONENT_LIB} PRIVATE "-u tlsf_set_rom_patches") + endif() + + if(CONFIG_ESP_ROM_MULTI_HEAP_WALK_PATCH) + target_link_libraries(${COMPONENT_LIB} PRIVATE "-u esp_rom_include_multi_heap_patch") + endif() + + target_linker_script(${COMPONENT_LIB} INTERFACE "port/${target}/ld/${target}.rom.heap.ld") +endif() + if(CONFIG_HEAP_TRACING) set(WRAP_FUNCTIONS heap_caps_realloc_base diff --git a/components/heap/multi_heap_poisoning.c b/components/heap/multi_heap_poisoning.c index 402df83db42..c171b9f8d1a 100644 --- a/components/heap/multi_heap_poisoning.c +++ b/components/heap/multi_heap_poisoning.c @@ -27,7 +27,7 @@ * fill and check memory region with given patterns in the heap * components. */ -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #endif #ifdef MULTI_HEAP_POISONING diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.heap.ld b/components/heap/port/esp32c2/ld/esp32c2.rom.heap.ld similarity index 100% rename from components/esp_rom/esp32c2/ld/esp32c2.rom.heap.ld rename to components/heap/port/esp32c2/ld/esp32c2.rom.heap.ld diff --git a/components/esp_rom/esp32c5/ld/esp32c5.rom.heap.ld b/components/heap/port/esp32c5/ld/esp32c5.rom.heap.ld similarity index 100% rename from components/esp_rom/esp32c5/ld/esp32c5.rom.heap.ld rename to components/heap/port/esp32c5/ld/esp32c5.rom.heap.ld diff --git a/components/esp_rom/esp32c6/ld/esp32c6.rom.heap.ld b/components/heap/port/esp32c6/ld/esp32c6.rom.heap.ld similarity index 100% rename from components/esp_rom/esp32c6/ld/esp32c6.rom.heap.ld rename to components/heap/port/esp32c6/ld/esp32c6.rom.heap.ld diff --git a/components/esp_rom/esp32c61/ld/esp32c61.rom.heap.ld b/components/heap/port/esp32c61/ld/esp32c61.rom.heap.ld similarity index 100% rename from components/esp_rom/esp32c61/ld/esp32c61.rom.heap.ld rename to components/heap/port/esp32c61/ld/esp32c61.rom.heap.ld diff --git a/components/esp_rom/esp32h2/ld/esp32h2.rom.heap.ld b/components/heap/port/esp32h2/ld/esp32h2.rom.heap.ld similarity index 100% rename from components/esp_rom/esp32h2/ld/esp32h2.rom.heap.ld rename to components/heap/port/esp32h2/ld/esp32h2.rom.heap.ld diff --git a/components/esp_rom/esp32h21/ld/esp32h21.rom.heap.ld b/components/heap/port/esp32h21/ld/esp32h21.rom.heap.ld similarity index 100% rename from components/esp_rom/esp32h21/ld/esp32h21.rom.heap.ld rename to components/heap/port/esp32h21/ld/esp32h21.rom.heap.ld diff --git a/components/esp_rom/esp32h4/ld/esp32h4.rom.heap.ld b/components/heap/port/esp32h4/ld/esp32h4.rom.heap.ld similarity index 100% rename from components/esp_rom/esp32h4/ld/esp32h4.rom.heap.ld rename to components/heap/port/esp32h4/ld/esp32h4.rom.heap.ld diff --git a/components/esp_rom/esp32s31/ld/esp32s31.rom.heap.ld b/components/heap/port/esp32s31/ld/esp32s31.rom.heap.ld similarity index 100% rename from components/esp_rom/esp32s31/ld/esp32s31.rom.heap.ld rename to components/heap/port/esp32s31/ld/esp32s31.rom.heap.ld diff --git a/components/esp_rom/esp32c2/esp_rom_heap_tlsf_stub_table.h b/components/heap/rom_patches/esp32c2/esp_rom_heap_tlsf_stub_table.h similarity index 98% rename from components/esp_rom/esp32c2/esp_rom_heap_tlsf_stub_table.h rename to components/heap/rom_patches/esp32c2/esp_rom_heap_tlsf_stub_table.h index 8ab496a6a37..370840d9c6a 100644 --- a/components/esp_rom/esp32c2/esp_rom_heap_tlsf_stub_table.h +++ b/components/heap/rom_patches/esp32c2/esp_rom_heap_tlsf_stub_table.h @@ -8,7 +8,7 @@ #pragma once #include -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_rom/esp32c5/esp_rom_heap_tlsf_stub_table.h b/components/heap/rom_patches/esp32c5/esp_rom_heap_tlsf_stub_table.h similarity index 98% rename from components/esp_rom/esp32c5/esp_rom_heap_tlsf_stub_table.h rename to components/heap/rom_patches/esp32c5/esp_rom_heap_tlsf_stub_table.h index 79ec6dbb54f..d4d0c1bf4c8 100644 --- a/components/esp_rom/esp32c5/esp_rom_heap_tlsf_stub_table.h +++ b/components/heap/rom_patches/esp32c5/esp_rom_heap_tlsf_stub_table.h @@ -8,7 +8,7 @@ #pragma once #include -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_rom/esp32c6/esp_rom_heap_tlsf_stub_table.h b/components/heap/rom_patches/esp32c6/esp_rom_heap_tlsf_stub_table.h similarity index 98% rename from components/esp_rom/esp32c6/esp_rom_heap_tlsf_stub_table.h rename to components/heap/rom_patches/esp32c6/esp_rom_heap_tlsf_stub_table.h index 1297940fd94..f63013c4a08 100644 --- a/components/esp_rom/esp32c6/esp_rom_heap_tlsf_stub_table.h +++ b/components/heap/rom_patches/esp32c6/esp_rom_heap_tlsf_stub_table.h @@ -8,7 +8,7 @@ #pragma once #include -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_rom/esp32c61/esp_rom_heap_tlsf_stub_table.h b/components/heap/rom_patches/esp32c61/esp_rom_heap_tlsf_stub_table.h similarity index 98% rename from components/esp_rom/esp32c61/esp_rom_heap_tlsf_stub_table.h rename to components/heap/rom_patches/esp32c61/esp_rom_heap_tlsf_stub_table.h index 472b5b086e9..fe6c2ae19bf 100644 --- a/components/esp_rom/esp32c61/esp_rom_heap_tlsf_stub_table.h +++ b/components/heap/rom_patches/esp32c61/esp_rom_heap_tlsf_stub_table.h @@ -8,7 +8,7 @@ #pragma once #include -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_rom/esp32h2/esp_rom_heap_tlsf_stub_table.h b/components/heap/rom_patches/esp32h2/esp_rom_heap_tlsf_stub_table.h similarity index 98% rename from components/esp_rom/esp32h2/esp_rom_heap_tlsf_stub_table.h rename to components/heap/rom_patches/esp32h2/esp_rom_heap_tlsf_stub_table.h index dfedf90477f..c5cbef5279a 100644 --- a/components/esp_rom/esp32h2/esp_rom_heap_tlsf_stub_table.h +++ b/components/heap/rom_patches/esp32h2/esp_rom_heap_tlsf_stub_table.h @@ -8,7 +8,7 @@ #pragma once #include -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_rom/esp32h21/esp_rom_heap_tlsf_stub_table.h b/components/heap/rom_patches/esp32h21/esp_rom_heap_tlsf_stub_table.h similarity index 98% rename from components/esp_rom/esp32h21/esp_rom_heap_tlsf_stub_table.h rename to components/heap/rom_patches/esp32h21/esp_rom_heap_tlsf_stub_table.h index c7771d64420..f3573f7e30a 100644 --- a/components/esp_rom/esp32h21/esp_rom_heap_tlsf_stub_table.h +++ b/components/heap/rom_patches/esp32h21/esp_rom_heap_tlsf_stub_table.h @@ -8,7 +8,7 @@ #pragma once #include -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_rom/esp32h4/esp_rom_heap_tlsf_stub_table.h b/components/heap/rom_patches/esp32h4/esp_rom_heap_tlsf_stub_table.h similarity index 98% rename from components/esp_rom/esp32h4/esp_rom_heap_tlsf_stub_table.h rename to components/heap/rom_patches/esp32h4/esp_rom_heap_tlsf_stub_table.h index 2301e84144d..27e2604f44d 100644 --- a/components/esp_rom/esp32h4/esp_rom_heap_tlsf_stub_table.h +++ b/components/heap/rom_patches/esp32h4/esp_rom_heap_tlsf_stub_table.h @@ -8,7 +8,7 @@ #pragma once #include -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_rom/esp32s31/esp_rom_heap_tlsf_stub_table.h b/components/heap/rom_patches/esp32s31/esp_rom_heap_tlsf_stub_table.h similarity index 98% rename from components/esp_rom/esp32s31/esp_rom_heap_tlsf_stub_table.h rename to components/heap/rom_patches/esp32s31/esp_rom_heap_tlsf_stub_table.h index 3f72f32284e..82a7578c67a 100644 --- a/components/esp_rom/esp32s31/esp_rom_heap_tlsf_stub_table.h +++ b/components/heap/rom_patches/esp32s31/esp_rom_heap_tlsf_stub_table.h @@ -8,7 +8,7 @@ #pragma once #include -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_rom/include/esp_rom_multi_heap.h b/components/heap/rom_patches/include/rom_patch_multi_heap.h similarity index 100% rename from components/esp_rom/include/esp_rom_multi_heap.h rename to components/heap/rom_patches/include/rom_patch_multi_heap.h diff --git a/components/esp_rom/include/esp_rom_tlsf.h b/components/heap/rom_patches/include/rom_patch_tlsf.h similarity index 100% rename from components/esp_rom/include/esp_rom_tlsf.h rename to components/heap/rom_patches/include/rom_patch_tlsf.h diff --git a/components/esp_rom/patches/esp_rom_multi_heap.c b/components/heap/rom_patches/rom_patch_multi_heap.c similarity index 98% rename from components/esp_rom/patches/esp_rom_multi_heap.c rename to components/heap/rom_patches/rom_patch_multi_heap.c index ae7aee1988a..a6093f94d75 100644 --- a/components/esp_rom/patches/esp_rom_multi_heap.c +++ b/components/heap/rom_patches/rom_patch_multi_heap.c @@ -15,8 +15,8 @@ #include #include "sdkconfig.h" -#include "esp_rom_multi_heap.h" -#include "esp_rom_tlsf.h" +#include "rom_patch_tlsf.h" +#include "rom_patch_multi_heap.h" // Hook to force the linker to include this file void esp_rom_include_multi_heap_patch(void) diff --git a/components/esp_rom/patches/esp_rom_tlsf.c b/components/heap/rom_patches/rom_patch_tlsf.c similarity index 99% rename from components/esp_rom/patches/esp_rom_tlsf.c rename to components/heap/rom_patches/rom_patch_tlsf.c index 522f0fa4078..63c9b23e8ec 100644 --- a/components/esp_rom/patches/esp_rom_tlsf.c +++ b/components/heap/rom_patches/rom_patch_tlsf.c @@ -19,8 +19,7 @@ #include #include "esp_rom_caps.h" -#include "esp_rom_tlsf.h" -#include "esp_rom_sys.h" +#include "rom_patch_tlsf.h" #include "tlsf_block_functions.h" #include "tlsf_control_functions.h"