2019-06-13 09:55:51 +00:00
|
|
|
idf_build_get_property(target IDF_TARGET)
|
|
|
|
|
2021-06-03 03:59:00 +00: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-25 07:08:51 +00:00
|
|
|
list(APPEND include_dirs "${IDF_PATH}/tools/mocks/soc/include")
|
2021-06-03 03:59:00 +00:00
|
|
|
else()
|
|
|
|
list(APPEND include_dirs "${target}")
|
|
|
|
list(APPEND sources "patches/esp_rom_crc.c"
|
|
|
|
"patches/esp_rom_sys.c"
|
2021-08-27 07:28:48 +00:00
|
|
|
"patches/esp_rom_uart.c"
|
2022-07-25 07:08:51 +00:00
|
|
|
"patches/esp_rom_tjpgd.c"
|
|
|
|
"patches/esp_rom_efuse.c")
|
2022-11-04 03:45:39 +00:00
|
|
|
list(APPEND private_required_comp soc hal efuse)
|
2021-06-03 03:59:00 +00:00
|
|
|
endif()
|
2021-04-08 04:16:17 +00:00
|
|
|
|
2021-06-11 03:56:58 +00:00
|
|
|
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
|
2021-04-08 04:16:17 +00:00
|
|
|
list(APPEND sources "patches/esp_rom_longjmp.S")
|
|
|
|
endif()
|
|
|
|
|
2023-06-19 02:27:23 +00:00
|
|
|
if(target STREQUAL "esp32s2" OR target STREQUAL "esp32s3")
|
|
|
|
list(APPEND sources "patches/esp_rom_cache.c")
|
|
|
|
endif()
|
|
|
|
|
2023-07-21 01:57:32 +00:00
|
|
|
if(target STREQUAL "esp32s3")
|
|
|
|
list(APPEND sources "patches/esp_rom_cache_writeback_esp32s3.S")
|
|
|
|
endif()
|
|
|
|
|
2023-07-03 08:08:41 +00:00
|
|
|
if(target STREQUAL "esp32s3" OR target STREQUAL "esp32c3" OR target STREQUAL "esp32h2")
|
|
|
|
list(APPEND sources "patches/esp_rom_mmap.c")
|
|
|
|
endif()
|
|
|
|
|
2021-04-08 04:16:17 +00:00
|
|
|
idf_component_register(SRCS ${sources}
|
2021-06-03 03:59:00 +00:00
|
|
|
INCLUDE_DIRS ${include_dirs}
|
2023-07-03 08:08:41 +00:00
|
|
|
PRIV_REQUIRES ${private_required_comp}
|
|
|
|
LDFRAGMENTS linker.lf)
|
2019-11-28 13:10:31 +00:00
|
|
|
|
2020-11-17 23:28:10 +00: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)
|
|
|
|
target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/ld/${target}.rom.${name}.ld")
|
|
|
|
endfunction()
|
|
|
|
|
2021-06-03 03:59:00 +00:00
|
|
|
if(target STREQUAL "linux")
|
|
|
|
# We need to disable some warnings due to the ROM code's printf implementation
|
|
|
|
if(${CMAKE_CXX_COMPILER_VERSION} GREATER "7.0.0") # TODO: clang compatibility
|
|
|
|
target_compile_options(${COMPONENT_LIB} PUBLIC -Wimplicit-fallthrough=0 -Wno-shift-count-overflow)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/ld/${target}.rom.ld")
|
|
|
|
rom_linker_script("api")
|
|
|
|
rom_linker_script("libgcc")
|
|
|
|
endif()
|
2020-11-17 23:28:10 +00:00
|
|
|
|
2019-03-14 09:29:32 +00:00
|
|
|
if(BOOTLOADER_BUILD)
|
2020-11-17 23:28:10 +00:00
|
|
|
if(target STREQUAL "esp32")
|
|
|
|
rom_linker_script("newlib-funcs")
|
2021-09-01 19:12:49 +00:00
|
|
|
if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
|
|
|
|
rom_linker_script("spiflash")
|
|
|
|
endif()
|
2022-03-17 13:58:15 +00:00
|
|
|
if(CONFIG_ESP32_REV_MIN_FULL EQUAL 300 OR CONFIG_ESP32_REV_MIN_FULL GREATER 300)
|
2020-11-17 23:28:10 +00:00
|
|
|
rom_linker_script("eco3")
|
|
|
|
endif()
|
2020-11-26 04:47:32 +00:00
|
|
|
|
2020-11-17 23:28:10 +00:00
|
|
|
elseif(target STREQUAL "esp32s2")
|
|
|
|
rom_linker_script("newlib-funcs")
|
|
|
|
rom_linker_script("spiflash")
|
2019-08-08 03:44:24 +00:00
|
|
|
|
2020-11-17 23:28:10 +00:00
|
|
|
elseif(target STREQUAL "esp32s3")
|
2021-03-17 10:48:05 +00:00
|
|
|
rom_linker_script("newlib")
|
2020-06-10 11:07:48 +00:00
|
|
|
|
2020-11-17 23:28:10 +00:00
|
|
|
elseif(target STREQUAL "esp32c3")
|
2020-12-22 07:24:39 +00:00
|
|
|
rom_linker_script("newlib")
|
2021-06-10 04:53:34 +00:00
|
|
|
|
|
|
|
elseif(target STREQUAL "esp32h2")
|
|
|
|
rom_linker_script("newlib")
|
2020-11-26 04:47:32 +00:00
|
|
|
endif()
|
2019-06-13 09:55:51 +00:00
|
|
|
|
2020-11-17 23:28:10 +00:00
|
|
|
else() # Regular app build
|
2019-11-28 13:10:31 +00:00
|
|
|
if(target STREQUAL "esp32")
|
2020-11-17 23:28:10 +00:00
|
|
|
rom_linker_script("newlib-data")
|
|
|
|
rom_linker_script("syscalls")
|
2019-03-14 09:29:32 +00:00
|
|
|
|
2019-05-27 06:29:43 +00:00
|
|
|
if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND)
|
2020-11-17 23:28:10 +00:00
|
|
|
rom_linker_script("newlib-funcs")
|
2020-01-10 04:58:54 +00:00
|
|
|
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
|
|
|
# If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined
|
|
|
|
# then all time functions from the ROM memory will not be linked.
|
|
|
|
# Instead, those functions can be used from the toolchain by ESP-IDF.
|
2020-11-17 23:28:10 +00:00
|
|
|
rom_linker_script("newlib-time")
|
2019-03-14 09:29:32 +00: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 14:20:04 +00:00
|
|
|
# Include in newlib nano from ROM only if SPIRAM cache workaround is disabled
|
|
|
|
# and sizeof(time_t) == 4
|
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
2020-02-07 10:35:37 +00: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 14:20:04 +00:00
|
|
|
endif()
|
2019-05-27 06:29:43 +00:00
|
|
|
endif()
|
2019-03-14 09:29:32 +00:00
|
|
|
|
2019-05-27 06:29:43 +00:00
|
|
|
if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
|
2020-11-17 23:28:10 +00:00
|
|
|
rom_linker_script("spiflash")
|
2019-05-27 06:29:43 +00:00
|
|
|
endif()
|
2019-03-29 04:37:51 +00:00
|
|
|
|
2022-03-17 13:58:15 +00:00
|
|
|
if(CONFIG_ESP32_REV_MIN_FULL EQUAL 300 OR CONFIG_ESP32_REV_MIN_FULL GREATER 300)
|
2020-11-17 23:28:10 +00:00
|
|
|
rom_linker_script("eco3")
|
2020-02-24 19:51:41 +00:00
|
|
|
endif()
|
|
|
|
|
2020-01-17 03:47:08 +00:00
|
|
|
elseif(target STREQUAL "esp32s2")
|
2020-11-17 23:28:10 +00:00
|
|
|
rom_linker_script("newlib-funcs")
|
|
|
|
rom_linker_script("newlib-data")
|
|
|
|
rom_linker_script("spiflash")
|
2020-01-23 17:02:29 +00: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 14:20:04 +00:00
|
|
|
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
|
|
|
# If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined
|
|
|
|
# then all time functions from the ROM memory will not be linked.
|
|
|
|
# Instead, those functions can be used from the toolchain by ESP-IDF.
|
|
|
|
|
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
rom_linker_script("newlib-time")
|
2020-01-23 17:02:29 +00:00
|
|
|
endif()
|
2020-06-10 11:07:48 +00: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 14:20:04 +00:00
|
|
|
|
2020-11-17 23:28:10 +00:00
|
|
|
# descirptors used by ROM code
|
|
|
|
target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_descriptors.c")
|
|
|
|
|
2020-06-10 11:07:48 +00:00
|
|
|
elseif(target STREQUAL "esp32s3")
|
2021-03-17 10:48:05 +00:00
|
|
|
rom_linker_script("newlib")
|
|
|
|
rom_linker_script("version")
|
2020-06-10 11:07:48 +00: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 14:20:04 +00:00
|
|
|
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
|
|
|
# If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined
|
|
|
|
# then all time functions from the ROM memory will not be linked.
|
|
|
|
# Instead, those functions can be used from the toolchain by ESP-IDF.
|
|
|
|
|
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
rom_linker_script("newlib-time")
|
2020-06-10 11:07:48 +00:00
|
|
|
endif()
|
|
|
|
|
2020-11-26 04:47:32 +00:00
|
|
|
elseif(target STREQUAL "esp32c3")
|
2020-11-17 23:28:10 +00:00
|
|
|
rom_linker_script("newlib")
|
|
|
|
rom_linker_script("version")
|
2020-11-26 04:47:32 +00: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 14:20:04 +00:00
|
|
|
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
|
|
|
# If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined
|
|
|
|
# then all time functions from the ROM memory will not be linked.
|
|
|
|
# Instead, those functions can be used from the toolchain by ESP-IDF.
|
|
|
|
|
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
rom_linker_script("newlib-time")
|
2020-11-26 04:47:32 +00:00
|
|
|
endif()
|
2021-03-03 03:57:58 +00:00
|
|
|
|
2022-03-17 13:58:15 +00:00
|
|
|
if(CONFIG_ESP32C3_REV_MIN_FULL EQUAL 3 OR CONFIG_ESP32C3_REV_MIN_FULL GREATER 3)
|
2021-03-03 03:57:58 +00:00
|
|
|
rom_linker_script("eco3")
|
|
|
|
endif()
|
2021-06-10 04:53:34 +00:00
|
|
|
|
2023-09-20 11:09:49 +00:00
|
|
|
if(CONFIG_ESP32C3_REV_MIN_FULL EQUAL 101 OR CONFIG_ESP32C3_REV_MIN_FULL GREATER 101)
|
|
|
|
rom_linker_script("eco7")
|
|
|
|
endif()
|
|
|
|
|
2021-06-10 04:53:34 +00:00
|
|
|
elseif(target STREQUAL "esp32h2")
|
|
|
|
rom_linker_script("newlib")
|
|
|
|
rom_linker_script("version")
|
|
|
|
|
|
|
|
if(CONFIG_NEWLIB_NANO_FORMAT)
|
|
|
|
rom_linker_script("newlib-nano")
|
|
|
|
endif()
|
2019-03-14 09:29:32 +00:00
|
|
|
endif()
|
2019-05-27 06:29:43 +00:00
|
|
|
|
2021-06-11 03:56:58 +00:00
|
|
|
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
|
2021-04-08 04:16:17 +00:00
|
|
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=longjmp")
|
|
|
|
endif()
|
2019-03-14 09:29:32 +00:00
|
|
|
endif()
|
2020-04-30 13:19:56 +00:00
|
|
|
|
|
|
|
if(target STREQUAL "esp32s2")
|
|
|
|
target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_descriptors.c")
|
|
|
|
endif()
|