Build: Convert secure_fw dir to modern cmake

Rewrite cmake files inside the secure_fw directory. Removed generated
files as they are now generated into the build tree. Alter header
includes where include paths have changed.

WARNING: This change will not build in isolation, it requires _all_
other cmake changes to successfully build. It is split out only for
clarity of changes.

Change-Id: Ib1b13c9b69f2fcb1ff354ed6b5e5b717a207e3b8
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/secure_fw/partitions/crypto/CMakeLists.inc b/secure_fw/partitions/crypto/CMakeLists.inc
deleted file mode 100644
index 7c1b880..0000000
--- a/secure_fw/partitions/crypto/CMakeLists.inc
+++ /dev/null
@@ -1,141 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2018-2020, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-#-------------------------------------------------------------------------------
-
-#Definitions to compile the "crypto" module.
-#This file assumes it will be included from a project specific cmakefile, and
-#will not create a library or executable.
-#Inputs:
-#       MBEDCRYPTO_INSTALL_DIR - directory where mbed-crypto headers and libraries can be found. Needed only when using CRYPTO_ENGINE_MBEDCRYPTO ON.
-#       TFM_ROOT_DIR        - root directory of the TF-M repository.
-#Outputs:
-#       Will modify include directories to make the source compile.
-#       ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
-#       ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
-#       ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
-#       Include directories will be modified by using the include_directories() commands as needed.
-
-#Get the current directory where this file is located.
-set(CRYPTO_DIR ${CMAKE_CURRENT_LIST_DIR})
-
-#Check input variables
-if (NOT DEFINED ENABLE_CRYPTO)
-  message(FATAL_ERROR "Incomplete build configuration: ENABLE_CRYPTO is undefined. ")
-endif()
-
-if (NOT DEFINED CRYPTO_ENGINE_MBEDTLS)
-  message(FATAL_ERROR "Incomplete build configuration: CRYPTO_ENGINE_MBEDTLS is undefined. ")
-endif()
-
-if (ENABLE_CRYPTO)
-  if (CRYPTO_ENGINE_MBEDTLS)
-    if (NOT DEFINED MBEDCRYPTO_INSTALL_DIR)
-      message(FATAL_ERROR "Please set MBEDCRYPTO_INSTALL_DIR before including this file.")
-    endif()
-  endif()
-
-  if (NOT DEFINED TFM_ROOT_DIR)
-    message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
-  endif()
-
-  set (CRYPTO_C_SRC "${CRYPTO_DIR}/crypto_init.c"
-                    "${CRYPTO_DIR}/crypto_alloc.c"
-                    "${CRYPTO_DIR}/crypto_cipher.c"
-                    "${CRYPTO_DIR}/crypto_hash.c"
-                    "${CRYPTO_DIR}/crypto_mac.c"
-                    "${CRYPTO_DIR}/crypto_key.c"
-                    "${CRYPTO_DIR}/crypto_aead.c"
-                    "${CRYPTO_DIR}/crypto_asymmetric.c"
-                    "${CRYPTO_DIR}/crypto_key_derivation.c"
-                    "${CRYPTO_DIR}/tfm_crypto_secure_api.c"
-      )
-
-  if (CRYPTO_ENGINE_MBEDTLS)
-    list(APPEND CRYPTO_C_SRC "${CRYPTO_DIR}/tfm_mbedcrypto_alt.c")
-  endif()
-
-  #Append all our source files to global lists.
-  list(APPEND ALL_SRC_C ${CRYPTO_C_SRC})
-  unset(CRYPTO_C_SRC)
-
-  #Setting include directories
-  embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
-  embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
-  if (CRYPTO_ENGINE_MBEDTLS)
-    embedded_include_directories(PATH ${MBEDCRYPTO_INSTALL_DIR}/include ABSOLUTE)
-  endif()
-
-  #Inform the user about Crypto service features selected based on the Crypto service cmake flags
-  message("The Crypto service compile configuration is as follows:")
-  if (NOT DEFINED CRYPTO_ENGINE_BUF_SIZE)
-    message("- CRYPTO_ENGINE_BUF_SIZE using default value")
-  else()
-    message("- CRYPTO_ENGINE_BUF_SIZE: " ${CRYPTO_ENGINE_BUF_SIZE})
-  endif()
-  if (NOT DEFINED CRYPTO_CONC_OPER_NUM)
-    message("- CRYPTO_CONC_OPER_NUM using default value")
-  else()
-    message("- CRYPTO_CONC_OPER_NUM: " ${CRYPTO_CONC_OPER_NUM})
-  endif()
-
-  if (NOT DEFINED CRYPTO_KEY_MODULE_DISABLED)
-    message("- KEY module enabled")
-    set(CRYPTO_KEY_MODULE_DISABLED 0)
-  else()
-    message("- CRYPTO_KEY_MODULE_DISABLED: " ${CRYPTO_KEY_MODULE_DISABLED})
-  endif()
-  if (NOT CRYPTO_KEY_MODULE_DISABLED AND
-      NOT TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
-    message(FATAL_ERROR "Internal trusted storage should be enabled for persistent key storage")
-  endif()
-
-  if (NOT DEFINED CRYPTO_AEAD_MODULE_DISABLED)
-    message("- AEAD module enabled")
-    set(CRYPTO_AEAD_MODULE_DISABLED 0)
-  else()
-    message("- CRYPTO_AEAD_MODULE_DISABLED: " ${CRYPTO_AEAD_MODULE_DISABLED})
-  endif()
-  if (NOT DEFINED CRYPTO_MAC_MODULE_DISABLED)
-    message("- MAC module enabled")
-    set(CRYPTO_MAC_MODULE_DISABLED 0)
-  else()
-    message("- CRYPTO_MAC_MODULE_DISABLED: " ${CRYPTO_MAC_MODULE_DISABLED})
-  endif()
-  if (NOT DEFINED CRYPTO_HASH_MODULE_DISABLED)
-    message("- HASH module enabled")
-    set(CRYPTO_HASH_MODULE_DISABLED 0)
-  else()
-    message("- CRYPTO_HASH_MODULE_DISABLED: " ${CRYPTO_HASH_MODULE_DISABLED})
-  endif()
-  if (NOT DEFINED CRYPTO_CIPHER_MODULE_DISABLED)
-    message("- CIPHER module enabled")
-    set(CRYPTO_CIPHER_MODULE_DISABLED 0)
-  else()
-    message("- CRYPTO_CIPHER_MODULE_DISABLED: " ${CRYPTO_CIPHER_MODULE_DISABLED})
-  endif()
-  if (NOT DEFINED CRYPTO_KEY_DERIVATION_MODULE_DISABLED)
-    message("- KEY_DERIVATION module enabled")
-    set(CRYPTO_KEY_DERIVATION_MODULE_DISABLED 0)
-  else()
-    message("- CRYPTO_KEY_DERIVATION_MODULE_DISABLED: " ${CRYPTO_KEY_DERIVATION_MODULE_DISABLED})
-  endif()
-  if (NOT DEFINED CRYPTO_ASYMMETRIC_MODULE_DISABLED)
-    message("- ASYMMETRIC module enabled")
-    set(CRYPTO_ASYMMETRIC_MODULE_DISABLED 0)
-  else()
-    message("- CRYPTO_ASYMMETRIC_MODULE_DISABLED: " ${CRYPTO_ASYMMETRIC_MODULE_DISABLED})
-  endif()
-  if (TFM_PSA_API)
-    if (NOT DEFINED CRYPTO_IOVEC_BUFFER_SIZE)
-      message("- CRYPTO_IOVEC_BUFFER_SIZE using default value")
-    else()
-      message("- CRYPTO_IOVEC_BUFFER_SIZE: " ${CRYPTO_IOVEC_BUFFER_SIZE})
-    endif()
-  endif()
-
-else()
-  message(FATAL_ERROR "Build system currently doesn't support selectively disabling of a service.")
-endif()
diff --git a/secure_fw/partitions/crypto/CMakeLists.txt b/secure_fw/partitions/crypto/CMakeLists.txt
index d076edc..e10de61 100644
--- a/secure_fw/partitions/crypto/CMakeLists.txt
+++ b/secure_fw/partitions/crypto/CMakeLists.txt
@@ -1,148 +1,156 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+# Copyright (c) 2020, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.7)
-
-#Tell cmake where our modules can be found
-list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../cmake)
-
-#Some project global settings
-set (CRYPTO_DIR "${CMAKE_CURRENT_LIST_DIR}")
-get_filename_component(TFM_ROOT_DIR "${CRYPTO_DIR}/../../.." ABSOLUTE)
-
-#Include common stuff to control cmake.
-include("Common/BuildSys")
-
-#Start an embedded project.
-embedded_project_start(CONFIG "${TFM_ROOT_DIR}/configs/ConfigDefault.cmake")
-project(tfm_crypto LANGUAGES ASM C)
-embedded_project_fixup()
-
-#Get the definition of what files we need to build
-set (ENABLE_CRYPTO ON)
-#The backend of the service is based on Mbed Crypto
-set (CRYPTO_ENGINE_MBEDTLS ON)
-
-if (CRYPTO_ENGINE_MBEDTLS)
-	if (NOT DEFINED MBEDTLS_CONFIG_FILE)
-		set (MBEDTLS_CONFIG_FILE "tfm_mbedcrypto_config.h")
-	endif()
-
-	if (NOT DEFINED MBEDTLS_CONFIG_PATH)
-		set (MBEDTLS_CONFIG_PATH "${PLATFORM_DIR}/common")
-	endif()
-
-	#Define location of Mbed-Crypto(MbedTLS) source, build, and installation directory.
-	get_filename_component(MBEDCRYPTO_SOURCE_DIR "${TFM_ROOT_DIR}/../mbedtls" ABSOLUTE)
-	set (MBEDCRYPTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/mbed-crypto/build")
-	set (MBEDCRYPTO_INSTALL_DIR ${MBEDCRYPTO_BINARY_DIR}/../install)
-	set (MBEDCRYPTO_TARGET_NAME "mbedcrypto_lib")
+if (NOT TFM_PARTITION_CRYPTO)
+    return()
 endif()
 
-include(CMakeLists.inc)
+cmake_minimum_required(VERSION 3.13)
+cmake_policy(SET CMP0079 NEW)
 
-if (CRYPTO_HW_ACCELERATOR)
-	if(NOT DEFINED CRYPTO_HW_ACCELERATOR_CMAKE_BUILD)
-		message(FATAL_ERROR "CRYPTO_HW_ACCELERATOR_CMAKE_BUILD not defined.")
-	endif()
-	include(${CRYPTO_HW_ACCELERATOR_CMAKE_BUILD})
+add_library(tfm_partition_crypto STATIC)
+
+target_sources(tfm_partition_crypto
+    PRIVATE
+        crypto_init.c
+        crypto_alloc.c
+        crypto_cipher.c
+        crypto_hash.c
+        crypto_mac.c
+        crypto_key.c
+        crypto_aead.c
+        crypto_asymmetric.c
+        crypto_key_derivation.c
+)
+
+target_include_directories(tfm_partition_crypto
+    PRIVATE
+        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+)
+
+# Linking to external interfaces
+target_link_libraries(tfm_partition_crypto
+    PRIVATE
+        tfm_secure_api
+        platform_s
+        mbedcrypto_crypto_service
+        psa_interface
+)
+target_compile_definitions(tfm_partition_crypto
+    PRIVATE
+    $<$<BOOL:${CRYPTO_KEY_MODULE_DISABLED}>:CRYPTO_KEY_MODULE_DISABLED>
+    $<$<BOOL:${CRYPTO_AEAD_MODULE_DISABLED}>:CRYPTO_AEAD_MODULE_DISABLED>
+    $<$<BOOL:${CRYPTO_MAC_MODULE_DISABLED}>:CRYPTO_MAC_MODULE_DISABLED>
+    $<$<BOOL:${CRYPTO_CIPHER_MODULE_DISABLED}>:CRYPTO_CIPHER_MODULE_DISABLED>
+    $<$<BOOL:${CRYPTO_HASH_MODULE_DISABLED}>:CRYPTO_HASH_MODULE_DISABLED>
+    $<$<BOOL:${CRYPTO_GENERATOR_MODULE_DISABLED}>:CRYPTO_GENERATOR_MODULE_DISABLED>
+    $<$<BOOL:${CRYPTO_ASYMMETRIC_MODULE_DISABLED}>:CRYPTO_ASYMMETRIC_MODULE_DISABLED>
+    $<$<BOOL:${CRYPTO_ENGINE_BUF_SIZE}>:CRYPTO_ENGINE_BUF_SIZE=${CRYPTO_ENGINE_BUF_SIZE}>
+    $<$<BOOL:${CRYPTO_CONC_OPER_NUM}>:CRYPTO_CONC_OPER_NUM=${CRYPTO_CONC_OPER_NUM}>
+    $<$<AND:$<NOT:$<BOOL:${TFM_PSA_API}>>,$<BOOL:${CRYPTO_IOVEC_BUFFER_SIZE}>>:CRYPTO_IOVEC_BUFFER_SIZE=${CRYPTO_IOVEC_BUFFER_SIZE}>
+)
+
+############################ Secure API ########################################
+
+target_sources(tfm_secure_api
+    PRIVATE
+        ${CMAKE_CURRENT_SOURCE_DIR}/tfm_crypto_secure_api.c
+)
+
+# The veneers give warnings about not being properly declared so they get hidden
+# to not overshadow _real_ warnings.
+set_source_files_properties(tfm_partition_crypto_secure_api.c
+    PROPERTIES
+        COMPILE_FLAGS -Wno-implicit-function-declaration
+)
+
+############################ Partition Defs ####################################
+
+target_link_libraries(tfm_partitions
+    INTERFACE
+        tfm_partition_crypto
+)
+
+target_compile_definitions(tfm_partition_defs
+    INTERFACE
+        TFM_PARTITION_CRYPTO
+)
+
+############################### MBEDCRYPTO #####################################
+
+add_library(mbedcrypto_crypto_service_config INTERFACE)
+
+target_compile_definitions(mbedcrypto_crypto_service_config
+    INTERFACE
+        MBEDTLS_CONFIG_FILE="${TFM_MBEDCRYPTO_CONFIG_PATH}"
+        $<$<BOOL:${TFM_MBEDCRYPTO_PLATFORM_EXTRA_CONFIG_PATH}>:MBEDTLS_USER_CONFIG_FILE="${TFM_MBEDCRYPTO_PLATFORM_EXTRA_CONFIG_PATH}">
+        PSA_CRYPTO_SECURE
+        # Workaround for https://github.com/ARMmbed/mbedtls/issues/1077
+        $<$<OR:$<STREQUAL:${CMAKE_SYSTEM_ARCHITECTURE},armv8-m.base>,$<STREQUAL:${CMAKE_SYSTEM_ARCHITECTURE},armv6-m>>:MULADDC_CANNOT_USE_R7>
+)
+cmake_policy(SET CMP0079 NEW)
+
+set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
+set(CMAKE_POLICY_DEFAULT_CMP0048 NEW)
+set(ENABLE_TESTING OFF)
+set(ENABLE_PROGRAMS OFF)
+set(MBEDTLS_FATAL_WARNINGS OFF)
+set(ENABLE_DOCS OFF)
+set(INSTALL_MBEDTLS OFF)
+set(INSTALL_MBEDTLS_HEADERS OFF)
+
+# Current variables
+set(mbedcrypto_static_target mbedcrypto_crypto_service)
+set(mbedcrypto_lib_target mbedcrypto_lib_crypto_service)
+# Future variables
+set(lib_target lib_crypto_service)
+set(mbedcrypto_target mbedcrypto_crypto_service)
+set(mbedtls_target mbedtls_crypto_service)
+set(mbedx509_target mbedx509_crypto_service)
+
+# Mbedcrypto is quite a large lib, and it uses too much memory for it to be
+# reasonable to build it in debug info. As a compromise, if `debug` build type
+# is selected mbedcrypto will build under `relwithdebinfo` which preserved debug
+# symbols whild optimizing space.
+set(SAVED_BUILD_TYPE ${CMAKE_BUILD_TYPE})
+set(CMAKE_BUILD_TYPE ${MBEDCRYPTO_BUILD_TYPE})
+add_subdirectory(${MBEDCRYPTO_PATH} ${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto)
+set(CMAKE_BUILD_TYPE ${SAVED_BUILD_TYPE} CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE)
+
+if(NOT TARGET mbedcrypto_crypto_service)
+    message(FATAL_ERROR "Target mbedcrypto_crypto_service does not exist. Have the patches in ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto been applied to the mbedcrypto repo at ${MBEDCRYPTO_PATH} ?
+    Hint: The command might be `cd ${MBEDCRYPTO_PATH} && git apply ${CMAKE_SOURCE_DIR}/lib/ext/mbedcrypto/*.patch`")
 endif()
 
-#Create a list of the C defines
-list(APPEND TFM_CRYPTO_C_DEFINES_LIST __thumb2__ TFM_LVL=${TFM_LVL})
+set_target_properties(${mbedtls_target} ${mbedx509_target}
+    PROPERTIES
+        EXCLUDE_FROM_ALL TRUE
+)
 
-if (CRYPTO_ENGINE_MBEDTLS)
-  list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_ENGINE_MBEDTLS MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
-  if (DEFINED MBEDTLS_USER_CONFIG_FILE)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}")
-  endif()
-endif()
+target_include_directories(mbedcrypto_crypto_service
+    PUBLIC
+        ${CMAKE_CURRENT_SOURCE_DIR}
+)
 
-#Add module configuration parameters in case they are provided during CMake configuration step
-if (CRYPTO_KEY_MODULE_DISABLED)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_KEY_MODULE_DISABLED)
-endif()
-if (CRYPTO_AEAD_MODULE_DISABLED)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_AEAD_MODULE_DISABLED)
-endif()
-if (CRYPTO_MAC_MODULE_DISABLED)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_MAC_MODULE_DISABLED)
-endif()
-if (CRYPTO_CIPHER_MODULE_DISABLED)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_CIPHER_MODULE_DISABLED)
-endif()
-if (CRYPTO_HASH_MODULE_DISABLED)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_HASH_MODULE_DISABLED)
-endif()
-if (CRYPTO_KEY_DERIVATION_MODULE_DISABLED)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_KEY_DERIVATION_MODULE_DISABLED)
-endif()
-if (CRYPTO_ASYMMETRIC_MODULE_DISABLED)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_ASYMMETRIC_MODULE_DISABLED)
-endif()
+target_sources(mbedcrypto_crypto_service
+    PRIVATE
+        $<$<NOT:$<BOOL:${CRYPTO_HW_ACCELERATOR}>>:${CMAKE_CURRENT_SOURCE_DIR}/tfm_mbedcrypto_alt.c>
+)
 
