CMakeLists.txt 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. idf_component_register(SRCS "esp_ota_ops.c"
  2. "esp_app_desc.c"
  3. INCLUDE_DIRS "include"
  4. REQUIRES spi_flash partition_table bootloader_support
  5. PRIV_REQUIRES esptool_py efuse)
  6. # esp_app_desc structure is added as an undefined symbol because otherwise the
  7. # linker will ignore this structure as it has no other files depending on it.
  8. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_app_desc")
  9. if(CONFIG_APP_PROJECT_VER_FROM_CONFIG)
  10. # Ignore current PROJECT_VER (which was set in __project_get_revision()).
  11. # Gets the version from the CONFIG_APP_PROJECT_VER.
  12. idf_build_set_property(PROJECT_VER "${CONFIG_APP_PROJECT_VER}")
  13. endif()
  14. # cut PROJECT_VER and PROJECT_NAME to required 32 characters.
  15. idf_build_get_property(project_ver PROJECT_VER)
  16. idf_build_get_property(project_name PROJECT_NAME)
  17. string(SUBSTRING "${project_ver}" 0 31 PROJECT_VER_CUT)
  18. string(SUBSTRING "${project_name}" 0 31 PROJECT_NAME_CUT)
  19. message(STATUS "App \"${PROJECT_NAME_CUT}\" version: ${PROJECT_VER_CUT}")
  20. set_source_files_properties(
  21. SOURCE "esp_app_desc.c"
  22. PROPERTIES COMPILE_DEFINITIONS
  23. "PROJECT_VER=\"${PROJECT_VER_CUT}\"; PROJECT_NAME=\"${PROJECT_NAME_CUT}\"")
  24. if(NOT BOOTLOADER_BUILD)
  25. partition_table_get_partition_info(otadata_offset "--partition-type data --partition-subtype ota" "offset")
  26. partition_table_get_partition_info(otadata_size "--partition-type data --partition-subtype ota" "size")
  27. # Add custom target for generating empty otadata partition for flashing
  28. if(otadata_size AND otadata_offset)
  29. idf_build_get_property(build_dir BUILD_DIR)
  30. set(blank_otadata_file ${build_dir}/ota_data_initial.bin)
  31. idf_build_get_property(idf_path IDF_PATH)
  32. idf_build_get_property(python PYTHON)
  33. idf_component_get_property(partition_table_dir partition_table COMPONENT_DIR)
  34. add_custom_command(OUTPUT ${blank_otadata_file}
  35. COMMAND ${python} ${partition_table_dir}/gen_empty_partition.py
  36. ${otadata_size} ${blank_otadata_file})
  37. add_custom_target(blank_ota_data ALL DEPENDS ${blank_otadata_file})
  38. add_dependencies(flash blank_ota_data)
  39. add_dependencies(encrypted-flash blank_ota_data)
  40. set(otatool_py ${python} ${COMPONENT_DIR}/otatool.py)
  41. set(esptool_args "--esptool-args;before=${CONFIG_ESPTOOLPY_BEFORE};after=${CONFIG_ESPTOOLPY_AFTER}")
  42. set(otatool_args "--partition-table-file;${PARTITION_CSV_PATH}"
  43. "--partition-table-offset;${PARTITION_TABLE_OFFSET}")
  44. idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
  45. add_custom_target(read-otadata DEPENDS "${PARTITION_CSV_PATH}"
  46. COMMAND ${CMAKE_COMMAND}
  47. -D IDF_PATH="${idf_path}"
  48. -D SERIAL_TOOL="${otatool_py}"
  49. -D SERIAL_TOOL_ARGS="${esptool_args};${otatool_args};read_otadata"
  50. -D WORKING_DIRECTORY="${build_dir}"
  51. -P ${esptool_py_dir}/run_serial_tool.cmake
  52. WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  53. USES_TERMINAL
  54. )
  55. add_deprecated_target_alias(read_otadata read-otadata)
  56. add_custom_target(erase-otadata DEPENDS "${PARTITION_CSV_PATH}"
  57. COMMAND ${CMAKE_COMMAND}
  58. -D IDF_PATH="${idf_path}"
  59. -D SERIAL_TOOL="${otatool_py}"
  60. -D SERIAL_TOOL_ARGS="${esptool_args};${otatool_args};erase_otadata"
  61. -D WORKING_DIRECTORY="${build_dir}"
  62. -P ${esptool_py_dir}/run_serial_tool.cmake
  63. WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  64. USES_TERMINAL
  65. )
  66. add_deprecated_target_alias(erase_otadata erase-otadata)
  67. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  68. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  69. esptool_py_flash_target(otadata-flash "${main_args}" "${sub_args}")
  70. esptool_py_flash_target_image(otadata-flash otadata "${otadata_offset}" "${blank_otadata_file}")
  71. esptool_py_flash_target_image(flash otadata "${otadata_offset}" "${blank_otadata_file}")
  72. endif()
  73. endif()