project_include.cmake 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. set(PARTITION_TABLE_OFFSET ${CONFIG_PARTITION_TABLE_OFFSET})
  2. set(PARTITION_TABLE_CHECK_SIZES_TOOL_PATH "${CMAKE_CURRENT_LIST_DIR}/check_sizes.py")
  3. idf_build_get_property(build_dir BUILD_DIR)
  4. idf_build_set_property(PARTITION_TABLE_BIN_PATH "${build_dir}/partition_table/partition-table.bin")
  5. if(NOT BOOTLOADER_BUILD)
  6. # Set PARTITION_CSV_PATH to the configured partition CSV file
  7. # absolute path
  8. if(CONFIG_PARTITION_TABLE_CUSTOM)
  9. idf_build_get_property(project_dir PROJECT_DIR)
  10. # Custom filename expands any path relative to the project
  11. get_filename_component(PARTITION_CSV_PATH "${CONFIG_PARTITION_TABLE_FILENAME}"
  12. ABSOLUTE BASE_DIR "${project_dir}")
  13. if(NOT EXISTS "${PARTITION_CSV_PATH}")
  14. message(WARNING "Partition table CSV file ${PARTITION_CSV_PATH} not found. "
  15. "Change custom partition CSV path in menuconfig.")
  16. # Note: partition_table CMakeLists.txt contains some logic to create a dummy
  17. # partition_table target in this case, see comments in that file.
  18. endif()
  19. else()
  20. # Other .csv files are always in the component directory
  21. get_filename_component(PARTITION_CSV_PATH "${COMPONENT_DIR}/${CONFIG_PARTITION_TABLE_FILENAME}" ABSOLUTE)
  22. if(NOT EXISTS "${PARTITION_CSV_PATH}")
  23. message(FATAL_ERROR "Internal error, built-in ${PARTITION_CSV_PATH} not found.")
  24. endif()
  25. endif()
  26. # need to re-run CMake if the partition CSV changes, as the offsets/sizes of partitions may change
  27. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${PARTITION_CSV_PATH})
  28. endif()
  29. # partition_table_get_partition_info
  30. #
  31. # Get information about a partition from the partition table
  32. function(partition_table_get_partition_info result get_part_info_args part_info)
  33. idf_build_get_property(python PYTHON)
  34. idf_build_get_property(idf_path IDF_PATH)
  35. idf_build_get_property(extra_subtypes EXTRA_PARTITION_SUBTYPES)
  36. if(extra_subtypes)
  37. # Remove all white spaces from the string
  38. string(REPLACE " " "" extra_subtypes "${extra_subtypes}")
  39. set(extra_partition_subtypes --extra-partition-subtypes ${extra_subtypes})
  40. else()
  41. set(extra_partition_subtypes "")
  42. endif()
  43. separate_arguments(get_part_info_args)
  44. execute_process(COMMAND ${python}
  45. ${idf_path}/components/partition_table/parttool.py -q
  46. --partition-table-offset ${PARTITION_TABLE_OFFSET}
  47. --partition-table-file ${PARTITION_CSV_PATH}
  48. get_partition_info ${get_part_info_args} --info ${part_info}
  49. ${extra_partition_subtypes}
  50. OUTPUT_VARIABLE info
  51. RESULT_VARIABLE exit_code
  52. OUTPUT_STRIP_TRAILING_WHITESPACE)
  53. if(NOT ${exit_code} EQUAL 0 AND NOT ${exit_code} EQUAL 1)
  54. # can't fail here as it would prevent the user from running 'menuconfig' again
  55. message(WARNING "parttool.py execution failed (${result}), problem with partition CSV file (see above)")
  56. endif()
  57. set(${result} ${info} PARENT_SCOPE)
  58. endfunction()
  59. # Add a custom target (see add_custom_target) that checks a given binary built by the build system
  60. # doesn't overflow any partitions with the given partition type and (optional) sub-type.
  61. #
  62. # Adding the target doesn't mean it gets called during the build, use add_dependencies to make another
  63. # target depend on this one.
  64. #
  65. # Arguments:
  66. # - target name - (first argument) name of the target to create
  67. # - DEPENDS - dependencies the target should have (i.e. whatever target generates the binary).
  68. # - BINARY_PATH - path to the target binary file to check
  69. # - PARTITION_TYPE - partition type to check against
  70. # - PARTITION_SUBTYPE - (optional) partition subtype to check against
  71. function(partition_table_add_check_size_target target_name)
  72. # result binary_path partition_type partition_subtype
  73. set(args BINARY_PATH PARTITION_TYPE PARTITION_SUBTYPE)
  74. set(multi_args DEPENDS)
  75. cmake_parse_arguments(CMD "" "${args}" "${multi_args}" ${ARGN})
  76. idf_build_get_property(python PYTHON)
  77. idf_build_get_property(table_bin PARTITION_TABLE_BIN_PATH)
  78. if(CMD_PARTITION_SUBTYPE)
  79. set(subtype_arg --subtype ${CMD_PARTITION_SUBTYPE})
  80. else()
  81. set(subtype_arg)
  82. endif()
  83. set(command ${python} ${PARTITION_TABLE_CHECK_SIZES_TOOL_PATH}
  84. --offset ${PARTITION_TABLE_OFFSET}
  85. partition --type ${CMD_PARTITION_TYPE} ${subtype_arg}
  86. ${table_bin} ${CMD_BINARY_PATH})
  87. add_custom_target(${target_name} COMMAND ${command} DEPENDS ${CMD_DEPENDS} partition_table_bin)
  88. endfunction()
  89. # Add a custom target (see add_custom_target) that checks a bootloader binary
  90. # built by the build system will not overlap the partition table.
  91. #
  92. # Adding the target doesn't mean it gets called during the build, use add_dependencies to make another
  93. # target depend on this one.
  94. #
  95. # Arguments:
  96. # - target name - (first argument) name of the target to create
  97. # - DEPENDS - dependencies the new target should have (i.e. whatever target generates the bootloader binary)
  98. # - BOOTLOADER_BINARY_PATH - path to bootloader binary file
  99. function(partition_table_add_check_bootloader_size_target target_name)
  100. cmake_parse_arguments(CMD "" "BOOTLOADER_BINARY_PATH" "DEPENDS" ${ARGN})
  101. idf_build_get_property(python PYTHON)
  102. set(command ${python} ${PARTITION_TABLE_CHECK_SIZES_TOOL_PATH}
  103. --offset ${PARTITION_TABLE_OFFSET}
  104. bootloader ${BOOTLOADER_OFFSET} ${CMD_BOOTLOADER_BINARY_PATH})
  105. add_custom_target(${target_name} COMMAND ${command} DEPENDS ${CMD_DEPENDS})
  106. endfunction()