Skip to content

Commit 1e4562a

Browse files
committed
cmake: sysbuild: Use zephyr found imgtool
Uses the version of imgtool that zephyr has found, which prefers the in-tree module version found inside the MCUboot directory Fixes: NCSDK-30894 Signed-off-by: Jamie McCrae <[email protected]>
1 parent 11f3037 commit 1e4562a

File tree

5 files changed

+12
-90
lines changed

5 files changed

+12
-90
lines changed

cmake/sysbuild/b0_mcuboot_signing.cmake

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,12 @@
1111
# function to avoid polluting the top-level scope.
1212

1313
function(ncs_secure_boot_mcuboot_sign application bin_files signed_targets prefix)
14+
find_program(IMGTOOL imgtool.py HINTS ${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/ NAMES imgtool NAMES_PER_DIR)
1415
set(keyfile "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}")
1516
string(CONFIGURE "${keyfile}" keyfile)
1617

17-
# Find imgtool. Even though west is installed, imgtool might not be.
18-
# The user may also have a custom manifest which doesn't include
19-
# MCUboot.
20-
#
21-
# Therefore, go with an explicitly installed imgtool first, falling
22-
# back on mcuboot/scripts/imgtool.py.
23-
if(IMGTOOL)
24-
set(imgtool_path "${IMGTOOL}")
25-
elseif(DEFINED ZEPHYR_MCUBOOT_MODULE_DIR)
26-
set(IMGTOOL_PY "${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/imgtool.py")
27-
if(EXISTS "${IMGTOOL_PY}")
28-
set(imgtool_path "${IMGTOOL_PY}")
29-
endif()
30-
endif()
31-
3218
# No imgtool, no signed binaries.
33-
if(NOT DEFINED imgtool_path)
19+
if(NOT DEFINED IMGTOOL)
3420
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.")
3521
return()
3622
endif()
@@ -40,7 +26,7 @@ function(ncs_secure_boot_mcuboot_sign application bin_files signed_targets prefi
4026
sysbuild_get(CONFIG_BUILD_OUTPUT_HEX IMAGE ${application} VAR CONFIG_BUILD_OUTPUT_HEX KCONFIG)
4127

4228
string(TOUPPER "${application}" application_uppercase)
43-
set(imgtool_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${SB_CONFIG_SECURE_BOOT_MCUBOOT_VERSION} --align 4 --slot-size $<TARGET_PROPERTY:partition_manager,${prefix}PM_${application_uppercase}_SIZE> --pad-header --header-size ${SB_CONFIG_PM_MCUBOOT_PAD})
29+
set(imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${SB_CONFIG_SECURE_BOOT_MCUBOOT_VERSION} --align 4 --slot-size $<TARGET_PROPERTY:partition_manager,${prefix}PM_${application_uppercase}_SIZE> --pad-header --header-size ${SB_CONFIG_PM_MCUBOOT_PAD})
4430

4531
if(SB_CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION)
4632
set(imgtool_extra --security-counter ${SB_CONFIG_MCUBOOT_HW_DOWNGRADE_PREVENTION_COUNTER_VALUE})

cmake/sysbuild/image_signing.cmake

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,8 @@ function(zephyr_mcuboot_tasks)
4949
endif()
5050
endforeach()
5151

52-
# Find imgtool. Even though west is installed, imgtool might not be.
53-
# The user may also have a custom manifest which doesn't include
54-
# MCUboot.
55-
#
56-
# Therefore, go with an explicitly installed imgtool first, falling
57-
# back on mcuboot/scripts/imgtool.py. We exclude the system imgtool when
58-
# compressed image support is enabled due to needing a version of imgtool
59-
# that has features not in the most recent public release.
60-
if(IMGTOOL AND
61-
(NOT CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT_ENABLED AND
62-
NOT (CONFIG_SOC_SERIES_NRF54LX AND CONFIG_MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_ED25519)))
63-
set(imgtool_path "${IMGTOOL}")
64-
elseif(DEFINED ZEPHYR_MCUBOOT_MODULE_DIR)
65-
set(IMGTOOL_PY "${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/imgtool.py")
66-
if(EXISTS "${IMGTOOL_PY}")
67-
set(imgtool_path "${IMGTOOL_PY}")
68-
endif()
69-
endif()
70-
7152
# No imgtool, no signed binaries.
72-
if(NOT DEFINED imgtool_path)
53+
if(NOT DEFINED IMGTOOL)
7354
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.")
7455
return()
7556
endif()
@@ -106,7 +87,7 @@ function(zephyr_mcuboot_tasks)
10687
# TODO: NCSDK-28461 sysbuild PM fields cannot be updated without a pristine build, will become
10788
# invalid if a static PM file is updated without pristine build
10889
set(imgtool_sign_sysbuild --slot-size @PM_MCUBOOT_PRIMARY_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_rom_command} CACHE STRING "imgtool sign sysbuild replacement")
109-
set(imgtool_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_sign_sysbuild})
90+
set(imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_sign_sysbuild})
11091

11192
# Arguments to imgtool.
11293
if(NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "")

cmake/sysbuild/image_signing_firmware_loader.cmake

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,8 @@ function(zephyr_mcuboot_tasks)
4747
endif()
4848
endforeach()
4949

