project_include.cmake 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. if("${CONFIG_FATFS_SECTORS_PER_CLUSTER_1}")
  16. set(sectors_per_cluster 1)
  17. elseif("${CONFIG_FATFS_SECTORS_PER_CLUSTER_2}")
  18. set(sectors_per_cluster 2)
  19. elseif("${CONFIG_FATFS_SECTORS_PER_CLUSTER_4}")
  20. set(sectors_per_cluster 4)
  21. elseif("${CONFIG_FATFS_SECTORS_PER_CLUSTER_8}")
  22. set(sectors_per_cluster 8)
  23. elseif("${CONFIG_FATFS_SECTORS_PER_CLUSTER_16}")
  24. set(sectors_per_cluster 16)
  25. elseif("${CONFIG_FATFS_SECTORS_PER_CLUSTER_32}")
  26. set(sectors_per_cluster 32)
  27. elseif("${CONFIG_FATFS_SECTORS_PER_CLUSTER_64}")
  28. set(sectors_per_cluster 64)
  29. elseif("${CONFIG_FATFS_SECTORS_PER_CLUSTER_128}")
  30. set(sectors_per_cluster 128)
  31. endif()
  32. if("${CONFIG_FATFS_SECTOR_512}")
  33. set(fatfs_sector_size 512)
  34. elseif("${CONFIG_FATFS_SECTOR_1024}")
  35. set(fatfs_sector_size 1024)
  36. elseif("${CONFIG_FATFS_SECTOR_2048}")
  37. set(fatfs_sector_size 2048)
  38. else()
  39. set(fatfs_sector_size 4096)
  40. endif()
  41. if("${CONFIG_FATFS_AUTO_TYPE}")
  42. set(fatfs_explicit_type 0)
  43. elseif("${CONFIG_FATFS_FAT12}")
  44. set(fatfs_explicit_type 12)
  45. elseif("${CONFIG_FATFS_FAT16}")
  46. set(fatfs_explicit_type 16)
  47. endif()
  48. get_filename_component(base_dir_full_path ${base_dir} ABSOLUTE)
  49. partition_table_get_partition_info(size "--partition-name ${partition}" "size")
  50. partition_table_get_partition_info(offset "--partition-name ${partition}" "offset")
  51. if("${size}" AND "${offset}")
  52. set(image_file ${CMAKE_BINARY_DIR}/${partition}.bin)
  53. # Execute FATFS image generation; this always executes as there is no way to specify for CMake to watch for
  54. # contents of the base dir changing.
  55. add_custom_target(fatfs_${partition}_bin ALL
  56. COMMAND ${fatfsgen_py} ${base_dir_full_path}
  57. --partition_size ${size}
  58. --output_file ${image_file}
  59. --sector_size "${fatfs_sector_size}"
  60. --sectors_per_cluster "${sectors_per_cluster}"
  61. --fat_type "${fatfs_explicit_type}"
  62. )
  63. set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
  64. ADDITIONAL_MAKE_CLEAN_FILES
  65. ${image_file})
  66. idf_component_get_property(main_args esptool_py FLASH_ARGS)
  67. idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
  68. # Last (optional) parameter is the encryption for the target. In our
  69. # case, fatfs is not encrypt so pass FALSE to the function.
  70. esptool_py_flash_target(${partition}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT)
  71. esptool_py_flash_to_partition(${partition}-flash "${partition}" "${image_file}")
  72. add_dependencies(${partition}-flash fatfs_${partition}_bin)
  73. if(arg_FLASH_IN_PROJECT)
  74. esptool_py_flash_to_partition(flash "${partition}" "${image_file}")
  75. add_dependencies(flash fatfs_${partition}_bin)
  76. endif()
  77. else()
  78. set(message "Failed to create FATFS image for partition '${partition}'. "
  79. "Check project configuration if using the correct partition table file.")
  80. fail_at_build_time(fatfs_${partition}_bin "${message}")
  81. endif()
  82. endfunction()
  83. function(fatfs_create_rawflash_image partition base_dir)
  84. set(options FLASH_IN_PROJECT)
  85. cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
  86. if(arg_FLASH_IN_PROJECT)
  87. fatfs_create_partition_image(${partition} ${base_dir} FLASH_IN_PROJECT)
  88. else()
  89. fatfs_create_partition_image(${partition} ${base_dir})
  90. endif()
  91. endfunction()
  92. function(fatfs_create_spiflash_image partition base_dir)
  93. set(options FLASH_IN_PROJECT)
  94. cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
  95. if(arg_FLASH_IN_PROJECT)
  96. fatfs_create_partition_image(${partition} ${base_dir} FLASH_IN_PROJECT WL_INIT)
  97. else()
  98. fatfs_create_partition_image(${partition} ${base_dir} WL_INIT)
  99. endif()
  100. endfunction()