project_include.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # fatfs_create_partition_image
  2. #
  3. # Create a fatfs image of the specified directory on the host during build and optionally
  4. # have the created image flashed using `idf.py flash`
  5. function(fatfs_create_partition_image partition base_dir)
  6. set(options FLASH_IN_PROJECT WL_INIT)
  7. cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
  8. idf_build_get_property(idf_path IDF_PATH)
  9. idf_build_get_property(python PYTHON)
  10. if(arg_WL_INIT)
  11. set(fatfsgen_py ${python} ${idf_path}/components/fatfs/wl_fatfsgen.py)
  12. else()
  13. set(fatfsgen_py ${python} ${idf_path}/components/fatfs/fatfsgen.py)
  14. endif()
  15. get_filename_component(base_dir_full_path ${base_dir} ABSOLUTE)
  16. partition_table_get_partition_info(size "--partition-name ${partition}" "size")
  17. partition_table_get_partition_info(offset "--partition-name ${partition}" "offset")
  18. if("${size}" AND "${offset}")
  19. set(image_file ${CMAKE_BINARY_DIR}/${partition}.bin)
  20. # Execute FATFS 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(fatfs_${partition}_bin ALL
  23. COMMAND ${fatfsgen_py} ${base_dir_full_path}
  24. --partition_size ${size}
  25. --output_file ${image_file}
  26. )
  27. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  28. ADDITIONAL_MAKE_CLEAN_FILES
  29. ${image_file})
  30. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  31. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  32. # Last (optional) parameter is the encryption for the target. In our
  33. # case, fatfs is not encrypt so pass FALSE to the function.
  34. esptool_py_flash_target(${partition}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT)
  35. esptool_py_flash_to_partition(${partition}-flash "${partition}" "${image_file}")
  36. add_dependencies(${partition}-flash fatfs_${partition}_bin)
  37. if(arg_FLASH_IN_PROJECT)
  38. esptool_py_flash_to_partition(flash "${partition}" "${image_file}")
  39. add_dependencies(flash fatfs_${partition}_bin)
  40. endif()
  41. else()
  42. set(message "Failed to create FATFS image for partition '${partition}'. "
  43. "Check project configuration if using the correct partition table file.")
  44. fail_at_build_time(fatfs_${partition}_bin "${message}")
  45. endif()
  46. endfunction()
  47. function(fatfs_create_rawflash_image partition base_dir)
  48. set(options FLASH_IN_PROJECT)
  49. cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
  50. if(arg_FLASH_IN_PROJECT)
  51. fatfs_create_partition_image(${partition} ${base_dir} FLASH_IN_PROJECT)
  52. else()
  53. fatfs_create_partition_image(${partition} ${base_dir})
  54. endif()
  55. endfunction()
  56. function(fatfs_create_spiflash_image partition base_dir)
  57. set(options FLASH_IN_PROJECT)
  58. cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
  59. if(arg_FLASH_IN_PROJECT)
  60. fatfs_create_partition_image(${partition} ${base_dir} FLASH_IN_PROJECT WL_INIT)
  61. else()
  62. fatfs_create_partition_image(${partition} ${base_dir} WL_INIT)
  63. endif()
  64. endfunction()