CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. idf_build_get_property(target IDF_TARGET)
  2. set(include_dirs "include" "include/${target}")
  3. set(private_required_comp "")
  4. set(sources "")
  5. if(target STREQUAL "linux")
  6. list(APPEND sources "${target}/esp_rom_sys.c"
  7. "${target}/esp_rom_crc.c"
  8. "${target}/esp_rom_md5.c"
  9. "${target}/esp_rom_efuse.c")
  10. else()
  11. list(APPEND include_dirs "${target}")
  12. list(APPEND sources "patches/esp_rom_crc.c"
  13. "patches/esp_rom_sys.c"
  14. "patches/esp_rom_uart.c"
  15. "patches/esp_rom_spiflash.c"
  16. "patches/esp_rom_efuse.c")
  17. # Override regi2c implementation in ROM
  18. if(CONFIG_ESP_ROM_HAS_REGI2C_BUG OR CONFIG_ESP_ROM_WITHOUT_REGI2C)
  19. if(target STREQUAL "esp32c6")
  20. list(APPEND sources "patches/esp_rom_hp_regi2c_${target}.c")
  21. else()
  22. list(APPEND sources "patches/esp_rom_regi2c_${target}.c")
  23. endif()
  24. endif()
  25. if(CONFIG_HEAP_TLSF_USE_ROM_IMPL AND (CONFIG_ESP_ROM_TLSF_CHECK_PATCH OR CONFIG_HEAP_TLSF_CHECK_PATCH))
  26. # This file shall be included in the build if TLSF in ROM is activated
  27. list(APPEND sources "patches/esp_rom_tlsf.c")
  28. endif()
  29. list(APPEND private_required_comp soc hal)
  30. endif()
  31. if(CONFIG_IDF_TARGET_ARCH_XTENSA)
  32. list(APPEND sources "patches/esp_rom_longjmp.S")
  33. endif()
  34. if(CONFIG_SOC_SYSTIMER_SUPPORTED)
  35. list(APPEND sources "patches/esp_rom_systimer.c")
  36. endif()
  37. if(CONFIG_HAL_WDT_USE_ROM_IMPL)
  38. list(APPEND sources "patches/esp_rom_wdt.c")
  39. endif()
  40. if(CONFIG_ESP_ROM_HAS_FLASH_COUNT_PAGES_BUG OR CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG)
  41. list(APPEND sources "patches/esp_rom_cache_esp32s2_esp32s3.c")
  42. endif()
  43. if(CONFIG_ESP_ROM_HAS_CACHE_WRITEBACK_BUG)
  44. list(APPEND sources "patches/esp_rom_cache_writeback_esp32s3.S")
  45. endif()
  46. idf_component_register(SRCS ${sources}
  47. INCLUDE_DIRS ${include_dirs}
  48. PRIV_REQUIRES ${private_required_comp}
  49. LDFRAGMENTS linker.lf)
  50. set(ld_folder "ld")
  51. # Append a target linker script at the target-specific path,
  52. # only the 'name' part is different for each script
  53. function(rom_linker_script name)
  54. target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/${ld_folder}/${target}.rom.${name}.ld")
  55. endfunction()
  56. if(target STREQUAL "linux")
  57. # We need to disable some warnings due to the ROM code's printf implementation
  58. if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION} GREATER "7.0.0")
  59. target_compile_options(${COMPONENT_LIB} PRIVATE -Wimplicit-fallthrough=0 -Wno-shift-count-overflow)
  60. endif()
  61. if(CMAKE_C_COMPILER_ID MATCHES "Clang") # Clang or AppleClang
  62. target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-integer-overflow -Wno-shift-count-overflow)
  63. endif()
  64. else()
  65. target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/${ld_folder}/${target}.rom.ld")
  66. rom_linker_script("api")
  67. if(CONFIG_COMPILER_FLOAT_LIB_FROM_GCCLIB)
  68. rom_linker_script("libgcc")
  69. else()
  70. rom_linker_script("rvfp")
  71. endif()
  72. endif()
  73. idf_build_get_property(time_t_size TIME_T_SIZE)
  74. if(BOOTLOADER_BUILD)
  75. if(target STREQUAL "esp32")
  76. rom_linker_script("newlib-funcs")
  77. if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
  78. rom_linker_script("spiflash")
  79. endif()
  80. if(CONFIG_ESP32_REV_MIN_FULL GREATER_EQUAL 300)
  81. rom_linker_script("eco3")
  82. endif()
  83. elseif(target STREQUAL "esp32s2")
  84. rom_linker_script("newlib-funcs")
  85. rom_linker_script("spiflash")
  86. elseif(target STREQUAL "esp32s3")
  87. rom_linker_script("newlib")
  88. elseif(target STREQUAL "esp32c3")
  89. rom_linker_script("newlib")
  90. elseif(target STREQUAL "esp32c2")
  91. rom_linker_script("newlib")
  92. elseif(target STREQUAL "esp32c6")
  93. rom_linker_script("newlib")
  94. # The linking of the bootloader needs to use the rom_i2c_writeReg_Mask in esp32c6.rom.phy.ld
  95. rom_linker_script("phy")
  96. if(CONFIG_HAL_WDT_USE_ROM_IMPL)
  97. rom_linker_script("wdt")
  98. endif()
  99. rom_linker_script("version")
  100. elseif(target STREQUAL "esp32h2")
  101. rom_linker_script("newlib")
  102. if(CONFIG_HAL_WDT_USE_ROM_IMPL)
  103. rom_linker_script("wdt")
  104. endif()
  105. elseif(target STREQUAL "esp32p4")
  106. rom_linker_script("newlib")
  107. if(CONFIG_HAL_WDT_USE_ROM_IMPL)
  108. rom_linker_script("wdt")
  109. endif()
  110. rom_linker_script("version")
  111. endif()
  112. else() # Regular app build
  113. if(target STREQUAL "esp32")
  114. rom_linker_script("newlib-data")
  115. rom_linker_script("syscalls")
  116. if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND)
  117. # ESP32 only: these ROM functions may only be used if PSRAM cache workaround is disabled.
  118. # Otherwise we need to link to a multilib version of libc compiled with PSRAM workaround.
  119. rom_linker_script("newlib-funcs")
  120. if(time_t_size EQUAL 4)
  121. # The ROM functions listed in this linker script depend on sizeof(time_t).
  122. # Since ROM for ESP32 was compiled for 32-bit time_t, only link these functions
  123. # if the toolchain is also using 32-bit time_t.
  124. rom_linker_script("newlib-time")
  125. if(CONFIG_NEWLIB_NANO_FORMAT)
  126. # nano formatting functions in ROM are also built for 32-bit time_t.
  127. rom_linker_script("newlib-nano")
  128. endif()
  129. endif()
  130. endif()
  131. if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
  132. rom_linker_script("spiflash")
  133. endif()
  134. if(CONFIG_ESP32_REV_MIN_FULL GREATER_EQUAL 300)
  135. rom_linker_script("eco3")
  136. endif()
  137. elseif(target STREQUAL "esp32s2")
  138. rom_linker_script("newlib-funcs")
  139. rom_linker_script("newlib-data")
  140. rom_linker_script("spiflash")
  141. if(time_t_size EQUAL 4)
  142. # The ROM functions listed in this linker script depend on sizeof(time_t).
  143. # Since ROM for ESP32-S2 was compiled for 32-bit time_t, only link these functions
  144. # if the toolchain is also using 32-bit time_t.
  145. rom_linker_script("newlib-time")
  146. if(CONFIG_NEWLIB_NANO_FORMAT)
  147. # nano formatting functions in ROM are also built for 32-bit time_t.
  148. rom_linker_script("newlib-nano")
  149. endif()
  150. endif()
  151. elseif(target STREQUAL "esp32s3")
  152. rom_linker_script("newlib")
  153. rom_linker_script("version")
  154. if(time_t_size EQUAL 4)
  155. # The ROM functions listed in this linker script depend on sizeof(time_t).
  156. # Since ROM for ESP32-S3 was compiled for 32-bit time_t, only link these functions
  157. # if the toolchain is also using 32-bit time_t.
  158. rom_linker_script("newlib-time")
  159. if(CONFIG_NEWLIB_NANO_FORMAT)
  160. # nano formatting functions in ROM are also built for 32-bit time_t.
  161. rom_linker_script("newlib-nano")
  162. endif()
  163. endif()
  164. elseif(target STREQUAL "esp32c3")
  165. rom_linker_script("newlib")
  166. rom_linker_script("version")
  167. if(time_t_size EQUAL 4)
  168. # The ROM functions listed in this linker script depend on sizeof(time_t).
  169. # Since ROM for ESP32-C3 was compiled for 32-bit time_t, only link these functions
  170. # if the toolchain is also using 32-bit time_t.
  171. rom_linker_script("newlib-time")
  172. if(CONFIG_NEWLIB_NANO_FORMAT)
  173. # nano formatting functions in ROM are also built for 32-bit time_t.
  174. rom_linker_script("newlib-nano")
  175. endif()
  176. endif()
  177. if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 3)
  178. rom_linker_script("eco3")
  179. endif()
  180. if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 101)
  181. rom_linker_script("eco7")
  182. endif()
  183. elseif(target STREQUAL "esp32c2")
  184. rom_linker_script("newlib")
  185. rom_linker_script("version")
  186. if(CONFIG_MBEDTLS_USE_CRYPTO_ROM_IMPL)
  187. rom_linker_script("mbedtls")
  188. endif()
  189. if(CONFIG_NEWLIB_NANO_FORMAT)
  190. # nano formatting functions in ROM are also built for 64-bit time_t.
  191. rom_linker_script("newlib-nano")
  192. endif()
  193. elseif(target STREQUAL "esp32c6")
  194. rom_linker_script("newlib")
  195. rom_linker_script("version")
  196. # esp32c6.rom.api.ld has been split to several lds by components.
  197. rom_linker_script("phy")
  198. rom_linker_script("coexist")
  199. rom_linker_script("net80211")
  200. rom_linker_script("pp")
  201. if(CONFIG_SPI_FLASH_ROM_IMPL)
  202. rom_linker_script("spiflash")
  203. endif()
  204. if(CONFIG_HAL_WDT_USE_ROM_IMPL)
  205. rom_linker_script("wdt")
  206. endif()
  207. if(NOT CONFIG_NEWLIB_NANO_FORMAT)
  208. # Normal(Non-nano) formatting functions in ROM are also built for 64-bit time_t.
  209. rom_linker_script("newlib-normal")
  210. endif()
  211. elseif(target STREQUAL "esp32h2")
  212. rom_linker_script("newlib")
  213. rom_linker_script("version")
  214. if(CONFIG_SPI_FLASH_ROM_IMPL)
  215. rom_linker_script("spiflash")
  216. endif()
  217. if(CONFIG_HAL_WDT_USE_ROM_IMPL)
  218. rom_linker_script("wdt")
  219. endif()
  220. if(CONFIG_NEWLIB_NANO_FORMAT)
  221. # nano formatting functions in ROM are also built for 64-bit time_t.
  222. rom_linker_script("newlib-nano")
  223. endif()
  224. elseif(target STREQUAL "esp32p4")
  225. rom_linker_script("newlib")
  226. rom_linker_script("version")
  227. # esp32p4 rom doesn't have esp_flash driver
  228. if(CONFIG_HAL_WDT_USE_ROM_IMPL)
  229. rom_linker_script("wdt")
  230. endif()
  231. if(CONFIG_NEWLIB_NANO_FORMAT)
  232. # nano formatting functions in ROM are also built for 64-bit time_t.
  233. rom_linker_script("newlib-nano")
  234. endif()
  235. endif()
  236. if(CONFIG_HEAP_TLSF_USE_ROM_IMPL)
  237. # After registering the component, set the tlsf_set_rom_patches symbol as undefined
  238. # to force the linker to integrate the whole `esp_rom_tlsf.c` object file inside the
  239. # final binary. This is necessary because tlsf_set_rom_patches is a constructor, thus,
  240. # there as no explicit reference/call to it in IDF.
  241. if((CONFIG_ESP_ROM_TLSF_CHECK_PATCH OR CONFIG_HEAP_TLSF_CHECK_PATCH))
  242. target_link_libraries(${COMPONENT_LIB} PRIVATE "-u tlsf_set_rom_patches")
  243. endif()
  244. rom_linker_script("heap")
  245. endif()
  246. if(CONFIG_IDF_TARGET_ARCH_XTENSA)
  247. target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=longjmp")
  248. endif()
  249. endif()
  250. if(target STREQUAL "esp32s2")
  251. target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_patches.c")
  252. endif()