123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- function(zephyr_runner_file type path)
-
-
- set_target_properties(runners_yaml_props_target PROPERTIES "${type}_file" "${path}")
- endfunction()
- function(zephyr_mcuboot_tasks)
- set(keyfile "${CONFIG_MCUBOOT_SIGNATURE_KEY_FILE}")
- set(keyfile_enc "${CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE}")
-
- if("${keyfile}" STREQUAL "")
-
-
- return()
- endif()
- if(NOT WEST)
-
- message(FATAL_ERROR "Can't sign images for MCUboot: west not found. To fix, install west and ensure it's on PATH.")
- endif()
- foreach(file keyfile keyfile_enc)
- if(NOT "${${file}}" STREQUAL "")
- if(NOT IS_ABSOLUTE "${${file}}")
-
- set(${file} "${WEST_TOPDIR}/${${file}}")
- endif()
- if(NOT EXISTS "${${file}}")
- message(FATAL_ERROR "west sign can't find file ${${file}} (Note: Relative paths are relative to the west workspace topdir \"${WEST_TOPDIR}\")")
- elseif(NOT (CONFIG_BUILD_OUTPUT_BIN OR CONFIG_BUILD_OUTPUT_HEX))
- message(FATAL_ERROR "Can't sign images for MCUboot: Neither CONFIG_BUILD_OUTPUT_BIN nor CONFIG_BUILD_OUTPUT_HEX is enabled, so there's nothing to sign.")
- endif()
- endif()
- endforeach()
-
-
-
-
-
-
- if(IMGTOOL)
- set(imgtool_path "${IMGTOOL}")
- elseif(DEFINED ZEPHYR_MCUBOOT_MODULE_DIR)
- set(IMGTOOL_PY "${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/imgtool.py")
- if(EXISTS "${IMGTOOL_PY}")
- set(imgtool_path "${IMGTOOL_PY}")
- endif()
- endif()
-
- if(NOT DEFINED imgtool_path)
- message(FATAL_ERROR "Can't sign images for MCUboot: can't find imgtool. To fix, install imgtool with pip3, or add the mcuboot repository to the west manifest and ensure it has a scripts/imgtool.py file.")
- return()
- endif()
-
- set(west_sign ${WEST} sign --quiet --tool imgtool
- --tool-path "${imgtool_path}"
- --build-dir "${APPLICATION_BINARY_DIR}")
-
- if(NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "")
-
-
-
-
-
- separate_arguments(imgtool_extra UNIX_COMMAND ${CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS})
- else()
- set(imgtool_extra)
- endif()
- set(imgtool_args -- --key "${keyfile}" ${imgtool_extra})
-
- set(output ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME})
-
- set(byproducts)
-
- set(unconfirmed_args)
- set(confirmed_args)
- set(encrypted_args)
-
- if(CONFIG_BUILD_OUTPUT_BIN)
- list(APPEND unconfirmed_args --bin --sbin ${output}.signed.bin)
- list(APPEND byproducts ${output}.signed.bin)
- zephyr_runner_file(bin ${output}.signed.bin)
- if(CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE)
- list(APPEND confirmed_args --bin --sbin ${output}.signed.confirmed.bin)
- list(APPEND byproducts ${output}.signed.confirmed.bin)
- endif()
- if(NOT "${keyfile_enc}" STREQUAL "")
- list(APPEND encrypted_args --bin --sbin ${output}.signed.encrypted.bin)
- list(APPEND byproducts ${output}.signed.encrypted.bin)
- endif()
- endif()
-
- if(CONFIG_BUILD_OUTPUT_HEX)
- list(APPEND unconfirmed_args --hex --shex ${output}.signed.hex)
- list(APPEND byproducts ${output}.signed.hex)
- zephyr_runner_file(hex ${output}.signed.hex)
- if(CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE)
- list(APPEND confirmed_args --hex --shex ${output}.signed.confirmed.hex)
- list(APPEND byproducts ${output}.signed.confirmed.hex)
- endif()
- if(NOT "${keyfile_enc}" STREQUAL "")
- list(APPEND encrypted_args --hex --shex ${output}.signed.encrypted.hex)
- list(APPEND byproducts ${output}.signed.encrypted.hex)
- endif()
- endif()
-
-
-
-
-
-
-
- set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
- ${west_sign} ${unconfirmed_args} ${imgtool_args})
- if(confirmed_args)
- set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
- ${west_sign} ${confirmed_args} ${imgtool_args} --pad --confirm)
- endif()
- if(encrypted_args)
- set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
- ${west_sign} ${encrypted_args} ${imgtool_args} --encrypt "${keyfile_enc}")
- endif()
- set_property(GLOBAL APPEND PROPERTY extra_post_build_byproducts ${byproducts})
- endfunction()
- zephyr_mcuboot_tasks()
|