blob: 1e93790011f462a740aa185ef3feccf4a8a4d527 [file] [log] [blame]
Awadhy Mohammed71bd9372023-08-07 14:46:15 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2023, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7cmake_minimum_required(VERSION 3.15)
8
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
20# Select toolchain file if it is not specified via command line or the absolutate path
21# is unavailable.
22if (NOT DEFINED TFM_TOOLCHAIN_FILE)
23 set(TFM_TOOLCHAIN_FILE ${CONFIG_SPE_PATH}/cmake/toolchain_ns_GNUARM.cmake)
24endif()
25
26if(NOT EXISTS ${TFM_TOOLCHAIN_FILE})
27 message(FATAL_ERROR "TFM_TOOLCHAIN_FILE ${TFM_TOOLCHAIN_FILE} doesn't exist."
28 "If it's relative path then please change to absolute path.")
29endif()
30
31include(${TFM_TOOLCHAIN_FILE})
32
33project("TF-M Example" LANGUAGES C)
34tfm_toolchain_reload_compiler()
35
36# The exported TF-M interfaces
37add_subdirectory(${CONFIG_SPE_PATH} ${CMAKE_BINARY_DIR}/spe)
38
39add_executable(tfm_ns
40 main.c
41 ${CONFIG_SPE_PATH}/interface/src/os_wrapper/tfm_ns_interface_bare_metal.c
42 # GNU Arm compiler version greater equal than *11.3.Rel1*
43 # has a linker issue that required system calls are missing,
44 # such as _read and _write. Add stub functions of required
45 # system calls to solve this issue.
46 $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:syscalls_stub.c>
47)
48
49target_link_libraries(tfm_ns
50 PRIVATE
51 tfm_api_ns
52)
53
Anton Komlev95add8a2024-05-09 14:33:11 +010054if (CONFIG_TFM_USE_TRUSTZONE)
55 target_link_libraries(tfm_ns
56 PRIVATE
57 tfm_api_ns_tz
58 )
59endif()
60
Awadhy Mohammed71bd9372023-08-07 14:46:15 +010061set_target_properties(tfm_ns PROPERTIES
62 SUFFIX ".axf"
63 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
64)
65
66target_add_scatter_file(tfm_ns ${CONFIG_SPE_PATH}/platform/linker_scripts)
67
68target_link_options(tfm_ns
69 PRIVATE
70 $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
71 $<$<C_COMPILER_ID:ARMClang>:--map>
72 $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
73)
74
75add_convert_to_bin_target(tfm_ns)