Jelle Sels | f1cb052 | 2022-06-30 11:31:31 +0200 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2022, Arm Limited and Contributors. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | macro(generate_uuid_formats uuid) |
| 8 | #Create a list of byte |
| 9 | string(REGEX MATCHALL "([A-Za-z0-9][A-Za-z0-9])" SEPARATED_HEX "${uuid}") |
| 10 | list(JOIN SEPARATED_HEX ", 0x" UUID_BYTES ) |
| 11 | #Generate the uuid_byte string |
| 12 | #{ 0x01, 0x10, 0x9c, 0xf8, 0xe5, 0xca, 0x44, 0x6f, |
| 13 | # 0x9b, 0x55, 0xf3, 0xcd, 0xc6, 0x51, 0x10, 0xc8, } |
| 14 | |
| 15 | string(PREPEND UUID_BYTES "{0x") |
| 16 | string(APPEND UUID_BYTES "}") |
| 17 | |
| 18 | #Split the list of bytes in to the struct fields |
| 19 | list(SUBLIST SEPARATED_HEX 0 4 uuid_timeLow) |
| 20 | list(SUBLIST SEPARATED_HEX 4 2 uuid_timeMid) |
| 21 | list(SUBLIST SEPARATED_HEX 6 2 uuid_timeHiAndVersion) |
| 22 | list(SUBLIST SEPARATED_HEX 8 8 uuid_clockSeqAndNode) |
| 23 | |
| 24 | #Combine the bytes in the fields |
| 25 | list(JOIN uuid_timeLow "" uuid_timeLow ) |
| 26 | string(PREPEND uuid_timeLow "0x") |
| 27 | |
| 28 | list(JOIN uuid_timeMid "" uuid_timeMid ) |
| 29 | string(PREPEND uuid_timeMid " 0x") |
| 30 | |
| 31 | list(JOIN uuid_timeHiAndVersion "" uuid_timeHiAndVersion ) |
| 32 | string(PREPEND uuid_timeHiAndVersion " 0x") |
| 33 | |
| 34 | list(JOIN uuid_clockSeqAndNode ", 0x" uuid_clockSeqAndNode ) |
| 35 | string(PREPEND uuid_clockSeqAndNode " 0x") |
| 36 | |
| 37 | #Combine the different fields into one uuid_struct string |
| 38 | #{ 0x01109cf8, 0xe5ca, 0x446f, \ |
| 39 | #{ 0x9b, 0x55, 0xf3, 0xcd, 0xc6, 0x51, 0x10, 0xc8 } } |
| 40 | |
| 41 | string(CONCAT UUID_STRUCT "{" ${uuid_timeLow} "," ${uuid_timeMid} |
| 42 | "," ${uuid_timeHiAndVersion} ", {" ${uuid_clockSeqAndNode} "}}") |
| 43 | |
| 44 | # Swith endianess |
| 45 | list(SUBLIST SEPARATED_HEX 0 4 hex1) |
| 46 | list(SUBLIST SEPARATED_HEX 4 4 hex2) |
| 47 | list(SUBLIST SEPARATED_HEX 8 4 hex3) |
| 48 | list(SUBLIST SEPARATED_HEX 12 4 hex4) |
| 49 | |
| 50 | list(REVERSE hex1) |
| 51 | list(REVERSE hex2) |
| 52 | list(REVERSE hex3) |
| 53 | list(REVERSE hex4) |
| 54 | string(CONCAT UUID_LE " 0x" ${hex1} " 0x" ${hex2} " 0x" ${hex3} |
| 55 | " 0x" ${hex4}) |
| 56 | |
| 57 | endmacro() |
| 58 | |
| 59 | #[===[.rst: |
| 60 | .. cmake:command:: set_target_uuids |
| 61 | |
| 62 | .. code:: cmake |
| 63 | |
| 64 | set_target_uuids( |
| 65 | SP_UUID <uuid> |
| 66 | SP_NAME <name> |
| 67 | ) |
| 68 | |
| 69 | INPUTS: |
| 70 | |
| 71 | ``SP_UUID`` |
| 72 | The UUID of the SP as a string. |
| 73 | |
| 74 | ``SP_NAME`` |
| 75 | The name of the SP. |
| 76 | |
Gyorgy Szing | 8a1e7f4 | 2023-07-26 18:26:48 +0200 | [diff] [blame^] | 77 | OUTPUTS: |
| 78 | |
| 79 | ``SP_UUID_LE`` |
| 80 | SP_UUID converted to little-endian binary format. |
| 81 | |
Jelle Sels | f1cb052 | 2022-06-30 11:31:31 +0200 | [diff] [blame] | 82 | #]===] |
| 83 | |
| 84 | function (set_target_uuids) |
| 85 | set(options) |
| 86 | set(oneValueArgs SP_UUID SP_NAME) |
| 87 | set(multiValueArgs) |
| 88 | cmake_parse_arguments(TARGET "${options}" "${oneValueArgs}" |
| 89 | "${multiValueArgs}" ${ARGN} ) |
| 90 | |
| 91 | if(NOT DEFINED TARGET_SP_UUID) |
| 92 | message(FATAL_ERROR "set_target_uuids: mandatory parameter SP_UUID not defined!") |
| 93 | endif() |
| 94 | if(NOT DEFINED TARGET_SP_NAME) |
| 95 | message(FATAL_ERROR "set_target_uuids: mandatory parameter SP_NAME not defined!") |
| 96 | endif() |
| 97 | |
| 98 | generate_uuid_formats(${TARGET_SP_UUID}) |
| 99 | target_compile_definitions(${TARGET_SP_NAME} |
| 100 | PRIVATE OPTEE_SP_UUID=${UUID_STRUCT} |
| 101 | PRIVATE OPTEE_SP_UUID_BYTES=${UUID_BYTES} |
| 102 | ) |
| 103 | set(SP_UUID_LE ${UUID_LE} PARENT_SCOPE) |
| 104 | endfunction() |