blob: f22e9cb5d87da3b402ede38cc210afaaf433a537 [file] [log] [blame]
Imre Kisa74aaf92021-12-14 17:13:06 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
3#
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(
14 SP_UUID <uuid> SP_NAME
15 <name> MK_IN <.mk path>
16 DTS_IN <DTS path>
17 DTS_MEM_REGIONS <Memory region manifest path>
18 JSON_IN <JSON path>
19 )
Imre Kisa74aaf92021-12-14 17:13:06 +010020
21 INPUTS:
22
23 ``SP_UUID``
24 The UUID of the SP as a string.
25
26 ``SP_NAME``
27 The name of the SP.
28
29 ``MK_IN``
30 Optional, Makefile template for OP-TEE build
31
32 ``DTS_IN``
33 Manifest file template
34
Imre Kis686bd272021-12-15 19:19:02 +010035 `DTS_MEM_REGIONS`
36 Optional, Memory region manifest file
37
Imre Kisa74aaf92021-12-14 17:13:06 +010038 ``JSON_IN``
39 Optional, SP layout JSON file template for TF-A
40
41#]===]
42function (export_sp)
43 set(options)
Imre Kis686bd272021-12-15 19:19:02 +010044 set(oneValueArgs SP_UUID SP_NAME MK_IN DTS_IN DTS_MEM_REGIONS JSON_IN)
Imre Kisa74aaf92021-12-14 17:13:06 +010045 set(multiValueArgs)
46 cmake_parse_arguments(EXPORT "${options}" "${oneValueArgs}"
47 "${multiValueArgs}" ${ARGN} )
48
49 if(NOT DEFINED EXPORT_SP_UUID)
50 message(FATAL_ERROR "export_sp: mandatory parameter SP_UUID not defined!")
51 endif()
52 if(NOT DEFINED EXPORT_SP_NAME)
53 message(FATAL_ERROR "export_sp: mandatory parameter SP_NAME not defined!")
54 endif()
55 if(NOT DEFINED EXPORT_DTS_IN)
56 message(FATAL_ERROR "export_sp: mandatory parameter DTS_IN not defined!")
57 endif()
58
59 if (DEFINED EXPORT_MK_IN)
60 configure_file(${EXPORT_MK_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk @ONLY NEWLINE_STYLE UNIX)
61 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk DESTINATION ${TS_ENV}/lib/make)
62 endif()
63
64 # Converting UUID from the canonical string format to four 32 bit unsigned integers.
65 # The first byte of the UUID is the MSB of the first integer.
66 # 01234567-89ab-cdef-0123-456789abcdef -> 0x01234567 0x89abcdef 0x01234567 0x89abcdef
67 string(REGEX REPLACE
68 "([a-f0-9]+)-([a-f0-9]+)-([a-f0-9]+)-([a-f0-9]+)-([a-f0-9][a-f0-9][a-f0-9][a-f0-9])([a-f0-9]+)"
69 "0x\\1 0x\\2\\3 0x\\4\\5 0x\\6"
70 EXPORT_SP_UUID_DT ${EXPORT_SP_UUID})
71
72 # As the .dtsi is meant to be included in .dts file, it shouldn't contain a separate
73 # /dts-v1/ tag and its node should be unique, i.e. the SP name.
74 set(DTS_TAG "")
75 set(DTS_NODE "${EXPORT_SP_NAME}")
76 configure_file(${EXPORT_DTS_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID}.dtsi @ONLY NEWLINE_STYLE UNIX)
77 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID}.dtsi DESTINATION ${TS_ENV}/manifest)
78
79 # The .dts file is a standalone structure, thus it should have the /dts-v1/ tag and it
80 # starts with the root node.
81 set(DTS_TAG "/dts-v1/;")
82 set(DTS_NODE "/")
83 configure_file(${EXPORT_DTS_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID}.dts @ONLY NEWLINE_STYLE UNIX)
84 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_UUID}.dts DESTINATION ${TS_ENV}/manifest)
85
Imre Kis686bd272021-12-15 19:19:02 +010086 if (DEFINED EXPORT_DTS_MEM_REGIONS)
87 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_DTS_MEM_REGIONS} DESTINATION ${TS_ENV}/manifest)
88 endif()
89
Imre Kisa74aaf92021-12-14 17:13:06 +010090 if (DEFINED EXPORT_JSON_IN)
91 configure_file(${EXPORT_JSON_IN} ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.json @ONLY NEWLINE_STYLE UNIX)
92 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.json DESTINATION ${TS_ENV}/json)
93 endif()
Imre Kis686bd272021-12-15 19:19:02 +010094endfunction()