blob: 31b7ef7837a2855319f0c427a8f94bf203caa950 [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
jk-arm7e6145a2021-07-19 19:36:14 +0530110 GCC_LINUX
111 INHERIT
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530112)
113
Øyvind Rønningstadc50804e2021-03-12 12:43:25 +0100114# list of supported CROSS_COMPILE toolchains
115list(APPEND CROSS_COMPILE_TOOLCHAIN_SUPPORT
116 GNUARM
jk-arm7e6145a2021-07-19 19:36:14 +0530117 ARMCLANG
118 INHERIT
Øyvind Rønningstadc50804e2021-03-12 12:43:25 +0100119)
120
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530121# list of suported CPU arch
122list(APPEND PSA_CPU_ARCH_SUPPORT
123 armv8m_ml
124 armv8m_bl
125 armv7m
jotman01bed7a152021-05-25 22:57:17 +0800126 armv8a
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530127)
128
129# list of VERBOSE options
130list(APPEND PSA_VERBOSE_OPTIONS 1 2 3 4 5)
131
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530132# list of PLATFORM_PSA_ISOLATION_LEVEL options
jotman016d7dd4e2020-11-10 17:32:28 +0800133if("${TFM_PROFILE}" STREQUAL "profile_medium")
134list(APPEND PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS 1 2)
135else()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530136list(APPEND PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS 1 2 3)
jotman016d7dd4e2020-11-10 17:32:28 +0800137endif()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530138
jk-armbf532fd2021-05-07 13:58:22 +0530139# list of available spec version
140if("${SUITE}" STREQUAL "STORAGE" OR ${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE" OR ${SUITE} STREQUAL "PROTECTED_STORAGE")
141list(APPEND PSA_SPEC_VERSION
142 1.0-BETA2
143 1.0
144)
145elseif("${SUITE}" STREQUAL "CRYPTO")
146list(APPEND PSA_SPEC_VERSION
147 1.0-BETA1
148 1.0-BETA2
149 1.0-BETA3
150)
151elseif("${SUITE}" STREQUAL "INITIAL_ATTESTATION")
152list(APPEND PSA_SPEC_VERSION
153 1.0-BETA0
154 1.0.0
155 1.0.1
156 1.0.2
157)
jk-arm957cfea2021-06-18 15:52:12 +0530158elseif("${SUITE}" STREQUAL "IPC")
159list(APPEND PSA_SPEC_VERSION
160 1.0
161 1.1
162)
163
164endif()
165
166#list of values available for connection based
167if(${SUITE} STREQUAL "IPC")
168list(APPEND PSA_STATELESS_ROT 0 1)
jk-armbf532fd2021-05-07 13:58:22 +0530169endif()
170
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530171message(STATUS "[PSA] : ----------Process input arguments- start-------------")
172
173# Check for TARGET command line argument
174_check_arguments("TARGET")
175# Check for SUTIE command line argument
176_check_arguments("SUITE")
177# Check for PSA_INCLUDE_PATHS command line argument
178_check_arguments("PSA_INCLUDE_PATHS")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530179
180string(TOLOWER ${SUITE} SUITE_LOWER)
181
182# Check for valid targets
183_get_sub_dir_list(PSA_TARGET_LIST ${PSA_ROOT_DIR}/platform/targets)
184if(NOT ${TARGET} IN_LIST PSA_TARGET_LIST)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100185 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DTARGET=${TARGET}, supported targets are : ${PSA_TARGET_LIST}")
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530186else()
187 message(STATUS "[PSA] : TARGET is set to ${TARGET}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530188endif()
189
190# Check for the presence of required test suite directories
191if((NOT IS_DIRECTORY ${PSA_ROOT_DIR}/dev_apis) OR (NOT IS_DIRECTORY ${PSA_ROOT_DIR}/ff))
192 message(STATUS "[PSA] : Error: Could not find architecture test suite directories in psa root path ${PSA_ROOT_DIR}")
193endif()
194
195if(FALSE)
196# Check for build directory specified
197if(NOT DEFINED BUILD)
198 set(BUILD ${CMAKE_CURRENT_BINARY_DIR}/BUILD CACHE INTERNAL "Defaulting build directory to ${BUILD}" FORCE)
199else()
200 set(BUILD ${CMAKE_CURRENT_BINARY_DIR}/${BUILD}/BUILD CACHE INTERNAL "Defaulting build directory to ${BUILD}" FORCE)
201endif()
202endif()
203
204# Check for valid suite cmake argument passed
205if(NOT ${SUITE} IN_LIST PSA_SUITES)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100206 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 +0530207else()
208 message(STATUS "[PSA] : SUITE is set to ${SUITE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530209endif()
210
211# Project variables
212set(PSA_TARGET_PRE_BUILD psa_pre_build)
213set(PSA_TARGET_GENERATE_DATABASE_PRE psa_generate_database_prerequisite)
214set(PSA_TARGET_GENERATE_DATABASE psa_generate_database)
215set(PSA_TARGET_GENERATE_DATABASE_POST psa_generate_database_cleanup)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530216if(${SUITE} STREQUAL "INITIAL_ATTESTATION")
217 set(PSA_TARGET_QCBOR psa_qcbor)
218endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530219set(PSA_TARGET_PAL_NSPE_LIB pal_nspe)
220set(PSA_TARGET_VAL_NSPE_LIB val_nspe)
221set(PSA_TARGET_TEST_COMBINE_LIB test_combine)
jk-armbf532fd2021-05-07 13:58:22 +0530222set(PSA_TARGET_DRIVER_PARTITION_LIB tfm_psa_rot_partition_driver_partition)
223set(PSA_TARGET_CLIENT_PARTITION_LIB tfm_app_rot_partition_client_partition)
224set(PSA_TARGET_SERVER_PARTITION_LIB tfm_app_rot_partition_server_partition)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530225if(${SUITE} STREQUAL "IPC")
226 set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/ff/${SUITE_LOWER})
227 set(PSA_SUITE_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/ff/${SUITE_LOWER})
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530228elseif((${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE") OR (${SUITE} STREQUAL "PROTECTED_STORAGE"))
229 set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/dev_apis/storage)
230 set(PSA_SUITE_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/dev_apis/storage)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530231else()
232 set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/dev_apis/${SUITE_LOWER})
233 set(PSA_SUITE_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/dev_apis/${SUITE_LOWER})
234endif()
235set(PSA_TARGET_CONFIG_HEADER_GENERATOR ${PSA_ROOT_DIR}/tools/scripts/target_cfg/targetConfigGen.py)
236set(PSA_TESTLIST_GENERATOR ${PSA_ROOT_DIR}/tools/scripts/gen_tests_list.py)
237set(TARGET_CONFIGURATION_FILE ${PSA_ROOT_DIR}/platform/targets/${TARGET}/target.cfg)
238set(TGT_CONFIG_SOURCE_C ${CMAKE_CURRENT_BINARY_DIR}/targetConfigGen.c)
239set(OUTPUT_HEADER target_database.h)
240set(DATABASE_TABLE_NAME target_database)
241set(DATABASE_TABLE_SECTION_NAME "NOSECTION")
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530242set(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 +0530243if(NOT DEFINED SPEC_VERSION)
244 if(${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE")
245 set(TESTSUITE_DB ${PSA_SUITE_DIR}/its_testsuite.db)
246 elseif((${SUITE} STREQUAL "PROTECTED_STORAGE") OR (${SUITE} STREQUAL "STORAGE"))
247 set(TESTSUITE_DB ${PSA_SUITE_DIR}/ps_testsuite.db)
248 else()
249 set(TESTSUITE_DB ${PSA_SUITE_DIR}/testsuite.db)
250 endif()
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530251else()
jk-armbf532fd2021-05-07 13:58:22 +0530252 if(${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE")
253 if(${SPEC_VERSION} STREQUAL "1.0-BETA2")
254 set(TESTSUITE_DB ${PSA_SUITE_DIR}/its_1.0-beta2_testsuite.db)
255 endif()
256 if(${SPEC_VERSION} STREQUAL "1.0")
257 set(TESTSUITE_DB ${PSA_SUITE_DIR}/its_1.0_testsuite.db)
258 endif()
259 elseif((${SUITE} STREQUAL "PROTECTED_STORAGE") OR (${SUITE} STREQUAL "STORAGE"))
260 if(${SPEC_VERSION} STREQUAL "1.0-BETA2")
261 set(TESTSUITE_DB ${PSA_SUITE_DIR}/ps_1.0-beta2_testsuite.db)
262 endif()
263 if(${SPEC_VERSION} STREQUAL "1.0")
264 set(TESTSUITE_DB ${PSA_SUITE_DIR}/ps_1.0_testsuite.db)
265 endif()
266 elseif(${SUITE} STREQUAL "CRYPTO")
267 if(${SPEC_VERSION} STREQUAL "1.0-BETA1")
268 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta1_testsuite.db)
269 endif()
270 if(${SPEC_VERSION} STREQUAL "1.0-BETA2")
271 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta2_testsuite.db)
272 endif()
273 if(${SPEC_VERSION} STREQUAL "1.0-BETA3")
274 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta3_testsuite.db)
275 endif()
276 elseif(${SUITE} STREQUAL "INITIAL_ATTESTATION")
277 if(${SPEC_VERSION} STREQUAL "1.0-BETA0")
278 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta0_testsuite.db)
279 endif()
280 if(${SPEC_VERSION} STREQUAL "1.0.0")
281 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0.0_testsuite.db)
282 endif()
283 if(${SPEC_VERSION} STREQUAL "1.0.1")
284 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0.1_testsuite.db)
285 endif()
286 if(${SPEC_VERSION} STREQUAL "1.0.2")
287 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0.2_testsuite.db)
288 endif()
jk-arm957cfea2021-06-18 15:52:12 +0530289 elseif(${SUITE} STREQUAL "IPC")
290 if(${SPEC_VERSION} STREQUAL "1.1")
291 if(DEFINED STATELESS_ROT_TESTS)
292 if(${STATELESS_ROT_TESTS} EQUAL 1)
293 set(TESTSUITE_DB ${PSA_SUITE_DIR}/stateless_rot_testsuite.db)
294 else()
295 set(TESTSUITE_DB ${PSA_SUITE_DIR}/testsuite.db)
296 endif()
297 else()
298 set(TESTSUITE_DB ${PSA_SUITE_DIR}/testsuite.db)
299 endif()
300 else()
301 set(TESTSUITE_DB ${PSA_SUITE_DIR}/testsuite.db)
302 endif()
303 endif()
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530304endif()
305set(PSA_TESTLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/${SUITE_LOWER}_testlist.txt)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530306set(PSA_TEST_ENTRY_LIST_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_list.inc)
307set(PSA_TEST_ENTRY_FUN_DECLARE_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_fn_declare_list.inc)
308set(PSA_CLIENT_TEST_LIST_DELCARE_INC ${CMAKE_CURRENT_BINARY_DIR}/client_tests_list_declare.inc)
309set(PSA_CLIENT_TEST_LIST_INC ${CMAKE_CURRENT_BINARY_DIR}/client_tests_list.inc)
310set(PSA_SERVER_TEST_LIST_DECLARE_INC ${CMAKE_CURRENT_BINARY_DIR}/server_tests_list_declare.inc)
311set(PSA_SERVER_TEST_LIST ${CMAKE_CURRENT_BINARY_DIR}/server_tests_list.inc)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530312if(${SUITE} STREQUAL "INITIAL_ATTESTATION")
313 set(PSA_QCBOR_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PSA_TARGET_QCBOR}/inc)
314endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530315
316# Validity check for required files for a given suite
317if(NOT DEFINED PSA_${SUITE}_FILES)
318 message(FATAL_ERROR "[PSA] : List of file/s to verify against ${suite} is not defined")
319endif()
320foreach(file_item ${PSA_${SUITE}_FILES})
321 set(PSA_FILE_FOUND FALSE)
322 foreach(include_path ${PSA_INCLUDE_PATHS})
323 if((EXISTS ${include_path}/${file_item}) AND
324 (NOT PSA_FILE_FOUND))
325 set(PSA_FILE_FOUND TRUE)
326 break()
327 endif()
328 endforeach()
329 if(NOT PSA_FILE_FOUND)
330 message(FATAL_ERROR "[PSA] : Couldn't find ${file_item} in ${PSA_INCLUDE_PATHS}")
331 endif()
332endforeach()
333
334# Check for TOOLCHAIN command line argument
335if(NOT DEFINED TOOLCHAIN)
336 set(TOOLCHAIN "GNUARM" CACHE INTERNAL "Compiler used" FORCE)
337 message(STATUS "[PSA] : Defaulting compiler to ${TOOLCHAIN}")
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530338else()
339 message(STATUS "[PSA] : TOOLCHAIN is set to ${TOOLCHAIN}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530340endif()
341
Gowtham Siddarth1d6d4692019-09-16 11:47:29 +0530342if(${TOOLCHAIN} STREQUAL "ARMCLANG" OR ${TOOLCHAIN} STREQUAL "GNUARM")
343 if(NOT DEFINED CPU_ARCH)
344 message(FATAL_ERROR "[PSA] : Error: -DCPU_ARCH option missing")
345 else()
346 # Check for CPU architecture
347 if(NOT ${CPU_ARCH} IN_LIST PSA_CPU_ARCH_SUPPORT)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100348 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 +0530349 endif()
350 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530351 message(STATUS "[PSA] : CPU_ARCH is set to ${CPU_ARCH}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530352endif()
353
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530354# Check for VERBOSE
355if(NOT DEFINED VERBOSE)
356 set(VERBOSE 3 CACHE INTERNAL "Default VERBOSE value" FORCE)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530357 message(STATUS "[PSA] : Defaulting VERBOSE to ${VERBOSE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530358else()
359 if(NOT ${VERBOSE} IN_LIST PSA_VERBOSE_OPTIONS)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100360 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DVERBOSE=${VERBOSE}, supported values are : ${PSA_VERBOSE_OPTIONS}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530361 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530362 message(STATUS "[PSA] : VERBOSE is set to ${VERBOSE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530363endif()
364
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530365# Check for PLATFORM_PSA_ISOLATION_LEVEL
366if(NOT DEFINED PLATFORM_PSA_ISOLATION_LEVEL)
jotman016d7dd4e2020-11-10 17:32:28 +0800367 if("${TFM_PROFILE}" STREQUAL "profile_medium")
368 set(PLATFORM_PSA_ISOLATION_LEVEL 2 CACHE INTERNAL "Default PLATFORM_PSA_ISOLATION_LEVEL value" FORCE)
369 else()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530370 set(PLATFORM_PSA_ISOLATION_LEVEL 3 CACHE INTERNAL "Default PLATFORM_PSA_ISOLATION_LEVEL value" FORCE)
jotman016d7dd4e2020-11-10 17:32:28 +0800371 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530372 if(${SUITE} STREQUAL "IPC")
373 message(STATUS "[PSA] : Defaulting PLATFORM_PSA_ISOLATION_LEVEL to ${PLATFORM_PSA_ISOLATION_LEVEL}")
374 endif()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530375else()
376 if(NOT ${PLATFORM_PSA_ISOLATION_LEVEL} IN_LIST PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100377 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 +0530378 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530379 if(${SUITE} STREQUAL "IPC")
380 message(STATUS "[PSA] : PLATFORM_PSA_ISOLATION_LEVEL is set to ${PLATFORM_PSA_ISOLATION_LEVEL}")
381 endif()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530382endif()
383
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530384if(NOT DEFINED INCLUDE_PANIC_TESTS)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530385 #By default panic tests are disabled
386 set(INCLUDE_PANIC_TESTS 0 CACHE INTERNAL "Default INCLUDE_PANIC_TESTS value" FORCE)
387 message(STATUS "[PSA] : Defaulting INCLUDE_PANIC_TESTS to ${INCLUDE_PANIC_TESTS}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530388else()
389 if(INCLUDE_PANIC_TESTS EQUAL 1)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530390 message(STATUS "[PSA] : "
391 "INCLUDE_PANIC_TESTS set to 1, therefore including PSA APIs panic tests into the regression,\n"
392 "\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 +0530393 endif()
394endif()
395
396if(NOT DEFINED WATCHDOG_AVAILABLE)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530397 #Assuming watchdog is available to program by test suite
398 set(WATCHDOG_AVAILABLE 1 CACHE INTERNAL "Default WATCHDOG_AVAILABLE value" FORCE)
399 message(STATUS "[PSA] : Defaulting WATCHDOG_AVAILABLE to ${WATCHDOG_AVAILABLE}")
400else()
401 message(STATUS "[PSA] : WATCHDOG_AVAILABLE is set to ${WATCHDOG_AVAILABLE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530402endif()
403
404if((INCLUDE_PANIC_TESTS EQUAL 1) AND
405 (WATCHDOG_AVAILABLE EQUAL 0))
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530406 message(WARNING "[PSA]: "
407 "Note that to test PSA APIs panic conditions, test harness may require to access"
408 "the watchdog timer in oder to recover from panic and to be able to continue with"
409 "next test. Ignore this warning if system under test has capability to reset the"
410 "system when it encounters panic condition.")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530411endif()
412
413if(NOT DEFINED SP_HEAP_MEM_SUPP)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530414 #Are dynamic memory functions available to secure partition?
415 set(SP_HEAP_MEM_SUPP 1 CACHE INTERNAL "Default SP_HEAP_MEM_SUPP value" FORCE)
416 message(STATUS "[PSA] : Defaulting SP_HEAP_MEM_SUPP to ${SP_HEAP_MEM_SUPP}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530417endif()
418
Vinay Kumar Kotegowderac218992020-04-03 12:56:00 +0530419if(NOT DEFINED SUITE_TEST_RANGE)
420 set(SUITE_TEST_RANGE_MIN None)
421 set(SUITE_TEST_RANGE_MAX None)
422else()
423 list(LENGTH SUITE_TEST_RANGE SUITE_TEST_RANGE_LENGTH)
424 if(${SUITE_TEST_RANGE_LENGTH} GREATER "2")
425 message(FATAL_ERROR "[PSA] : -DSUITE_TEST_RANGE=<...> value error! accepts two "
426 " numbers in quotes separated with ';'")
427 endif()
428 if(${SUITE_TEST_RANGE_LENGTH} EQUAL "2")
429 list(GET SUITE_TEST_RANGE 0 SUITE_TEST_RANGE_MIN)
430 list(GET SUITE_TEST_RANGE 1 SUITE_TEST_RANGE_MAX)
431 message(STATUS "[PSA] : Testing (${SUITE_TEST_RANGE_MIN}, ${SUITE_TEST_RANGE_MAX}) of ${SUITE} suite")
432 endif()
433 if(${SUITE_TEST_RANGE_LENGTH} EQUAL "1")
434 set(SUITE_TEST_RANGE_MIN ${SUITE_TEST_RANGE})
435 set(SUITE_TEST_RANGE_MAX ${SUITE_TEST_RANGE})
436 message(STATUS "[PSA] : Testing ${SUITE_TEST_RANGE_MIN} of ${SUITE} suite")
437 endif()
438endif()
439
jk-armbf532fd2021-05-07 13:58:22 +0530440if(NOT DEFINED SPEC_VERSION)
441 message(STATUS "[PSA] : Default spec version")
442else()
443 if(NOT ${SPEC_VERSION} IN_LIST PSA_SPEC_VERSION)
444 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DSPEC_VERSION=${SPEC_VERSION}, supported values are : ${PSA_SPEC_VERSION} for ${SUITE}")
445 else()
446 message(STATUS "[PSA] : Testing ${SUITE} for spec version ${SPEC_VERSION}")
447 endif()
448endif()
449
jk-arm957cfea2021-06-18 15:52:12 +0530450if(DEFINED STATELESS_ROT_TESTS)
451 if(NOT ${STATELESS_ROT_TESTS} IN_LIST PSA_STATELESS_ROT)
452 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DSTATELESS_ROT_TESTS=${STATELESS_ROT_TESTS}, supported values are : ${PSA_STATELESS_ROT}")
453 elseif(${STATELESS_ROT_TESTS} EQUAL 1)
454 message(STATUS "[PSA] : Testing ${SUITE} for stateless rot")
455 elseif(${STATELESS_ROT_TESTS} EQUAL 0)
456 message(STATUS "[PSA] : Testing ${SUITE} for connection based")
457 endif()
458
459 if(NOT DEFINED SPEC_VERSION)
460 message(FATAL_ERROR "[PSA] : Error: SPEC_VERSION is require for STATELESS_ROT_TESTS.")
461 elseif(${SUITE} STREQUAL "IPC")
462 if(${SPEC_VERSION} STREQUAL "1.0")
463 message(FATAL_ERROR "[PSA] : Error: STATELESS_ROT_TESTS is only valid for SPEC_VERSION=1.1.")
464 elseif(${SPEC_VERSION} STREQUAL "1.1")
465 add_definitions(-DSPEC_VERSION=11)
466 if(${STATELESS_ROT_TESTS} EQUAL 1)
467 add_definitions(-DSTATELESS_ROT=1)
468 elseif(${STATELESS_ROT_TESTS} EQUAL 0)
469 add_definitions(-DSTATELESS_ROT=0)
470 endif()
471 endif()
472 else()
473 message(FATAL_ERROR "[PSA] : Error: STATELESS_ROT_TESTS is only applicable to IPC Test Suite.")
474 endif()
475else()
476 add_definitions(-DSTATELESS_ROT=0)
477 if(DEFINED SPEC_VERSION)
478 if(${SUITE} STREQUAL "IPC")
479 if(${SPEC_VERSION} STREQUAL "1.0")
480 add_definitions(-DSPEC_VERSION=10)
481 endif()
482 if(${SPEC_VERSION} STREQUAL "1.1")
483 add_definitions(-DSPEC_VERSION=11)
484 endif()
485 endif()
486 endif()
487endif()
488
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530489message(STATUS "[PSA] : ----------Process input arguments- complete-------------")
490
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530491
jotman016d7dd4e2020-11-10 17:32:28 +0800492if((${SUITE} STREQUAL "INITIAL_ATTESTATION") AND (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${PSA_TARGET_QCBOR}))
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530493# Clone QCBOR and move to specified tag
494execute_process(COMMAND ${GIT_EXECUTABLE} clone ${PSA_QCBOR_GIT_REPO_LINK} ${PSA_TARGET_QCBOR}
495 RESULT_VARIABLE ${PSA_TARGET_QCBOR}_clone_result
496 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
497if(${PSA_TARGET_QCBOR}_clone_result)
498 message(FATAL_ERROR "git clone failed for ${PSA_QCBOR_GIT_REPO_LINK}")
499endif()
500
501if(NOT ${PSA_TARGET_QCBOR}_clone_result)
502execute_process(COMMAND ${GIT_EXECUTABLE} checkout -q "${PSA_QCBOR_GIT_REPO_TAG}"
503 RESULT_VARIABLE ${PSA_TARGET_QCBOR}_checkout_result
504 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PSA_TARGET_QCBOR})
505if(${PSA_TARGET_QCBOR}_checkout_result)
506 message(FATAL_ERROR "git checkout failed for Repo : ${PSA_QCBOR_GIT_REPO_LINK}, Tag : ${PSA_QCBOR_GIT_REPO_TAG}")
507endif()
508endif()
509endif()
gowtham siddarth12833042020-02-10 22:11:11 +0530510
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530511# Create PSA clean list
512list(APPEND PSA_CLEAN_LIST
513 ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_HEADER}
514 ${PSA_TESTLIST_FILE}
515 ${PSA_TEST_ENTRY_LIST_INC}
516 ${PSA_TEST_ENTRY_FUN_DECLARE_INC}
517 ${PSA_CLIENT_TEST_LIST_DELCARE_INC}
518 ${PSA_CLIENT_TEST_LIST_INC}
519 ${PSA_SERVER_TEST_LIST_DECLARE_INC}
520 ${PSA_SERVER_TEST_LIST}
521)
522
523# Process testsuite.db
524message(STATUS "[PSA] : Creating testlist.txt 'available at ${PSA_TESTLIST_FILE}'")
525execute_process(COMMAND ${PYTHON_EXECUTABLE} ${PSA_TESTLIST_GENERATOR}
526 ${SUITE_LOWER}
527 ${TESTSUITE_DB}
528 ${INCLUDE_PANIC_TESTS}
529 ${PSA_TESTLIST_FILE}
530 ${PSA_TEST_ENTRY_LIST_INC}
531 ${PSA_TEST_ENTRY_FUN_DECLARE_INC}
532 ${PSA_CLIENT_TEST_LIST_DELCARE_INC}
533 ${PSA_CLIENT_TEST_LIST_INC}
534 ${PSA_SERVER_TEST_LIST_DECLARE_INC}
Vinay Kumar Kotegowderac218992020-04-03 12:56:00 +0530535 ${PSA_SERVER_TEST_LIST}
536 ${SUITE_TEST_RANGE_MIN}
537 ${SUITE_TEST_RANGE_MAX})
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530538
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530539# Creating CMake list variable from file
540file(READ ${PSA_TESTLIST_FILE} PSA_TEST_LIST)
Vinay Kumar Kotegowderac218992020-04-03 12:56:00 +0530541if(NOT PSA_TEST_LIST)
542 message(FATAL_ERROR "[PSA] : Invalid test number!")
543endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530544string(REGEX REPLACE "\n" ";" PSA_TEST_LIST "${PSA_TEST_LIST}")
545
546add_custom_target(
547 ${PSA_TARGET_GENERATE_DATABASE_PRE}
548 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/platform
549 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/val
550 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/partition
551 COMMAND ${CMAKE_COMMAND} -E make_directory ${PSA_SUITE_OUT_DIR}
552)
553
554# Generate target files from User provided data base
555include(ExternalProject)
556ExternalProject_Add(
557 ${PSA_TARGET_GENERATE_DATABASE}
558 PREFIX ${CMAKE_CURRENT_BINARY_DIR}
559 DOWNLOAD_COMMAND ""
560 UPDATE_COMMAND ""
561 PATCH_COMMAND ""
562 BUILD_COMMAND ""
563 SOURCE_DIR "${PSA_ROOT_DIR}/tools/scripts/target_cfg"
564 CMAKE_ARGS -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
565 -DOUT_DIR=${CMAKE_CURRENT_BINARY_DIR}
566 -DTARGET=${TARGET}
567 -DGENERATOR_FILE=${PSA_TARGET_CONFIG_HEADER_GENERATOR}
568 -DINCLUDE_DIR=${PSA_ROOT_DIR}/val/common
569 -DTARGET_CONFIGURATION_FILE=${TARGET_CONFIGURATION_FILE}
570 -DTGT_CONFIG_SOURCE_C=${TGT_CONFIG_SOURCE_C}
571 -DOUTPUT_HEADER=${OUTPUT_HEADER}
572 -DDATABASE_TABLE_NAME=${DATABASE_TABLE_NAME}
573 -DDATABASE_TABLE_SECTION_NAME=${DATABASE_TABLE_SECTION_NAME}
574 -DTARGET_HEADER_GEN_INCLUDE_PATHS=${TARGET_HEADER_GEN_INCLUDE_PATHS}
575 LIST_SEPARATOR |
576 TEST_COMMAND ""
577)
578
579# Add custom target to clean generated files of the external project
580add_custom_target(
581 ${PSA_TARGET_GENERATE_DATABASE_POST}
582 COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/src/${PSA_TARGET_GENERATE_DATABASE}-build/ -- clean
583)
584
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530585# Check for supported toolchain/s
586if(${TOOLCHAIN} IN_LIST PSA_TOOLCHAIN_SUPPORT)
jk-armbf532fd2021-05-07 13:58:22 +0530587 if (DEFINED CROSS_COMPILE)
jk-arm7e6145a2021-07-19 19:36:14 +0530588 if(NOT (${TOOLCHAIN} IN_LIST CROSS_COMPILE_TOOLCHAIN_SUPPORT))
589 message(FATAL_ERROR "[PSA] : Error: CROSS_COMPILE not supported for this toolchain, supported toolchain are : ${CROSS_COMPILE_TOOLCHAIN_SUPPORT}")
590 endif()
jk-armbf532fd2021-05-07 13:58:22 +0530591 endif()
jk-arm7e6145a2021-07-19 19:36:14 +0530592 include(${PSA_ROOT_DIR}/tools/cmake/compiler/${TOOLCHAIN}.cmake)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530593else()
jk-arm7e6145a2021-07-19 19:36:14 +0530594 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DTOOLCHAIN=${TOOLCHAIN}, supported toolchain are : ${PSA_TOOLCHAIN_SUPPORT}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530595endif()
596
597# Global macro to identify the PSA test suite cmake build
598add_definitions(-DPSA_CMAKE_BUILD)
599add_definitions(-D${SUITE})
600add_definitions(-DVERBOSE=${VERBOSE})
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530601add_definitions(-DPLATFORM_PSA_ISOLATION_LEVEL=${PLATFORM_PSA_ISOLATION_LEVEL})
Vinay Kumar Kotegowder52bbfc92020-07-03 17:23:59 +0530602add_definitions(-D${TARGET})
jotman016d7dd4e2020-11-10 17:32:28 +0800603if("${TFM_PROFILE}" STREQUAL "profile_small")
604 message(STATUS "[PSA] : Building SMALL profile")
605 add_definitions(-DTF_M_PROFILE_SMALL)
606elseif("${TFM_PROFILE}" STREQUAL "profile_medium")
607 message(STATUS "[PSA] : Building MEDIUM profile")
608 add_definitions(-DTF_M_PROFILE_MEDIUM)
609endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530610if(${SP_HEAP_MEM_SUPP} EQUAL 1)
611 add_definitions(-DSP_HEAP_MEM_SUPP)
612endif()
613
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530614# Build PAL NSPE LIB
615include(${PSA_ROOT_DIR}/platform/targets/${TARGET}/target.cmake)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530616# Build VAL NSPE LIB
617#add_definitions(-DVAL_NSPE_BUILD)
618include(${PSA_ROOT_DIR}/val/val_nspe.cmake)
619# Build test
620include(${PSA_SUITE_DIR}/suite.cmake)
621if(${SUITE} STREQUAL "IPC")
622# Build SPE LIB
623include(${PSA_ROOT_DIR}/val/val_spe.cmake)
624endif()
625
626add_dependencies(${PSA_TARGET_GENERATE_DATABASE} ${PSA_TARGET_GENERATE_DATABASE_PRE})
627add_dependencies(${PSA_TARGET_GENERATE_DATABASE_POST} ${PSA_TARGET_GENERATE_DATABASE})
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530628add_dependencies(${PSA_TARGET_PAL_NSPE_LIB} ${PSA_TARGET_GENERATE_DATABASE_POST})
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530629add_dependencies(${PSA_TARGET_VAL_NSPE_LIB} ${PSA_TARGET_PAL_NSPE_LIB})
630add_dependencies(${PSA_TARGET_TEST_COMBINE_LIB} ${PSA_TARGET_VAL_NSPE_LIB})
631if(${SUITE} STREQUAL "IPC")
632add_dependencies(${PSA_TARGET_DRIVER_PARTITION_LIB} ${PSA_TARGET_TEST_COMBINE_LIB})
633add_dependencies(${PSA_TARGET_CLIENT_PARTITION_LIB} ${PSA_TARGET_DRIVER_PARTITION_LIB})
634add_dependencies(${PSA_TARGET_SERVER_PARTITION_LIB} ${PSA_TARGET_CLIENT_PARTITION_LIB})
635endif()
636
637# Include the files for make clean
638foreach(clean_item ${PSA_CLEAN_LIST})
639 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clean_item})
640endforeach()
641
642set_property(TARGET ${PSA_TARGET_VAL_NSPE_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/val)
643set_property(TARGET ${PSA_TARGET_PAL_NSPE_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/platform)
644set_property(TARGET ${PSA_TARGET_TEST_COMBINE_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${PSA_SUITE_OUT_DIR})
645if(${SUITE} STREQUAL "IPC")
646set_property(TARGET ${PSA_TARGET_DRIVER_PARTITION_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/partition)
647set_property(TARGET ${PSA_TARGET_CLIENT_PARTITION_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/partition)
648set_property(TARGET ${PSA_TARGET_SERVER_PARTITION_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/partition)
649endif()