Skip to content

Commit fb4c524

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 fb4c524

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

soc/st/stm32/stm32n6x/CMakeLists.txt

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
zephyr_include_directories(${ZEPHYR_BASE}/drivers)
44
zephyr_sources(
55
soc.c
6-
)
6+
)
77

88
zephyr_sources_ifdef(CONFIG_STM32N6_NPU
99
npu/npu_stm32n6.c
10-
)
10+
)
1111

1212
zephyr_include_directories(.)
1313

@@ -22,26 +22,57 @@ zephyr_linker_sources_ifdef(CONFIG_BOOTLOADER_MCUBOOT SECTIONS ram_check.ld)
2222

2323
if(NOT CONFIG_BOOTLOADER_MCUBOOT)
2424

25-
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
26-
set(SIGNING_TOOL STM32_SigningTool_CLI.exe)
27-
else()
28-
set(SIGNING_TOOL STM32_SigningTool_CLI)
29-
endif()
25+
set(signing_tool STM32_SigningTool_CLI)
3026

31-
find_file(SIGNING_TOOL_FIND ${SIGNING_TOOL})
32-
if(SIGNING_TOOL_FIND STREQUAL SIGNING_TOOL_FIND-NOTFOUND)
27+
# find_program will automatically search for .exe extension on Windows
28+
find_program(signing_tool_find ${signing_tool})
29+
if(signing_tool_find STREQUAL signing_tool_find-NOTFOUND)
3330
message(WARNING "
34-
Signing Image tool (${SIGNING_TOOL}) is not available.
35-
Signed image will not be generated.
36-
You won't be able to run application on the board.
37-
Refer to board documentation for more information")
31+
Signing Image tool (${signing_tool}) is not available.
32+
Signed image will not be generated.
33+
You won't be able to run application on the board.
34+
Refer to board documentation for more information.
35+
")
3836
else()
39-
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
40-
COMMAND ${SIGNING_TOOL}
37+
message(STATUS "Found STM32 signing tool: ${signing_tool_find}")
38+
39+
execute_process(
40+
COMMAND ${signing_tool_find} --version
41+
OUTPUT_VARIABLE version
42+
RESULT_VARIABLE result
43+
)
44+
45+
set(signing_tool_args
4146
-in ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.bin
4247
-nk -t fsbl -hv 2.3 --silent
4348
-o ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
4449
-dump ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
50+
)
51+
52+
set(signing_tool_version_regex "v([0-9]+[.][0-9]+[.][0-9]+)")
53+
if(result EQUAL 0 AND version MATCHES ${signing_tool_version_regex})
54+
set(signing_tool_version ${CMAKE_MATCH_1})
55+
set(signing_tool_version_min 2.21.0)
56+
57+
if(signing_tool_version VERSION_GREATER_EQUAL signing_tool_version_min)
58+
list(APPEND signing_tool_args -align)
59+
60+
message(STATUS
61+
"${signing_tool} version is v${signing_tool_version}, "
62+
"appending \"-align\" flag to post-build signing command "
63+
"(applicable only with header v2.3 for MCUs, starting from "
64+
"version v${signing_tool_version_min})"
65+
)
66+
endif()
67+
else()
68+
message(FATAL_ERROR "
69+
Unable to determine ${signing_tool} version (expected match to
70+
${signing_tool_version_regex} regex)
71+
")
72+
endif()
73+
74+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
75+
COMMAND ${signing_tool} ${signing_tool_args}
4576
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
4677
)
4778

0 commit comments

Comments
 (0)