1idf_build_get_property(target IDF_TARGET) 2 3set(include_dirs "include" "include/${target}") 4 5set(private_required_comp "") 6 7set(sources "") 8 9if(target STREQUAL "linux") 10 list(APPEND sources "${target}/esp_rom_sys.c" 11 "${target}/esp_rom_crc.c" 12 "${target}/esp_rom_md5.c" 13 "${target}/esp_rom_efuse.c") 14else() 15 list(APPEND include_dirs "${target}") 16 list(APPEND sources "patches/esp_rom_crc.c" 17 "patches/esp_rom_sys.c" 18 "patches/esp_rom_uart.c" 19 "patches/esp_rom_tjpgd.c") 20 list(APPEND private_required_comp soc hal) 21endif() 22 23if(CONFIG_IDF_TARGET_ARCH_XTENSA) 24 list(APPEND sources "patches/esp_rom_longjmp.S") 25endif() 26 27idf_component_register(SRCS ${sources} 28 INCLUDE_DIRS ${include_dirs} 29 PRIV_REQUIRES ${private_required_comp}) 30 31# Append a target linker script at the target-specific path, 32# only the 'name' part is different for each script 33function(rom_linker_script name) 34 target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/ld/${target}.rom.${name}.ld") 35endfunction() 36 37if(target STREQUAL "linux") 38 # We need to disable some warnings due to the ROM code's printf implementation 39 if(${CMAKE_CXX_COMPILER_VERSION} GREATER "7.0.0") # TODO: clang compatibility 40 target_compile_options(${COMPONENT_LIB} PUBLIC -Wimplicit-fallthrough=0 -Wno-shift-count-overflow) 41 endif() 42else() 43 target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/ld/${target}.rom.ld") 44 rom_linker_script("api") 45 rom_linker_script("libgcc") 46endif() 47 48if(BOOTLOADER_BUILD) 49 if(target STREQUAL "esp32") 50 rom_linker_script("newlib-funcs") 51 if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH) 52 rom_linker_script("spiflash") 53 endif() 54 if(CONFIG_ESP32_REV_MIN_3) 55 rom_linker_script("eco3") 56 endif() 57 58 elseif(target STREQUAL "esp32s2") 59 rom_linker_script("newlib-funcs") 60 rom_linker_script("spiflash") 61 62 elseif(target STREQUAL "esp32s3") 63 rom_linker_script("newlib") 64 65 elseif(target STREQUAL "esp32c3") 66 rom_linker_script("newlib") 67 68 elseif(target STREQUAL "esp32h2") 69 rom_linker_script("newlib") 70 endif() 71 72else() # Regular app build 73 if(target STREQUAL "esp32") 74 rom_linker_script("newlib-data") 75 rom_linker_script("syscalls") 76 77 if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND) 78 rom_linker_script("newlib-funcs") 79 if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS) 80 # If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined 81 # then all time functions from the ROM memory will not be linked. 82 # Instead, those functions can be used from the toolchain by ESP-IDF. 83 rom_linker_script("newlib-time") 84 85 # Include in newlib nano from ROM only if SPIRAM cache workaround is disabled 86 # and sizeof(time_t) == 4 87 if(CONFIG_NEWLIB_NANO_FORMAT) 88 rom_linker_script("newlib-nano") 89 endif() 90 91 endif() 92 endif() 93 94 if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH) 95 rom_linker_script("spiflash") 96 endif() 97 98 if(CONFIG_ESP32_REV_MIN_3) 99 rom_linker_script("eco3") 100 endif() 101 102 elseif(target STREQUAL "esp32s2") 103 rom_linker_script("newlib-funcs") 104 rom_linker_script("newlib-data") 105 rom_linker_script("spiflash") 106 107 if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS) 108 # If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined 109 # then all time functions from the ROM memory will not be linked. 110 # Instead, those functions can be used from the toolchain by ESP-IDF. 111 112 if(CONFIG_NEWLIB_NANO_FORMAT) 113 rom_linker_script("newlib-nano") 114 endif() 115 116 rom_linker_script("newlib-time") 117 endif() 118 119 120 # descirptors used by ROM code 121 target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_descriptors.c") 122 123 elseif(target STREQUAL "esp32s3") 124 rom_linker_script("newlib") 125 rom_linker_script("version") 126 127 if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS) 128 # If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined 129 # then all time functions from the ROM memory will not be linked. 130 # Instead, those functions can be used from the toolchain by ESP-IDF. 131 132 if(CONFIG_NEWLIB_NANO_FORMAT) 133 rom_linker_script("newlib-nano") 134 endif() 135 136 rom_linker_script("newlib-time") 137 endif() 138 139 elseif(target STREQUAL "esp32c3") 140 rom_linker_script("newlib") 141 rom_linker_script("version") 142 143 if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS) 144 # If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined 145 # then all time functions from the ROM memory will not be linked. 146 # Instead, those functions can be used from the toolchain by ESP-IDF. 147 148 if(CONFIG_NEWLIB_NANO_FORMAT) 149 rom_linker_script("newlib-nano") 150 endif() 151 152 rom_linker_script("newlib-time") 153 endif() 154 155 if(CONFIG_ESP32C3_REV_MIN_3) 156 rom_linker_script("eco3") 157 endif() 158 159 elseif(target STREQUAL "esp32h2") 160 rom_linker_script("newlib") 161 rom_linker_script("version") 162 163 if(CONFIG_NEWLIB_NANO_FORMAT) 164 rom_linker_script("newlib-nano") 165 endif() 166 endif() 167 168 if(CONFIG_IDF_TARGET_ARCH_XTENSA) 169 target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=longjmp") 170 endif() 171endif() 172 173if(target STREQUAL "esp32s2") 174 target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_descriptors.c") 175endif() 176