Skip to content

Commit 5220936

Browse files
cdwilsonfabiobaltieri
authored andcommitted
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. It also changes local CMake variable names to lower case and corrects some indentation issues. Fixes #99456 Signed-off-by: Chris Wilson <[email protected]>
1 parent 599e3bb commit 5220936

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

soc/st/stm32/stm32n6x/CMakeLists.txt

Lines changed: 36 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,47 @@ 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+
if(${CMAKE_MATCH_1} VERSION_GREATER_EQUAL 2.21.0)
55+
list(APPEND signing_tool_args -align)
56+
endif()
57+
else()
58+
message(FATAL_ERROR "
59+
Unable to determine ${signing_tool} version (expected match to
60+
${signing_tool_version_regex} regex)
61+
")
62+
endif()
63+
64+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
65+
COMMAND ${signing_tool} ${signing_tool_args}
4566
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
4667
)
4768

0 commit comments

Comments
 (0)