From 6bf5d9bf7d0b85fdb589b7fb16c44ebe2a7a0f0f Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Wed, 20 Nov 2024 22:43:05 +0000 Subject: [PATCH] Enforce ordering of pico_add_extra_outputs and picotool functions (#2054) * Thow FATAL_ERROR when using post-processing functions after pico_add_extra_outputs * Remove property definition, and rename to `PICOTOOL_PROCESSING_CONFIGURED` and `picotool_check_configurable` * done -> configured --- tools/CMakeLists.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index d7204bc9a..d98ea4d15 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -146,6 +146,13 @@ function(pico_init_picotool) endif() endfunction() +function(picotool_check_configurable TARGET) + get_target_property(configured ${TARGET} PICOTOOL_PROCESSING_CONFIGURED) + if (configured) + message(FATAL_ERROR "All picotool post-processing functions for \"${TARGET}\" must come before pico_add_extra_outputs(${TARGET})") + endif() +endfunction() + # Generate pio header and include it in the build # PICO_CMAKE_CONFIG: PICO_DEFAULT_PIOASM_OUTPUT_FORMAT, Default output format used by pioasm when using pico_generate_pio_header, type=string, default=c-sdk, group=build function(pico_generate_pio_header TARGET PIO) @@ -198,6 +205,7 @@ endfunction() # dropping, and it will be copied to SRAM by the bootrom before execution. # This sets PICOTOOL_UF2_PACKAGE_ADDR to PACKADDR. function(pico_package_uf2_output TARGET PACKADDR) + picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES PICOTOOL_UF2_PACKAGE_ADDR ${PACKADDR} ) @@ -207,6 +215,7 @@ endfunction() # Output the public key hash and other necessary rows to an otp JSON file. # This sets PICOTOOL_OTP_FILE to OTPFILE. function(pico_set_otp_key_output_file TARGET OTPFILE) + picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES PICOTOOL_OTP_FILE ${OTPFILE} ) @@ -217,6 +226,7 @@ endfunction() # before loading the binary. This appends the `--clear` argument # to PICOTOOL_EXTRA_PROCESS_ARGS. function(pico_load_map_clear_sram TARGET) + picotool_check_configurable(${TARGET}) # get and set, to inherit list get_target_property(extra_args ${TARGET} PICOTOOL_EXTRA_PROCESS_ARGS) if (extra_args) @@ -234,6 +244,7 @@ endfunction() # to PICOTOOL_EXTRA_PROCESS_ARGS if setting the rollback version, or set as compile # definitions if only setting the major/minor versions. function(pico_set_binary_version TARGET) + picotool_check_configurable(${TARGET}) set(oneValueArgs MAJOR MINOR ROLLBACK) set(multiValueArgs ROWS) cmake_parse_arguments(PARSE_ARGV 1 SV "" "${oneValueArgs}" "${multiValueArgs}") @@ -283,6 +294,7 @@ endfunction() # Set the UF2 family to use when creating the UF2. # This sets PICOTOOL_UF2_FAMILY to FAMILY. function(pico_set_uf2_family TARGET FAMILY) + picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES PICOTOOL_UF2_FAMILY ${FAMILY} ) @@ -295,6 +307,7 @@ endfunction() # specify a common SIGFILE for multiple targets, the SIGFILE property can be # set for a given scope, and then the SIGFILE argument is optional. function(pico_sign_binary TARGET) + picotool_check_configurable(${TARGET}) # Enforce signing through target properties set_target_properties(${TARGET} PROPERTIES PICOTOOL_SIGN_OUTPUT true @@ -320,6 +333,7 @@ endfunction() # pico_hash_binary(TARGET) # Hash the target binary. This sets PICOTOOL_HASH_OUTPUT to true. function(pico_hash_binary TARGET) + picotool_check_configurable(${TARGET}) # Enforce hashing through target properties set_target_properties(${TARGET} PROPERTIES PICOTOOL_HASH_OUTPUT true @@ -330,6 +344,7 @@ endfunction() # Create the specified partition table from JSON, and embed it in the # block loop. This sets PICOTOOL_EMBED_PT to PTFILE. function(pico_embed_pt_in_binary TARGET PTFILE) + picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES PICOTOOL_EMBED_PT ${PTFILE} ) @@ -341,6 +356,7 @@ endfunction() # This sets PICOTOOL_AESFILE to AESFILE, and PICOTOOL_ENC_SIGFILE to SIGFILE # if present, else PICOTOOL_SIGFILE. function(pico_encrypt_binary TARGET AESFILE) + picotool_check_configurable(${TARGET}) set_target_properties(${TARGET} PROPERTIES PICOTOOL_AESFILE ${AESFILE} ) @@ -422,6 +438,9 @@ endfunction() # Run picotool post-processing on the binary - must be called after # all required properties have been set function(picotool_postprocess_binary TARGET) + set_target_properties(${TARGET} PROPERTIES + PICOTOOL_PROCESSING_CONFIGURED true + ) # Read target properties get_target_property(picotool_sign_output ${TARGET} PICOTOOL_SIGN_OUTPUT) if (picotool_sign_output)