Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Raef Coles | d97a7e7 | 2021-12-10 14:58:06 +0000 | [diff] [blame] | 2 | # Copyright (c) 2020-2022, Arm Limited. All rights reserved. |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
Raef Coles | 6981732 | 2020-10-19 14:14:14 +0100 | [diff] [blame] | 8 | cmake_minimum_required(VERSION 3.15) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 9 | find_package(Python3) |
| 10 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 11 | ############################### Manifest lists declaration ##################### |
| 12 | list(APPEND MANIFEST_LISTS ${TFM_MANIFEST_LIST}) |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 13 | |
David Hu | 12f2587 | 2021-08-23 14:55:46 +0800 | [diff] [blame] | 14 | if (TFM_NS_REG_TEST OR TFM_S_REG_TEST) |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 15 | list(APPEND MANIFEST_LISTS ${TFM_TEST_PATH}/secure_fw/tfm_test_manifest_list.yaml) |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 16 | endif() |
| 17 | |
| 18 | if ("${TEST_PSA_API}" STREQUAL "IPC") |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 19 | # The manifest tool does not recognize CMake varibles. Do configure_file() first. |
| 20 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tfm_psa_ff_test_manifest_list.yaml |
| 21 | ${CMAKE_CURRENT_BINARY_DIR}/tfm_psa_ff_test_manifest_list.yaml) |
| 22 | list(APPEND MANIFEST_LISTS ${CMAKE_CURRENT_BINARY_DIR}/tfm_psa_ff_test_manifest_list.yaml) |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 23 | endif() |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 24 | |
David Hu | f5f1209 | 2021-07-12 16:11:47 +0800 | [diff] [blame] | 25 | if (TFM_EXTRA_MANIFEST_LIST_FILES) |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 26 | list(APPEND MANIFEST_LISTS ${TFM_EXTRA_MANIFEST_LIST_FILES}) |
David Hu | f5f1209 | 2021-07-12 16:11:47 +0800 | [diff] [blame] | 27 | endif() |
| 28 | |
Maulik Patel | 7cfee4a | 2022-07-19 09:39:38 +0100 | [diff] [blame] | 29 | if (TFM_EXTRAS_REPO_EXTRA_MANIFEST_LIST) |
| 30 | set(TMP_MANIFEST_LISTS ${TFM_EXTRAS_REPO_EXTRA_MANIFEST_LIST}) |
| 31 | list(TRANSFORM TMP_MANIFEST_LISTS PREPEND ${TFM_EXTRAS_REPO_PATH}/) |
| 32 | list(APPEND MANIFEST_LISTS ${TMP_MANIFEST_LISTS}) |
| 33 | endif() |
| 34 | |
| 35 | # Remove any duplicate entries to prevent same path appended twice in case of mulitiple runs |
| 36 | list(REMOVE_DUPLICATES MANIFEST_LISTS) |
| 37 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 38 | ############################### File list declaration ########################## |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 39 | set(GENERATED_FILE_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/tfm_generated_file_list.yaml) |
| 40 | set(GENERATED_FILE_LISTS ${GENERATED_FILE_LISTS} ${TFM_EXTRA_GENERATED_FILE_LIST_PATH}) |
| 41 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 42 | ############################### Functions declaration ########################## |
| 43 | # Parses the given YAML "files" to find out all the items of the given "field" |
| 44 | # and put them to the "output_variable" as a list. |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 45 | function(parse_field_from_yaml files field output_variable) |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 46 | set(local_variable "") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 47 | foreach(yaml_file ${files}) |
| 48 | # Load the lines that refer to the key we selected |
| 49 | file(STRINGS ${yaml_file} temp_variable REGEX " *\"${field}\":") |
| 50 | # Take only the value of the key |
| 51 | list(TRANSFORM temp_variable REPLACE " *\"${field}\": *" ";") |
| 52 | # Remove all commas |
| 53 | list(TRANSFORM temp_variable REPLACE "," "") |
| 54 | # Remove all quote marks |
| 55 | list(TRANSFORM temp_variable REPLACE "\"" "") |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 56 | list(APPEND local_variable ${temp_variable}) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 57 | endforeach() |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 58 | set(${output_variable} ${local_variable} PARENT_SCOPE) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 59 | endfunction() |
| 60 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 61 | ############################### Dependency generation ########################## |
| 62 | # Get all the manifest files from manifest lists |
| 63 | foreach(MANIFEST_LIST ${MANIFEST_LISTS}) |
| 64 | if (NOT EXISTS ${MANIFEST_LIST}) |
| 65 | message(FATAL_ERROR "Manifest list ${MANIFEST_LIST} doesn't exist") |
| 66 | endif() |
| 67 | |
| 68 | # Get the path of the manifest list |
| 69 | get_filename_component(MANIFEST_LIST_PATH ${MANIFEST_LIST} DIRECTORY) |
| 70 | |
| 71 | # Get all the "manifest" |
| 72 | parse_field_from_yaml(${MANIFEST_LIST} manifest MANIFESTS) |
| 73 | |
| 74 | foreach(MANIFEST ${MANIFESTS}) |
| 75 | # Convert to absolute paths |
| 76 | if (NOT IS_ABSOLUTE ${MANIFEST}) |
| 77 | get_filename_component(MANIFEST "${MANIFEST_LIST_PATH}/${MANIFEST}" ABSOLUTE) |
| 78 | endif() |
| 79 | list(APPEND MANIFEST_FILES ${MANIFEST}) |
| 80 | endforeach() |
| 81 | endforeach() |
| 82 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 83 | parse_field_from_yaml("${GENERATED_FILE_LISTS}" template TEMPLATE_FILES) |
| 84 | # Replace relative paths with absolute paths |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 85 | # Paths used in GENERATED_FILE_LISTS are all relative to TF-M root (${CMAKE_SOURCE_DIR}) |
Ken Liu | a2ac1f9 | 2020-10-12 10:58:21 +0800 | [diff] [blame] | 86 | list(TRANSFORM TEMPLATE_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_SOURCE_DIR}/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 87 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 88 | ############################### Generate Manifest config header ################ |
Kevin Peng | 93efad0 | 2022-08-01 17:58:13 +0800 | [diff] [blame] | 89 | |
| 90 | # The function appends the given `config` to the `out_var` variable. |
| 91 | # Supported `type` are [BOOL, STRING]. |
| 92 | # The format of contents appended is |
| 93 | # #cmakedefine01 config for BOOL types |
| 94 | # #cmakedefine config @config@ for STRING types |
| 95 | function(append_manifest_config out_var config type) |
| 96 | # Operate on a local var and write back to the out_var later |
| 97 | set(local_var ${${out_var}}) |
| 98 | |
| 99 | # Avoid duplications of configs |
| 100 | string(FIND "${local_var}" ${config} config_exists) |
| 101 | if(${config_exists} EQUAL -1) # Not found |
| 102 | if (${type} STREQUAL "BOOL") |
| 103 | string(APPEND local_var "#cmakedefine01 ${config}\r\n") |
| 104 | elseif(${type} STREQUAL "STRING") |
| 105 | string(APPEND local_var "#cmakedefine ${config} @${config}@\r\n") |
| 106 | else() |
| 107 | message(FATAL_ERROR "Unsupported config type: ${type}") |
| 108 | endif() |
| 109 | endif() |
| 110 | |
| 111 | set(${out_var} ${local_var} PARENT_SCOPE) |
| 112 | endfunction() |
| 113 | |
| 114 | # The following build configurations are required to pass to manifest tool via the config header |
| 115 | # - The isolation level |
| 116 | # - The SPM backend |
| 117 | # - "conditional" attributes for every Secure Partition in manifest lists |
Kevin Peng | 93efad0 | 2022-08-01 17:58:13 +0800 | [diff] [blame] | 118 | append_manifest_config(MANIFEST_CONFIG_H_CONTENT TFM_ISOLATION_LEVEL STRING) |
| 119 | append_manifest_config(MANIFEST_CONFIG_H_CONTENT CONFIG_TFM_SPM_BACKEND STRING) |
| 120 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 121 | parse_field_from_yaml("${MANIFEST_LISTS}" conditional CONDITIONS) |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 122 | foreach(CON ${CONDITIONS}) |
Kevin Peng | 93efad0 | 2022-08-01 17:58:13 +0800 | [diff] [blame] | 123 | append_manifest_config(MANIFEST_CONFIG_H_CONTENT ${CON} BOOL) |
| 124 | endforeach() |
| 125 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 126 | # Generate the config header |
| 127 | file(WRITE |
| 128 | ${CMAKE_CURRENT_BINARY_DIR}/manifest_config.h.in |
| 129 | ${MANIFEST_CONFIG_H_CONTENT}) |
| 130 | |
| 131 | configure_file(${CMAKE_CURRENT_BINARY_DIR}/manifest_config.h.in |
| 132 | ${CMAKE_CURRENT_BINARY_DIR}/manifest_config.h) |
| 133 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 134 | ############################### Command declaration ############################ |
| 135 | |
| 136 | # Workaround for heap support |
| 137 | if ("${TEST_PSA_API}" STREQUAL "IPC") |
| 138 | execute_process( |
| 139 | WORKING_DIRECTORY ${PSA_ARCH_TESTS_PATH}/api-tests |
| 140 | COMMAND ${Python3_EXECUTABLE} tools/scripts/manifest_update.py |
| 141 | ) |
| 142 | endif() |
| 143 | |
Kevin Peng | c32279d | 2022-02-10 11:11:55 +0800 | [diff] [blame] | 144 | if (CONFIG_TFM_PARSE_MANIFEST_QUIET) |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 145 | set(PARSE_MANIFEST_QUIET_FLAG "-q") |
| 146 | else() |
| 147 | set(PARSE_MANIFEST_QUIET_FLAG "") |
| 148 | endif() |
| 149 | |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 150 | set(MANIFEST_COMMAND |
| 151 | ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tfm_parse_manifest_list.py |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 152 | -m ${MANIFEST_LISTS} |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 153 | -f ${GENERATED_FILE_LISTS} |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 154 | -c ${CMAKE_CURRENT_BINARY_DIR}/manifest_config.h |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 155 | -o ${CMAKE_BINARY_DIR}/generated |
| 156 | ${PARSE_MANIFEST_QUIET_FLAG}) |
| 157 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 158 | # The files need to be generated before cmake will allow them to be used as |
| 159 | # sources. Due to issue with custom_command scoping the easiest way to do this |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 160 | # is to run the script at cmake-time. |
| 161 | execute_process( |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 162 | COMMAND ${MANIFEST_COMMAND} |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 163 | RESULT_VARIABLE RET |
| 164 | ) |
| 165 | |
Sherry Zhang | f58f2bd | 2022-01-10 17:21:11 +0800 | [diff] [blame] | 166 | if(RET EQUAL 0) |
| 167 | include(${CMAKE_BINARY_DIR}/generated/tools/config_impl.cmake) |
| 168 | else() |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 169 | message(FATAL_ERROR "Manifest tool failed to generate files!") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 170 | endif() |