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 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 29 | ############################### File list declaration ########################## |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 30 | set(GENERATED_FILE_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/tfm_generated_file_list.yaml) |
| 31 | set(GENERATED_FILE_LISTS ${GENERATED_FILE_LISTS} ${TFM_EXTRA_GENERATED_FILE_LIST_PATH}) |
| 32 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 33 | ############################### Functions declaration ########################## |
| 34 | # Parses the given YAML "files" to find out all the items of the given "field" |
| 35 | # and put them to the "output_variable" as a list. |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 36 | function(parse_field_from_yaml files field output_variable) |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 37 | set(local_variable "") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 38 | foreach(yaml_file ${files}) |
| 39 | # Load the lines that refer to the key we selected |
| 40 | file(STRINGS ${yaml_file} temp_variable REGEX " *\"${field}\":") |
| 41 | # Take only the value of the key |
| 42 | list(TRANSFORM temp_variable REPLACE " *\"${field}\": *" ";") |
| 43 | # Remove all commas |
| 44 | list(TRANSFORM temp_variable REPLACE "," "") |
| 45 | # Remove all quote marks |
| 46 | list(TRANSFORM temp_variable REPLACE "\"" "") |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 47 | list(APPEND local_variable ${temp_variable}) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 48 | endforeach() |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 49 | set(${output_variable} ${local_variable} PARENT_SCOPE) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 50 | endfunction() |
| 51 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 52 | ############################### Dependency generation ########################## |
| 53 | # Get all the manifest files from manifest lists |
| 54 | foreach(MANIFEST_LIST ${MANIFEST_LISTS}) |
| 55 | if (NOT EXISTS ${MANIFEST_LIST}) |
| 56 | message(FATAL_ERROR "Manifest list ${MANIFEST_LIST} doesn't exist") |
| 57 | endif() |
| 58 | |
| 59 | # Get the path of the manifest list |
| 60 | get_filename_component(MANIFEST_LIST_PATH ${MANIFEST_LIST} DIRECTORY) |
| 61 | |
| 62 | # Get all the "manifest" |
| 63 | parse_field_from_yaml(${MANIFEST_LIST} manifest MANIFESTS) |
| 64 | |
| 65 | foreach(MANIFEST ${MANIFESTS}) |
| 66 | # Convert to absolute paths |
| 67 | if (NOT IS_ABSOLUTE ${MANIFEST}) |
| 68 | get_filename_component(MANIFEST "${MANIFEST_LIST_PATH}/${MANIFEST}" ABSOLUTE) |
| 69 | endif() |
| 70 | list(APPEND MANIFEST_FILES ${MANIFEST}) |
| 71 | endforeach() |
| 72 | endforeach() |
| 73 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 74 | parse_field_from_yaml("${GENERATED_FILE_LISTS}" template TEMPLATE_FILES) |
| 75 | # Replace relative paths with absolute paths |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 76 | # 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] | 77 | list(TRANSFORM TEMPLATE_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_SOURCE_DIR}/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 78 | |
| 79 | parse_field_from_yaml("${GENERATED_FILE_LISTS}" output OUTPUT_FILES) |
| 80 | # Replace relative paths with absolute paths |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 81 | # 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] | 82 | list(TRANSFORM OUTPUT_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_BINARY_DIR}/generated/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 83 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 84 | ############################### Generate Manifest config header ################ |
| 85 | parse_field_from_yaml("${MANIFEST_LISTS}" conditional CONDITIONS) |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 86 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 87 | # Isolation level and backend are required by the manifest tool |
| 88 | string(APPEND MANIFEST_CONFIG_H_CONTENT |
| 89 | "#cmakedefine TFM_ISOLATION_LEVEL @TFM_ISOLATION_LEVEL@\r\n") |
| 90 | string(APPEND MANIFEST_CONFIG_H_CONTENT |
| 91 | "#cmakedefine CONFIG_TFM_SPM_BACKEND @CONFIG_TFM_SPM_BACKEND@\r\n") |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 92 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 93 | foreach(CON ${CONDITIONS}) |
| 94 | # Secure Partitions may share the same conditions, perform duplication check here |
| 95 | string(FIND ${MANIFEST_CONFIG_H_CONTENT} ${CON} CON_EXISTS) |
| 96 | if (${CON_EXISTS} EQUAL -1) # Not found |
| 97 | string(APPEND MANIFEST_CONFIG_H_CONTENT |
| 98 | "#cmakedefine01 ${CON}\r\n") |
| 99 | endif() |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 100 | endforeach() |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 101 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 102 | # Generate the config header |
| 103 | file(WRITE |
| 104 | ${CMAKE_CURRENT_BINARY_DIR}/manifest_config.h.in |
| 105 | ${MANIFEST_CONFIG_H_CONTENT}) |
| 106 | |
| 107 | configure_file(${CMAKE_CURRENT_BINARY_DIR}/manifest_config.h.in |
| 108 | ${CMAKE_CURRENT_BINARY_DIR}/manifest_config.h) |
| 109 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 110 | ############################### Command declaration ############################ |
| 111 | |
| 112 | # Workaround for heap support |
| 113 | if ("${TEST_PSA_API}" STREQUAL "IPC") |
| 114 | execute_process( |
| 115 | WORKING_DIRECTORY ${PSA_ARCH_TESTS_PATH}/api-tests |
| 116 | COMMAND ${Python3_EXECUTABLE} tools/scripts/manifest_update.py |
| 117 | ) |
| 118 | endif() |
| 119 | |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 120 | add_custom_target(tfm_generated_files |
| 121 | SOURCES ${OUTPUT_FILES} |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 122 | ) |
| 123 | |
Kevin Peng | c32279d | 2022-02-10 11:11:55 +0800 | [diff] [blame] | 124 | if (CONFIG_TFM_PARSE_MANIFEST_QUIET) |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 125 | set(PARSE_MANIFEST_QUIET_FLAG "-q") |
| 126 | else() |
| 127 | set(PARSE_MANIFEST_QUIET_FLAG "") |
| 128 | endif() |
| 129 | |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 130 | set(MANIFEST_COMMAND |
| 131 | ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tfm_parse_manifest_list.py |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 132 | -m ${MANIFEST_LISTS} |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 133 | -f ${GENERATED_FILE_LISTS} |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 134 | -c ${CMAKE_CURRENT_BINARY_DIR}/manifest_config.h |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 135 | -o ${CMAKE_BINARY_DIR}/generated |
| 136 | ${PARSE_MANIFEST_QUIET_FLAG}) |
| 137 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 138 | add_custom_command(OUTPUT ${OUTPUT_FILES} |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 139 | COMMAND ${MANIFEST_COMMAND} |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 140 | DEPENDS ${TEMPLATE_FILES} ${MANIFEST_FILES} |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 141 | DEPENDS ${MANIFEST_LISTS} ${GENERATED_FILE_LISTS} |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 142 | ) |
| 143 | |
| 144 | # The files need to be generated before cmake will allow them to be used as |
| 145 | # 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] | 146 | # is to run the script at cmake-time. |
| 147 | execute_process( |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 148 | COMMAND ${MANIFEST_COMMAND} |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 149 | RESULT_VARIABLE RET |
| 150 | ) |
| 151 | |
Sherry Zhang | f58f2bd | 2022-01-10 17:21:11 +0800 | [diff] [blame] | 152 | if(RET EQUAL 0) |
| 153 | include(${CMAKE_BINARY_DIR}/generated/tools/config_impl.cmake) |
| 154 | else() |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame^] | 155 | message(FATAL_ERROR "Manifest tool failed to generate files!") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 156 | endif() |