Skip to content

Commit b177591

Browse files
ckhardinkartben
authored andcommitted
cmake: mcuboot: refactor the checks for west and the key files
As of c952f09 the calls to west sign were replaced with imgtool but a lingering integration with WEST_TOPDIR was allowed to remain which is not needed when there are absolute paths available for the configuration. So, this attempts to refactor the code to allow a few things - allow a search of relative paths to application config and then west topdir - only fatal error when a west workspace is needed but not found, so if the config is all absolute files then a west workspace is not required Fixes: #86438 Signed-off-by: Charles Hardin <[email protected]>
1 parent 0dffe7c commit b177591

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

cmake/mcuboot.cmake

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,50 @@ function(zephyr_mcuboot_tasks)
3131
"CONFIG_MCUBOOT_SIGNATURE_KEY_FILE are set, the generated build will not be "
3232
"bootable by MCUboot unless it is signed manually/externally.")
3333
return()
34+
elseif(NOT (CONFIG_BUILD_OUTPUT_BIN OR CONFIG_BUILD_OUTPUT_HEX))
35+
message(FATAL_ERROR "Can't sign images for MCUboot: Neither "
36+
"CONFIG_BUILD_OUTPUT_BIN nor CONFIG_BUILD_OUTPUT_HEX "
37+
"is enabled, so there's nothing to sign.")
3438
endif()
35-
endif()
3639

37-
if(NOT WEST)
38-
# This feature requires west.
39-
message(FATAL_ERROR "Can't sign images for MCUboot: west not found. To fix, install west and ensure it's on PATH.")
40-
endif()
40+
foreach(file keyfile keyfile_enc)
41+
if("${${file}}" STREQUAL "")
42+
continue()
43+
endif()
4144

42-
foreach(file keyfile keyfile_enc)
43-
if(NOT "${${file}}" STREQUAL "")
45+
# Find the key files in the order of preference for a simple search
46+
# modeled by the if checks across the various locations
47+
#
48+
# 1. absolute
49+
# 2. application config
50+
# 3. west topdir (optional when the workspace is not west managed)
51+
#
4452
if(NOT IS_ABSOLUTE "${${file}}")
45-
# Relative paths are relative to 'west topdir'.
46-
set(${file} "${WEST_TOPDIR}/${${file}}")
53+
if(EXISTS "${APPLICATION_CONFIG_DIR}/${${file}}")
54+
set(${file} "${APPLICATION_CONFIG_DIR}/${${file}}")
55+
else()
56+
# Relative paths are relative to 'west topdir'.
57+
#
58+
# This is the only file that has a relative check to topdir likely
59+
# from the historical callouts to "west" itself before using
60+
# imgtool. So, this is maintained here for backward compatibility
61+
#
62+
if(NOT WEST OR NOT WEST_TOPDIR)
63+
message(FATAL_ERROR "Can't sign images for MCUboot: west workspace undefined. "
64+
"To fix, ensure `west topdir` is a valid workspace directory.")
65+
endif()
66+
set(${file} "${WEST_TOPDIR}/${${file}}")
67+
endif()
4768
endif()
4869

49-
if(NOT EXISTS "${${file}}" AND NOT "${CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE}")
50-
message(FATAL_ERROR "west sign can't find file ${${file}} (Note: Relative paths are relative to the west workspace topdir \"${WEST_TOPDIR}\")")
51-
elseif(NOT (CONFIG_BUILD_OUTPUT_BIN OR CONFIG_BUILD_OUTPUT_HEX))
52-
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.")
70+
if(NOT EXISTS "${${file}}")
71+
message(FATAL_ERROR "Can't sign images for MCUboot: can't find file ${${file}} "
72+
"(Note: Relative paths are searched through "
73+
"APPLICATION_CONFIG_DIR=\"${APPLICATION_CONFIG_DIR}\" "
74+
"and WEST_TOPDIR=\"${WEST_TOPDIR}\")")
5375
endif()
54-
endif()
55-
endforeach()
76+
endforeach()
77+
endif()
5678

5779
# No imgtool, no signed binaries.
5880
if(NOT DEFINED IMGTOOL)

0 commit comments

Comments
 (0)