2019-06-13 05:55:51 -04:00
|
|
|
idf_build_get_property(target IDF_TARGET)
|
|
|
|
|
2024-06-11 03:29:21 -04:00
|
|
|
set(target_folder "${target}")
|
2024-02-20 02:40:55 -05:00
|
|
|
|
2024-05-22 10:42:03 -04:00
|
|
|
set(include_dirs "include"
|
2024-06-19 00:09:05 -04:00
|
|
|
"${target_folder}/include"
|
|
|
|
"${target_folder}/include/${target_folder}"
|
2024-05-22 10:42:03 -04:00
|
|
|
"${target_folder}")
|
2021-06-02 23:59:00 -04:00
|
|
|
|
|
|
|
set(private_required_comp "")
|
|
|
|
|
2024-05-22 10:42:03 -04:00
|
|
|
set(sources "patches/esp_rom_sys.c"
|
|
|
|
"patches/esp_rom_print.c")
|
2021-06-02 23:59:00 -04:00
|
|
|
|
|
|
|
if(target STREQUAL "linux")
|
|
|
|
list(APPEND sources "${target}/esp_rom_sys.c"
|
|
|
|
"${target}/esp_rom_crc.c"
|
|
|
|
"${target}/esp_rom_md5.c"
|
|
|
|
"${target}/esp_rom_efuse.c")
|
|
|
|
else()
|
|
|
|
list(APPEND sources "patches/esp_rom_crc.c"
|
2021-08-27 03:28:48 -04:00
|
|
|
"patches/esp_rom_uart.c"
|
2021-09-28 07:35:36 -04:00
|
|
|
"patches/esp_rom_spiflash.c"
|
2022-07-21 07:14:26 -04:00
|
|
|
"patches/esp_rom_efuse.c")
|
2022-08-12 05:28:16 -04:00
|
|
|
|
2022-11-17 02:34:27 -05:00
|
|
|
|
2022-12-03 08:48:01 -05:00
|
|
|
# Override regi2c implementation in ROM
|
2023-02-06 08:41:33 -05:00
|
|
|
if(CONFIG_ESP_ROM_HAS_REGI2C_BUG OR CONFIG_ESP_ROM_WITHOUT_REGI2C)
|
2023-11-09 04:23:50 -05:00
|
|
|
if(target STREQUAL "esp32c6" OR target STREQUAL "esp32c5")
|
2024-06-05 22:55:16 -04:00
|
|
|
list(APPEND sources "patches/esp_rom_hp_regi2c_${target}.c")
|
2023-06-19 06:04:03 -04:00
|
|
|
else()
|
|
|
|
list(APPEND sources "patches/esp_rom_regi2c_${target}.c")
|
|
|
|
endif()
|
2022-12-03 08:48:01 -05:00
|
|
|
endif()
|
2022-11-17 02:34:27 -05:00
|
|
|
|
2024-03-19 08:56:32 -04:00
|
|
|
if(CONFIG_HEAP_TLSF_USE_ROM_IMPL AND CONFIG_ESP_ROM_TLSF_CHECK_PATCH)
|
2022-08-29 07:46:49 -04:00
|
|
|
# This file shall be included in the build if TLSF in ROM is activated
|
2022-08-12 05:28:16 -04:00
|
|
|
list(APPEND sources "patches/esp_rom_tlsf.c")
|
|
|
|
endif()
|
|
|
|
|
2024-02-14 07:03:09 -05:00
|
|
|
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()
|
|
|
|
|
2021-06-02 23:59:00 -04:00
|
|
|
list(APPEND private_required_comp soc hal)
|
|
|
|
endif()
|
2021-04-08 00:16:17 -04:00
|
|
|
|
2021-06-10 23:56:58 -04:00
|
|
|
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
|
2021-04-08 00:16:17 -04:00
|
|
|
list(APPEND sources "patches/esp_rom_longjmp.S")
|
|
|
|
endif()
|
|
|
|
|
2022-07-24 23:27:42 -04:00
|
|
|
if(CONFIG_SOC_SYSTIMER_SUPPORTED)
|
|
|
|
list(APPEND sources "patches/esp_rom_systimer.c")
|
|
|
|
endif()
|
|
|
|
|
2023-01-12 22:36:19 -05:00
|
|
|
if(CONFIG_HAL_WDT_USE_ROM_IMPL)
|
|
|
|
list(APPEND sources "patches/esp_rom_wdt.c")
|
|
|
|
endif()
|
|
|
|
|
2024-06-14 00:03:51 -04:00
|
|
|
if(CONFIG_ESP_ROM_CLIC_INT_TYPE_PATCH)
|
2023-12-27 21:54:19 -05:00
|
|
|
list(APPEND sources "patches/esp_rom_clic.c")
|
|
|
|
endif()
|
2024-02-14 07:03:09 -05:00
|
|
|
|
2023-07-10 22:46:59 -04:00
|
|
|
if(CONFIG_ESP_ROM_HAS_FLASH_COUNT_PAGES_BUG OR CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG)
|
2023-06-16 02:04:00 -04:00
|
|
|
list(APPEND sources "patches/esp_rom_cache_esp32s2_esp32s3.c")
|
|
|
|
endif()
|
|
|
|
|
2023-07-17 02:30:26 -04:00
|
|
|
if(CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG)
|
|
|
|
list(APPEND sources "patches/esp_rom_cache_writeback_esp32s3.S")
|
|
|
|
endif()
|
|
|
|
|
2021-04-08 00:16:17 -04:00
|
|
|
idf_component_register(SRCS ${sources}
|
2021-06-02 23:59:00 -04:00
|
|
|
INCLUDE_DIRS ${include_dirs}
|
2021-09-28 07:35:36 -04:00
|
|
|
PRIV_REQUIRES ${private_required_comp}
|
|
|
|
LDFRAGMENTS linker.lf)
|
2019-11-28 08:10:31 -05:00
|
|
|
|
2023-04-13 02:32:25 -04:00
|
|
|
set(ld_folder "ld")
|
2021-10-24 23:46:16 -04:00
|
|
|
|
2020-11-17 18:28:10 -05:00
|
|
|
# Append a target linker script at the target-specific path,
|
|
|
|
# only the 'name' part is different for each script
|
|
|
|
function(rom_linker_script name)
|
2024-02-20 02:40:55 -05:00
|
|
|
target_linker_script(${COMPONENT_LIB} INTERFACE "${target_folder}/${ld_folder}/${target}.rom.${name}.ld")
|
2020-11-17 18:28:10 -05:00
|
|
|
endfunction()
|
|
|
|
|
2021-06-02 23:59:00 -04:00
|
|
|
if(target STREQUAL "linux")
|
|
|
|
# We need to disable some warnings due to the ROM code's printf implementation
|
2021-11-15 18:06:57 -05:00
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION} GREATER "7.0.0")
|
|
|
|
target_compile_options(${COMPONENT_LIB} PRIVATE -Wimplicit-fallthrough=0 -Wno-shift-count-overflow)
|
|
|
|
endif()
|
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang") # Clang or AppleClang
|
|
|
|
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-integer-overflow -Wno-shift-count-overflow)
|
2021-06-02 23:59:00 -04:00
|
|
|
endif()
|
|
|
|
else()
|
2024-02-20 02:40:55 -05:00
|
|
|
target_linker_script(${COMPONENT_LIB} INTERFACE "${target_folder}/${ld_folder}/${target}.rom.ld")
|
2021-06-02 23:59:00 -04:00
|
|
|
rom_linker_script("api")
|
2022-07-12 08:28:06 -04:00
|
|
|
|
2022-05-08 05:57:40 -04:00
|
|
|
if(CONFIG_COMPILER_FLOAT_LIB_FROM_GCCLIB)
|
|
|
|
rom_linker_script("libgcc")
|
|
|
|
else()
|
|
|
|
rom_linker_script("rvfp")
|
|
|
|
endif()
|
2021-06-02 23:59:00 -04:00
|
|
|
endif()
|
2020-11-17 18:28:10 -05:00
|
|
|
|
2024-03-01 02:53:20 -05:00
|
|
|
# Common API which is linked both for bootloader and app builds
|
|
|
|
|
|
|
|
if(CONFIG_HAL_WDT_USE_ROM_IMPL)
|
|
|
|
rom_linker_script("wdt")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_HAL_SYSTIMER_USE_ROM_IMPL)
|
|
|
|
rom_linker_script("systimer")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_ESP_ROM_HAS_VERSION)
|
|
|
|
rom_linker_script("version")
|
|
|
|
endif()
|
2022-01-06 12:02:09 -05:00
|
|
|
|
2019-03-14 05:29:32 -04:00
|
|
|
if(BOOTLOADER_BUILD)
|
2020-11-17 18:28:10 -05:00
|
|
|
if(target STREQUAL "esp32")
|
2021-09-01 15:12:49 -04:00
|
|
|
if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
|
2024-03-01 02:53:20 -05:00
|
|
|
rom_linker_script("spiflash_legacy")
|
2021-09-01 15:12:49 -04:00
|
|
|
endif()
|
2022-03-17 09:58:15 -04:00
|
|
|
if(CONFIG_ESP32_REV_MIN_FULL GREATER_EQUAL 300)
|
2020-11-17 18:28:10 -05:00
|
|
|
rom_linker_script("eco3")
|
|
|
|
endif()
|
2020-11-25 23:47:32 -05:00
|
|
|
|
2020-11-17 18:28:10 -05:00
|
|
|
elseif(target STREQUAL "esp32s2")
|
2024-03-01 02:53:20 -05:00
|
|
|
rom_linker_script("spiflash_legacy")
|
|
|
|
endif()
|
2023-07-11 04:54:13 -04:00
|
|
|
|
2024-03-01 02:53:20 -05:00
|
|
|
if(CONFIG_ESP_ROM_HAS_NEWLIB)
|
|
|
|
if(target STREQUAL "esp32" OR target STREQUAL "esp32s2")
|
|
|
|
rom_linker_script("newlib-funcs")
|
|
|
|
else()
|
|
|
|
rom_linker_script("newlib")
|
2024-02-29 23:03:50 -05:00
|
|
|
endif()
|
2020-11-25 23:47:32 -05:00
|
|
|
endif()
|
2019-06-13 05:55:51 -04:00
|
|
|
|
2024-03-01 02:53:20 -05:00
|
|
|
|
2020-11-17 18:28:10 -05:00
|
|
|
else() # Regular app build
|
2019-11-28 08:10:31 -05:00
|
|
|
if(target STREQUAL "esp32")
|
2020-11-17 18:28:10 -05:00
|
|
|
rom_linker_script("newlib-data")
|
|
|
|
rom_linker_script("syscalls")
|
2019-03-14 05:29:32 -04:00
|
|
|
|
2019-05-27 02:29:43 -04:00
|
|
|
if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND)
|
2022-01-06 12:02:09 -05:00
|
|
|
# ESP32 only: these ROM functions may only be used if PSRAM cache workaround is disabled.
|
|
|
|
# Otherwise we need to link to a multilib version of libc compiled with PSRAM workaround.
|
2020-11-17 18:28:10 -05:00
|
|
|
rom_linker_script("newlib-funcs")
|
2019-05-27 02:29:43 -04:00
|
|
|
endif()
|
2019-03-14 05:29:32 -04:00
|
|
|
|
2019-05-27 02:29:43 -04:00
|
|
|
if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
|
2024-03-01 02:53:20 -05:00
|
|
|
# For ESP32, inclusion of ROM driver do not depend on CONFIG_SPI_FLASH_ROM_IMPL
|
|
|
|
rom_linker_script("spiflash_legacy")
|
2019-05-27 02:29:43 -04:00
|
|
|
endif()
|
2019-03-29 00:37:51 -04:00
|
|
|
|
2022-03-17 09:58:15 -04:00
|
|
|
if(CONFIG_ESP32_REV_MIN_FULL GREATER_EQUAL 300)
|
2020-11-17 18:28:10 -05:00
|
|
|
rom_linker_script("eco3")
|
2020-02-24 14:51:41 -05:00
|
|
|
endif()
|
|
|
|
|
2020-01-16 22:47:08 -05:00
|
|
|
elseif(target STREQUAL "esp32s2")
|
2020-11-17 18:28:10 -05:00
|
|
|
rom_linker_script("newlib-funcs")
|
|
|
|
rom_linker_script("newlib-data")
|
esp_rom: remove functions which depend on sizeof(struct stat)
...and all their callers.
With the upcoming switch from sizeof(time_t)==4 to sizeof(time_t)==8,
sizeof(struct stat) is also increasing.
A few newlib functions present in ROM allocate 'struct stat' on the
stack and call _fstat_r on this structure. The implementation of
fstat is provided in ESP-IDF. This implementation will often do
memset(st, 0, sizeof(*st)), where st is 'struct stat*', before setting
some fields of this structure. If IDF is built with sizeof(st)
different from sizeof(st) which ROM was built with, this will lead
to an out-of-bounds write and a stack corruption.
This commit removes problematic ROM functions from the linker script.
Here are the functions which allocate 'struct stat':
* _isatty_r (in ROM)
* __swhatbuf_r, called by __smakebuf_r, called by __swsetup_r and
__srefill_r (in ROM)
* _fseeko_r (not in ROM)
* glob2 (not in ROM)
* _gettemp (not in ROM)
As a result, these functions are used from libc.a, and use correct
size of 'stat' structure.
Closes https://github.com/espressif/esp-idf/issues/7980
2022-01-06 09:20:04 -05:00
|
|
|
|
2024-03-01 02:53:20 -05:00
|
|
|
# For ESP32S2, inclusion of ROM driver do not depend on CONFIG_SPI_FLASH_ROM_IMPL
|
|
|
|
rom_linker_script("spiflash_legacy")
|
2020-06-10 07:07:48 -04:00
|
|
|
|
2020-11-25 23:47:32 -05:00
|
|
|
elseif(target STREQUAL "esp32c3")
|
2021-03-02 22:57:58 -05:00
|
|
|
|
2022-03-17 09:58:15 -04:00
|
|
|
if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 3)
|
2021-03-02 22:57:58 -05:00
|
|
|
rom_linker_script("eco3")
|
|
|
|
endif()
|
2021-06-10 00:53:34 -04:00
|
|
|
|
2023-09-20 07:09:49 -04:00
|
|
|
if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 101)
|
|
|
|
rom_linker_script("eco7")
|
|
|
|
endif()
|
|
|
|
|
2022-07-12 08:28:06 -04:00
|
|
|
elseif(target STREQUAL "esp32c6")
|
2022-11-02 07:46:55 -04:00
|
|
|
# esp32c6.rom.api.ld has been split to several lds by components.
|
2023-11-30 07:08:51 -05:00
|
|
|
# esp32c6.rom.api.ld is still reserved to map the APIs
|
2022-11-02 07:46:55 -04:00
|
|
|
rom_linker_script("phy")
|
|
|
|
rom_linker_script("coexist")
|
|
|
|
rom_linker_script("net80211")
|
|
|
|
rom_linker_script("pp")
|
2024-07-02 09:47:19 -04:00
|
|
|
elseif(target STREQUAL "esp32c5")
|
|
|
|
# esp32c5.rom.api.ld has been split to several lds by components.
|
|
|
|
# esp32c5.rom.api.ld is still reserved to map the APIs
|
|
|
|
rom_linker_script("phy")
|
|
|
|
rom_linker_script("coexist")
|
|
|
|
rom_linker_script("net80211")
|
|
|
|
rom_linker_script("pp")
|
2024-03-01 02:53:20 -05:00
|
|
|
endif()
|
2022-11-02 07:46:55 -04:00
|
|
|
|
2024-07-02 09:47:19 -04:00
|
|
|
|
2024-03-01 02:53:20 -05:00
|
|
|
if(CONFIG_ESP_ROM_HAS_NEWLIB AND NOT target STREQUAL "esp32" AND NOT target STREQUAL "esp32s2")
|
|
|
|
# ESP32 and S2 are a bit different, keep them as special cases in the target specific include section
|
2023-11-09 04:23:50 -05:00
|
|
|
rom_linker_script("newlib")
|
|
|
|
|
2024-03-01 02:53:20 -05:00
|
|
|
if(CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT AND CONFIG_NEWLIB_NANO_FORMAT)
|
2024-05-20 04:10:57 -04:00
|
|
|
if(NOT CONFIG_ESP_ROM_HAS_NEWLIB_32BIT_TIME AND NOT CONFIG_ESP_ROM_HAS_NEWLIB_NANO_PRINTF_FLOAT_BUG)
|
2024-03-01 02:53:20 -05:00
|
|
|
# Newlib-nano functions contains time_t related functions
|
|
|
|
# and cannot be used if they were compiled with 32 bit time_t
|
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
2023-11-09 04:23:50 -05:00
|
|
|
endif()
|
|
|
|
|
2024-03-01 02:53:20 -05:00
|
|
|
if(CONFIG_ESP_ROM_HAS_NEWLIB_NORMAL_FORMAT AND NOT CONFIG_NEWLIB_NANO_FORMAT)
|
2023-01-28 21:09:02 -05:00
|
|
|
rom_linker_script("newlib-normal")
|
2022-12-01 07:27:51 -05:00
|
|
|
endif()
|
2022-07-12 08:28:06 -04:00
|
|
|
endif()
|
2022-08-29 07:46:49 -04:00
|
|
|
|
2022-07-12 08:28:06 -04:00
|
|
|
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.
|
2023-10-20 09:23:10 -04:00
|
|
|
if((CONFIG_ESP_ROM_TLSF_CHECK_PATCH OR CONFIG_HEAP_TLSF_CHECK_PATCH))
|
2022-07-12 08:28:06 -04:00
|
|
|
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u tlsf_set_rom_patches")
|
2021-03-19 05:29:42 -04:00
|
|
|
endif()
|
2022-07-12 08:28:06 -04:00
|
|
|
|
2024-02-14 07:03:09 -05:00
|
|
|
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()
|
|
|
|
|
2022-07-12 08:28:06 -04:00
|
|
|
rom_linker_script("heap")
|
2019-03-14 05:29:32 -04:00
|
|
|
endif()
|
2019-05-27 02:29:43 -04:00
|
|
|
|
2024-03-01 02:53:20 -05:00
|
|
|
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")
|
|
|
|
rom_linker_script("spiflash")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL)
|
|
|
|
rom_linker_script("mbedtls")
|
|
|
|
endif()
|
|
|
|
|
2021-06-10 23:56:58 -04:00
|
|
|
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
|
2021-04-08 00:16:17 -04:00
|
|
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=longjmp")
|
|
|
|
endif()
|
2019-03-14 05:29:32 -04:00
|
|
|
endif()
|
2020-04-30 09:19:56 -04:00
|
|
|
|
|
|
|
if(target STREQUAL "esp32s2")
|
2022-01-18 14:48:37 -05:00
|
|
|
target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_patches.c")
|
2020-04-30 09:19:56 -04:00
|
|
|
endif()
|