blob: 4588472d9e9339548005a071cc8813165619fd9b [file] [log] [blame]
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +05301#/** @file
jk-armbf532fd2021-05-07 13:58:22 +05302# * Copyright (c) 2019-2021, Arm Limited or its affiliates. All rights reserved.
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +05303# * SPDX-License-Identifier : Apache-2.0
4# *
5# * Licensed under the Apache License, Version 2.0 (the "License");
6# * you may not use this file except in compliance with the License.
7# * You may obtain a copy of the License at
8# *
9# * http://www.apache.org/licenses/LICENSE-2.0
10# *
11# * Unless required by applicable law or agreed to in writing, software
12# * distributed under the License is distributed on an "AS IS" BASIS,
13# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# * See the License for the specific language governing permissions and
15# * limitations under the License.
16#**/
17
18# Set the minimum required version of CMake for the project
19cmake_minimum_required(VERSION 3.10)
20
21# cmake_policy
22cmake_policy(SET CMP0057 NEW)
23
24# Find python interpreter version 3 or greater
25find_package(PythonInterp 3 REQUIRED)
26# Find Git package
27find_package(Git REQUIRED)
28
29get_filename_component(PSA_ROOT_DIR . ABSOLUTE)
30
Lingkai Dong9d4e7df2021-01-13 16:57:54 +000031include(${PSA_ROOT_DIR}/tools/cmake/common/Utils.cmake)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053032include(${PSA_ROOT_DIR}/tools/cmake/common/CMakeSettings.cmake)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +053033include(${PSA_ROOT_DIR}/tools/cmake/common/CMakeExternal.cmake)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053034
jotman016d7dd4e2020-11-10 17:32:28 +080035if(NOT DEFINED TFM_PROFILE)
36 message(STATUS "[PSA] : Building Default profile")
37list(APPEND PSA_SUITES
38 "IPC"
39 "CRYPTO"
40 "INTERNAL_TRUSTED_STORAGE"
41 "PROTECTED_STORAGE"
42 "STORAGE"
43 "INITIAL_ATTESTATION"
44)
45else()
46
47if("${TFM_PROFILE}" STREQUAL "profile_small")
48# list of supported suites
49list(APPEND PSA_SUITES
50 "CRYPTO"
51 "INTERNAL_TRUSTED_STORAGE"
52 "INITIAL_ATTESTATION"
53)
54else()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053055# list of supported suites
56list(APPEND PSA_SUITES
57 "IPC"
58 "CRYPTO"
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053059 "INTERNAL_TRUSTED_STORAGE"
jotman016d7dd4e2020-11-10 17:32:28 +080060 "PROTECTED_STORAGE"
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +053061 "STORAGE"
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053062 "INITIAL_ATTESTATION"
63)
jotman016d7dd4e2020-11-10 17:32:28 +080064endif()
65endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053066# list of ipc files required
67list(APPEND PSA_IPC_FILES
68 "psa/client.h"
69 "psa/service.h"
Jaykumar Pitambarbhai Patel1c2b0282019-11-06 11:29:13 +053070 "psa/lifecycle.h"
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053071 "psa_manifest/sid.h"
72 "psa_manifest/pid.h"
Jaykumar Pitambarbhai Patel1c2b0282019-11-06 11:29:13 +053073 "psa_manifest/driver_partition_psa.h"
74 "psa_manifest/client_partition_psa.h"
75 "psa_manifest/server_partition_psa.h"
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053076)
77
78# list of crypto files required
79list(APPEND PSA_CRYPTO_FILES
80 "psa/crypto.h"
81)
82
83# list of protected_storage files required
84list(APPEND PSA_PROTECTED_STORAGE_FILES
85 "psa/protected_storage.h"
86)
87
88# list of internal_trusted_storage files required
89list(APPEND PSA_INTERNAL_TRUSTED_STORAGE_FILES
90 "psa/internal_trusted_storage.h"
91)
92
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +053093# list of storage files required
94list(APPEND PSA_STORAGE_FILES
95 ${PSA_INTERNAL_TRUSTED_STORAGE_FILES}
96 ${PSA_PROTECTED_STORAGE_FILES}
97)
98
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +053099# list of initial_attestation files required
100list(APPEND PSA_INITIAL_ATTESTATION_FILES
101 "psa/initial_attestation.h"
102 "psa/crypto.h"
103)
104
105# list of supported toolchains
106list(APPEND PSA_TOOLCHAIN_SUPPORT
107 GNUARM
108 ARMCLANG
109 HOST_GCC
110)
111
Øyvind Rønningstadc50804e2021-03-12 12:43:25 +0100112# list of supported CROSS_COMPILE toolchains
113list(APPEND CROSS_COMPILE_TOOLCHAIN_SUPPORT
114 GNUARM
115)
116
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530117# list of suported CPU arch
118list(APPEND PSA_CPU_ARCH_SUPPORT
119 armv8m_ml
120 armv8m_bl
121 armv7m
122)
123
124# list of VERBOSE options
125list(APPEND PSA_VERBOSE_OPTIONS 1 2 3 4 5)
126
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530127# list of PLATFORM_PSA_ISOLATION_LEVEL options
jotman016d7dd4e2020-11-10 17:32:28 +0800128if("${TFM_PROFILE}" STREQUAL "profile_medium")
129list(APPEND PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS 1 2)
130else()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530131list(APPEND PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS 1 2 3)
jotman016d7dd4e2020-11-10 17:32:28 +0800132endif()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530133
jk-armbf532fd2021-05-07 13:58:22 +0530134# list of available spec version
135if("${SUITE}" STREQUAL "STORAGE" OR ${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE" OR ${SUITE} STREQUAL "PROTECTED_STORAGE")
136list(APPEND PSA_SPEC_VERSION
137 1.0-BETA2
138 1.0
139)
140elseif("${SUITE}" STREQUAL "CRYPTO")
141list(APPEND PSA_SPEC_VERSION
142 1.0-BETA1
143 1.0-BETA2
144 1.0-BETA3
145)
146elseif("${SUITE}" STREQUAL "INITIAL_ATTESTATION")
147list(APPEND PSA_SPEC_VERSION
148 1.0-BETA0
149 1.0.0
150 1.0.1
151 1.0.2
152)
153endif()
154
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530155message(STATUS "[PSA] : ----------Process input arguments- start-------------")
156
157# Check for TARGET command line argument
158_check_arguments("TARGET")
159# Check for SUTIE command line argument
160_check_arguments("SUITE")
161# Check for PSA_INCLUDE_PATHS command line argument
162_check_arguments("PSA_INCLUDE_PATHS")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530163
164string(TOLOWER ${SUITE} SUITE_LOWER)
165
166# Check for valid targets
167_get_sub_dir_list(PSA_TARGET_LIST ${PSA_ROOT_DIR}/platform/targets)
168if(NOT ${TARGET} IN_LIST PSA_TARGET_LIST)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100169 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DTARGET=${TARGET}, supported targets are : ${PSA_TARGET_LIST}")
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530170else()
171 message(STATUS "[PSA] : TARGET is set to ${TARGET}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530172endif()
173
174# Check for the presence of required test suite directories
175if((NOT IS_DIRECTORY ${PSA_ROOT_DIR}/dev_apis) OR (NOT IS_DIRECTORY ${PSA_ROOT_DIR}/ff))
176 message(STATUS "[PSA] : Error: Could not find architecture test suite directories in psa root path ${PSA_ROOT_DIR}")
177endif()
178
179if(FALSE)
180# Check for build directory specified
181if(NOT DEFINED BUILD)
182 set(BUILD ${CMAKE_CURRENT_BINARY_DIR}/BUILD CACHE INTERNAL "Defaulting build directory to ${BUILD}" FORCE)
183else()
184 set(BUILD ${CMAKE_CURRENT_BINARY_DIR}/${BUILD}/BUILD CACHE INTERNAL "Defaulting build directory to ${BUILD}" FORCE)
185endif()
186endif()
187
188# Check for valid suite cmake argument passed
189if(NOT ${SUITE} IN_LIST PSA_SUITES)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100190 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DSUITE=${SUITE}, select one from supported suites which are : ${PSA_SUITES}")
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530191else()
192 message(STATUS "[PSA] : SUITE is set to ${SUITE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530193endif()
194
195# Project variables
196set(PSA_TARGET_PRE_BUILD psa_pre_build)
197set(PSA_TARGET_GENERATE_DATABASE_PRE psa_generate_database_prerequisite)
198set(PSA_TARGET_GENERATE_DATABASE psa_generate_database)
199set(PSA_TARGET_GENERATE_DATABASE_POST psa_generate_database_cleanup)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530200if(${SUITE} STREQUAL "INITIAL_ATTESTATION")
201 set(PSA_TARGET_QCBOR psa_qcbor)
202endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530203set(PSA_TARGET_PAL_NSPE_LIB pal_nspe)
204set(PSA_TARGET_VAL_NSPE_LIB val_nspe)
205set(PSA_TARGET_TEST_COMBINE_LIB test_combine)
jk-armbf532fd2021-05-07 13:58:22 +0530206set(PSA_TARGET_DRIVER_PARTITION_LIB tfm_psa_rot_partition_driver_partition)
207set(PSA_TARGET_CLIENT_PARTITION_LIB tfm_app_rot_partition_client_partition)
208set(PSA_TARGET_SERVER_PARTITION_LIB tfm_app_rot_partition_server_partition)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530209if(${SUITE} STREQUAL "IPC")
210 set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/ff/${SUITE_LOWER})
211 set(PSA_SUITE_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/ff/${SUITE_LOWER})
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530212elseif((${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE") OR (${SUITE} STREQUAL "PROTECTED_STORAGE"))
213 set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/dev_apis/storage)
214 set(PSA_SUITE_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/dev_apis/storage)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530215else()
216 set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/dev_apis/${SUITE_LOWER})
217 set(PSA_SUITE_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/dev_apis/${SUITE_LOWER})
218endif()
219set(PSA_TARGET_CONFIG_HEADER_GENERATOR ${PSA_ROOT_DIR}/tools/scripts/target_cfg/targetConfigGen.py)
220set(PSA_TESTLIST_GENERATOR ${PSA_ROOT_DIR}/tools/scripts/gen_tests_list.py)
221set(TARGET_CONFIGURATION_FILE ${PSA_ROOT_DIR}/platform/targets/${TARGET}/target.cfg)
222set(TGT_CONFIG_SOURCE_C ${CMAKE_CURRENT_BINARY_DIR}/targetConfigGen.c)
223set(OUTPUT_HEADER target_database.h)
224set(DATABASE_TABLE_NAME target_database)
225set(DATABASE_TABLE_SECTION_NAME "NOSECTION")
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530226set(TARGET_HEADER_GEN_INCLUDE_PATHS "${PSA_ROOT_DIR}/val/nspe|${PSA_ROOT_DIR}/val/common|${PSA_ROOT_DIR}/platform/targets/common/nspe|${PSA_ROOT_DIR}/platform/targets/common/nspe/crypto|${PSA_ROOT_DIR}/platform/targets/${TARGET}/nspe")
jk-armbf532fd2021-05-07 13:58:22 +0530227if(NOT DEFINED SPEC_VERSION)
228 if(${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE")
229 set(TESTSUITE_DB ${PSA_SUITE_DIR}/its_testsuite.db)
230 elseif((${SUITE} STREQUAL "PROTECTED_STORAGE") OR (${SUITE} STREQUAL "STORAGE"))
231 set(TESTSUITE_DB ${PSA_SUITE_DIR}/ps_testsuite.db)
232 else()
233 set(TESTSUITE_DB ${PSA_SUITE_DIR}/testsuite.db)
234 endif()
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530235else()
jk-armbf532fd2021-05-07 13:58:22 +0530236 if(${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE")
237 if(${SPEC_VERSION} STREQUAL "1.0-BETA2")
238 set(TESTSUITE_DB ${PSA_SUITE_DIR}/its_1.0-beta2_testsuite.db)
239 endif()
240 if(${SPEC_VERSION} STREQUAL "1.0")
241 set(TESTSUITE_DB ${PSA_SUITE_DIR}/its_1.0_testsuite.db)
242 endif()
243 elseif((${SUITE} STREQUAL "PROTECTED_STORAGE") OR (${SUITE} STREQUAL "STORAGE"))
244 if(${SPEC_VERSION} STREQUAL "1.0-BETA2")
245 set(TESTSUITE_DB ${PSA_SUITE_DIR}/ps_1.0-beta2_testsuite.db)
246 endif()
247 if(${SPEC_VERSION} STREQUAL "1.0")
248 set(TESTSUITE_DB ${PSA_SUITE_DIR}/ps_1.0_testsuite.db)
249 endif()
250 elseif(${SUITE} STREQUAL "CRYPTO")
251 if(${SPEC_VERSION} STREQUAL "1.0-BETA1")
252 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta1_testsuite.db)
253 endif()
254 if(${SPEC_VERSION} STREQUAL "1.0-BETA2")
255 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta2_testsuite.db)
256 endif()
257 if(${SPEC_VERSION} STREQUAL "1.0-BETA3")
258 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta3_testsuite.db)
259 endif()
260 elseif(${SUITE} STREQUAL "INITIAL_ATTESTATION")
261 if(${SPEC_VERSION} STREQUAL "1.0-BETA0")
262 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta0_testsuite.db)
263 endif()
264 if(${SPEC_VERSION} STREQUAL "1.0.0")
265 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0.0_testsuite.db)
266 endif()
267 if(${SPEC_VERSION} STREQUAL "1.0.1")
268 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0.1_testsuite.db)
269 endif()
270 if(${SPEC_VERSION} STREQUAL "1.0.2")
271 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0.2_testsuite.db)
272 endif()
273 endif()
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530274endif()
275set(PSA_TESTLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/${SUITE_LOWER}_testlist.txt)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530276set(PSA_TEST_ENTRY_LIST_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_list.inc)
277set(PSA_TEST_ENTRY_FUN_DECLARE_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_fn_declare_list.inc)
278set(PSA_CLIENT_TEST_LIST_DELCARE_INC ${CMAKE_CURRENT_BINARY_DIR}/client_tests_list_declare.inc)
279set(PSA_CLIENT_TEST_LIST_INC ${CMAKE_CURRENT_BINARY_DIR}/client_tests_list.inc)
280set(PSA_SERVER_TEST_LIST_DECLARE_INC ${CMAKE_CURRENT_BINARY_DIR}/server_tests_list_declare.inc)
281set(PSA_SERVER_TEST_LIST ${CMAKE_CURRENT_BINARY_DIR}/server_tests_list.inc)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530282if(${SUITE} STREQUAL "INITIAL_ATTESTATION")
283 set(PSA_QCBOR_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PSA_TARGET_QCBOR}/inc)
284endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530285
286# Validity check for required files for a given suite
287if(NOT DEFINED PSA_${SUITE}_FILES)
288 message(FATAL_ERROR "[PSA] : List of file/s to verify against ${suite} is not defined")
289endif()
290foreach(file_item ${PSA_${SUITE}_FILES})
291 set(PSA_FILE_FOUND FALSE)
292 foreach(include_path ${PSA_INCLUDE_PATHS})
293 if((EXISTS ${include_path}/${file_item}) AND
294 (NOT PSA_FILE_FOUND))
295 set(PSA_FILE_FOUND TRUE)
296 break()
297 endif()
298 endforeach()
299 if(NOT PSA_FILE_FOUND)
300 message(FATAL_ERROR "[PSA] : Couldn't find ${file_item} in ${PSA_INCLUDE_PATHS}")
301 endif()
302endforeach()
303
304# Check for TOOLCHAIN command line argument
305if(NOT DEFINED TOOLCHAIN)
306 set(TOOLCHAIN "GNUARM" CACHE INTERNAL "Compiler used" FORCE)
307 message(STATUS "[PSA] : Defaulting compiler to ${TOOLCHAIN}")
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530308else()
309 message(STATUS "[PSA] : TOOLCHAIN is set to ${TOOLCHAIN}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530310endif()
311
Gowtham Siddarth1d6d4692019-09-16 11:47:29 +0530312if(${TOOLCHAIN} STREQUAL "ARMCLANG" OR ${TOOLCHAIN} STREQUAL "GNUARM")
313 if(NOT DEFINED CPU_ARCH)
314 message(FATAL_ERROR "[PSA] : Error: -DCPU_ARCH option missing")
315 else()
316 # Check for CPU architecture
317 if(NOT ${CPU_ARCH} IN_LIST PSA_CPU_ARCH_SUPPORT)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100318 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DCPU_ARCH=${CPU_ARCH}, supported CPU arch are : ${PSA_CPU_ARCH_SUPPORT}")
Gowtham Siddarth1d6d4692019-09-16 11:47:29 +0530319 endif()
320 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530321 message(STATUS "[PSA] : CPU_ARCH is set to ${CPU_ARCH}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530322endif()
323
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530324# Check for VERBOSE
325if(NOT DEFINED VERBOSE)
326 set(VERBOSE 3 CACHE INTERNAL "Default VERBOSE value" FORCE)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530327 message(STATUS "[PSA] : Defaulting VERBOSE to ${VERBOSE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530328else()
329 if(NOT ${VERBOSE} IN_LIST PSA_VERBOSE_OPTIONS)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100330 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DVERBOSE=${VERBOSE}, supported values are : ${PSA_VERBOSE_OPTIONS}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530331 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530332 message(STATUS "[PSA] : VERBOSE is set to ${VERBOSE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530333endif()
334
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530335# Check for PLATFORM_PSA_ISOLATION_LEVEL
336if(NOT DEFINED PLATFORM_PSA_ISOLATION_LEVEL)
jotman016d7dd4e2020-11-10 17:32:28 +0800337 if("${TFM_PROFILE}" STREQUAL "profile_medium")
338 set(PLATFORM_PSA_ISOLATION_LEVEL 2 CACHE INTERNAL "Default PLATFORM_PSA_ISOLATION_LEVEL value" FORCE)
339 else()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530340 set(PLATFORM_PSA_ISOLATION_LEVEL 3 CACHE INTERNAL "Default PLATFORM_PSA_ISOLATION_LEVEL value" FORCE)
jotman016d7dd4e2020-11-10 17:32:28 +0800341 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530342 if(${SUITE} STREQUAL "IPC")
343 message(STATUS "[PSA] : Defaulting PLATFORM_PSA_ISOLATION_LEVEL to ${PLATFORM_PSA_ISOLATION_LEVEL}")
344 endif()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530345else()
346 if(NOT ${PLATFORM_PSA_ISOLATION_LEVEL} IN_LIST PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100347 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DPLATFORM_PSA_ISOLATION_LEVEL=${PLATFORM_PSA_ISOLATION_LEVEL}, supported values are : ${PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS}")
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530348 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530349 if(${SUITE} STREQUAL "IPC")
350 message(STATUS "[PSA] : PLATFORM_PSA_ISOLATION_LEVEL is set to ${PLATFORM_PSA_ISOLATION_LEVEL}")
351 endif()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530352endif()
353
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530354if(NOT DEFINED INCLUDE_PANIC_TESTS)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530355 #By default panic tests are disabled
356 set(INCLUDE_PANIC_TESTS 0 CACHE INTERNAL "Default INCLUDE_PANIC_TESTS value" FORCE)
357 message(STATUS "[PSA] : Defaulting INCLUDE_PANIC_TESTS to ${INCLUDE_PANIC_TESTS}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530358else()
359 if(INCLUDE_PANIC_TESTS EQUAL 1)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530360 message(STATUS "[PSA] : "
361 "INCLUDE_PANIC_TESTS set to 1, therefore including PSA APIs panic tests into the regression,\n"
362 "\tensure that watchdog.num is set to 1 in ${PSA_ROOT_DIR}/platform/targets/${TARGET}/target.cfg")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530363 endif()
364endif()
365
366if(NOT DEFINED WATCHDOG_AVAILABLE)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530367 #Assuming watchdog is available to program by test suite
368 set(WATCHDOG_AVAILABLE 1 CACHE INTERNAL "Default WATCHDOG_AVAILABLE value" FORCE)
369 message(STATUS "[PSA] : Defaulting WATCHDOG_AVAILABLE to ${WATCHDOG_AVAILABLE}")
370else()
371 message(STATUS "[PSA] : WATCHDOG_AVAILABLE is set to ${WATCHDOG_AVAILABLE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530372endif()
373
374if((INCLUDE_PANIC_TESTS EQUAL 1) AND
375 (WATCHDOG_AVAILABLE EQUAL 0))
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530376 message(WARNING "[PSA]: "
377 "Note that to test PSA APIs panic conditions, test harness may require to access"
378 "the watchdog timer in oder to recover from panic and to be able to continue with"
379 "next test. Ignore this warning if system under test has capability to reset the"
380 "system when it encounters panic condition.")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530381endif()
382
383if(NOT DEFINED SP_HEAP_MEM_SUPP)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530384 #Are dynamic memory functions available to secure partition?
385 set(SP_HEAP_MEM_SUPP 1 CACHE INTERNAL "Default SP_HEAP_MEM_SUPP value" FORCE)
386 message(STATUS "[PSA] : Defaulting SP_HEAP_MEM_SUPP to ${SP_HEAP_MEM_SUPP}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530387endif()
388
Vinay Kumar Kotegowderac218992020-04-03 12:56:00 +0530389if(NOT DEFINED SUITE_TEST_RANGE)
390 set(SUITE_TEST_RANGE_MIN None)
391 set(SUITE_TEST_RANGE_MAX None)
392else()
393 list(LENGTH SUITE_TEST_RANGE SUITE_TEST_RANGE_LENGTH)
394 if(${SUITE_TEST_RANGE_LENGTH} GREATER "2")
395 message(FATAL_ERROR "[PSA] : -DSUITE_TEST_RANGE=<...> value error! accepts two "
396 " numbers in quotes separated with ';'")
397 endif()
398 if(${SUITE_TEST_RANGE_LENGTH} EQUAL "2")
399 list(GET SUITE_TEST_RANGE 0 SUITE_TEST_RANGE_MIN)
400 list(GET SUITE_TEST_RANGE 1 SUITE_TEST_RANGE_MAX)
401 message(STATUS "[PSA] : Testing (${SUITE_TEST_RANGE_MIN}, ${SUITE_TEST_RANGE_MAX}) of ${SUITE} suite")
402 endif()
403 if(${SUITE_TEST_RANGE_LENGTH} EQUAL "1")
404 set(SUITE_TEST_RANGE_MIN ${SUITE_TEST_RANGE})
405 set(SUITE_TEST_RANGE_MAX ${SUITE_TEST_RANGE})
406 message(STATUS "[PSA] : Testing ${SUITE_TEST_RANGE_MIN} of ${SUITE} suite")
407 endif()
408endif()
409
jk-armbf532fd2021-05-07 13:58:22 +0530410if(NOT DEFINED SPEC_VERSION)
411 message(STATUS "[PSA] : Default spec version")
412else()
413 if(NOT ${SPEC_VERSION} IN_LIST PSA_SPEC_VERSION)
414 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DSPEC_VERSION=${SPEC_VERSION}, supported values are : ${PSA_SPEC_VERSION} for ${SUITE}")
415 else()
416 message(STATUS "[PSA] : Testing ${SUITE} for spec version ${SPEC_VERSION}")
417 endif()
418endif()
419
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530420message(STATUS "[PSA] : ----------Process input arguments- complete-------------")
421
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530422
jotman016d7dd4e2020-11-10 17:32:28 +0800423if((${SUITE} STREQUAL "INITIAL_ATTESTATION") AND (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${PSA_TARGET_QCBOR}))
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530424# Clone QCBOR and move to specified tag
425execute_process(COMMAND ${GIT_EXECUTABLE} clone ${PSA_QCBOR_GIT_REPO_LINK} ${PSA_TARGET_QCBOR}
426 RESULT_VARIABLE ${PSA_TARGET_QCBOR}_clone_result
427 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
428if(${PSA_TARGET_QCBOR}_clone_result)
429 message(FATAL_ERROR "git clone failed for ${PSA_QCBOR_GIT_REPO_LINK}")
430endif()
431
432if(NOT ${PSA_TARGET_QCBOR}_clone_result)
433execute_process(COMMAND ${GIT_EXECUTABLE} checkout -q "${PSA_QCBOR_GIT_REPO_TAG}"
434 RESULT_VARIABLE ${PSA_TARGET_QCBOR}_checkout_result
435 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PSA_TARGET_QCBOR})
436if(${PSA_TARGET_QCBOR}_checkout_result)
437 message(FATAL_ERROR "git checkout failed for Repo : ${PSA_QCBOR_GIT_REPO_LINK}, Tag : ${PSA_QCBOR_GIT_REPO_TAG}")
438endif()
439endif()
440endif()
gowtham siddarth12833042020-02-10 22:11:11 +0530441
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530442# Create PSA clean list
443list(APPEND PSA_CLEAN_LIST
444 ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_HEADER}
445 ${PSA_TESTLIST_FILE}
446 ${PSA_TEST_ENTRY_LIST_INC}
447 ${PSA_TEST_ENTRY_FUN_DECLARE_INC}
448 ${PSA_CLIENT_TEST_LIST_DELCARE_INC}
449 ${PSA_CLIENT_TEST_LIST_INC}
450 ${PSA_SERVER_TEST_LIST_DECLARE_INC}
451 ${PSA_SERVER_TEST_LIST}
452)
453
454# Process testsuite.db
455message(STATUS "[PSA] : Creating testlist.txt 'available at ${PSA_TESTLIST_FILE}'")
456execute_process(COMMAND ${PYTHON_EXECUTABLE} ${PSA_TESTLIST_GENERATOR}
457 ${SUITE_LOWER}
458 ${TESTSUITE_DB}
459 ${INCLUDE_PANIC_TESTS}
460 ${PSA_TESTLIST_FILE}
461 ${PSA_TEST_ENTRY_LIST_INC}
462 ${PSA_TEST_ENTRY_FUN_DECLARE_INC}
463 ${PSA_CLIENT_TEST_LIST_DELCARE_INC}
464 ${PSA_CLIENT_TEST_LIST_INC}
465 ${PSA_SERVER_TEST_LIST_DECLARE_INC}
Vinay Kumar Kotegowderac218992020-04-03 12:56:00 +0530466 ${PSA_SERVER_TEST_LIST}
467 ${SUITE_TEST_RANGE_MIN}
468 ${SUITE_TEST_RANGE_MAX})
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530469
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530470# Creating CMake list variable from file
471file(READ ${PSA_TESTLIST_FILE} PSA_TEST_LIST)
Vinay Kumar Kotegowderac218992020-04-03 12:56:00 +0530472if(NOT PSA_TEST_LIST)
473 message(FATAL_ERROR "[PSA] : Invalid test number!")
474endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530475string(REGEX REPLACE "\n" ";" PSA_TEST_LIST "${PSA_TEST_LIST}")
476
477add_custom_target(
478 ${PSA_TARGET_GENERATE_DATABASE_PRE}
479 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/platform
480 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/val
481 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/partition
482 COMMAND ${CMAKE_COMMAND} -E make_directory ${PSA_SUITE_OUT_DIR}
483)
484
485# Generate target files from User provided data base
486include(ExternalProject)
487ExternalProject_Add(
488 ${PSA_TARGET_GENERATE_DATABASE}
489 PREFIX ${CMAKE_CURRENT_BINARY_DIR}
490 DOWNLOAD_COMMAND ""
491 UPDATE_COMMAND ""
492 PATCH_COMMAND ""
493 BUILD_COMMAND ""
494 SOURCE_DIR "${PSA_ROOT_DIR}/tools/scripts/target_cfg"
495 CMAKE_ARGS -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
496 -DOUT_DIR=${CMAKE_CURRENT_BINARY_DIR}
497 -DTARGET=${TARGET}
498 -DGENERATOR_FILE=${PSA_TARGET_CONFIG_HEADER_GENERATOR}
499 -DINCLUDE_DIR=${PSA_ROOT_DIR}/val/common
500 -DTARGET_CONFIGURATION_FILE=${TARGET_CONFIGURATION_FILE}
501 -DTGT_CONFIG_SOURCE_C=${TGT_CONFIG_SOURCE_C}
502 -DOUTPUT_HEADER=${OUTPUT_HEADER}
503 -DDATABASE_TABLE_NAME=${DATABASE_TABLE_NAME}
504 -DDATABASE_TABLE_SECTION_NAME=${DATABASE_TABLE_SECTION_NAME}
505 -DTARGET_HEADER_GEN_INCLUDE_PATHS=${TARGET_HEADER_GEN_INCLUDE_PATHS}
506 LIST_SEPARATOR |
507 TEST_COMMAND ""
508)
509
510# Add custom target to clean generated files of the external project
511add_custom_target(
512 ${PSA_TARGET_GENERATE_DATABASE_POST}
513 COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/src/${PSA_TARGET_GENERATE_DATABASE}-build/ -- clean
514)
515
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530516# Check for supported toolchain/s
517if(${TOOLCHAIN} IN_LIST PSA_TOOLCHAIN_SUPPORT)
jk-armbf532fd2021-05-07 13:58:22 +0530518 if (DEFINED CROSS_COMPILE)
519 if(${CROSS_COMPILE} AND NOT (${TOOLCHAIN} IN_LIST CROSS_COMPILE_TOOLCHAIN_SUPPORT))
Øyvind Rønningstadc50804e2021-03-12 12:43:25 +0100520 message(FATAL_ERROR "[PSA] : Error: CROSS_COMPILE not supported for this toolchain, supported toolchain are : ${CROSS_COMPILE_TOOLCHAIN_SUPPORT}")
jk-armbf532fd2021-05-07 13:58:22 +0530521 endif()
522 endif()
523 include(${PSA_ROOT_DIR}/tools/cmake/compiler/${TOOLCHAIN}.cmake)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530524else()
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100525 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DTOOLCHAIN=${TOOLCHAIN}, supported toolchain are : ${PSA_TOOLCHAIN_SUPPORT}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530526endif()
527
528# Global macro to identify the PSA test suite cmake build
529add_definitions(-DPSA_CMAKE_BUILD)
530add_definitions(-D${SUITE})
531add_definitions(-DVERBOSE=${VERBOSE})
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530532add_definitions(-DPLATFORM_PSA_ISOLATION_LEVEL=${PLATFORM_PSA_ISOLATION_LEVEL})
Vinay Kumar Kotegowder52bbfc92020-07-03 17:23:59 +0530533add_definitions(-D${TARGET})
jotman016d7dd4e2020-11-10 17:32:28 +0800534if("${TFM_PROFILE}" STREQUAL "profile_small")
535 message(STATUS "[PSA] : Building SMALL profile")
536 add_definitions(-DTF_M_PROFILE_SMALL)
537elseif("${TFM_PROFILE}" STREQUAL "profile_medium")
538 message(STATUS "[PSA] : Building MEDIUM profile")
539 add_definitions(-DTF_M_PROFILE_MEDIUM)
540endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530541if(${SP_HEAP_MEM_SUPP} EQUAL 1)
542 add_definitions(-DSP_HEAP_MEM_SUPP)
543endif()
544
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530545# Build PAL NSPE LIB
546include(${PSA_ROOT_DIR}/platform/targets/${TARGET}/target.cmake)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530547# Build VAL NSPE LIB
548#add_definitions(-DVAL_NSPE_BUILD)
549include(${PSA_ROOT_DIR}/val/val_nspe.cmake)
550# Build test
551include(${PSA_SUITE_DIR}/suite.cmake)
552if(${SUITE} STREQUAL "IPC")
553# Build SPE LIB
554include(${PSA_ROOT_DIR}/val/val_spe.cmake)
555endif()
556
557add_dependencies(${PSA_TARGET_GENERATE_DATABASE} ${PSA_TARGET_GENERATE_DATABASE_PRE})
558add_dependencies(${PSA_TARGET_GENERATE_DATABASE_POST} ${PSA_TARGET_GENERATE_DATABASE})
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530559add_dependencies(${PSA_TARGET_PAL_NSPE_LIB} ${PSA_TARGET_GENERATE_DATABASE_POST})
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530560add_dependencies(${PSA_TARGET_VAL_NSPE_LIB} ${PSA_TARGET_PAL_NSPE_LIB})
561add_dependencies(${PSA_TARGET_TEST_COMBINE_LIB} ${PSA_TARGET_VAL_NSPE_LIB})
562if(${SUITE} STREQUAL "IPC")
563add_dependencies(${PSA_TARGET_DRIVER_PARTITION_LIB} ${PSA_TARGET_TEST_COMBINE_LIB})
564add_dependencies(${PSA_TARGET_CLIENT_PARTITION_LIB} ${PSA_TARGET_DRIVER_PARTITION_LIB})
565add_dependencies(${PSA_TARGET_SERVER_PARTITION_LIB} ${PSA_TARGET_CLIENT_PARTITION_LIB})
566endif()
567
568# Include the files for make clean
569foreach(clean_item ${PSA_CLEAN_LIST})
570 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clean_item})
571endforeach()
572
573set_property(TARGET ${PSA_TARGET_VAL_NSPE_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/val)
574set_property(TARGET ${PSA_TARGET_PAL_NSPE_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/platform)
575set_property(TARGET ${PSA_TARGET_TEST_COMBINE_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${PSA_SUITE_OUT_DIR})
576if(${SUITE} STREQUAL "IPC")
577set_property(TARGET ${PSA_TARGET_DRIVER_PARTITION_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/partition)
578set_property(TARGET ${PSA_TARGET_CLIENT_PARTITION_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/partition)
579set_property(TARGET ${PSA_TARGET_SERVER_PARTITION_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/partition)
580endif()