CMakeLists.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. idf_build_get_property(target IDF_TARGET)
  2. if(${target} STREQUAL "linux")
  3. return() # This component is not supported by the POSIX/Linux simulator
  4. endif()
  5. idf_component_register(SRCS "esp_ota_ops.c" "esp_ota_app_desc.c"
  6. INCLUDE_DIRS "include"
  7. REQUIRES partition_table bootloader_support esp_app_format esp_bootloader_format esp_partition
  8. PRIV_REQUIRES esptool_py efuse spi_flash)
  9. if(NOT BOOTLOADER_BUILD)
  10. partition_table_get_partition_info(otadata_offset "--partition-type data --partition-subtype ota" "offset")
  11. partition_table_get_partition_info(otadata_size "--partition-type data --partition-subtype ota" "size")
  12. # Add custom target for generating empty otadata partition for flashing
  13. if(otadata_size AND otadata_offset)
  14. idf_build_get_property(build_dir BUILD_DIR)
  15. set(blank_otadata_file ${build_dir}/ota_data_initial.bin)
  16. idf_build_get_property(idf_path IDF_PATH)
  17. idf_build_get_property(python PYTHON)
  18. idf_component_get_property(partition_table_dir partition_table COMPONENT_DIR)
  19. add_custom_command(OUTPUT ${blank_otadata_file}
  20. COMMAND ${python} ${partition_table_dir}/gen_empty_partition.py
  21. ${otadata_size} ${blank_otadata_file})
  22. add_custom_target(blank_ota_data ALL DEPENDS ${blank_otadata_file})
  23. add_dependencies(flash blank_ota_data)
  24. add_dependencies(encrypted-flash blank_ota_data)
  25. set(otatool_py "${python}" "${COMPONENT_DIR}/otatool.py")
  26. set(esptool_args --esptool-args before=${CONFIG_ESPTOOLPY_BEFORE} after=${CONFIG_ESPTOOLPY_AFTER})
  27. set(otatool_args --partition-table-file ${PARTITION_CSV_PATH})
  28. list(APPEND otatool_args --partition-table-offset ${PARTITION_TABLE_OFFSET})
  29. idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
  30. add_custom_target(read-otadata DEPENDS "${PARTITION_CSV_PATH}"
  31. COMMAND ${CMAKE_COMMAND}
  32. -D "IDF_PATH=${idf_path}"
  33. -D "SERIAL_TOOL=${otatool_py}"
  34. -D "SERIAL_TOOL_ARGS=${esptool_args};${otatool_args};read_otadata"
  35. -D "WORKING_DIRECTORY=${build_dir}"
  36. -P ${esptool_py_dir}/run_serial_tool.cmake
  37. WORKING_DIRECTORY "${build_dir}"
  38. USES_TERMINAL
  39. VERBATIM
  40. )
  41. add_deprecated_target_alias(read_otadata read-otadata)
  42. add_custom_target(erase-otadata DEPENDS "${PARTITION_CSV_PATH}"
  43. COMMAND ${CMAKE_COMMAND}
  44. -D "IDF_PATH=${idf_path}"
  45. -D "SERIAL_TOOL=${otatool_py}"
  46. -D "SERIAL_TOOL_ARGS=${esptool_args};${otatool_args};erase_otadata"
  47. -D "WORKING_DIRECTORY=${build_dir}"
  48. -P ${esptool_py_dir}/run_serial_tool.cmake
  49. WORKING_DIRECTORY "${build_dir}"
  50. USES_TERMINAL
  51. VERBATIM
  52. )
  53. add_deprecated_target_alias(erase_otadata erase-otadata)
  54. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  55. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  56. esptool_py_flash_target(otadata-flash "${main_args}" "${sub_args}")
  57. esptool_py_flash_target_image(otadata-flash otadata "${otadata_offset}" "${blank_otadata_file}")
  58. esptool_py_flash_target_image(flash otadata "${otadata_offset}" "${blank_otadata_file}")
  59. endif()
  60. endif()