Skip to content

Commit 92bee62

Browse files
committed
soc: st: stm32: add '-align' flag for signing tool v2.21.0+
Starting in v2.21.0, the STM32 signing tool ('STM32_SigningTool_CLI') stopped automatically adding padding bytes at the beginning of the payload to align it to the 0x400 offset. To restore this behavior, the '-align' flag must be passed to the signing tool post-build command. This commit checks for signing tool version v2.21.0 or higher and appends the '-align' flag to the post-build signing command. Fixes #99456 Signed-off-by: Chris Wilson <chris@binho.io>
1 parent da9aa8f commit 92bee62

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

soc/st/stm32/stm32n6x/CMakeLists.txt

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,55 @@ if(NOT CONFIG_BOOTLOADER_MCUBOOT)
2828
set(SIGNING_TOOL STM32_SigningTool_CLI)
2929
endif()
3030

31-
find_file(SIGNING_TOOL_FIND ${SIGNING_TOOL})
31+
32+
33+
# find_file(SIGNING_TOOL_FIND ${SIGNING_TOOL})
34+
find_program(SIGNING_TOOL_FIND ${SIGNING_TOOL})
3235
if(SIGNING_TOOL_FIND STREQUAL SIGNING_TOOL_FIND-NOTFOUND)
3336
message(WARNING "
3437
Signing Image tool (${SIGNING_TOOL}) is not available.
3538
Signed image will not be generated.
3639
You won't be able to run application on the board.
3740
Refer to board documentation for more information")
3841
else()
39-
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
40-
COMMAND ${SIGNING_TOOL}
42+
set(SIGNING_TOOL_MIN_VERSION "2.21.0")
43+
set(SIGNING_TOOL_VERSION_REGEX "v([0-9]+[.][0-9]+[.][0-9]+)")
44+
45+
execute_process(
46+
COMMAND ${SIGNING_TOOL_FIND} --version
47+
OUTPUT_VARIABLE version
48+
RESULT_VARIABLE result
49+
)
50+
51+
set(SIGNING_TOOL_ARGS
4152
-in ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.bin
4253
-nk -t fsbl -hv 2.3 --silent
4354
-o ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
4455
-dump ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
56+
)
57+
58+
if(result EQUAL 0 AND version MATCHES ${SIGNING_TOOL_VERSION_REGEX})
59+
set(SIGNING_TOOL_VERSION ${CMAKE_MATCH_1})
60+
61+
if(SIGNING_TOOL_VERSION VERSION_GREATER_EQUAL SIGNING_TOOL_MIN_VERSION)
62+
list(APPEND SIGNING_TOOL_ARGS -align)
63+
64+
message(STATUS
65+
"Found ${SIGNING_TOOL} version v${SIGNING_TOOL_VERSION}, "
66+
"appending \"-align\" flag to post-build signing command "
67+
"(applicable only with header v2.3 for MCUs, starting from "
68+
"version v${SIGNING_TOOL_MIN_VERSION})"
69+
)
70+
endif()
71+
else()
72+
message(FATAL_ERROR
73+
"Unable to determine ${SIGNING_TOOL} version (expected match to "
74+
"${SIGNING_TOOL_VERSION_REGEX} regex)"
75+
)
76+
endif()
77+
78+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
79+
COMMAND ${SIGNING_TOOL} ${SIGNING_TOOL_ARGS}
4580
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
4681
)
4782

0 commit comments

Comments
 (0)