1+ # Include additional cmake files for specific functionalities
2+ include ("${CMAKE_CURRENT_LIST_DIR} /flash_targets.cmake" )
3+ include ("${CMAKE_CURRENT_LIST_DIR} /post_build_validation.cmake" )
4+
15# idf_build_get_property
26#
37# @brief Retrieve the value of the specified property related to ESP-IDF build.
@@ -776,18 +780,11 @@ function(idf_build_executable elf)
776780 # Add dependency of the build target to the executable
777781 add_dependencies (${elf} __idf_build_target)
778782
779- # Set up esptool_py flash targets
780- # This must be done after the executable properties are set but before the function exits
781- # so that all components have had a chance to add their images to the phony flash targets
782- idf_build_get_property(bootloader_build BOOTLOADER_BUILD)
783- idf_build_get_property(esp_tee_build ESP_TEE_BUILD)
784- idf_build_get_property(target IDF_TARGET)
785-
786783 # This is the main orchestrator for generating binaries and flash targets
787784 # It is responsible for -
788785 # - Setting up the binary generation targets
789786 # - Setting up the signed binary generation targets
790- # - Setting up the main 'flash' target
787+ # - Setting up the main 'flash' target and generating flasher_args.json
791788 # - Setting up the app-flash and flash targets
792789 # - Setting up the app_check_size target
793790 #
@@ -798,6 +795,10 @@ function(idf_build_executable elf)
798795 # Note: We need to have this block here instead of in project.cmake because
799796 # idf_build_executable() is called directly when ESP-IDF is compiled
800797 # as a library (idf_as_lib).
798+
799+ idf_build_get_property(bootloader_build BOOTLOADER_BUILD)
800+ idf_build_get_property(esp_tee_build ESP_TEE_BUILD)
801+
801802 if (NOT bootloader_build AND NOT esp_tee_build)
802803 # All of the following logic for generating binaries and flash targets
803804 # depends on the esptool_py component. For some builds (such as those
@@ -828,88 +829,14 @@ function(idf_build_executable elf)
828829 __idf_build_secure_binary("${project_bin_unsigned} " "${project_bin} " "${signed_target_name} " )
829830 endif ()
830831
831- # The following block is placed here to ensure that the application binary is added to the 'flash'
832- # target's properties *before* __esptool_py_setup_main_flash_target is called.
833- # This is because __esptool_py_setup_main_flash_target copies properties from the 'flash'
834- # target to an internal '_flash_impl' target, from which the final 'flash_args' file is generated.
835- # If the app target is not added to the 'flash' target *before* the properties are copied,
836- # the app binary will be missing from the final 'flash_args' file.
837- #
838- # Set up app-flash and flash targets. The app-flash target is specifically for flashing
839- # just the application, while the flash target is for flashing the entire system.
840- idf_build_get_property(build_dir BUILD_DIR)
841- idf_build_get_property(project_bin PROJECT_BIN)
842- partition_table_get_partition_info(app_partition_offset "--partition-boot-default" "offset" )
843- esptool_py_custom_target(app-flash app "app" )
844-
845- esptool_py_flash_target_image(app-flash app "${app_partition_offset} " "${build_dir} /${project_bin} " )
846- esptool_py_flash_target_image(flash app "${app_partition_offset} " "${build_dir} /${project_bin} " )
832+ # Setup flash targets and flash configuration
833+ __idf_build_setup_flash_targets()
847834
848835 # Setup utility targets such as monitor, erase_flash, merge-bin
849836 __esptool_py_setup_utility_targets()
850837
851- # Setup the main flash target and dependencies
852- __esptool_py_setup_main_flash_target()
853-
854- # Generate flasher_args.json for tools that need it. The variables below are used
855- # in configuring the template flasher_args.json.in.
856- # Some of the variables (flash mode, size, frequency) are set as esptool_py component's properties.
857-
858- idf_build_get_property(target IDF_TARGET)
859- set (ESPTOOLPY_CHIP "${target} " )
860- set (ESPTOOLPY_BEFORE "${CONFIG_ESPTOOLPY_BEFORE} " )
861- set (ESPTOOLPY_AFTER "${CONFIG_ESPTOOLPY_AFTER} " )
862- if (CONFIG_ESPTOOLPY_NO_STUB)
863- set (ESPTOOLPY_WITH_STUB false )
864- else ()
865- set (ESPTOOLPY_WITH_STUB true )
866- endif ()
867-
868- if (CONFIG_SECURE_BOOT OR CONFIG_SECURE_FLASH_ENC_ENABLED)
869- # If security enabled then override post flash option
870- set (ESPTOOLPY_AFTER "no_reset" )
871- endif ()
872-
873- idf_component_get_property(ESPFLASHMODE esptool_py ESPFLASHMODE)
874- idf_component_get_property(ESPFLASHFREQ esptool_py ESPFLASHFREQ)
875- idf_component_get_property(ESPFLASHSIZE esptool_py ESPFLASHSIZE)
876- idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
877-
878- # Generate flasher args files
879- file (READ "${esptool_py_dir} /flasher_args.json.in" flasher_args_content)
880- string (CONFIGURE "${flasher_args_content} " flasher_args_content)
881-
882- # We need to create a flasher_args.json.in to create the final flasher_args.json
883- # because CMake only resolves generator expressions in the file_generate command
884- # with the INPUT keyword during the generation phase.
885- file_generate("${build_dir} /flasher_args.json.in"
886- CONTENT "${flasher_args_content} " )
887- file_generate("${build_dir} /flasher_args.json"
888- INPUT "${build_dir} /flasher_args.json.in" )
889-
890- # Create the following post-build targets after __idf_build_binary() is called to ensure that the
891- # app target is available.
892-
893- # If anti-rollback option is set then factory partition should not be in Partition Table.
894- # In this case, should be used the partition table with two ota app without the factory.
895- partition_table_get_partition_info(factory_offset
896- "--partition-type app --partition-subtype factory" "offset" )
897- partition_table_get_partition_info(test_offset "--partition-type app --partition-subtype test" "offset" )
898- if (CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK AND (factory_offset OR test_offset))
899- fail_at_build_time(check_table_contents "\
900- ERROR: Anti-rollback option is enabled. Partition table should \
901- consist of two ota app without factory or test partitions." )
902- add_dependencies (app check_table_contents)
903- endif ()
904-
905- if (CONFIG_APP_BUILD_TYPE_APP_2NDBOOT)
906- # Generate app_check_size_command target to check the app size against the partition table parameters
907- partition_table_add_check_size_target(app_check_size
908- DEPENDS gen_project_binary
909- BINARY_PATH "${build_dir} /${project_bin} "
910- PARTITION_TYPE app)
911- add_dependencies (app app_check_size)
912- endif ()
838+ # Setup post-build validation checks
839+ __idf_build_setup_post_build_validation()
913840 endif () # if(TARGET idf::esptool_py AND CONFIG_APP_BUILD_GENERATE_BINARIES)
914841 endif () # if(NOT bootloader_build AND NOT esp_tee_build)
915842endfunction ()
0 commit comments