From 73ee5ee8e226badbffb32892e98db126d36eb240 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Tue, 9 Sep 2025 08:40:38 +0200 Subject: [PATCH] feat(cmakev2/build): add idf_check_binary_size function Given the binary target created by the idf_build_binary or idf_sign_binary function, add a new dependency that verifies whether the binary image fits within the smallest application partition. Signed-off-by: Frantisek Hrbata --- tools/cmakev2/build.cmake | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index e936278545d..54551533930 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -872,3 +872,35 @@ function(idf_flash_binary binary) add_dependencies(flash "${binary}") endif() endfunction() + +#[[api +.. cmakev2:function:: idf_check_binary_size + + .. code-block:: cmake + + idf_check_binary_size() + + :binary[in]: Binary image target to which to add a partition size check. + The ``binary`` target is created by the ``idf_build_binary`` + or ``idf_sign_binary`` function. + + Ensure that the generated binary image fits within the smallest available + application partition. The file path of the binary image should be stored in + the ``BINARY_PATH`` property of the ``binary`` target. +#]] +function(idf_check_binary_size binary) + if(NOT CONFIG_APP_BUILD_TYPE_APP_2NDBOOT) + return() + endif() + + get_target_property(binary_path ${binary} BINARY_PATH) + if(NOT binary_path) + idf_die("Binary target '${binary}' is missing 'BINARY_PATH' property.") + endif() + + partition_table_add_check_size_target("${binary}_check_size" + DEPENDS "${binary_path}" + BINARY_PATH "${binary_path}" + PARTITION_TYPE app) + add_dependencies("${binary}" "${binary}_check_size") +endfunction()