-if (DEFINED CRYPTO_ENGINE_BUF_SIZE)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_ENGINE_BUF_SIZE=${CRYPTO_ENGINE_BUF_SIZE})
-endif()
-if (DEFINED CRYPTO_CONC_OPER_NUM)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_CONC_OPER_NUM=${CRYPTO_CONC_OPER_NUM})
-endif()
-if (TFM_PSA_API AND DEFINED CRYPTO_IOVEC_BUFFER_SIZE)
-	list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_IOVEC_BUFFER_SIZE=${CRYPTO_IOVEC_BUFFER_SIZE})
-endif()
+target_compile_options(mbedcrypto_crypto_service
+    PRIVATE
+        -Wno-unused-parameter
+)
 
-if (CRYPTO_ENGINE_MBEDTLS)
-	#Set Mbed Crypto compiler flags
-	string(APPEND MBEDCRYPTO_C_FLAGS " ${MBEDCRYPTO_C_FLAGS_SERVICES}")
-	string(APPEND MBEDCRYPTO_C_FLAGS " -DMBEDTLS_CONFIG_FILE=\\\\\\\"${MBEDTLS_CONFIG_FILE}\\\\\\\""
-	                                 " -I${CMAKE_CURRENT_LIST_DIR}")
-	if ((DEFINED MBEDTLS_USER_CONFIG_FILE) AND (DEFINED MBEDTLS_USER_CONFIG_PATH))
-		string(APPEND MBEDCRYPTO_C_FLAGS " -DMBEDTLS_USER_CONFIG_FILE=\\\\\\\"${MBEDTLS_USER_CONFIG_FILE}\\\\\\\""
-		" -I${MBEDTLS_USER_CONFIG_PATH}")
-	endif()
-	#Add TF-M include directory so Mbed Crypto can include PSA ITS headers
-	string(APPEND MBEDCRYPTO_C_FLAGS " -I${TFM_ROOT_DIR}/interface/include")
-
-	#Build Mbed Crypto as external project.
-	#This ensures Mbed Crypto is built with exactly defined settings.
-	#Mbed Crypto will be used from its install location
-	include(${TFM_ROOT_DIR}/BuildMbedCrypto.cmake)
-endif()
-
-#Specify what we build (for the crypto service, build as a static library)
-add_library(tfm_crypto STATIC ${ALL_SRC_ASM} ${ALL_SRC_C})
-embedded_set_target_compile_defines(TARGET tfm_crypto LANGUAGE C DEFINES ${TFM_CRYPTO_C_DEFINES_LIST})
-
-if (DEFINED CMSE_FLAGS)
-	embedded_set_target_compile_flags(TARGET tfm_crypto LANGUAGE C APPEND FLAGS ${CMSE_FLAGS})
-endif()
-
-if (CRYPTO_ENGINE_MBEDTLS)
-	#Add a dependency on the Mbed Crypto install target.
-	add_dependencies(tfm_crypto ${MBEDCRYPTO_TARGET_NAME}_install)
-	#Ask the compiler to merge the Mbed Crypto and crypto service libraries.
-	compiler_merge_library(DEST tfm_crypto LIBS "${MBEDCRYPTO_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX_C}mbedcrypto${CMAKE_STATIC_LIBRARY_SUFFIX_C}")
-
-	#Link crypto accelerator libraries if applicable
-	if (CRYPTO_HW_ACCELERATOR)
-		if(NOT DEFINED CRYPTO_HW_ACCELERATOR_CMAKE_LINK)
-			message(FATAL_ERROR "CRYPTO_HW_ACCELERATOR_CMAKE_LINK not defined.")
-		endif()
-		include(${CRYPTO_HW_ACCELERATOR_CMAKE_LINK})
-	endif()
-endif()
-
-#Persistent key requires ITS service
-if (NOT CRYPTO_KEY_MODULE_DISABLED)
-	target_link_libraries(tfm_crypto PRIVATE tfm_internal_trusted_storage)
-endif()
-
-#Set common compiler and linker flags
-config_setting_shared_compiler_flags(tfm_crypto)
-config_setting_shared_linker_flags(tfm_crypto)
-
-embedded_project_end(tfm_crypto)
+target_link_libraries(mbedcrypto_crypto_service
+    PRIVATE
+        psa_interface
+        tfm_secure_api
+        platform_s
+    PUBLIC
+        mbedcrypto_crypto_service_config
+)
diff --git a/secure_fw/partitions/crypto/tfm_mbedcrypto_include.h b/secure_fw/partitions/crypto/tfm_mbedcrypto_include.h
index 69342b1..7bb7f46 100644
--- a/secure_fw/partitions/crypto/tfm_mbedcrypto_include.h
+++ b/secure_fw/partitions/crypto/tfm_mbedcrypto_include.h
@@ -14,6 +14,6 @@
  * Mbed Crypto
  */
 #include "crypto_spe.h"
-#include "mbedcrypto/psa/crypto.h"
+#include "psa/crypto.h"
 
 #endif /* __TFM_MBEDCRYPTO_INCLUDE_H__ */