Build: Generalize NS build steps for various toolchains
Various toolchains have different behaviours and requirements in CMake
implementation.
Generalize several steps in build sequence in NS build example, to
conceal differences between various toolchains.
- Define a tfm_toolchain_reload_compiler() in NS toolchain file example
to enable Armclang to setup compiler flags after project().
Add a dummy one in GNU toolchain file.
- Wrap the binary generation in NS toolchain file example as toolchains
require different implementation.
- Move the code of some build steps to tf-m-tests from TF-M NS build
example. NS target names are hard-coded in those steps. TF-M shall
remove those code to avoid coupling NS and S implementation.
Change-Id: Ib787f3b24e9a6623b8384aa00551cd7abc0f74ff
Signed-off-by: David Hu <david.hu@arm.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56ce8b8..bf72481 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,7 @@
set(CMAKE_CXX_COMPILER_FORCED true)
project("Trusted Firmware M" VERSION ${TFM_VERSION} LANGUAGES C CXX ASM)
+tfm_toolchain_reload_compiler()
add_subdirectory(lib/ext)
add_subdirectory(lib/fih)
diff --git a/cmake/spe-CMakeLists.cmake b/cmake/spe-CMakeLists.cmake
index 6c537c3..d75c67f 100644
--- a/cmake/spe-CMakeLists.cmake
+++ b/cmake/spe-CMakeLists.cmake
@@ -41,13 +41,6 @@
$<$<BOOL:${CONFIG_TFM_USE_TRUSTZONE}>:${CMAKE_CURRENT_SOURCE_DIR}/interface/lib/s_veneers.o>
)
-add_custom_target(tfm_ns_binaries
- DEPENDS tfm_ns
- COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:tfm_ns> ${CMAKE_BINARY_DIR}/tfm_ns.bin
- COMMAND ${CMAKE_OBJCOPY} -O elf32-littlearm $<TARGET_FILE:tfm_ns> ${CMAKE_BINARY_DIR}/tfm_ns.elf
- COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:tfm_ns> ${CMAKE_BINARY_DIR}/tfm_ns.hex
-)
-
if (MCUBOOT_IMAGE_NUMBER GREATER 1)
add_custom_target(tfm_app_binaries
@@ -68,12 +61,12 @@
-s ${MCUBOOT_SECURITY_COUNTER_NS}
-L ${MCUBOOT_ENC_KEY_LEN}
-d \"\(0, ${MCUBOOT_S_IMAGE_MIN_VER}\)\"
- ${CMAKE_BINARY_DIR}/tfm_ns.bin
+ ${CMAKE_BINARY_DIR}/bin/tfm_ns.bin
$<$<STREQUAL:${MCUBOOT_UPGRADE_STRATEGY},OVERWRITE_ONLY>:--overwrite-only>
$<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
$<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${MCUBOOT_KEY_ENC}>
$<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
- ${CMAKE_BINARY_DIR}/tfm_ns_signed.bin
+ ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
# Create concatenated binary image from the two independently signed
# binary file. This only uses the local assemble.py script (not from
@@ -82,7 +75,7 @@
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
--layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s.o
--secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s_signed.bin
- --non_secure ${CMAKE_BINARY_DIR}/tfm_ns_signed.bin
+ --non_secure ${CMAKE_BINARY_DIR}/bin/tfm_ns_signed.bin
--output ${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
# merge bootloader and application into Hex image for upload
COMMAND srec_cat ${CMAKE_CURRENT_SOURCE_DIR}/bin/bl2.bin -Binary -offset 0xA000000
@@ -100,8 +93,8 @@
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/scripts/assemble.py
--layout ${CMAKE_CURRENT_SOURCE_DIR}/image_signing/layout_files/signing_layout_s_ns.o
--secure ${CMAKE_CURRENT_SOURCE_DIR}/bin/tfm_s.bin
- --non_secure ${CMAKE_BINARY_DIR}/tfm_ns.bin
- --output ${CMAKE_BINARY_DIR}/tfm_s_ns.bin
+ --non_secure ${CMAKE_BINARY_DIR}/bin/tfm_ns.bin
+ --output ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
# sign the combined tfm_s_ns.bin file
COMMAND ${Python3_EXECUTABLE}
@@ -120,7 +113,7 @@
$<$<BOOL:${MCUBOOT_CONFIRM_IMAGE}>:--confirm>
$<$<BOOL:${MCUBOOT_ENC_IMAGES}>:-E${MCUBOOT_KEY_ENC}>
$<$<BOOL:${MCUBOOT_MEASURED_BOOT}>:--measured-boot-record>
- ${CMAKE_BINARY_DIR}/tfm_s_ns.bin
+ ${CMAKE_BINARY_DIR}/bin/tfm_s_ns.bin
${CMAKE_BINARY_DIR}/tfm_s_ns_signed.bin
)
endif()
diff --git a/platform/ns/toolchain_ns_GNUARM.cmake b/platform/ns/toolchain_ns_GNUARM.cmake
index fa5d5b5..15c48d2 100644
--- a/platform/ns/toolchain_ns_GNUARM.cmake
+++ b/platform/ns/toolchain_ns_GNUARM.cmake
@@ -10,6 +10,10 @@
set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)
+if(NOT DEFINED CROSS_COMPILE)
+ set(CROSS_COMPILE arm-none-eabi CACHE STRING "Cross-compiler prefix")
+endif()
+
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}-gcc)
find_program(CMAKE_CXX_COMPILER ${CROSS_COMPILE}-g++)
@@ -241,3 +245,48 @@
add_dependencies(${target} ${target}_scatter)
endmacro()
+
+macro(add_convert_to_bin_target target)
+ get_target_property(bin_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
+
+ add_custom_target(${target}_bin
+ SOURCES ${bin_dir}/${target}.bin
+ )
+ add_custom_command(OUTPUT ${bin_dir}/${target}.bin
+ DEPENDS ${target}
+ COMMAND ${CMAKE_OBJCOPY}
+ -O binary $<TARGET_FILE:${target}>
+ ${bin_dir}/${target}.bin
+ )
+
+ add_custom_target(${target}_elf
+ SOURCES ${bin_dir}/${target}.elf
+ )
+ add_custom_command(OUTPUT ${bin_dir}/${target}.elf
+ DEPENDS ${target}
+ COMMAND ${CMAKE_OBJCOPY}
+ -O elf32-littlearm $<TARGET_FILE:${target}>
+ ${bin_dir}/${target}.elf
+ )
+
+ add_custom_target(${target}_hex
+ SOURCES ${bin_dir}/${target}.hex
+ )
+ add_custom_command(OUTPUT ${bin_dir}/${target}.hex
+ DEPENDS ${target}
+ COMMAND ${CMAKE_OBJCOPY}
+ -O ihex $<TARGET_FILE:${target}>
+ ${bin_dir}/${target}.hex
+ )
+
+ add_custom_target(${target}_binaries
+ ALL
+ DEPENDS ${target}_bin
+ DEPENDS ${target}_elf
+ DEPENDS ${target}_hex
+ )
+endmacro()
+
+# A dummy macro to align with Armclang workaround
+macro(tfm_toolchain_reload_compiler)
+endmacro()
diff --git a/toolchain_GNUARM.cmake b/toolchain_GNUARM.cmake
index 2e81909..c65734e 100644
--- a/toolchain_GNUARM.cmake
+++ b/toolchain_GNUARM.cmake
@@ -364,3 +364,7 @@
ARGS $<TARGET_FILE:${dependency}> --wildcard ${SYMBOL_LIST} $<TARGET_FILE:${dependency}>
)
endmacro()
+
+# A dummy macro to align with Armclang workaround
+macro(tfm_toolchain_reload_compiler)
+endmacro()