project_include.cmake 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. cmake_parse_arguments(arg "${options}" "" "" "${ARGN}")
  8. set(spiffsgen_py ${PYTHON} ${IDF_PATH}/components/spiffs/spiffsgen.py)
  9. get_filename_component(base_dir_full_path ${base_dir} ABSOLUTE)
  10. partition_table_get_partition_info(size "--partition-name ${partition}" "size")
  11. partition_table_get_partition_info(offset "--partition-name ${partition}" "offset")
  12. set(image_file ${CMAKE_BINARY_DIR}/${partition}.bin)
  13. if(CONFIG_SPIFFS_USE_MAGIC)
  14. set(use_magic "--use-magic")
  15. endif()
  16. if(CONFIG_SPIFFS_USE_MAGIC_LENGTH)
  17. set(use_magic_len "--use-magic-len")
  18. endif()
  19. # Execute SPIFFS image generation; this always executes as there is no way to specify for CMake to watch for
  20. # contents of the base dir changing.
  21. add_custom_target(spiffs_${partition}_bin ALL
  22. COMMAND ${spiffsgen_py} ${size} ${base_dir_full_path} ${image_file}
  23. --page-size=${CONFIG_SPIFFS_PAGE_SIZE}
  24. --obj-name-len=${CONFIG_SPIFFS_OBJ_NAME_LEN}
  25. --meta-len=${CONFIG_SPIFFS_META_LENGTH}
  26. ${use_magic}
  27. ${use_magic_len}
  28. )
  29. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  30. ADDITIONAL_MAKE_CLEAN_FILES
  31. ${image_file})
  32. if(arg_FLASH_IN_PROJECT)
  33. esptool_py_flash_project_args(${partition} ${offset} ${image_file} FLASH_IN_PROJECT)
  34. else()
  35. esptool_py_flash_project_args(${partition} ${offset} ${image_file})
  36. endif()
  37. endfunction()