50-
# Find imgtool. Even though west is installed, imgtool might not be.
51-
# The user may also have a custom manifest which doesn't include
52-
# MCUboot.
53-
#
54-
# Therefore, go with an explicitly installed imgtool first, falling
55-
# back on mcuboot/scripts/imgtool.py.
56-
if(IMGTOOL)
57-
set(imgtool_path "${IMGTOOL}")
58-
elseif(DEFINED ZEPHYR_MCUBOOT_MODULE_DIR)
59-
set(IMGTOOL_PY "${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/imgtool.py")
60-
if(EXISTS "${IMGTOOL_PY}")
61-
set(imgtool_path "${IMGTOOL_PY}")
62-
endif()
63-
endif()
64-
6550
# No imgtool, no signed binaries.
66-
if(NOT DEFINED imgtool_path)
51+
if(NOT DEFINED IMGTOOL)
6752
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.")
6853
return()
6954
endif()
@@ -85,7 +70,7 @@ function(zephyr_mcuboot_tasks)
8570
# TODO: NCSDK-28461 sysbuild PM fields cannot be updated without a pristine build, will become
8671
# invalid if a static PM file is updated without pristine build
8772
set(imgtool_sign_sysbuild --slot-size @PM_MCUBOOT_SECONDARY_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_rom_command} CACHE STRING "imgtool sign sysbuild replacement")
88-
set(imgtool_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_sign_sysbuild})
73+
set(imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_sign_sysbuild})
8974

9075
# Arguments to imgtool.
9176
if(NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "")

cmake/sysbuild/image_signing_nrf700x.cmake

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,8 @@ function(nrf7x_signing_tasks input output_hex output_bin dependencies)
1919
endif()
2020
endif()
2121

22-
# Find imgtool. Even though west is installed, imgtool might not be.
23-
# The user may also have a custom manifest which doesn't include
24-
# MCUboot.
25-
#
26-
# Therefore, go with an explicitly installed imgtool first, falling
27-
# back on mcuboot/scripts/imgtool.py.
28-
if(IMGTOOL)
29-
set(imgtool_path "${IMGTOOL}")
30-
elseif(DEFINED ZEPHYR_MCUBOOT_MODULE_DIR)
31-
set(IMGTOOL_PY "${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/imgtool.py")
32-
if(EXISTS "${IMGTOOL_PY}")
33-
set(imgtool_path "${IMGTOOL_PY}")
34-
endif()
35-
endif()
36-
3722
# No imgtool, no signed binaries.
38-
if(NOT DEFINED imgtool_path)
23+
if(NOT DEFINED IMGTOOL)
3924
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.")
4025
return()
4126
endif()
@@ -52,7 +37,7 @@ function(nrf7x_signing_tasks input output_hex output_bin dependencies)
5237
endif()
5338

5439
sysbuild_get(CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION IMAGE ${DEFAULT_IMAGE} VAR CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION KCONFIG)
55-
set(imgtool_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align 4 --slot-size $<TARGET_PROPERTY:partition_manager,PM_NRF70_WIFI_FW_SIZE> --pad-header --header-size ${SB_CONFIG_PM_MCUBOOT_PAD})
40+
set(imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align 4 --slot-size $<TARGET_PROPERTY:partition_manager,PM_NRF70_WIFI_FW_SIZE> --pad-header --header-size ${SB_CONFIG_PM_MCUBOOT_PAD})
5641

5742
sysbuild_get(CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION IMAGE ${DEFAULT_IMAGE} VAR CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION KCONFIG)
5843
if(CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION)

cmake/sysbuild/image_signing_split.cmake

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,8 @@ function(zephyr_mcuboot_tasks)
7474
endif()
7575
endforeach()
7676

77-
# Find imgtool. Even though west is installed, imgtool might not be.
78-
# The user may also have a custom manifest which doesn't include
79-
# MCUboot.
80-
#
81-
# Therefore, go with an explicitly installed imgtool first, falling
82-
# back on mcuboot/scripts/imgtool.py.
83-
if(IMGTOOL)
84-
set(imgtool_path "${IMGTOOL}")
85-
elseif(DEFINED ZEPHYR_MCUBOOT_MODULE_DIR)
86-
set(IMGTOOL_PY "${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/imgtool.py")
87-
if(EXISTS "${IMGTOOL_PY}")
88-
set(imgtool_path "${IMGTOOL_PY}")
89-
endif()
90-
endif()
91-
9277
# No imgtool, no signed binaries.
93-
if(NOT DEFINED imgtool_path)
78+
if(NOT DEFINED IMGTOOL)
9479
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.")
9580
return()
9681
endif()
@@ -127,8 +112,8 @@ function(zephyr_mcuboot_tasks)
127112
# invalid if a static PM file is updated without pristine build
128113
set(imgtool_internal_sign_sysbuild --slot-size @PM_MCUBOOT_PRIMARY_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_internal_rom_command} CACHE STRING "imgtool sign (internal flash) sysbuild replacement")
129114
set(imgtool_external_sign_sysbuild --slot-size @PM_MCUBOOT_PRIMARY_${qspi_xip_image_number}_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_external_rom_command} CACHE STRING "imgtool sign (external flash) sysbuild replacement")
130-
set(imgtool_internal_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_internal_sign_sysbuild})
131-
set(imgtool_external_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_external_sign_sysbuild})
115+
set(imgtool_internal_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_internal_sign_sysbuild})
116+
set(imgtool_external_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_external_sign_sysbuild})
132117

133118
# Arguments to imgtool.
134119
if(NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "")

0 commit comments

Comments
 (0)