blob: 3726e2f7cfde00196359deeb0ee4aadd5c80c5ca [file] [log] [blame]
Gyorgy Szing49091802020-11-24 00:33:09 +01001#-------------------------------------------------------------------------------
Imre Kisd47a1452024-05-29 14:25:59 +02002# Copyright (c) 2020-2024, Arm Limited and Contributors. All rights reserved.
Gyorgy Szing49091802020-11-24 00:33:09 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
Gyorgy Szingb8d6f262023-06-05 12:36:02 +02008# Check mandatory variables.
9foreach(_var IN ITEMS TGT)
10 if (NOT DEFINED ${_var})
11 message(FATAL_ERROR "Mandatory parameter '${_var}' missing.")
12 endif()
13endforeach()
14
Gyorgy Szing3e3db702023-07-21 14:18:19 +020015# Ensure elf output naming is symbolize.py compatible.
16# If binary UUID is not defined, fall back to using the SP UUID value.
17if (NOT SP_BIN_UUID_CANON)
Jelle Sels4960c412023-02-01 09:43:24 +010018 set(SP_BIN_UUID_CANON "${SP_FFA_UUID_CANON}")
Gyorgy Szing3e3db702023-07-21 14:18:19 +020019endif()
20ts_add_uuid_to_exe_name(TGT "${TGT}" UUID "${SP_BIN_UUID_CANON}" )
Gyorgy Szing49091802020-11-24 00:33:09 +010021
Gyorgy Szing6a0d9922023-07-20 14:55:42 +020022get_target_property(_tgt_type ${TGT} TYPE)
23if ("${_tgt_type}" STREQUAL "EXECUTABLE")
24 compiler_generate_stripped_elf(TARGET ${TGT} NAME "${SP_BIN_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
25 install(FILES ${STRIPPED_ELF} DESTINATION ${TS_ENV}/bin)
Gyorgy Szing8a1e7f42023-07-26 18:26:48 +020026
27 # Get the name of the SP.
28 get_target_property(_tgt_name ${TGT} NAME )
29 set(SP_NAME "${_tgt_name}" CACHE STRING "Name of the SP.")
30
31 include(${TS_ROOT}/tools/cmake/common/TargetCompileDefinitions.cmake)
32 set_target_uuids(
Jelle Sels4960c412023-02-01 09:43:24 +010033 SP_UUID ${SP_FFA_UUID_CANON}
Gyorgy Szingfd03e0a2023-07-27 20:04:24 +020034 TGT ${SP_NAME}
Gyorgy Szing8a1e7f42023-07-26 18:26:48 +020035 )
Jelle Sels4960c412023-02-01 09:43:24 +010036
Gyorgy Szing6a0d9922023-07-20 14:55:42 +020037endif()
38
Gyorgy Szing49091802020-11-24 00:33:09 +010039target_sources(${TGT} PRIVATE
Imre Kise6d73412021-10-18 14:01:47 +020040 "${CMAKE_CURRENT_LIST_DIR}/optee_sp_header.c"
Imre Kisef5c2642021-12-17 14:07:35 +010041 "${CMAKE_CURRENT_LIST_DIR}/sp_assert.c"
Imre Kise6d73412021-10-18 14:01:47 +020042 "${CMAKE_CURRENT_LIST_DIR}/sp_entry.c"
Imre Kis2ccd8e82021-10-08 11:21:14 +020043 "${CMAKE_CURRENT_LIST_DIR}/sp_trace.c"
Imre Kise6d73412021-10-18 14:01:47 +020044)
Andrew Beggs97a00d42021-06-15 15:45:46 +000045
46target_include_directories(${TGT}
Imre Kis2ccd8e82021-10-08 11:21:14 +020047 PUBLIC
48 "${CMAKE_CURRENT_LIST_DIR}/include"
49 )
50
Imre Kise6d73412021-10-18 14:01:47 +020051# Default trace configuration, can be overwritten by setting the same variables
52# in the deployment specific file before including this file.
53set(TRACE_PREFIX "SP" CACHE STRING "Trace prefix")
54set(TRACE_LEVEL "TRACE_LEVEL_ERROR" CACHE STRING "Trace level")
Imre Kis2ccd8e82021-10-08 11:21:14 +020055
Imre Kiseeee9642021-12-17 13:59:46 +010056if (NOT DEFINED SP_HEAP_SIZE)
57 message(FATAL_ERROR "SP_HEAP_SIZE is not defined")
58endif()
59
Imre Kis2ccd8e82021-10-08 11:21:14 +020060target_compile_definitions(${TGT} PRIVATE
61 TRACE_LEVEL=${TRACE_LEVEL}
62 TRACE_PREFIX="${TRACE_PREFIX}"
Imre Kiseeee9642021-12-17 13:59:46 +010063 SP_HEAP_SIZE=${SP_HEAP_SIZE}
Imre Kis2ccd8e82021-10-08 11:21:14 +020064)
Imre Kise6d73412021-10-18 14:01:47 +020065
Imre Kisd47a1452024-05-29 14:25:59 +020066add_subdirectory(${TS_ROOT}/components/common/libc ${CMAKE_BINARY_DIR}/libc_build)
67add_components(TARGET ${TGT}
68 BASE_DIR ${TS_ROOT}
69 COMPONENTS
70 "components/common/dlmalloc"
71)
Imre Kise6d73412021-10-18 14:01:47 +020072
73target_link_libraries(${TGT} PRIVATE
Gyorgy Szing693877e2021-12-12 02:51:10 +010074 stdlib::c
Imre Kise6d73412021-10-18 14:01:47 +020075)
76
77target_link_options(${TGT} PRIVATE
78 -Wl,--hash-style=sysv
79 -Wl,--as-needed
80 -Wl,--gc-sections
81)
82
83compiler_set_linker_script(TARGET ${TGT} FILE ${CMAKE_CURRENT_LIST_DIR}/sp.ld.S DEF ARM64=1)