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