blob: 40479fd23941534686c9f93b56dbb8d0f9470872 [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
jotman01bed7a152021-05-25 22:57:17 +0800110 GCC_LINUX
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530111)
112
Øyvind Rønningstadc50804e2021-03-12 12:43:25 +0100113# list of supported CROSS_COMPILE toolchains
114list(APPEND CROSS_COMPILE_TOOLCHAIN_SUPPORT
115 GNUARM
116)
117
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530118# list of suported CPU arch
119list(APPEND PSA_CPU_ARCH_SUPPORT
120 armv8m_ml
121 armv8m_bl
122 armv7m
jotman01bed7a152021-05-25 22:57:17 +0800123 armv8a
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530124)
125
126# list of VERBOSE options
127list(APPEND PSA_VERBOSE_OPTIONS 1 2 3 4 5)
128
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530129# list of PLATFORM_PSA_ISOLATION_LEVEL options
jotman016d7dd4e2020-11-10 17:32:28 +0800130if("${TFM_PROFILE}" STREQUAL "profile_medium")
131list(APPEND PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS 1 2)
132else()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530133list(APPEND PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS 1 2 3)
jotman016d7dd4e2020-11-10 17:32:28 +0800134endif()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530135
jk-armbf532fd2021-05-07 13:58:22 +0530136# list of available spec version
137if("${SUITE}" STREQUAL "STORAGE" OR ${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE" OR ${SUITE} STREQUAL "PROTECTED_STORAGE")
138list(APPEND PSA_SPEC_VERSION
139 1.0-BETA2
140 1.0
141)
142elseif("${SUITE}" STREQUAL "CRYPTO")
143list(APPEND PSA_SPEC_VERSION
144 1.0-BETA1
145 1.0-BETA2
146 1.0-BETA3
147)
148elseif("${SUITE}" STREQUAL "INITIAL_ATTESTATION")
149list(APPEND PSA_SPEC_VERSION
150 1.0-BETA0
151 1.0.0
152 1.0.1
153 1.0.2
154)
155endif()
156
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530157message(STATUS "[PSA] : ----------Process input arguments- start-------------")
158
159# Check for TARGET command line argument
160_check_arguments("TARGET")
161# Check for SUTIE command line argument
162_check_arguments("SUITE")
163# Check for PSA_INCLUDE_PATHS command line argument
164_check_arguments("PSA_INCLUDE_PATHS")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530165
166string(TOLOWER ${SUITE} SUITE_LOWER)
167
168# Check for valid targets
169_get_sub_dir_list(PSA_TARGET_LIST ${PSA_ROOT_DIR}/platform/targets)
170if(NOT ${TARGET} IN_LIST PSA_TARGET_LIST)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100171 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DTARGET=${TARGET}, supported targets are : ${PSA_TARGET_LIST}")
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530172else()
173 message(STATUS "[PSA] : TARGET is set to ${TARGET}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530174endif()
175
176# Check for the presence of required test suite directories
177if((NOT IS_DIRECTORY ${PSA_ROOT_DIR}/dev_apis) OR (NOT IS_DIRECTORY ${PSA_ROOT_DIR}/ff))
178 message(STATUS "[PSA] : Error: Could not find architecture test suite directories in psa root path ${PSA_ROOT_DIR}")
179endif()
180
181if(FALSE)
182# Check for build directory specified
183if(NOT DEFINED BUILD)
184 set(BUILD ${CMAKE_CURRENT_BINARY_DIR}/BUILD CACHE INTERNAL "Defaulting build directory to ${BUILD}" FORCE)
185else()
186 set(BUILD ${CMAKE_CURRENT_BINARY_DIR}/${BUILD}/BUILD CACHE INTERNAL "Defaulting build directory to ${BUILD}" FORCE)
187endif()
188endif()
189
190# Check for valid suite cmake argument passed
191if(NOT ${SUITE} IN_LIST PSA_SUITES)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100192 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 +0530193else()
194 message(STATUS "[PSA] : SUITE is set to ${SUITE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530195endif()
196
197# Project variables
198set(PSA_TARGET_PRE_BUILD psa_pre_build)
199set(PSA_TARGET_GENERATE_DATABASE_PRE psa_generate_database_prerequisite)
200set(PSA_TARGET_GENERATE_DATABASE psa_generate_database)
201set(PSA_TARGET_GENERATE_DATABASE_POST psa_generate_database_cleanup)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530202if(${SUITE} STREQUAL "INITIAL_ATTESTATION")
203 set(PSA_TARGET_QCBOR psa_qcbor)
204endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530205set(PSA_TARGET_PAL_NSPE_LIB pal_nspe)
206set(PSA_TARGET_VAL_NSPE_LIB val_nspe)
207set(PSA_TARGET_TEST_COMBINE_LIB test_combine)
jk-armbf532fd2021-05-07 13:58:22 +0530208set(PSA_TARGET_DRIVER_PARTITION_LIB tfm_psa_rot_partition_driver_partition)
209set(PSA_TARGET_CLIENT_PARTITION_LIB tfm_app_rot_partition_client_partition)
210set(PSA_TARGET_SERVER_PARTITION_LIB tfm_app_rot_partition_server_partition)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530211if(${SUITE} STREQUAL "IPC")
212 set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/ff/${SUITE_LOWER})
213 set(PSA_SUITE_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/ff/${SUITE_LOWER})
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530214elseif((${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE") OR (${SUITE} STREQUAL "PROTECTED_STORAGE"))
215 set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/dev_apis/storage)
216 set(PSA_SUITE_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/dev_apis/storage)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530217else()
218 set(PSA_SUITE_DIR ${PSA_ROOT_DIR}/dev_apis/${SUITE_LOWER})
219 set(PSA_SUITE_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/dev_apis/${SUITE_LOWER})
220endif()
221set(PSA_TARGET_CONFIG_HEADER_GENERATOR ${PSA_ROOT_DIR}/tools/scripts/target_cfg/targetConfigGen.py)
222set(PSA_TESTLIST_GENERATOR ${PSA_ROOT_DIR}/tools/scripts/gen_tests_list.py)
223set(TARGET_CONFIGURATION_FILE ${PSA_ROOT_DIR}/platform/targets/${TARGET}/target.cfg)
224set(TGT_CONFIG_SOURCE_C ${CMAKE_CURRENT_BINARY_DIR}/targetConfigGen.c)
225set(OUTPUT_HEADER target_database.h)
226set(DATABASE_TABLE_NAME target_database)
227set(DATABASE_TABLE_SECTION_NAME "NOSECTION")
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530228set(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 +0530229if(NOT DEFINED SPEC_VERSION)
230 if(${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE")
231 set(TESTSUITE_DB ${PSA_SUITE_DIR}/its_testsuite.db)
232 elseif((${SUITE} STREQUAL "PROTECTED_STORAGE") OR (${SUITE} STREQUAL "STORAGE"))
233 set(TESTSUITE_DB ${PSA_SUITE_DIR}/ps_testsuite.db)
234 else()
235 set(TESTSUITE_DB ${PSA_SUITE_DIR}/testsuite.db)
236 endif()
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530237else()
jk-armbf532fd2021-05-07 13:58:22 +0530238 if(${SUITE} STREQUAL "INTERNAL_TRUSTED_STORAGE")
239 if(${SPEC_VERSION} STREQUAL "1.0-BETA2")
240 set(TESTSUITE_DB ${PSA_SUITE_DIR}/its_1.0-beta2_testsuite.db)
241 endif()
242 if(${SPEC_VERSION} STREQUAL "1.0")
243 set(TESTSUITE_DB ${PSA_SUITE_DIR}/its_1.0_testsuite.db)
244 endif()
245 elseif((${SUITE} STREQUAL "PROTECTED_STORAGE") OR (${SUITE} STREQUAL "STORAGE"))
246 if(${SPEC_VERSION} STREQUAL "1.0-BETA2")
247 set(TESTSUITE_DB ${PSA_SUITE_DIR}/ps_1.0-beta2_testsuite.db)
248 endif()
249 if(${SPEC_VERSION} STREQUAL "1.0")
250 set(TESTSUITE_DB ${PSA_SUITE_DIR}/ps_1.0_testsuite.db)
251 endif()
252 elseif(${SUITE} STREQUAL "CRYPTO")
253 if(${SPEC_VERSION} STREQUAL "1.0-BETA1")
254 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta1_testsuite.db)
255 endif()
256 if(${SPEC_VERSION} STREQUAL "1.0-BETA2")
257 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta2_testsuite.db)
258 endif()
259 if(${SPEC_VERSION} STREQUAL "1.0-BETA3")
260 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta3_testsuite.db)
261 endif()
262 elseif(${SUITE} STREQUAL "INITIAL_ATTESTATION")
263 if(${SPEC_VERSION} STREQUAL "1.0-BETA0")
264 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0-beta0_testsuite.db)
265 endif()
266 if(${SPEC_VERSION} STREQUAL "1.0.0")
267 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0.0_testsuite.db)
268 endif()
269 if(${SPEC_VERSION} STREQUAL "1.0.1")
270 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0.1_testsuite.db)
271 endif()
272 if(${SPEC_VERSION} STREQUAL "1.0.2")
273 set(TESTSUITE_DB ${PSA_SUITE_DIR}/1.0.2_testsuite.db)
274 endif()
275 endif()
Vinay Kumar Kotegowder18fcd402020-04-27 17:38:41 +0530276endif()
277set(PSA_TESTLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/${SUITE_LOWER}_testlist.txt)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530278set(PSA_TEST_ENTRY_LIST_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_list.inc)
279set(PSA_TEST_ENTRY_FUN_DECLARE_INC ${CMAKE_CURRENT_BINARY_DIR}/test_entry_fn_declare_list.inc)
280set(PSA_CLIENT_TEST_LIST_DELCARE_INC ${CMAKE_CURRENT_BINARY_DIR}/client_tests_list_declare.inc)
281set(PSA_CLIENT_TEST_LIST_INC ${CMAKE_CURRENT_BINARY_DIR}/client_tests_list.inc)
282set(PSA_SERVER_TEST_LIST_DECLARE_INC ${CMAKE_CURRENT_BINARY_DIR}/server_tests_list_declare.inc)
283set(PSA_SERVER_TEST_LIST ${CMAKE_CURRENT_BINARY_DIR}/server_tests_list.inc)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530284if(${SUITE} STREQUAL "INITIAL_ATTESTATION")
285 set(PSA_QCBOR_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PSA_TARGET_QCBOR}/inc)
286endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530287
288# Validity check for required files for a given suite
289if(NOT DEFINED PSA_${SUITE}_FILES)
290 message(FATAL_ERROR "[PSA] : List of file/s to verify against ${suite} is not defined")
291endif()
292foreach(file_item ${PSA_${SUITE}_FILES})
293 set(PSA_FILE_FOUND FALSE)
294 foreach(include_path ${PSA_INCLUDE_PATHS})
295 if((EXISTS ${include_path}/${file_item}) AND
296 (NOT PSA_FILE_FOUND))
297 set(PSA_FILE_FOUND TRUE)
298 break()
299 endif()
300 endforeach()
301 if(NOT PSA_FILE_FOUND)
302 message(FATAL_ERROR "[PSA] : Couldn't find ${file_item} in ${PSA_INCLUDE_PATHS}")
303 endif()
304endforeach()
305
306# Check for TOOLCHAIN command line argument
307if(NOT DEFINED TOOLCHAIN)
308 set(TOOLCHAIN "GNUARM" CACHE INTERNAL "Compiler used" FORCE)
309 message(STATUS "[PSA] : Defaulting compiler to ${TOOLCHAIN}")
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530310else()
311 message(STATUS "[PSA] : TOOLCHAIN is set to ${TOOLCHAIN}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530312endif()
313
Gowtham Siddarth1d6d4692019-09-16 11:47:29 +0530314if(${TOOLCHAIN} STREQUAL "ARMCLANG" OR ${TOOLCHAIN} STREQUAL "GNUARM")
315 if(NOT DEFINED CPU_ARCH)
316 message(FATAL_ERROR "[PSA] : Error: -DCPU_ARCH option missing")
317 else()
318 # Check for CPU architecture
319 if(NOT ${CPU_ARCH} IN_LIST PSA_CPU_ARCH_SUPPORT)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100320 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 +0530321 endif()
322 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530323 message(STATUS "[PSA] : CPU_ARCH is set to ${CPU_ARCH}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530324endif()
325
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530326# Check for VERBOSE
327if(NOT DEFINED VERBOSE)
328 set(VERBOSE 3 CACHE INTERNAL "Default VERBOSE value" FORCE)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530329 message(STATUS "[PSA] : Defaulting VERBOSE to ${VERBOSE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530330else()
331 if(NOT ${VERBOSE} IN_LIST PSA_VERBOSE_OPTIONS)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100332 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DVERBOSE=${VERBOSE}, supported values are : ${PSA_VERBOSE_OPTIONS}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530333 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530334 message(STATUS "[PSA] : VERBOSE is set to ${VERBOSE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530335endif()
336
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530337# Check for PLATFORM_PSA_ISOLATION_LEVEL
338if(NOT DEFINED PLATFORM_PSA_ISOLATION_LEVEL)
jotman016d7dd4e2020-11-10 17:32:28 +0800339 if("${TFM_PROFILE}" STREQUAL "profile_medium")
340 set(PLATFORM_PSA_ISOLATION_LEVEL 2 CACHE INTERNAL "Default PLATFORM_PSA_ISOLATION_LEVEL value" FORCE)
341 else()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530342 set(PLATFORM_PSA_ISOLATION_LEVEL 3 CACHE INTERNAL "Default PLATFORM_PSA_ISOLATION_LEVEL value" FORCE)
jotman016d7dd4e2020-11-10 17:32:28 +0800343 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530344 if(${SUITE} STREQUAL "IPC")
345 message(STATUS "[PSA] : Defaulting PLATFORM_PSA_ISOLATION_LEVEL to ${PLATFORM_PSA_ISOLATION_LEVEL}")
346 endif()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530347else()
348 if(NOT ${PLATFORM_PSA_ISOLATION_LEVEL} IN_LIST PLATFORM_PSA_ISOLATION_LEVEL_OPTIONS)
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100349 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 +0530350 endif()
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530351 if(${SUITE} STREQUAL "IPC")
352 message(STATUS "[PSA] : PLATFORM_PSA_ISOLATION_LEVEL is set to ${PLATFORM_PSA_ISOLATION_LEVEL}")
353 endif()
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530354endif()
355
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530356if(NOT DEFINED INCLUDE_PANIC_TESTS)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530357 #By default panic tests are disabled
358 set(INCLUDE_PANIC_TESTS 0 CACHE INTERNAL "Default INCLUDE_PANIC_TESTS value" FORCE)
359 message(STATUS "[PSA] : Defaulting INCLUDE_PANIC_TESTS to ${INCLUDE_PANIC_TESTS}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530360else()
361 if(INCLUDE_PANIC_TESTS EQUAL 1)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530362 message(STATUS "[PSA] : "
363 "INCLUDE_PANIC_TESTS set to 1, therefore including PSA APIs panic tests into the regression,\n"
364 "\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 +0530365 endif()
366endif()
367
368if(NOT DEFINED WATCHDOG_AVAILABLE)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530369 #Assuming watchdog is available to program by test suite
370 set(WATCHDOG_AVAILABLE 1 CACHE INTERNAL "Default WATCHDOG_AVAILABLE value" FORCE)
371 message(STATUS "[PSA] : Defaulting WATCHDOG_AVAILABLE to ${WATCHDOG_AVAILABLE}")
372else()
373 message(STATUS "[PSA] : WATCHDOG_AVAILABLE is set to ${WATCHDOG_AVAILABLE}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530374endif()
375
376if((INCLUDE_PANIC_TESTS EQUAL 1) AND
377 (WATCHDOG_AVAILABLE EQUAL 0))
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530378 message(WARNING "[PSA]: "
379 "Note that to test PSA APIs panic conditions, test harness may require to access"
380 "the watchdog timer in oder to recover from panic and to be able to continue with"
381 "next test. Ignore this warning if system under test has capability to reset the"
382 "system when it encounters panic condition.")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530383endif()
384
385if(NOT DEFINED SP_HEAP_MEM_SUPP)
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530386 #Are dynamic memory functions available to secure partition?
387 set(SP_HEAP_MEM_SUPP 1 CACHE INTERNAL "Default SP_HEAP_MEM_SUPP value" FORCE)
388 message(STATUS "[PSA] : Defaulting SP_HEAP_MEM_SUPP to ${SP_HEAP_MEM_SUPP}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530389endif()
390
Vinay Kumar Kotegowderac218992020-04-03 12:56:00 +0530391if(NOT DEFINED SUITE_TEST_RANGE)
392 set(SUITE_TEST_RANGE_MIN None)
393 set(SUITE_TEST_RANGE_MAX None)
394else()
395 list(LENGTH SUITE_TEST_RANGE SUITE_TEST_RANGE_LENGTH)
396 if(${SUITE_TEST_RANGE_LENGTH} GREATER "2")
397 message(FATAL_ERROR "[PSA] : -DSUITE_TEST_RANGE=<...> value error! accepts two "
398 " numbers in quotes separated with ';'")
399 endif()
400 if(${SUITE_TEST_RANGE_LENGTH} EQUAL "2")
401 list(GET SUITE_TEST_RANGE 0 SUITE_TEST_RANGE_MIN)
402 list(GET SUITE_TEST_RANGE 1 SUITE_TEST_RANGE_MAX)
403 message(STATUS "[PSA] : Testing (${SUITE_TEST_RANGE_MIN}, ${SUITE_TEST_RANGE_MAX}) of ${SUITE} suite")
404 endif()
405 if(${SUITE_TEST_RANGE_LENGTH} EQUAL "1")
406 set(SUITE_TEST_RANGE_MIN ${SUITE_TEST_RANGE})
407 set(SUITE_TEST_RANGE_MAX ${SUITE_TEST_RANGE})
408 message(STATUS "[PSA] : Testing ${SUITE_TEST_RANGE_MIN} of ${SUITE} suite")
409 endif()
410endif()
411
jk-armbf532fd2021-05-07 13:58:22 +0530412if(NOT DEFINED SPEC_VERSION)
413 message(STATUS "[PSA] : Default spec version")
414else()
415 if(NOT ${SPEC_VERSION} IN_LIST PSA_SPEC_VERSION)
416 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DSPEC_VERSION=${SPEC_VERSION}, supported values are : ${PSA_SPEC_VERSION} for ${SUITE}")
417 else()
418 message(STATUS "[PSA] : Testing ${SUITE} for spec version ${SPEC_VERSION}")
419 endif()
420endif()
421
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530422message(STATUS "[PSA] : ----------Process input arguments- complete-------------")
423
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530424
jotman016d7dd4e2020-11-10 17:32:28 +0800425if((${SUITE} STREQUAL "INITIAL_ATTESTATION") AND (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${PSA_TARGET_QCBOR}))
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530426# Clone QCBOR and move to specified tag
427execute_process(COMMAND ${GIT_EXECUTABLE} clone ${PSA_QCBOR_GIT_REPO_LINK} ${PSA_TARGET_QCBOR}
428 RESULT_VARIABLE ${PSA_TARGET_QCBOR}_clone_result
429 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
430if(${PSA_TARGET_QCBOR}_clone_result)
431 message(FATAL_ERROR "git clone failed for ${PSA_QCBOR_GIT_REPO_LINK}")
432endif()
433
434if(NOT ${PSA_TARGET_QCBOR}_clone_result)
435execute_process(COMMAND ${GIT_EXECUTABLE} checkout -q "${PSA_QCBOR_GIT_REPO_TAG}"
436 RESULT_VARIABLE ${PSA_TARGET_QCBOR}_checkout_result
437 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PSA_TARGET_QCBOR})
438if(${PSA_TARGET_QCBOR}_checkout_result)
439 message(FATAL_ERROR "git checkout failed for Repo : ${PSA_QCBOR_GIT_REPO_LINK}, Tag : ${PSA_QCBOR_GIT_REPO_TAG}")
440endif()
441endif()
442endif()
gowtham siddarth12833042020-02-10 22:11:11 +0530443
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530444# Create PSA clean list
445list(APPEND PSA_CLEAN_LIST
446 ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_HEADER}
447 ${PSA_TESTLIST_FILE}
448 ${PSA_TEST_ENTRY_LIST_INC}
449 ${PSA_TEST_ENTRY_FUN_DECLARE_INC}
450 ${PSA_CLIENT_TEST_LIST_DELCARE_INC}
451 ${PSA_CLIENT_TEST_LIST_INC}
452 ${PSA_SERVER_TEST_LIST_DECLARE_INC}
453 ${PSA_SERVER_TEST_LIST}
454)
455
456# Process testsuite.db
457message(STATUS "[PSA] : Creating testlist.txt 'available at ${PSA_TESTLIST_FILE}'")
458execute_process(COMMAND ${PYTHON_EXECUTABLE} ${PSA_TESTLIST_GENERATOR}
459 ${SUITE_LOWER}
460 ${TESTSUITE_DB}
461 ${INCLUDE_PANIC_TESTS}
462 ${PSA_TESTLIST_FILE}
463 ${PSA_TEST_ENTRY_LIST_INC}
464 ${PSA_TEST_ENTRY_FUN_DECLARE_INC}
465 ${PSA_CLIENT_TEST_LIST_DELCARE_INC}
466 ${PSA_CLIENT_TEST_LIST_INC}
467 ${PSA_SERVER_TEST_LIST_DECLARE_INC}
Vinay Kumar Kotegowderac218992020-04-03 12:56:00 +0530468 ${PSA_SERVER_TEST_LIST}
469 ${SUITE_TEST_RANGE_MIN}
470 ${SUITE_TEST_RANGE_MAX})
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530471
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530472# Creating CMake list variable from file
473file(READ ${PSA_TESTLIST_FILE} PSA_TEST_LIST)
Vinay Kumar Kotegowderac218992020-04-03 12:56:00 +0530474if(NOT PSA_TEST_LIST)
475 message(FATAL_ERROR "[PSA] : Invalid test number!")
476endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530477string(REGEX REPLACE "\n" ";" PSA_TEST_LIST "${PSA_TEST_LIST}")
478
479add_custom_target(
480 ${PSA_TARGET_GENERATE_DATABASE_PRE}
481 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/platform
482 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/val
483 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/partition
484 COMMAND ${CMAKE_COMMAND} -E make_directory ${PSA_SUITE_OUT_DIR}
485)
486
487# Generate target files from User provided data base
488include(ExternalProject)
489ExternalProject_Add(
490 ${PSA_TARGET_GENERATE_DATABASE}
491 PREFIX ${CMAKE_CURRENT_BINARY_DIR}
492 DOWNLOAD_COMMAND ""
493 UPDATE_COMMAND ""
494 PATCH_COMMAND ""
495 BUILD_COMMAND ""
496 SOURCE_DIR "${PSA_ROOT_DIR}/tools/scripts/target_cfg"
497 CMAKE_ARGS -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
498 -DOUT_DIR=${CMAKE_CURRENT_BINARY_DIR}
499 -DTARGET=${TARGET}
500 -DGENERATOR_FILE=${PSA_TARGET_CONFIG_HEADER_GENERATOR}
501 -DINCLUDE_DIR=${PSA_ROOT_DIR}/val/common
502 -DTARGET_CONFIGURATION_FILE=${TARGET_CONFIGURATION_FILE}
503 -DTGT_CONFIG_SOURCE_C=${TGT_CONFIG_SOURCE_C}
504 -DOUTPUT_HEADER=${OUTPUT_HEADER}
505 -DDATABASE_TABLE_NAME=${DATABASE_TABLE_NAME}
506 -DDATABASE_TABLE_SECTION_NAME=${DATABASE_TABLE_SECTION_NAME}
507 -DTARGET_HEADER_GEN_INCLUDE_PATHS=${TARGET_HEADER_GEN_INCLUDE_PATHS}
508 LIST_SEPARATOR |
509 TEST_COMMAND ""
510)
511
512# Add custom target to clean generated files of the external project
513add_custom_target(
514 ${PSA_TARGET_GENERATE_DATABASE_POST}
515 COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/src/${PSA_TARGET_GENERATE_DATABASE}-build/ -- clean
516)
517
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530518# Check for supported toolchain/s
519if(${TOOLCHAIN} IN_LIST PSA_TOOLCHAIN_SUPPORT)
jk-armbf532fd2021-05-07 13:58:22 +0530520 if (DEFINED CROSS_COMPILE)
521 if(${CROSS_COMPILE} AND NOT (${TOOLCHAIN} IN_LIST CROSS_COMPILE_TOOLCHAIN_SUPPORT))
Øyvind Rønningstadc50804e2021-03-12 12:43:25 +0100522 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 +0530523 endif()
524 endif()
525 include(${PSA_ROOT_DIR}/tools/cmake/compiler/${TOOLCHAIN}.cmake)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530526else()
Øyvind Rønningstadabbb7272020-11-09 14:50:54 +0100527 message(FATAL_ERROR "[PSA] : Error: Unsupported value for -DTOOLCHAIN=${TOOLCHAIN}, supported toolchain are : ${PSA_TOOLCHAIN_SUPPORT}")
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530528endif()
529
530# Global macro to identify the PSA test suite cmake build
531add_definitions(-DPSA_CMAKE_BUILD)
532add_definitions(-D${SUITE})
533add_definitions(-DVERBOSE=${VERBOSE})
Jaykumar Pitambarbhai Patelccf5bf22019-12-06 11:58:32 +0530534add_definitions(-DPLATFORM_PSA_ISOLATION_LEVEL=${PLATFORM_PSA_ISOLATION_LEVEL})
Vinay Kumar Kotegowder52bbfc92020-07-03 17:23:59 +0530535add_definitions(-D${TARGET})
jotman016d7dd4e2020-11-10 17:32:28 +0800536if("${TFM_PROFILE}" STREQUAL "profile_small")
537 message(STATUS "[PSA] : Building SMALL profile")
538 add_definitions(-DTF_M_PROFILE_SMALL)
539elseif("${TFM_PROFILE}" STREQUAL "profile_medium")
540 message(STATUS "[PSA] : Building MEDIUM profile")
541 add_definitions(-DTF_M_PROFILE_MEDIUM)
542endif()
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530543if(${SP_HEAP_MEM_SUPP} EQUAL 1)
544 add_definitions(-DSP_HEAP_MEM_SUPP)
545endif()
546
Jaykumar Pitambarbhai Patel6c3b8082020-02-26 19:51:37 +0530547# Build PAL NSPE LIB
548include(${PSA_ROOT_DIR}/platform/targets/${TARGET}/target.cmake)
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530549# Build VAL NSPE LIB
550#add_definitions(-DVAL_NSPE_BUILD)
551include(${PSA_ROOT_DIR}/val/val_nspe.cmake)
552# Build test
553include(${PSA_SUITE_DIR}/suite.cmake)
554if(${SUITE} STREQUAL "IPC")
555# Build SPE LIB
556include(${PSA_ROOT_DIR}/val/val_spe.cmake)
557endif()
558
559add_dependencies(${PSA_TARGET_GENERATE_DATABASE} ${PSA_TARGET_GENERATE_DATABASE_PRE})
560add_dependencies(${PSA_TARGET_GENERATE_DATABASE_POST} ${PSA_TARGET_GENERATE_DATABASE})
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530561add_dependencies(${PSA_TARGET_PAL_NSPE_LIB} ${PSA_TARGET_GENERATE_DATABASE_POST})
Vinay Kumar Kotegowder9982f902019-07-15 09:13:54 +0530562add_dependencies(${PSA_TARGET_VAL_NSPE_LIB} ${PSA_TARGET_PAL_NSPE_LIB})
563add_dependencies(${PSA_TARGET_TEST_COMBINE_LIB} ${PSA_TARGET_VAL_NSPE_LIB})
564if(${SUITE} STREQUAL "IPC")
565add_dependencies(${PSA_TARGET_DRIVER_PARTITION_LIB} ${PSA_TARGET_TEST_COMBINE_LIB})
566add_dependencies(${PSA_TARGET_CLIENT_PARTITION_LIB} ${PSA_TARGET_DRIVER_PARTITION_LIB})
567add_dependencies(${PSA_TARGET_SERVER_PARTITION_LIB} ${PSA_TARGET_CLIENT_PARTITION_LIB})
568endif()
569
570# Include the files for make clean
571foreach(clean_item ${PSA_CLEAN_LIST})
572 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${clean_item})
573endforeach()
574
575set_property(TARGET ${PSA_TARGET_VAL_NSPE_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/val)
576set_property(TARGET ${PSA_TARGET_PAL_NSPE_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/platform)
577set_property(TARGET ${PSA_TARGET_TEST_COMBINE_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${PSA_SUITE_OUT_DIR})
578if(${SUITE} STREQUAL "IPC")
579set_property(TARGET ${PSA_TARGET_DRIVER_PARTITION_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/partition)
580set_property(TARGET ${PSA_TARGET_CLIENT_PARTITION_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/partition)
581set_property(TARGET ${PSA_TARGET_SERVER_PARTITION_LIB} PROPERTY ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/partition)
582endif()