2019-06-13 17:55:51 +08:00
|
|
|
idf_build_get_property(target IDF_TARGET)
|
|
|
|
|
2021-06-03 11:59:00 +08:00
|
|
|
set(include_dirs "include" "include/${target}")
|
|
|
|
|
|
|
|
set(private_required_comp "")
|
|
|
|
|
|
|
|
set(sources "")
|
|
|
|
|
|
|
|
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")
|
2022-07-21 19:14:26 +08:00
|
|
|
list(APPEND include_dirs "${IDF_PATH}/tools/mocks/soc/include")
|
2021-06-03 11:59:00 +08:00
|
|
|
else()
|
|
|
|
list(APPEND include_dirs "${target}")
|
|
|
|
list(APPEND sources "patches/esp_rom_crc.c"
|
|
|
|
"patches/esp_rom_sys.c"
|
2021-08-27 15:28:48 +08:00
|
|
|
"patches/esp_rom_uart.c"
|
2021-09-28 19:35:36 +08:00
|
|
|
"patches/esp_rom_spiflash.c"
|
2022-07-21 19:14:26 +08:00
|
|
|
"patches/esp_rom_efuse.c")
|
2022-08-12 11:28:16 +02:00
|
|
|
|
2022-11-17 15:34:27 +08:00
|
|
|
|
2022-12-03 21:48:01 +08:00
|
|
|
# Override regi2c implementation in ROM
|
2023-02-06 21:41:33 +08:00
|
|
|
if(CONFIG_ESP_ROM_HAS_REGI2C_BUG OR CONFIG_ESP_ROM_WITHOUT_REGI2C)
|
2023-06-19 18:04:03 +08:00
|
|
|
if(target STREQUAL "esp32c6")
|
|
|
|
list(APPEND sources "patches/esp_rom_hp_regi2c_${target}.c")
|
|
|
|
else()
|
|
|
|
list(APPEND sources "patches/esp_rom_regi2c_${target}.c")
|
|
|
|
endif()
|
2022-12-03 21:48:01 +08:00
|
|
|
endif()
|
2022-11-17 15:34:27 +08:00
|
|
|
|
2023-10-20 15:23:10 +02:00
|
|
|
if(CONFIG_HEAP_TLSF_USE_ROM_IMPL AND (CONFIG_ESP_ROM_TLSF_CHECK_PATCH OR CONFIG_HEAP_TLSF_CHECK_PATCH))
|
2022-08-29 19:46:49 +08:00
|
|
|
# This file shall be included in the build if TLSF in ROM is activated
|
2022-08-12 11:28:16 +02:00
|
|
|
list(APPEND sources "patches/esp_rom_tlsf.c")
|
|
|
|
endif()
|
|
|
|
|
2021-06-03 11:59:00 +08:00
|
|
|
list(APPEND private_required_comp soc hal)
|
|
|
|
endif()
|
2021-04-08 12:16:17 +08:00
|
|
|
|
2021-06-11 11:56:58 +08:00
|
|
|
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
|
2021-04-08 12:16:17 +08:00
|
|
|
list(APPEND sources "patches/esp_rom_longjmp.S")
|
|
|
|
endif()
|
|
|
|
|
2022-07-25 11:27:42 +08:00
|
|
|
if(CONFIG_SOC_SYSTIMER_SUPPORTED)
|
|
|
|
list(APPEND sources "patches/esp_rom_systimer.c")
|
|
|
|
endif()
|
|
|
|
|
2023-01-13 11:36:19 +08:00
|
|
|
if(CONFIG_HAL_WDT_USE_ROM_IMPL)
|
|
|
|
list(APPEND sources "patches/esp_rom_wdt.c")
|
|
|
|
endif()
|
|
|
|
|
2023-07-21 11:28:12 +08:00
|
|
|
if(CONFIG_ESP_ROM_HAS_FLASH_COUNT_PAGES_BUG OR CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG)
|
2023-06-19 10:44:41 +08:00
|
|
|
list(APPEND sources "patches/esp_rom_cache_esp32s2_esp32s3.c")
|
|
|
|
endif()
|
|
|
|
|
2023-07-21 11:28:12 +08:00
|
|
|
if(CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG)
|
|
|
|
list(APPEND sources "patches/esp_rom_cache_writeback_esp32s3.S")
|
|
|
|
endif()
|
|
|
|
|
2021-04-08 12:16:17 +08:00
|
|
|
idf_component_register(SRCS ${sources}
|
2021-06-03 11:59:00 +08:00
|
|
|
INCLUDE_DIRS ${include_dirs}
|
2021-09-28 19:35:36 +08:00
|
|
|
PRIV_REQUIRES ${private_required_comp}
|
|
|
|
LDFRAGMENTS linker.lf)
|
2019-11-28 21:10:31 +08:00
|
|
|
|
2023-04-13 14:32:25 +08:00
|
|
|
set(ld_folder "ld")
|
2021-10-25 11:46:16 +08:00
|
|
|
|
2020-11-18 10:28:10 +11: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)
|
2021-11-16 20:15:12 +08:00
|
|
|
target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/${ld_folder}/${target}.rom.${name}.ld")
|
2020-11-18 10:28:10 +11:00
|
|
|
endfunction()
|
|
|
|
|
2021-06-03 11:59:00 +08:00
|
|
|
if(target STREQUAL "linux")
|
|
|
|
# We need to disable some warnings due to the ROM code's printf implementation
|
2021-11-16 00:06:57 +01: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-03 11:59:00 +08:00
|
|
|
endif()
|
|
|
|
else()
|
2021-11-16 20:15:12 +08:00
|
|
|
target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/${ld_folder}/${target}.rom.ld")
|
2021-06-03 11:59:00 +08:00
|
|
|
rom_linker_script("api")
|
2022-07-12 20:28:06 +08:00
|
|
|
|
2022-05-08 17:57:40 +08:00
|
|
|
if(CONFIG_COMPILER_FLOAT_LIB_FROM_GCCLIB)
|
|
|
|
rom_linker_script("libgcc")
|
|
|
|
else()
|
|
|
|
rom_linker_script("rvfp")
|
|
|
|
endif()
|
2021-06-03 11:59:00 +08:00
|
|
|
endif()
|
2020-11-18 10:28:10 +11:00
|
|
|
|
2022-01-06 18:02:09 +01:00
|
|
|
idf_build_get_property(time_t_size TIME_T_SIZE)
|
|
|
|
|
2019-03-14 17:29:32 +08:00
|
|
|
if(BOOTLOADER_BUILD)
|
2020-11-18 10:28:10 +11:00
|
|
|
if(target STREQUAL "esp32")
|
|
|
|
rom_linker_script("newlib-funcs")
|
2021-09-02 05:12:49 +10:00
|
|
|
if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
|
|
|
|
rom_linker_script("spiflash")
|
|
|
|
endif()
|
2022-03-17 21:58:15 +08:00
|
|
|
if(CONFIG_ESP32_REV_MIN_FULL GREATER_EQUAL 300)
|
2020-11-18 10:28:10 +11:00
|
|
|
rom_linker_script("eco3")
|
|
|
|
endif()
|
2020-11-26 15:47:32 +11:00
|
|
|
|
2020-11-18 10:28:10 +11:00
|
|
|
elseif(target STREQUAL "esp32s2")
|
|
|
|
rom_linker_script("newlib-funcs")
|
|
|
|
rom_linker_script("spiflash")
|
2019-08-08 13:44:24 +10:00
|
|
|
|
2020-11-18 10:28:10 +11:00
|
|
|
elseif(target STREQUAL "esp32s3")
|
2021-03-17 18:48:05 +08:00
|
|
|
rom_linker_script("newlib")
|
2020-06-10 19:07:48 +08:00
|
|
|
|
2020-11-18 10:28:10 +11:00
|
|
|
elseif(target STREQUAL "esp32c3")
|
2020-12-22 18:24:39 +11:00
|
|
|
rom_linker_script("newlib")
|
2021-06-10 12:53:34 +08:00
|
|
|
|
2022-01-18 10:32:56 +08:00
|
|
|
elseif(target STREQUAL "esp32c2")
|
2021-11-06 17:21:57 +08:00
|
|
|
rom_linker_script("newlib")
|
2022-07-12 20:28:06 +08:00
|
|
|
|
|
|
|
elseif(target STREQUAL "esp32c6")
|
|
|
|
rom_linker_script("newlib")
|
2022-11-02 19:46:55 +08:00
|
|
|
# The linking of the bootloader needs to use the rom_i2c_writeReg_Mask in esp32c6.rom.phy.ld
|
|
|
|
rom_linker_script("phy")
|
2023-02-17 14:51:00 +08:00
|
|
|
if(CONFIG_HAL_WDT_USE_ROM_IMPL)
|
|
|
|
rom_linker_script("wdt")
|
|
|
|
endif()
|
2023-01-09 22:32:19 +05:30
|
|
|
rom_linker_script("version")
|
2022-11-30 11:13:37 +08:00
|
|
|
|
|
|
|
elseif(target STREQUAL "esp32h2")
|
|
|
|
rom_linker_script("newlib")
|
2023-02-17 14:51:00 +08:00
|
|
|
if(CONFIG_HAL_WDT_USE_ROM_IMPL)
|
|
|
|
rom_linker_script("wdt")
|
|
|
|
endif()
|
2020-11-26 15:47:32 +11:00
|
|
|
endif()
|
2019-06-13 17:55:51 +08:00
|
|
|
|
2020-11-18 10:28:10 +11:00
|
|
|
else() # Regular app build
|
2019-11-28 21:10:31 +08:00
|
|
|
if(target STREQUAL "esp32")
|
2020-11-18 10:28:10 +11:00
|
|
|
rom_linker_script("newlib-data")
|
|
|
|
rom_linker_script("syscalls")
|
2019-03-14 17:29:32 +08:00
|
|
|
|
2019-05-27 14:29:43 +08:00
|
|
|
if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND)
|
2022-01-06 18:02:09 +01: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-18 10:28:10 +11:00
|
|
|
rom_linker_script("newlib-funcs")
|
2022-01-06 18:02:09 +01:00
|
|
|
|
|
|
|
if(time_t_size EQUAL 4)
|
|
|
|
# The ROM functions listed in this linker script depend on sizeof(time_t).
|
|
|
|
# Since ROM for ESP32 was compiled for 32-bit time_t, only link these functions
|
|
|
|
# if the toolchain is also using 32-bit time_t.
|
2020-11-18 10:28:10 +11:00
|
|
|
rom_linker_script("newlib-time")
|
2019-03-14 17:29:32 +08:00
|
|
|
|
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 15:20:04 +01:00
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
2022-01-06 18:02:09 +01:00
|
|
|
# nano formatting functions in ROM are also built for 32-bit time_t.
|
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 15:20:04 +01:00
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
|
|
|
endif()
|
2019-05-27 14:29:43 +08:00
|
|
|
endif()
|
2019-03-14 17:29:32 +08:00
|
|
|
|
2019-05-27 14:29:43 +08:00
|
|
|
if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
|
2020-11-18 10:28:10 +11:00
|
|
|
rom_linker_script("spiflash")
|
2019-05-27 14:29:43 +08:00
|
|
|
endif()
|
2019-03-29 12:37:51 +08:00
|
|
|
|
2022-03-17 21:58:15 +08:00
|
|
|
if(CONFIG_ESP32_REV_MIN_FULL GREATER_EQUAL 300)
|
2020-11-18 10:28:10 +11:00
|
|
|
rom_linker_script("eco3")
|
2020-02-25 01:21:41 +05:30
|
|
|
endif()
|
|
|
|
|
2020-01-17 11:47:08 +08:00
|
|
|
elseif(target STREQUAL "esp32s2")
|
2020-11-18 10:28:10 +11:00
|
|
|
rom_linker_script("newlib-funcs")
|
|
|
|
rom_linker_script("newlib-data")
|
|
|
|
rom_linker_script("spiflash")
|
2020-01-23 18:02:29 +01:00
|
|
|
|
2022-01-06 18:02:09 +01:00
|
|
|
if(time_t_size EQUAL 4)
|
|
|
|
# The ROM functions listed in this linker script depend on sizeof(time_t).
|
|
|
|
# Since ROM for ESP32-S2 was compiled for 32-bit time_t, only link these functions
|
|
|
|
# if the toolchain is also using 32-bit time_t.
|
|
|
|
rom_linker_script("newlib-time")
|
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 15:20:04 +01:00
|
|
|
|
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
2022-01-06 18:02:09 +01:00
|
|
|
# nano formatting functions in ROM are also built for 32-bit time_t.
|
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 15:20:04 +01:00
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
2020-01-23 18:02:29 +01:00
|
|
|
endif()
|
2020-06-10 19:07:48 +08:00
|
|
|
|
|
|
|
elseif(target STREQUAL "esp32s3")
|
2021-03-17 18:48:05 +08:00
|
|
|
rom_linker_script("newlib")
|
|
|
|
rom_linker_script("version")
|
2020-06-10 19:07:48 +08:00
|
|
|
|
2022-01-06 18:02:09 +01:00
|
|
|
if(time_t_size EQUAL 4)
|
|
|
|
# The ROM functions listed in this linker script depend on sizeof(time_t).
|
|
|
|
# Since ROM for ESP32-S3 was compiled for 32-bit time_t, only link these functions
|
|
|
|
# if the toolchain is also using 32-bit time_t.
|
|
|
|
rom_linker_script("newlib-time")
|
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 15:20:04 +01:00
|
|
|
|
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
2022-01-06 18:02:09 +01:00
|
|
|
# nano formatting functions in ROM are also built for 32-bit time_t.
|
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 15:20:04 +01:00
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
2020-06-10 19:07:48 +08:00
|
|
|
endif()
|
|
|
|
|
2020-11-26 15:47:32 +11:00
|
|
|
elseif(target STREQUAL "esp32c3")
|
2020-11-18 10:28:10 +11:00
|
|
|
rom_linker_script("newlib")
|
|
|
|
rom_linker_script("version")
|
2020-11-26 15:47:32 +11:00
|
|
|
|
2022-01-06 18:02:09 +01:00
|
|
|
if(time_t_size EQUAL 4)
|
|
|
|
# The ROM functions listed in this linker script depend on sizeof(time_t).
|
|
|
|
# Since ROM for ESP32-C3 was compiled for 32-bit time_t, only link these functions
|
|
|
|
# if the toolchain is also using 32-bit time_t.
|
|
|
|
rom_linker_script("newlib-time")
|
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 15:20:04 +01:00
|
|
|
|
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
2022-01-06 18:02:09 +01:00
|
|
|
# nano formatting functions in ROM are also built for 32-bit time_t.
|
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 15:20:04 +01:00
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
2020-11-26 15:47:32 +11:00
|
|
|
endif()
|
2021-03-03 11:57:58 +08:00
|
|
|
|
2022-03-17 21:58:15 +08:00
|
|
|
if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 3)
|
2021-03-03 11:57:58 +08:00
|
|
|
rom_linker_script("eco3")
|
|
|
|
endif()
|
2021-06-10 12:53:34 +08:00
|
|
|
|
2023-09-20 19:09:49 +08:00
|
|
|
if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 101)
|
|
|
|
rom_linker_script("eco7")
|
|
|
|
endif()
|
|
|
|
|
2022-01-18 10:32:56 +08:00
|
|
|
elseif(target STREQUAL "esp32c2")
|
2021-11-06 17:21:57 +08:00
|
|
|
rom_linker_script("newlib")
|
|
|
|
rom_linker_script("version")
|
2023-08-08 20:58:44 +08:00
|
|
|
|
|
|
|
if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL)
|
|
|
|
rom_linker_script("mbedtls")
|
|
|
|
endif()
|
2021-11-06 17:21:57 +08:00
|
|
|
|
2023-01-29 10:09:02 +08:00
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
|
|
|
# nano formatting functions in ROM are also built for 64-bit time_t.
|
|
|
|
rom_linker_script("newlib-nano")
|
2021-06-10 12:53:34 +08:00
|
|
|
endif()
|
2021-03-19 17:29:42 +08:00
|
|
|
|
2022-07-12 20:28:06 +08:00
|
|
|
elseif(target STREQUAL "esp32c6")
|
|
|
|
rom_linker_script("newlib")
|
|
|
|
rom_linker_script("version")
|
2022-11-02 19:46:55 +08:00
|
|
|
|
|
|
|
# esp32c6.rom.api.ld has been split to several lds by components.
|
|
|
|
rom_linker_script("phy")
|
|
|
|
rom_linker_script("coexist")
|
|
|
|
rom_linker_script("net80211")
|
|
|
|
rom_linker_script("pp")
|
|
|
|
|
|
|
|
if(CONFIG_SPI_FLASH_ROM_IMPL)
|
|
|
|
rom_linker_script("spiflash")
|
|
|
|
endif()
|
|
|
|
|
2023-01-13 11:36:19 +08:00
|
|
|
if(CONFIG_HAL_WDT_USE_ROM_IMPL)
|
|
|
|
rom_linker_script("wdt")
|
|
|
|
endif()
|
|
|
|
|
2023-01-29 10:09:02 +08:00
|
|
|
if(NOT CONFIG_NEWLIB_NANO_FORMAT)
|
|
|
|
# Normal(Non-nano) formatting functions in ROM are also built for 64-bit time_t.
|
|
|
|
rom_linker_script("newlib-normal")
|
2022-12-01 20:27:51 +08:00
|
|
|
endif()
|
2022-11-02 19:49:48 +08:00
|
|
|
|
2022-11-30 11:13:37 +08:00
|
|
|
elseif(target STREQUAL "esp32h2")
|
2022-12-01 20:27:51 +08:00
|
|
|
rom_linker_script("newlib")
|
|
|
|
rom_linker_script("version")
|
|
|
|
|
|
|
|
if(CONFIG_SPI_FLASH_ROM_IMPL)
|
|
|
|
rom_linker_script("spiflash")
|
|
|
|
endif()
|
2023-02-17 14:51:00 +08:00
|
|
|
|
|
|
|
if(CONFIG_HAL_WDT_USE_ROM_IMPL)
|
|
|
|
rom_linker_script("wdt")
|
|
|
|
endif()
|
2022-12-01 20:27:51 +08:00
|
|
|
|
2023-01-29 10:09:02 +08:00
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
|
|
|
# nano formatting functions in ROM are also built for 64-bit time_t.
|
|
|
|
rom_linker_script("newlib-nano")
|
2022-12-01 20:27:51 +08:00
|
|
|
endif()
|
2022-11-30 11:13:37 +08:00
|
|
|
|
2022-07-12 20:28:06 +08:00
|
|
|
endif()
|
2022-08-29 19:46:49 +08:00
|
|
|
|
2022-07-12 20:28:06 +08: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 15:23:10 +02:00
|
|
|
if((CONFIG_ESP_ROM_TLSF_CHECK_PATCH OR CONFIG_HEAP_TLSF_CHECK_PATCH))
|
2022-07-12 20:28:06 +08:00
|
|
|
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u tlsf_set_rom_patches")
|
2021-03-19 17:29:42 +08:00
|
|
|
endif()
|
2022-07-12 20:28:06 +08:00
|
|
|
|
|
|
|
rom_linker_script("heap")
|
2019-03-14 17:29:32 +08:00
|
|
|
endif()
|
2019-05-27 14:29:43 +08:00
|
|
|
|
2021-06-11 11:56:58 +08:00
|
|
|
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
|
2021-04-08 12:16:17 +08:00
|
|
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=longjmp")
|
|
|
|
endif()
|
2019-03-14 17:29:32 +08:00
|
|
|
endif()
|
2020-04-30 15:19:56 +02:00
|
|
|
|
|
|
|
if(target STREQUAL "esp32s2")
|
2022-01-18 20:48:37 +01:00
|
|
|
target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_patches.c")
|
2020-04-30 15:19:56 +02:00
|
|
|
endif()
|