Skip to content

Commit 93ff119

Browse files
yestinioannisg
authored andcommitted
boards: nucleo_l552ze_q: Leverage consolidated TFM signing code
This commit removes the signing commands from the post build steps, in order to leverage the consolidated TFM signing code. Also with the support to adjust the hex base address when signing, there is no need to run the TFM_UPDATE.sh script. We can use west flash to flash the merged hex file on the board. Signed-off-by: Yestin Sun <[email protected]>
1 parent 46cab05 commit 93ff119

File tree

3 files changed

+24
-55
lines changed

3 files changed

+24
-55
lines changed

boards/arm/nucleo_l552ze_q/CMakeLists.txt

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,8 @@ elseif(${ZEPHYR_TOOLCHAIN_VARIANT} STREQUAL "gnuarmemb")
1111
endif()
1212

1313
if (CONFIG_BUILD_WITH_TFM)
14-
# Set default image versions if not defined elsewhere
15-
if (NOT DEFINED TFM_IMAGE_VERSION_S)
16-
set(TFM_IMAGE_VERSION_S 0.0.0+0)
17-
endif()
18-
19-
if (NOT DEFINED TFM_IMAGE_VERSION_NS)
20-
set(TFM_IMAGE_VERSION_NS 0.0.0+0)
21-
endif()
22-
23-
set(PREPROCESSED_FILE_S "${CMAKE_BINARY_DIR}/tfm/bl2/ext/mcuboot/CMakeFiles/signing_layout_s.dir/signing_layout_s.o")
24-
set(PREPROCESSED_FILE_NS "${CMAKE_BINARY_DIR}/tfm/bl2/ext/mcuboot/CMakeFiles/signing_layout_ns.dir/signing_layout_ns.o")
25-
set(TFM_MCUBOOT_DIR "${ZEPHYR_TRUSTED_FIRMWARE_M_MODULE_DIR}/trusted-firmware-m/bl2/ext/mcuboot")
26-
27-
# Configure which format (full or hash) to include the public key in
28-
# the image manifest
29-
set(TFM_PUBLIC_KEY_FORMAT "full")
30-
31-
#Create and sign for concatenated binary image, should align with the TF-M BL2
32-
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
33-
34-
#Sign secure binary image with public key
35-
COMMAND ${PYTHON_EXECUTABLE} ${TFM_MCUBOOT_DIR}/scripts/wrapper/wrapper.py
36-
--layout ${PREPROCESSED_FILE_S}
37-
-k ${CONFIG_TFM_KEY_FILE_S}
38-
--public-key-format ${TFM_PUBLIC_KEY_FORMAT}
39-
--align 1
40-
-v ${TFM_IMAGE_VERSION_S}
41-
--pad
42-
--pad-header
43-
${ADD_NS_IMAGE_MIN_VER}
44-
-s auto
45-
-H 0x400
46-
$<TARGET_PROPERTY:tfm,TFM_S_BIN_FILE>
47-
${CMAKE_BINARY_DIR}/tfm_s_signed.bin
48-
49-
#Sign non-secure binary image with public key
50-
COMMAND ${PYTHON_EXECUTABLE} ${TFM_MCUBOOT_DIR}/scripts/wrapper/wrapper.py
51-
--layout ${PREPROCESSED_FILE_NS}
52-
-k ${CONFIG_TFM_KEY_FILE_NS}
53-
--public-key-format ${TFM_PUBLIC_KEY_FORMAT}
54-
--align 1
55-
-v ${TFM_IMAGE_VERSION_NS}
56-
-s auto
57-
${ADD_S_IMAGE_MIN_VER}
58-
-H 0x400
59-
${CMAKE_BINARY_DIR}/zephyr/${KERNEL_BIN_NAME}
60-
${CMAKE_BINARY_DIR}/zephyr_ns_signed.bin
61-
62-
#Copy mcuboot.bin
63-
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:tfm,BL2_BIN_FILE> ${CMAKE_BINARY_DIR}/mcuboot.bin
64-
14+
set_property(GLOBAL APPEND PROPERTY extra_post_build_byproducts
6515
#Execute post build script postbuild.sh
6616
COMMAND ${CMAKE_BINARY_DIR}/tfm/postbuild.sh ${COMPILER_FULL_PATH}
67-
)
17+
)
6818
endif()

boards/arm/nucleo_l552ze_q/board.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
2-
set_ifndef(BOARD_FLASH_RUNNER pyocd)
1+
if(CONFIG_BUILD_WITH_TFM)
2+
set(FLASH_BASE_ADDRESS_S 0x0C000000)
3+
4+
if (CONFIG_HAS_FLASH_LOAD_OFFSET)
5+
MATH(EXPR TFM_HEX_BASE_ADDRESS_NS "${FLASH_BASE_ADDRESS_S}+${CONFIG_FLASH_LOAD_OFFSET}")
6+
else()
7+
set(TFM_HEX_BASE_ADDRESS_NS ${TFM_FLASH_BASE_ADDRESS_S})
8+
endif()
9+
endif()
10+
11+
set_ifndef(BOARD_DEBUG_RUNNER pyocd)
12+
set_ifndef(BOARD_FLASH_RUNNER pyocd)
313

414
board_runner_args(pyocd "--target=stm32l552zetxq")
515

boards/arm/nucleo_l552ze_q/doc/nucleol552ze_q.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,16 @@ You should see the following message on the console:
276276
Building a secure/non-secure with Arm |reg| TrustZone |reg|
277277
-----------------------------------------------------------
278278

279-
The TF-M integration sample :ref:`tfm_ipc` can be run by a Nucleo L552ZE Q, using the ``nucleo_l552ze_q_ns`` target. When building a ``*_ns`` image with TF-M, a ``build/tfm/install/postbuild.sh`` bash script will be run as a post-build step to make some required flash layout changes. The ``build/tfm/install/postbuild.sh`` script will also be used to flash the board. Check the ``build/tfm/install`` directory to ensure that the commands required by these scripts (``readlink``, etc.) are available on your system.
279+
The TF-M integration sample :ref:`tfm_ipc` can be run by a Nucleo L552ZE Q,
280+
using the ``nucleo_l552ze_q_ns`` target. When building a ``*_ns`` image with TF-M,
281+
a ``build/tfm/install/postbuild.sh`` bash script will be run as a post-build step
282+
to make some required flash layout changes. The ``build/tfm/regression.sh`` script
283+
will need to be run to perform device initialization, and then run ``west flash --hex-file build/tfm_merged.hex``
284+
to flash the board.
285+
286+
Check the ``build/tfm/`` directory to ensure that the commands required by these scripts
287+
(``readlink``, etc.) are available on your system. Please also check ``STM32_Programmer_CLI``
288+
used for initialization is available in the PATH.
280289

281290
Debugging
282291
=========

0 commit comments

Comments
 (0)