project_include.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. if(CONFIG_SPIFFS_FOLLOW_SYMLINKS)
  22. set(follow_symlinks "--follow-symlinks")
  23. endif()
  24. # Execute SPIFFS image generation; this always executes as there is no way to specify for CMake to watch for
  25. # contents of the base dir changing.
  26. add_custom_target(spiffs_${partition}_bin ALL
  27. COMMAND ${spiffsgen_py} ${size} ${base_dir_full_path} ${image_file}
  28. --page-size=${CONFIG_SPIFFS_PAGE_SIZE}
  29. --obj-name-len=${CONFIG_SPIFFS_OBJ_NAME_LEN}
  30. --meta-len=${CONFIG_SPIFFS_META_LENGTH}
  31. ${follow_symlinks}
  32. ${use_magic}
  33. ${use_magic_len}
  34. DEPENDS ${arg_DEPENDS}
  35. )
  36. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  37. ADDITIONAL_MAKE_CLEAN_FILES
  38. ${image_file})
  39. if(arg_FLASH_IN_PROJECT)
  40. esptool_py_flash_project_args(${partition} ${offset} ${image_file} FLASH_IN_PROJECT)
  41. else()
  42. esptool_py_flash_project_args(${partition} ${offset} ${image_file})
  43. endif()
  44. endfunction()