project_include.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. if(NOT "${size}")
  15. message(WARNING "spiffsgen: Unable to resolve size of partition '${partition}'. "
  16. "Check config if using correct partition table.")
  17. endif()
  18. if(NOT "${offset}")
  19. message(WARNING "spiffsgen: Unable to resolve offset of partition '${partition}'. "
  20. "Check config if using correct partition table.")
  21. endif()
  22. set(image_file ${CMAKE_BINARY_DIR}/${partition}.bin)
  23. if(CONFIG_SPIFFS_USE_MAGIC)
  24. set(use_magic "--use-magic")
  25. endif()
  26. if(CONFIG_SPIFFS_USE_MAGIC_LENGTH)
  27. set(use_magic_len "--use-magic-len")
  28. endif()
  29. # Execute SPIFFS image generation; this always executes as there is no way to specify for CMake to watch for
  30. # contents of the base dir changing.
  31. add_custom_target(spiffs_${partition}_bin ALL
  32. COMMAND ${spiffsgen_py} ${size} ${base_dir_full_path} ${image_file}
  33. --page-size=${CONFIG_SPIFFS_PAGE_SIZE}
  34. --obj-name-len=${CONFIG_SPIFFS_OBJ_NAME_LEN}
  35. --meta-len=${CONFIG_SPIFFS_META_LENGTH}
  36. ${use_magic}
  37. ${use_magic_len}
  38. DEPENDS ${arg_DEPENDS}
  39. )
  40. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  41. ADDITIONAL_MAKE_CLEAN_FILES
  42. ${image_file})
  43. if(arg_FLASH_IN_PROJECT)
  44. esptool_py_flash_project_args("${partition}" "${offset}" "${image_file}" FLASH_IN_PROJECT)
  45. else()
  46. esptool_py_flash_project_args("${partition}" "${offset}" "${image_file}")
  47. endif()
  48. endfunction()