1#------------------------------------------------------------------------------- 2# Copyright (c) 2020-2024, Arm Limited and Contributors. All rights reserved. 3# 4# SPDX-License-Identifier: BSD-3-Clause 5# 6#------------------------------------------------------------------------------- 7 8# 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 15# 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) 18 set(SP_BIN_UUID_CANON "${SP_FFA_UUID_CANON}") 19endif() 20ts_add_uuid_to_exe_name(TGT "${TGT}" UUID "${SP_BIN_UUID_CANON}" ) 21 22get_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) 26 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( 33 SP_UUID ${SP_FFA_UUID_CANON} 34 TGT ${SP_NAME} 35 ) 36 37endif() 38 39target_sources(${TGT} PRIVATE 40 "${CMAKE_CURRENT_LIST_DIR}/optee_sp_header.c" 41 "${CMAKE_CURRENT_LIST_DIR}/sp_assert.c" 42 "${CMAKE_CURRENT_LIST_DIR}/sp_entry.c" 43 "${CMAKE_CURRENT_LIST_DIR}/sp_trace.c" 44) 45 46target_include_directories(${TGT} 47 PUBLIC 48 "${CMAKE_CURRENT_LIST_DIR}/include" 49 ) 50 51# 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") 55 56if (NOT DEFINED SP_HEAP_SIZE) 57 message(FATAL_ERROR "SP_HEAP_SIZE is not defined") 58endif() 59 60target_compile_definitions(${TGT} PRIVATE 61 TRACE_LEVEL=${TRACE_LEVEL} 62 TRACE_PREFIX="${TRACE_PREFIX}" 63 SP_HEAP_SIZE=${SP_HEAP_SIZE} 64) 65 66add_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) 72 73target_link_libraries(${TGT} PRIVATE 74 stdlib::c 75) 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) 84