project_include.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # spiffs_create_partition_image
  2. #
  3. # Create a spiffs image of the specified directory on the host during build and optionally
  4. # have the created image flashed using `idf.py flash`
  5. function(spiffs_create_partition_image partition base_dir)
  6. set(options FLASH_IN_PROJECT)
  7. set(multi DEPENDS)
  8. cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
  9. idf_build_get_property(idf_path IDF_PATH)
  10. set(spiffsgen_py ${PYTHON} ${idf_path}/components/spiffs/spiffsgen.py)
  11. get_filename_component(base_dir_full_path ${base_dir} ABSOLUTE)
  12. partition_table_get_partition_info(size "--partition-name ${partition}" "size")
  13. partition_table_get_partition_info(offset "--partition-name ${partition}" "offset")
  14. set(image_file ${CMAKE_BINARY_DIR}/${partition}.bin)
  15. if(CONFIG_SPIFFS_USE_MAGIC)
  16. set(use_magic "--use-magic")
  17. endif()
  18. if(CONFIG_SPIFFS_USE_MAGIC_LENGTH)
  19. set(use_magic_len "--use-magic-len")
  20. endif()
  21. # Execute SPIFFS image generation; this always executes as there is no way to specify for CMake to watch for
  22. # contents of the base dir changing.
  23. add_custom_target(spiffs_${partition}_bin ALL
  24. COMMAND ${spiffsgen_py} ${size} ${base_dir_full_path} ${image_file}
  25. --page-size=${CONFIG_SPIFFS_PAGE_SIZE}
  26. --obj-name-len=${CONFIG_SPIFFS_OBJ_NAME_LEN}
  27. --meta-len=${CONFIG_SPIFFS_META_LENGTH}
  28. ${use_magic}
  29. ${use_magic_len}
  30. DEPENDS ${arg_DEPENDS}
  31. )
  32. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  33. ADDITIONAL_MAKE_CLEAN_FILES
  34. ${image_file})
  35. if(arg_FLASH_IN_PROJECT)
  36. esptool_py_flash_project_args(${partition} ${offset} ${image_file} FLASH_IN_PROJECT)
  37. else()
  38. esptool_py_flash_project_args(${partition} ${offset} ${image_file})
  39. endif()
  40. endfunction()