Skip to content

Commit 3a9147c

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 3a9147c

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

soc/st/stm32/stm32n6x/CMakeLists.txt

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

31-
find_file(SIGNING_TOOL_FIND ${SIGNING_TOOL})
31+
find_program(SIGNING_TOOL_FIND ${SIGNING_TOOL})
3232
if(SIGNING_TOOL_FIND STREQUAL SIGNING_TOOL_FIND-NOTFOUND)
3333
message(WARNING "
3434
Signing Image tool (${SIGNING_TOOL}) is not available.
3535
Signed image will not be generated.
3636
You won't be able to run application on the board.
3737
Refer to board documentation for more information")
3838
else()
39-
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
40-
COMMAND ${SIGNING_TOOL}
39+
set(SIGNING_TOOL_MIN_VERSION "2.21.0")
40+
set(SIGNING_TOOL_VERSION_REGEX "v([0-9]+[.][0-9]+[.][0-9]+)")
41+
42+
execute_process(
43+
COMMAND ${SIGNING_TOOL_FIND} --version
44+
OUTPUT_VARIABLE version
45+
RESULT_VARIABLE result
46+
)
47+
48+
set(SIGNING_TOOL_ARGS
4149
-in ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.bin
4250
-nk -t fsbl -hv 2.3 --silent
4351
-o ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
4452
-dump ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
53+
)
54+
55+
if(result EQUAL 0 AND version MATCHES ${SIGNING_TOOL_VERSION_REGEX})
56+
set(SIGNING_TOOL_VERSION ${CMAKE_MATCH_1})
57+
58+
if(SIGNING_TOOL_VERSION VERSION_GREATER_EQUAL SIGNING_TOOL_MIN_VERSION)
59+
list(APPEND SIGNING_TOOL_ARGS -align)
60+
61+
message(STATUS
62+
"Found ${SIGNING_TOOL} version v${SIGNING_TOOL_VERSION}, "
63+
"appending \"-align\" flag to post-build signing command "
64+
"(applicable only with header v2.3 for MCUs, starting from "
65+
"version v${SIGNING_TOOL_MIN_VERSION})"
66+
)
67+
endif()
68+
else()
69+
message(FATAL_ERROR
70+
"Unable to determine ${SIGNING_TOOL} version (expected match to "
71+
"${SIGNING_TOOL_VERSION_REGEX} regex)"
72+
)
73+
endif()
74+
75+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
76+
COMMAND ${SIGNING_TOOL} ${SIGNING_TOOL_ARGS}
4577
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
4678
)
4779

0 commit comments

Comments
 (0)