CMakeLists.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. # esp_app_desc structure is added as an undefined symbol because otherwise the
  6. # linker will ignore this structure as it has no other files depending on it.
  7. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_app_desc")
  8. if(CONFIG_APP_PROJECT_VER_FROM_CONFIG)
  9. # Ignore current PROJECT_VER (which was set in __project_get_revision()).
  10. # Gets the version from the CONFIG_APP_PROJECT_VER.
  11. idf_build_set_property(PROJECT_VER "${CONFIG_APP_PROJECT_VER}")
  12. endif()
  13. # cut PROJECT_VER and PROJECT_NAME to required 32 characters.
  14. idf_build_get_property(project_ver PROJECT_VER)
  15. idf_build_get_property(project_name PROJECT_NAME)
  16. string(SUBSTRING "${project_ver}" 0 31 PROJECT_VER_CUT)
  17. string(SUBSTRING "${project_name}" 0 31 PROJECT_NAME_CUT)
  18. message(STATUS "App \"${PROJECT_NAME_CUT}\" version: ${PROJECT_VER_CUT}")
  19. set_source_files_properties(
  20. SOURCE "esp_app_desc.c"
  21. PROPERTIES COMPILE_DEFINITIONS
  22. "PROJECT_VER=\"${PROJECT_VER_CUT}\"; PROJECT_NAME=\"${PROJECT_NAME_CUT}\"")
  23. if(NOT BOOTLOADER_BUILD)
  24. partition_table_get_partition_info(otadata_offset "--partition-type data --partition-subtype ota" "offset")
  25. partition_table_get_partition_info(otadata_size "--partition-type data --partition-subtype ota" "size")
  26. # Add custom target for generating empty otadata partition for flashing
  27. if(otadata_size AND otadata_offset)
  28. idf_build_get_property(build_dir BUILD_DIR)
  29. set(blank_otadata_file ${build_dir}/ota_data_initial.bin)
  30. idf_build_get_property(idf_path IDF_PATH)
  31. idf_build_get_property(python PYTHON)
  32. idf_component_get_property(partition_table_dir partition_table COMPONENT_DIR)
  33. add_custom_command(OUTPUT ${blank_otadata_file}
  34. COMMAND ${python} ${partition_table_dir}/gen_empty_partition.py
  35. ${otadata_size} ${blank_otadata_file})
  36. add_custom_target(blank_ota_data ALL DEPENDS ${blank_otadata_file})
  37. add_dependencies(flash blank_ota_data)
  38. set(otatool_py ${python} ${COMPONENT_DIR}/otatool.py)
  39. set(esptool_args --esptool-args before=${CONFIG_ESPTOOLPY_BEFORE} after=${CONFIG_ESPTOOLPY_AFTER})
  40. add_custom_target(read_otadata DEPENDS "${PARTITION_CSV_PATH}"
  41. COMMAND ${otatool_py} ${esptool_args}
  42. --partition-table-file ${PARTITION_CSV_PATH}
  43. --partition-table-offset ${PARTITION_TABLE_OFFSET}
  44. read_otadata)
  45. add_custom_target(erase_otadata DEPENDS "${PARTITION_CSV_PATH}"
  46. COMMAND ${otatool_py} ${esptool_args}
  47. --partition-table-file ${PARTITION_CSV_PATH}
  48. --partition-table-offset ${PARTITION_TABLE_OFFSET}
  49. erase_otadata)
  50. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  51. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  52. esptool_py_flash_target(otadata-flash "${main_args}" "${sub_args}")
  53. esptool_py_flash_target_image(otadata-flash otadata "${otadata_offset}" "${blank_otadata_file}")
  54. esptool_py_flash_target_image(flash otadata "${otadata_offset}" "${blank_otadata_file}")
  55. endif()
  56. endif()