feat(heap): move TLSF ROM patches and related files from esp_rom to heap

The TLSF ROM patch code (rom_patch_tlsf.c, rom_patch_multi_heap.c),
their headers, and the per-target *.rom.heap.ld linker scripts are
semantically owned by the heap component, not esp_rom. Move them
accordingly:

- components/esp_rom/patches/esp_rom_tlsf.c
  → components/heap/rom_patches/rom_patch_tlsf.c
- components/esp_rom/patches/esp_rom_multi_heap.c
  → components/heap/rom_patches/rom_patch_multi_heap.c
- components/esp_rom/include/esp_rom_tlsf.h
  → components/heap/rom_patches/include/rom_patch_tlsf.h
- components/esp_rom/include/esp_rom_multi_heap.h
  → components/heap/rom_patches/include/rom_patch_multi_heap.h
- components/esp_rom/<target>/ld/<target>.rom.heap.ld (×8)
  → components/heap/port/<target>/ld/<target>.rom.heap.ld

Update heap/CMakeLists.txt to:
- use target_linker_script() directly for *.rom.heap.ld
- guard post-registration ROM patch setup with NOT BOOTLOADER_BUILD
- drop stale CONFIG_HEAP_TLSF_CHECK_PATCH symbol reference
- drop esp_rom_include_multi_heap_patch from TLSF_CHECK_PATCH guard

Remove the corresponding entries from esp_rom/CMakeLists.txt.
This commit is contained in:
Guillaume Souchere
2026-04-23 12:21:31 +02:00
parent 3f3ef6f08e
commit a56354e9ab
27 changed files with 50 additions and 45 deletions
-29
View File
@@ -24,18 +24,6 @@ else()
"patches/esp_rom_efuse.c" "patches/esp_rom_efuse.c"
"patches/esp_rom_gpio.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) list(APPEND private_required_comp soc hal esp_hal_uart)
endif() endif()
@@ -119,7 +107,6 @@ if(CONFIG_ESP_ROM_HAS_VERSION)
endif() endif()
if(ESP_TEE_BUILD) if(ESP_TEE_BUILD)
rom_linker_script("heap")
if(CONFIG_LIBC_NEWLIB AND CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT) if(CONFIG_LIBC_NEWLIB AND CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT)
rom_linker_script("newlib-nano") rom_linker_script("newlib-nano")
endif() endif()
@@ -347,22 +334,6 @@ else() # Regular app build
endif() endif()
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) if(CONFIG_SPI_FLASH_ROM_IMPL)
# Older targets do not have a separate ld file for spiflash # 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") if(NOT target STREQUAL "esp32c3" AND NOT target STREQUAL "esp32s3" AND NOT target STREQUAL "esp32c2")
@@ -58,6 +58,7 @@ list(APPEND srcs "common/multi_heap.c")
# TLSF implementation for heap # TLSF implementation for heap
list(APPEND include "${heap_dir}/tlsf") list(APPEND include "${heap_dir}/tlsf")
list(APPEND include "${heap_dir}/rom_patches/include")
# esp_app_desc_t configuration structure for TEE # esp_app_desc_t configuration structure for TEE
list(APPEND srcs "common/esp_app_desc_tee.c") list(APPEND srcs "common/esp_app_desc_tee.c")
@@ -6,7 +6,7 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#include "esp_rom_sys.h" #include "esp_rom_sys.h"
#include "tlsf_block_functions.h" #include "tlsf_block_functions.h"
#include "multi_heap.h" #include "multi_heap.h"
@@ -13,6 +13,9 @@ set(ld_output "${CMAKE_CURRENT_BINARY_DIR}/ld/esp_tee.ld")
target_linker_script(${COMPONENT_LIB} INTERFACE "${ld_output}") 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") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ld")
# Preprocess esp_tee.ld.in linker script to include configuration, becomes esp_tee.ld # Preprocess esp_tee.ld.in linker script to include configuration, becomes esp_tee.ld
@@ -5,7 +5,7 @@
*/ */
#include "esp_rom_sys.h" #include "esp_rom_sys.h"
#include "multi_heap.h" #include "multi_heap.h"
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
typedef struct { typedef struct {
int *ptr; int *ptr;
+32 -1
View File
@@ -13,7 +13,7 @@ set(srcs "heap_caps_base.c"
"multi_heap.c") "multi_heap.c")
# the root dir of TLSF submodule contains headers with static inline # 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. # the tlsf/ dir must be included in the list of public includes.
set(includes "include" set(includes "include"
"tlsf") "tlsf")
@@ -49,6 +49,21 @@ endif()
if(NOT BOOTLOADER_BUILD) if(NOT BOOTLOADER_BUILD)
list(APPEND srcs "port/memory_layout_utils.c") list(APPEND srcs "port/memory_layout_utils.c")
list(APPEND srcs "port/${target}/memory_layout.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() endif()
idf_component_register(SRCS "${srcs}" idf_component_register(SRCS "${srcs}"
@@ -57,6 +72,22 @@ idf_component_register(SRCS "${srcs}"
LDFRAGMENTS linker.lf LDFRAGMENTS linker.lf
PRIV_REQUIRES soc) 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) if(CONFIG_HEAP_TRACING)
set(WRAP_FUNCTIONS set(WRAP_FUNCTIONS
heap_caps_realloc_base heap_caps_realloc_base
+1 -1
View File
@@ -27,7 +27,7 @@
* fill and check memory region with given patterns in the heap * fill and check memory region with given patterns in the heap
* components. * components.
*/ */
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#endif #endif
#ifdef MULTI_HEAP_POISONING #ifdef MULTI_HEAP_POISONING
@@ -8,7 +8,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -8,7 +8,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -8,7 +8,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -8,7 +8,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -8,7 +8,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -8,7 +8,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -8,7 +8,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -8,7 +8,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -15,8 +15,8 @@
#include <assert.h> #include <assert.h>
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_rom_multi_heap.h" #include "rom_patch_tlsf.h"
#include "esp_rom_tlsf.h" #include "rom_patch_multi_heap.h"
// Hook to force the linker to include this file // Hook to force the linker to include this file
void esp_rom_include_multi_heap_patch(void) void esp_rom_include_multi_heap_patch(void)
@@ -19,8 +19,7 @@
#include <assert.h> #include <assert.h>
#include "esp_rom_caps.h" #include "esp_rom_caps.h"
#include "esp_rom_tlsf.h" #include "rom_patch_tlsf.h"
#include "esp_rom_sys.h"
#include "tlsf_block_functions.h" #include "tlsf_block_functions.h"
#include "tlsf_control_functions.h" #include "tlsf_control_functions.h"