blob: 124489e9d73a8ec499fe749934fcd3238e84cb3d [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
8#[===[.rst:
9.. cmake:command:: export_sp
10
11 .. code:: cmake
12
Imre Kis686bd272021-12-15 19:19:02 +010013 export_sp(
Balint Dobszayc9daea92022-06-15 15:17:11 +020014 SP_UUID_CANON <uuid_str_canon>
15 SP_UUID_LE <uuid_le_bytes>
16 SP_NAME <name> MK_IN <.mk path>
Imre Kis686bd272021-12-15 19:19:02 +010017 DTS_IN <DTS path>
18 DTS_MEM_REGIONS <Memory region manifest path>
19 JSON_IN <JSON path>
20 )
Imre Kisa74aaf92021-12-14 17:13:06 +010021
22 INPUTS:
23
Balint Dobszayc9daea92022-06-15 15:17:11 +020024 ``SP_UUID_CANON``
25 The UUID of the SP as a canonical string.
26
27 ``SP_UUID_LE``
28 The UUID of the SP as four 32 bit little-endian unsigned integers.
Imre Kisa74aaf92021-12-14 17:13:06 +010029
30 ``SP_NAME``
31 The name of the SP.
32
33 ``MK_IN``
34 Optional, Makefile template for OP-TEE build
35
36 ``DTS_IN``
37 Manifest file template
38
Imre Kis686bd272021-12-15 19:19:02 +010039 `DTS_MEM_REGIONS`
40 Optional, Memory region manifest file
41
Imre Kisa74aaf92021-12-14 17:13:06 +010042 ``JSON_IN``
43 Optional, SP layout JSON file template for TF-A
44
45#]===]
46function (export_sp)
47 set(options)
Balint Dobszayc9daea92022-06-15 15:17:11 +020048 set(oneValueArgs SP_UUID_CANON SP_UUID_LE SP_NAME MK_IN DTS_IN DTS_MEM_REGIONS JSON_IN)
Imre Kisa74aaf92021-12-14 17:13:06 +010049 set(multiValueArgs)
50 cmake_parse_arguments(EXPORT "${options}" "${oneValueArgs}"
51 "${multiValueArgs}" ${ARGN} )
52
Balint Dobszayc9daea92022-06-15 15:17:11 +020053 if(NOT DEFINED EXPORT_SP_UUID_CANON)
54 message(FATAL_ERROR "export_sp: mandatory parameter SP_UUID_CANON not defined!")
55 endif()
56 if(NOT DEFINED EXPORT_SP_UUID_LE)
57 message(FATAL_ERROR "export_sp: mandatory parameter SP_UUID_LE not defined!")
Imre Kisa74aaf92021-12-14 17:13:06 +010058 endif()
59 if(NOT DEFINED EXPORT_SP_NAME)
60 message(FATAL_ERROR "export_sp: mandatory parameter SP_NAME not defined!")
61 endif()
62 if(NOT DEFINED EXPORT_DTS_IN)
63 message(FATAL_ERROR "export_sp: mandatory parameter DTS_IN not defined!")
64 endif()
65
66 if (DEFINED EXPORT_MK_IN)
67 configure_file(${EXPORT_MK_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk @ONLY NEWLINE_STYLE UNIX)
68 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk DESTINATION ${TS_ENV}/lib/make)
69 endif()
70
Balint Dobszayc9daea92022-06-15 15:17:11 +020071 # In the SP manifest DT the UUID format is four uint32 numbers (little-endian)
72 set(EXPORT_SP_UUID_DT "${EXPORT_SP_UUID_LE}")
Imre Kisa74aaf92021-12-14 17:13:06 +010073
74 # As the .dtsi is meant to be included in .dts file, it shouldn't contain a separate
75 # /dts-v1/ tag and its node should be unique, i.e. the SP name.
76 set(DTS_TAG "")
77 set(DTS_NODE "${EXPORT_SP_NAME}")
Imre Kis7dfd4972022-10-27 16:55:57 +020078 configure_file(${EXPORT_DTS_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID_CANON}_before_preprocessing.dtsi @ONLY NEWLINE_STYLE UNIX)
79
80 compiler_preprocess_file(
81 SRC ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID_CANON}_before_preprocessing.dtsi
82 DST ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID_CANON}.dtsi
83 TARGET ${EXPORT_SP_NAME}
84 )
85
Balint Dobszayc9daea92022-06-15 15:17:11 +020086 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID_CANON}.dtsi DESTINATION ${TS_ENV}/manifest)
Imre Kisa74aaf92021-12-14 17:13:06 +010087
88 # The .dts file is a standalone structure, thus it should have the /dts-v1/ tag and it
89 # starts with the root node.
90 set(DTS_TAG "/dts-v1/;")
91 set(DTS_NODE "/")
Imre Kis7dfd4972022-10-27 16:55:57 +020092 configure_file(${EXPORT_DTS_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID_CANON}_before_preprocessing.dts @ONLY NEWLINE_STYLE UNIX)
Imre Kisa74aaf92021-12-14 17:13:06 +010093
Imre Kis7dfd4972022-10-27 16:55:57 +020094 compiler_preprocess_file(
95 SRC ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID_CANON}_before_preprocessing.dts
96 DST ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID_CANON}.dts
97 TARGET ${EXPORT_SP_NAME}
98 )
99
100 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID_CANON}.dts DESTINATION ${TS_ENV}/manifest)
Imre Kis686bd272021-12-15 19:19:02 +0100101
Imre Kisa74aaf92021-12-14 17:13:06 +0100102 if (DEFINED EXPORT_JSON_IN)
103 configure_file(${EXPORT_JSON_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.json @ONLY NEWLINE_STYLE UNIX)
104 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.json DESTINATION ${TS_ENV}/json)
Balint Dobszay9e2573d2022-08-10 15:15:21 +0200105
106 find_package(Python3 REQUIRED COMPONENTS Interpreter)
107 execute_process(COMMAND ${Python3_EXECUTABLE} ${TS_ROOT}/tools/python/merge_json.py
108 ${CMAKE_INSTALL_PREFIX}/${TS_ENV}/json/sp_layout.json
109 ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.json
110 )
Imre Kisa74aaf92021-12-14 17:13:06 +0100111 endif()
Imre Kis686bd272021-12-15 19:19:02 +0100112endfunction()