blob: 1c6d9db87a7a037f77d54a29dfd48803df6da81f [file] [log] [blame]
Imre Kisa74aaf92021-12-14 17:13:06 +01001#-------------------------------------------------------------------------------
Imre Kis7dfd4972022-10-27 16:55:57 +02002# Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
Imre Kisa74aaf92021-12-14 17:13:06 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
Gyorgy Szingfd03e0a2023-07-27 20:04:24 +02008include(${CMAKE_CURRENT_LIST_DIR}/Uuid.cmake)
9
Imre Kisa74aaf92021-12-14 17:13:06 +010010#[===[.rst:
11.. cmake:command:: export_sp
12
13 .. code:: cmake
14
Imre Kis686bd272021-12-15 19:19:02 +010015 export_sp(
Balint Dobszayc9daea92022-06-15 15:17:11 +020016 SP_UUID_CANON <uuid_str_canon>
Balint Dobszayc9daea92022-06-15 15:17:11 +020017 SP_NAME <name> MK_IN <.mk path>
Imre Kis686bd272021-12-15 19:19:02 +010018 DTS_IN <DTS path>
19 DTS_MEM_REGIONS <Memory region manifest path>
20 JSON_IN <JSON path>
21 )
Imre Kisa74aaf92021-12-14 17:13:06 +010022
23 INPUTS:
24
Balint Dobszayc9daea92022-06-15 15:17:11 +020025 ``SP_UUID_CANON``
Jelle Selsc85a0c22022-12-07 14:04:49 +010026 The FF_A UUID of the SP as a canonical string.
27
28 ``SP_BIN_UUID_CANON``
29 The UUID of the SP binary a canonical string. When not set use the
30 SP_UUID_CANON as the SP_BIN_UUID_CANON.
Balint Dobszayc9daea92022-06-15 15:17:11 +020031
Imre Kisa74aaf92021-12-14 17:13:06 +010032 ``SP_NAME``
33 The name of the SP.
34
35 ``MK_IN``
36 Optional, Makefile template for OP-TEE build
37
38 ``DTS_IN``
39 Manifest file template
40
Imre Kis686bd272021-12-15 19:19:02 +010041 `DTS_MEM_REGIONS`
42 Optional, Memory region manifest file
43
Imre Kisa74aaf92021-12-14 17:13:06 +010044 ``JSON_IN``
45 Optional, SP layout JSON file template for TF-A
46
47#]===]
48function (export_sp)
49 set(options)
Jelle Selsc85a0c22022-12-07 14:04:49 +010050 set(oneValueArgs SP_UUID_CANON SP_BIN_UUID_CANON SP_UUID_LE SP_NAME MK_IN DTS_IN DTS_MEM_REGIONS JSON_IN)
Imre Kisa74aaf92021-12-14 17:13:06 +010051 set(multiValueArgs)
52 cmake_parse_arguments(EXPORT "${options}" "${oneValueArgs}"
53 "${multiValueArgs}" ${ARGN} )
54
Balint Dobszayc9daea92022-06-15 15:17:11 +020055 if(NOT DEFINED EXPORT_SP_UUID_CANON)
56 message(FATAL_ERROR "export_sp: mandatory parameter SP_UUID_CANON not defined!")
57 endif()
Jelle Selsc85a0c22022-12-07 14:04:49 +010058 if(NOT DEFINED EXPORT_SP_BIN_UUID_CANON)
59 # We use the same UUID for the binary and FF-A if the UUID of the SP binary is not set
60 set(EXPORT_SP_BIN_UUID_CANON ${EXPORT_SP_UUID_CANON})
61 endif()
Imre Kisa74aaf92021-12-14 17:13:06 +010062 if(NOT DEFINED EXPORT_SP_NAME)
63 message(FATAL_ERROR "export_sp: mandatory parameter SP_NAME not defined!")
64 endif()
65 if(NOT DEFINED EXPORT_DTS_IN)
66 message(FATAL_ERROR "export_sp: mandatory parameter DTS_IN not defined!")
67 endif()
68
69 if (DEFINED EXPORT_MK_IN)
70 configure_file(${EXPORT_MK_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk @ONLY NEWLINE_STYLE UNIX)
71 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk DESTINATION ${TS_ENV}/lib/make)
72 endif()
73
Balint Dobszayc9daea92022-06-15 15:17:11 +020074 # In the SP manifest DT the UUID format is four uint32 numbers (little-endian)
Gyorgy Szingfd03e0a2023-07-27 20:04:24 +020075 # Create a litte endian 4 digit octests representation.
76 uuid_canon_to_le_words(UUID ${EXPORT_SP_UUID_CANON} RES _le_words)
77 list(JOIN _le_words " 0x" _uuid_le)
78 set(SP_UUID_LE " 0x${_uuid_le}" PARENT_SCOPE)
79 set(EXPORT_SP_UUID_DT " 0x${_uuid_le}")
Imre Kisa74aaf92021-12-14 17:13:06 +010080
81 # As the .dtsi is meant to be included in .dts file, it shouldn't contain a separate
82 # /dts-v1/ tag and its node should be unique, i.e. the SP name.
83 set(DTS_TAG "")
84 set(DTS_NODE "${EXPORT_SP_NAME}")
Jelle Selsc85a0c22022-12-07 14:04:49 +010085 configure_file(${EXPORT_DTS_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_BIN_UUID_CANON}_before_preprocessing.dtsi @ONLY NEWLINE_STYLE UNIX)
Imre Kis7dfd4972022-10-27 16:55:57 +020086
87 compiler_preprocess_file(
Jelle Selsc85a0c22022-12-07 14:04:49 +010088 SRC ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_BIN_UUID_CANON}_before_preprocessing.dtsi
89 DST ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_BIN_UUID_CANON}.dtsi
Imre Kis7dfd4972022-10-27 16:55:57 +020090 TARGET ${EXPORT_SP_NAME}
91 )
92
Jelle Selsc85a0c22022-12-07 14:04:49 +010093 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_BIN_UUID_CANON}.dtsi DESTINATION ${TS_ENV}/manifest)
Imre Kisa74aaf92021-12-14 17:13:06 +010094
95 # The .dts file is a standalone structure, thus it should have the /dts-v1/ tag and it
96 # starts with the root node.
97 set(DTS_TAG "/dts-v1/;")
98 set(DTS_NODE "/")
Jelle Selsc85a0c22022-12-07 14:04:49 +010099 configure_file(${EXPORT_DTS_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_BIN_UUID_CANON}_before_preprocessing.dts @ONLY NEWLINE_STYLE UNIX)
Imre Kisa74aaf92021-12-14 17:13:06 +0100100
Imre Kis7dfd4972022-10-27 16:55:57 +0200101 compiler_preprocess_file(
Jelle Selsc85a0c22022-12-07 14:04:49 +0100102 SRC ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_BIN_UUID_CANON}_before_preprocessing.dts
103 DST ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_BIN_UUID_CANON}.dts
Imre Kis7dfd4972022-10-27 16:55:57 +0200104 TARGET ${EXPORT_SP_NAME}
105 )
106
Jelle Selsc85a0c22022-12-07 14:04:49 +0100107 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_BIN_UUID_CANON}.dts DESTINATION ${TS_ENV}/manifest)
108
109 if (DEFINED EXPORT_DTS_MEM_REGIONS)
110 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_DTS_MEM_REGIONS} DESTINATION ${TS_ENV}/manifest)
111 endif()
Imre Kis686bd272021-12-15 19:19:02 +0100112
Imre Kisa74aaf92021-12-14 17:13:06 +0100113 if (DEFINED EXPORT_JSON_IN)
114 configure_file(${EXPORT_JSON_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.json @ONLY NEWLINE_STYLE UNIX)
115 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.json DESTINATION ${TS_ENV}/json)
116 endif()
Imre Kis686bd272021-12-15 19:19:02 +0100117endfunction()