project_include.cmake 1.7 KB

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