CMakeLists.txt 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. list(APPEND include_dirs "${IDF_PATH}/tools/mocks/soc/include")
  11. else()
  12. list(APPEND include_dirs "${target}")
  13. list(APPEND sources "patches/esp_rom_crc.c"
  14. "patches/esp_rom_sys.c"
  15. "patches/esp_rom_uart.c"
  16. "patches/esp_rom_spiflash.c"
  17. "patches/esp_rom_regi2c.c"
  18. "patches/esp_rom_efuse.c")
  19. list(APPEND private_required_comp soc hal)
  20. endif()
  21. if(CONFIG_IDF_TARGET_ARCH_XTENSA)
  22. list(APPEND sources "patches/esp_rom_longjmp.S")
  23. endif()
  24. if(CONFIG_SOC_SYSTIMER_SUPPORTED)
  25. list(APPEND sources "patches/esp_rom_systimer.c")
  26. endif()
  27. idf_component_register(SRCS ${sources}
  28. INCLUDE_DIRS ${include_dirs}
  29. PRIV_REQUIRES ${private_required_comp}
  30. LDFRAGMENTS linker.lf)
  31. if(target STREQUAL "esp32h2")
  32. if(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_1)
  33. set(ld_folder "ld/rev1")
  34. elseif(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2)
  35. set(ld_folder "ld/rev2")
  36. endif()
  37. else()
  38. set(ld_folder "ld")
  39. endif()
  40. # Append a target linker script at the target-specific path,
  41. # only the 'name' part is different for each script
  42. function(rom_linker_script name)
  43. target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/${ld_folder}/${target}.rom.${name}.ld")
  44. endfunction()
  45. if(target STREQUAL "linux")
  46. # We need to disable some warnings due to the ROM code's printf implementation
  47. if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION} GREATER "7.0.0")
  48. target_compile_options(${COMPONENT_LIB} PRIVATE -Wimplicit-fallthrough=0 -Wno-shift-count-overflow)
  49. endif()
  50. if(CMAKE_C_COMPILER_ID MATCHES "Clang") # Clang or AppleClang
  51. target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-integer-overflow -Wno-shift-count-overflow)
  52. endif()
  53. else()
  54. target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/${ld_folder}/${target}.rom.ld")
  55. rom_linker_script("api")
  56. if(CONFIG_COMPILER_FLOAT_LIB_FROM_GCCLIB)
  57. rom_linker_script("libgcc")
  58. else()
  59. rom_linker_script("rvfp")
  60. endif()
  61. endif()
  62. idf_build_get_property(time_t_size TIME_T_SIZE)
  63. if(BOOTLOADER_BUILD)
  64. if(target STREQUAL "esp32")
  65. rom_linker_script("newlib-funcs")
  66. if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
  67. rom_linker_script("spiflash")
  68. endif()
  69. if(CONFIG_ESP32_REV_MIN_3)
  70. rom_linker_script("eco3")
  71. endif()
  72. elseif(target STREQUAL "esp32s2")
  73. rom_linker_script("newlib-funcs")
  74. rom_linker_script("spiflash")
  75. elseif(target STREQUAL "esp32s3")
  76. rom_linker_script("newlib")
  77. elseif(target STREQUAL "esp32c3")
  78. rom_linker_script("newlib")
  79. elseif(target STREQUAL "esp32h2")
  80. rom_linker_script("newlib")
  81. elseif(target STREQUAL "esp32c2")
  82. rom_linker_script("newlib")
  83. rom_linker_script("mbedtls")
  84. endif()
  85. else() # Regular app build
  86. if(target STREQUAL "esp32")
  87. rom_linker_script("newlib-data")
  88. rom_linker_script("syscalls")
  89. if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND)
  90. # ESP32 only: these ROM functions may only be used if PSRAM cache workaround is disabled.
  91. # Otherwise we need to link to a multilib version of libc compiled with PSRAM workaround.
  92. rom_linker_script("newlib-funcs")
  93. if(time_t_size EQUAL 4)
  94. # The ROM functions listed in this linker script depend on sizeof(time_t).
  95. # Since ROM for ESP32 was compiled for 32-bit time_t, only link these functions
  96. # if the toolchain is also using 32-bit time_t.
  97. rom_linker_script("newlib-time")
  98. if(CONFIG_NEWLIB_NANO_FORMAT)
  99. # nano formatting functions in ROM are also built for 32-bit time_t.
  100. rom_linker_script("newlib-nano")
  101. endif()
  102. endif()
  103. endif()
  104. if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
  105. rom_linker_script("spiflash")
  106. endif()
  107. if(CONFIG_ESP32_REV_MIN_3)
  108. rom_linker_script("eco3")
  109. endif()
  110. elseif(target STREQUAL "esp32s2")
  111. rom_linker_script("newlib-funcs")
  112. rom_linker_script("newlib-data")
  113. rom_linker_script("spiflash")
  114. if(time_t_size EQUAL 4)
  115. # The ROM functions listed in this linker script depend on sizeof(time_t).
  116. # Since ROM for ESP32-S2 was compiled for 32-bit time_t, only link these functions
  117. # if the toolchain is also using 32-bit time_t.
  118. rom_linker_script("newlib-time")
  119. if(CONFIG_NEWLIB_NANO_FORMAT)
  120. # nano formatting functions in ROM are also built for 32-bit time_t.
  121. rom_linker_script("newlib-nano")
  122. endif()
  123. endif()
  124. elseif(target STREQUAL "esp32s3")
  125. rom_linker_script("newlib")
  126. rom_linker_script("version")
  127. if(time_t_size EQUAL 4)
  128. # The ROM functions listed in this linker script depend on sizeof(time_t).
  129. # Since ROM for ESP32-S3 was compiled for 32-bit time_t, only link these functions
  130. # if the toolchain is also using 32-bit time_t.
  131. rom_linker_script("newlib-time")
  132. if(CONFIG_NEWLIB_NANO_FORMAT)
  133. # nano formatting functions in ROM are also built for 32-bit time_t.
  134. rom_linker_script("newlib-nano")
  135. endif()
  136. endif()
  137. elseif(target STREQUAL "esp32c3")
  138. rom_linker_script("newlib")
  139. rom_linker_script("version")
  140. if(time_t_size EQUAL 4)
  141. # The ROM functions listed in this linker script depend on sizeof(time_t).
  142. # Since ROM for ESP32-C3 was compiled for 32-bit time_t, only link these functions
  143. # if the toolchain is also using 32-bit time_t.
  144. rom_linker_script("newlib-time")
  145. if(CONFIG_NEWLIB_NANO_FORMAT)
  146. # nano formatting functions in ROM are also built for 32-bit time_t.
  147. rom_linker_script("newlib-nano")
  148. endif()
  149. endif()
  150. if(CONFIG_ESP32C3_REV_MIN_3 OR CONFIG_ESP32C3_REV_MIN_4)
  151. rom_linker_script("eco3")
  152. endif()
  153. elseif(target STREQUAL "esp32h2")
  154. rom_linker_script("newlib")
  155. rom_linker_script("version")
  156. if(CONFIG_NEWLIB_NANO_FORMAT AND time_t_size EQUAL 4)
  157. # nano formatting functions in ROM are built for 32-bit time_t,
  158. # only link them if the toolchain is also using 32-bit time_t and nano formatting was requested.
  159. rom_linker_script("newlib-nano")
  160. endif()
  161. elseif(target STREQUAL "esp32c2")
  162. rom_linker_script("newlib")
  163. rom_linker_script("version")
  164. rom_linker_script("mbedtls")
  165. if(time_t_size EQUAL 8)
  166. # The ROM functions listed in this linker script depend on sizeof(time_t).
  167. # Since ROM for ESP32-C2 was compiled for 64-bit time_t, only link these functions
  168. # if the toolchain is also using 64-bit time_t.
  169. rom_linker_script("newlib-time")
  170. if(CONFIG_NEWLIB_NANO_FORMAT)
  171. # nano formatting functions in ROM are also built for 64-bit time_t.
  172. rom_linker_script("newlib-nano")
  173. endif()
  174. endif()
  175. if(CONFIG_HEAP_TLSF_USE_ROM_IMPL)
  176. rom_linker_script("heap")
  177. endif()
  178. endif()
  179. if(CONFIG_IDF_TARGET_ARCH_XTENSA)
  180. target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=longjmp")
  181. endif()
  182. endif()
  183. if(target STREQUAL "esp32s2")
  184. target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_descriptors.c")
  185. endif()