blob: d48d8df5208ff96610c0a48b671ec31145a8fa44 [file] [log] [blame]
Awadhy Mohammed71bd9372023-08-07 14:46:15 +01001#-------------------------------------------------------------------------------
Gergely Korcsák525d05c2024-05-13 17:40:27 +02002# Copyright (c) 2023-2024, Arm Limited. All rights reserved.
Awadhy Mohammed71bd9372023-08-07 14:46:15 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
Nik Dewally4a063d72024-06-26 15:49:15 +01007cmake_minimum_required(VERSION 3.21)
Awadhy Mohammed71bd9372023-08-07 14:46:15 +01008
9if (NOT DEFINED CONFIG_SPE_PATH OR NOT EXISTS ${CONFIG_SPE_PATH})
10 message(FATAL_ERROR "CONFIG_SPE_PATH = ${CONFIG_SPE_PATH} is not defined or incorrect. Please provide full path to TF-M build artifacts using -DCONFIG_SPE_PATH=")
11endif()
12
13list(APPEND CMAKE_MODULE_PATH ${CONFIG_SPE_PATH}/cmake)
14
15# A platform specific MCPU and architecture flags for NS side
16include(${CONFIG_SPE_PATH}/platform/cpuarch.cmake)
17# Include common configs exported from TF-M
18include(${CONFIG_SPE_PATH}/cmake/spe_config.cmake)
19
Gergely Korcsák525d05c2024-05-13 17:40:27 +020020# Select toolchain file if it is not specified via command line or the absolute path
Awadhy Mohammed71bd9372023-08-07 14:46:15 +010021# is unavailable.
22if (NOT DEFINED TFM_TOOLCHAIN_FILE)
Gergely Korcsák525d05c2024-05-13 17:40:27 +020023 if (NOT DEFINED TFM_TOOLCHAIN)
24 set(TFM_TOOLCHAIN "GNUARM")
25 message(WARNING "TFM_TOOLCHAIN or TFM_TOOLCHAIN_FILE is not defined")
26 message(WARNING "TFM_TOOLCHAIN is set to ${TFM_TOOLCHAIN}")
27 endif()
28 set(TFM_TOOLCHAIN_FILE ${CONFIG_SPE_PATH}/cmake/toolchain_ns_${TFM_TOOLCHAIN}.cmake)
Awadhy Mohammed71bd9372023-08-07 14:46:15 +010029endif()
30
31include(${TFM_TOOLCHAIN_FILE})
William Vinnicombee3559432025-06-23 13:02:10 +010032project("TF-M Example" LANGUAGES C ASM)
Awadhy Mohammed71bd9372023-08-07 14:46:15 +010033
Gergely Korcsák525d05c2024-05-13 17:40:27 +020034add_executable(tfm_ns)
35
Awadhy Mohammed71bd9372023-08-07 14:46:15 +010036# The exported TF-M interfaces
37add_subdirectory(${CONFIG_SPE_PATH} ${CMAKE_BINARY_DIR}/spe)
38
Gergely Korcsák525d05c2024-05-13 17:40:27 +020039target_sources(tfm_ns
40 PRIVATE
41 main.c
42 ${CONFIG_SPE_PATH}/interface/src/os_wrapper/tfm_ns_interface_bare_metal.c
43 # GNU Arm compiler version greater equal than *11.3.Rel1*
44 # has a linker issue that required system calls are missing,
45 # such as _read and _write. Add stub functions of required
46 # system calls to solve this issue.
47 $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:syscalls_stub.c>
Awadhy Mohammed71bd9372023-08-07 14:46:15 +010048)
49
50target_link_libraries(tfm_ns
51 PRIVATE
52 tfm_api_ns
53)
54
Anton Komlev95add8a2024-05-09 14:33:11 +010055if (CONFIG_TFM_USE_TRUSTZONE)
56 target_link_libraries(tfm_ns
57 PRIVATE
58 tfm_api_ns_tz
59 )
60endif()
61
Awadhy Mohammed71bd9372023-08-07 14:46:15 +010062set_target_properties(tfm_ns PROPERTIES
63 SUFFIX ".axf"
64 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
65)
66
67target_add_scatter_file(tfm_ns ${CONFIG_SPE_PATH}/platform/linker_scripts)
68
69target_link_options(tfm_ns
70 PRIVATE
71 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
72 $<$<C_COMPILER_ID:ARMClang>:--map>
73 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
74)
75
76add_convert_to_bin_target(tfm_ns)