blob: b6a1963a1ef15eedc612ed808e02f1c0bf40ffd9 [file] [log] [blame]
Feder Liang55194382021-11-22 16:45:33 +08001#-------------------------------------------------------------------------------
Dávid Házicc45a7b2024-04-15 22:30:28 +02002# Copyright (c) 2022-2024, Arm Limited. All rights reserved.
Feder Liang55194382021-11-22 16:45:33 +08003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
David Hu95223512023-12-04 23:07:46 +08008cmake_minimum_required(VERSION 3.21)
Jianliang Shenbd624ed2023-10-24 15:42:59 +08009
Dávid Házi61277a62023-11-15 11:05:45 +010010if(NOT COMMAND tfm_invalid_config)
11 function(tfm_invalid_config)
12 if (${ARGV})
13 string (REPLACE ";" " " ARGV_STRING "${ARGV}")
14 string (REPLACE "STREQUAL" "=" ARGV_STRING "${ARGV_STRING}")
15 string (REPLACE "GREATER" ">" ARGV_STRING "${ARGV_STRING}")
16 string (REPLACE "LESS" "<" ARGV_STRING "${ARGV_STRING}")
17 string (REPLACE "VERSION_LESS" "<" ARGV_STRING "${ARGV_STRING}")
18 string (REPLACE "EQUAL" "=" ARGV_STRING "${ARGV_STRING}")
19 string (REPLACE "IN_LIST" "in" ARGV_STRING "${ARGV_STRING}")
20
21 message(FATAL_ERROR "INVALID CONFIG: ${ARGV_STRING}")
22 endif()
23 endfunction()
24endif()
25
Gabor Toth4d414112021-11-10 17:44:50 +010026########################## FPU and MVE #########################################
27
chesun01ea11c822022-12-15 15:53:05 +080028tfm_invalid_config(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" AND (CONFIG_TFM_ENABLE_MVE OR CONFIG_TFM_ENABLE_MVE_FP))
Gabor Toth4d414112021-11-10 17:44:50 +010029tfm_invalid_config((NOT CONFIG_TFM_FP_ARCH) AND (CONFIG_TFM_ENABLE_FP OR CONFIG_TFM_ENABLE_MVE_FP))
chesun01a94a9c72023-02-14 16:19:51 +080030tfm_invalid_config((CMAKE_C_COMPILER_ID STREQUAL "ARMClang") AND (NOT CONFIG_TFM_FP_ARCH_ASM) AND CONFIG_TFM_ENABLE_FP)
Gabor Toth4d414112021-11-10 17:44:50 +010031tfm_invalid_config((NOT CONFIG_TFM_ENABLE_FP AND NOT CONFIG_TFM_ENABLE_MVE AND NOT CONFIG_TFM_ENABLE_MVE_FP) AND CONFIG_TFM_LAZY_STACKING)
32tfm_invalid_config((CONFIG_TFM_ENABLE_FP OR CONFIG_TFM_ENABLE_MVE OR CONFIG_TFM_ENABLE_MVE_FP) AND NOT CONFIG_TFM_ENABLE_CP10CP11)
Roman Mazurak0a79e672024-08-14 16:48:13 +030033tfm_invalid_config(CONFIG_TFM_ENABLE_CP10CP11 AND CONFIG_TFM_DISABLE_CP10CP11)
Gabor Toth4d414112021-11-10 17:44:50 +010034
Feder Liang55194382021-11-22 16:45:33 +080035###################### Check compiler for FP vulnerability #####################
36
37# Check compiler with mitigation for the VLLDM instruction security vulnerability or not.
38# For more information, please check https://developer.arm.com/support/arm-security-updates/vlldm-instruction-security-vulnerability.
Gabor Toth4d414112021-11-10 17:44:50 +010039if (CONFIG_TFM_FLOAT_ABI STREQUAL "hard")
Feder Liang55194382021-11-22 16:45:33 +080040 # Create test C file.
41 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c "int x;")
42 # Compile with mitigation -mfix-cmse-cve-2021-35465.
chesun01ea11c822022-12-15 15:53:05 +080043 if (CMAKE_C_COMPILER_ID STREQUAL "ARMClang")
Jianliang Shenbd624ed2023-10-24 15:42:59 +080044 # This flag is dedicated for this check.
45 # Check command will fail if C flags consist of keyword other than cpu/arch type.
46 # Toolchain file shall define a dedicated CP_CHECK_C_FLAGS to collect cpu/arch type
47 # if CMAKE_C_FLAGS is appended with other flags already before this check.
48 if(NOT DEFINED CP_CHECK_C_FLAGS)
49 set(CP_CHECK_C_FLAGS ${CMAKE_C_FLAGS})
50 endif()
51
chesun01ea11c822022-12-15 15:53:05 +080052 execute_process (
Jianliang Shenbd624ed2023-10-24 15:42:59 +080053 COMMAND ${CMAKE_C_COMPILER} --target=${CROSS_COMPILE} ${CP_CHECK_C_FLAGS} -mcmse -mfix-cmse-cve-2021-35465 -S ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c -o ${CMAKE_CURRENT_BINARY_DIR}/cvetest.s
chesun01ea11c822022-12-15 15:53:05 +080054 RESULT_VARIABLE ret
55 ERROR_VARIABLE err
56 )
Dávid Házicc45a7b2024-04-15 22:30:28 +020057 elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
chesun01ea11c822022-12-15 15:53:05 +080058 execute_process (
59 COMMAND ${CMAKE_C_COMPILER} -mfix-cmse-cve-2021-35465 -S ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c -o ${CMAKE_CURRENT_BINARY_DIR}/cvetest.s
60 RESULT_VARIABLE ret
61 ERROR_VARIABLE err
62 )
Dávid Házicc45a7b2024-04-15 22:30:28 +020063 elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
64 execute_process (
65 COMMAND ${CMAKE_C_COMPILER} --enable_hardware_workaround fix-cmse-cve-2021-35465 ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c -o ${CMAKE_CURRENT_BINARY_DIR}/cvetest.s
66 RESULT_VARIABLE ret
67 ERROR_VARIABLE err
68 )
69 else()
70 message(FATAL_ERROR "Unsupported compiler.")
chesun01ea11c822022-12-15 15:53:05 +080071 endif()
Feder Liang55194382021-11-22 16:45:33 +080072 file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cvetest.c)
73 # Check result
74 if(NOT ret EQUAL 0)
75 message(FATAL_ERROR "To enable FPU usage in SPE and NSPE both, please use the compiler with '-mfix-cmse-cve-2021-35465' support")
76 else()
77 file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cvetest.s)
78 endif()
79endif()