CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. idf_build_get_property(idf_target IDF_TARGET)
  2. if(CONFIG_ESP32_NO_BLOBS OR CONFIG_ESP32S2_NO_BLOBS)
  3. set(link_binary_libs 0)
  4. set(ldfragments)
  5. else()
  6. set(link_binary_libs 1)
  7. set(ldfragments "linker.lf")
  8. endif()
  9. if(IDF_TARGET STREQUAL "esp32h2")
  10. set(srcs "src/phy_init_esp32hxx.c")
  11. else()
  12. set(srcs "src/phy_init.c")
  13. endif()
  14. idf_build_get_property(build_dir BUILD_DIR)
  15. if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN)
  16. if(NOT EXISTS "${build_dir}/phy_multiple_init_data.bin")
  17. file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${idf_target}/phy_multiple_init_data.bin DESTINATION "${build_dir}")
  18. endif()
  19. endif()
  20. if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED)
  21. idf_component_register(SRCS "${srcs}"
  22. INCLUDE_DIRS "include" "${idf_target}/include"
  23. PRIV_REQUIRES nvs_flash
  24. LDFRAGMENTS "${ldfragments}"
  25. EMBED_FILES "${build_dir}/phy_multiple_init_data.bin"
  26. )
  27. else()
  28. idf_component_register(SRCS "${srcs}"
  29. INCLUDE_DIRS "include" "${idf_target}/include"
  30. PRIV_REQUIRES nvs_flash
  31. LDFRAGMENTS "${ldfragments}"
  32. )
  33. endif()
  34. set(target_name "${idf_target}")
  35. target_link_libraries(${COMPONENT_LIB} PUBLIC "-L \"${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}\"")
  36. if(link_binary_libs)
  37. target_link_libraries(${COMPONENT_LIB} PUBLIC phy)
  38. idf_component_get_property(esp_phy_lib esp_phy COMPONENT_LIB)
  39. if(CONFIG_IDF_TARGET_ESP32)
  40. target_link_libraries(${COMPONENT_LIB} PUBLIC rtc)
  41. target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${esp_phy_lib}> libphy.a librtc.a
  42. $<TARGET_FILE:${esp_phy_lib}>)
  43. endif()
  44. if(CONFIG_IDF_TARGET_ESP32S2)
  45. target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${esp_phy_lib}> libphy.a
  46. $<TARGET_FILE:${esp_phy_lib}>)
  47. endif()
  48. if(CONFIG_IDF_TARGET_ESP32C3 OR CONFIG_IDF_TARGET_ESP32S3 OR CONFIG_IDF_TARGET_ESP32H2)
  49. target_link_libraries(${COMPONENT_LIB} PUBLIC btbb)
  50. target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${esp_phy_lib}> libphy.a libbtbb.a
  51. $<TARGET_FILE:${esp_phy_lib}>)
  52. endif()
  53. endif()
  54. if(CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION)
  55. idf_component_get_property(esp_common_dir esp_common COMPONENT_DIR)
  56. partition_table_get_partition_info(phy_partition_offset "--partition-type data --partition-subtype phy" "offset")
  57. if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN)
  58. set(phy_init_data_bin "${build_dir}/phy_multiple_init_data.bin")
  59. if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED)
  60. set(COMPONENT_EMBED_FILES "${build_dir}/phy_multiple_init_data.bin")
  61. endif()
  62. else()
  63. set(phy_init_data_bin "${build_dir}/phy_init_data.bin")
  64. # To get the phy_init_data.bin file, compile phy_init_data.h as a C file and then objcopy
  65. # the object file to a raw binary
  66. idf_build_get_property(config_dir CONFIG_DIR)
  67. add_custom_command(
  68. OUTPUT ${phy_init_data_bin}
  69. DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h
  70. COMMAND ${CMAKE_C_COMPILER} -x c -c
  71. -I ${esp_common_dir}/include -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${config_dir}
  72. -o phy_init_data.obj
  73. ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h
  74. COMMAND ${CMAKE_OBJCOPY} -O binary phy_init_data.obj ${phy_init_data_bin}
  75. )
  76. add_custom_target(phy_init_data ALL DEPENDS ${phy_init_data_bin})
  77. add_dependencies(flash phy_init_data)
  78. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  79. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  80. endif()
  81. set(phy_name "phy")
  82. esptool_py_flash_target(${phy_name}-flash "${main_args}" "${sub_args}")
  83. esptool_py_flash_target_image(${phy_name}-flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}")
  84. esptool_py_flash_target_image(flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}")
  85. endif()