Add platform support

TS project structure and build system extended to accommodate
hardware specific drivers. The concept of a platform is introduced
to allow hardware specific drivers from external providers to be
used. This change implements the Portability Model described in
the project documentation.

Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I61e678ae103e0bf139f2c440ba6cd010620af37e
diff --git a/deployments/component-test/arm-linux/CMakeLists.txt b/deployments/component-test/arm-linux/CMakeLists.txt
index d96a793..a0ad971 100644
--- a/deployments/component-test/arm-linux/CMakeLists.txt
+++ b/deployments/component-test/arm-linux/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -29,6 +29,17 @@
 target_link_libraries(component-test PRIVATE CppUTest)
 
 #-------------------------------------------------------------------------------
+#  Components that are specific to deployment in the arm-linux environment.
+#
+#-------------------------------------------------------------------------------
+add_components(
+	TARGET "component-test"
+	BASE_DIR ${TS_ROOT}
+    COMPONENTS
+        "components/service/crypto/provider/mbedcrypto/entropy_adapter/linux"
+)
+
+#-------------------------------------------------------------------------------
 #  Extend with components that are common across all deployments of
 #  component-test
 #
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index deadf11..dcb0d2d 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -40,7 +40,6 @@
 		"components/service/crypto/client/test"
 		"components/service/crypto/client/test/standalone"
 		"components/service/crypto/provider/mbedcrypto"
-		"components/service/crypto/provider/mbedcrypto/entropy_source/mock"
 		"components/service/crypto/provider/serializer/protobuf"
 		"components/service/crypto/provider/serializer/packed-c"
 		"components/service/crypto/test/unit"
diff --git a/deployments/component-test/linux-pc/CMakeLists.txt b/deployments/component-test/linux-pc/CMakeLists.txt
index 3e56d83..a3ed949 100644
--- a/deployments/component-test/linux-pc/CMakeLists.txt
+++ b/deployments/component-test/linux-pc/CMakeLists.txt
@@ -64,6 +64,17 @@
 target_include_directories(component-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
 
 #-------------------------------------------------------------------------------
+#  Components that are specific to deployment in the linux-pc environment.
+#
+#-------------------------------------------------------------------------------
+add_components(
+	TARGET "component-test"
+	BASE_DIR ${TS_ROOT}
+    COMPONENTS
+        "components/service/crypto/provider/mbedcrypto/entropy_adapter/linux"
+)
+
+#-------------------------------------------------------------------------------
 #  Extend with components that are common across all deployments of
 #  component-test
 #
diff --git a/deployments/crypto/opteesp/CMakeLists.txt b/deployments/crypto/opteesp/CMakeLists.txt
index 38bc42d..13447b1 100644
--- a/deployments/crypto/opteesp/CMakeLists.txt
+++ b/deployments/crypto/opteesp/CMakeLists.txt
@@ -27,7 +27,10 @@
 sp_dev_kit_configure_linking(TARGET crypto-sp DEFINES ARM64=1)
 target_link_libraries(crypto-sp PRIVATE ${SP_DEV_KIT_LIBRARIES})
 
-
+#-------------------------------------------------------------------------------
+#  Components that are specific to deployment in the opteesp environment.
+#
+#-------------------------------------------------------------------------------
 add_components(TARGET "crypto-sp"
 	BASE_DIR ${TS_ROOT}
 	COMPONENTS
@@ -42,7 +45,7 @@
 		"components/service/common/serializer/protobuf"
 		"components/service/common/provider"
 		"components/service/crypto/provider/mbedcrypto"
-		"components/service/crypto/provider/mbedcrypto/entropy_source/mock"
+		"components/service/crypto/provider/mbedcrypto/entropy_adapter/platform"
 		"components/service/crypto/provider/serializer/protobuf"
 		"components/service/crypto/provider/serializer/packed-c"
 		"components/service/secure_storage/client/psa"
@@ -56,12 +59,28 @@
 	crypto_sp.c
 )
 
-######################################################## Build protobuf files
+#-------------------------------------------------------------------------------
+#  Use the selected platform to provide drivers needed by the deployment
+#
+#-------------------------------------------------------------------------------
+# temporarily force platform - with this change, the build interface to
+# an external builder such as a Yocto recipe is unchanged.  Should remove
+# once the build interface is published.
+set(TS_PLATFORM "ts/mock" CACHE STRING "Overridden" FORCE)
+
+add_platform(TARGET "crypto-sp")
+
+#-------------------------------------------------------------------------------
+#  Components used from external projects
+#
+#-------------------------------------------------------------------------------
+
+# Nanopb
 include(../../../external/nanopb/nanopb.cmake)
 target_link_libraries(crypto-sp PRIVATE nanopb::protobuf-nanopb-static)
 protobuf_generate_all(TGT "crypto-sp" NAMESPACE "protobuf" BASE_DIR "${TS_ROOT}/protocols")
 
-################################################################# mbedcrypto
+# Mbedcrypto
 include(../../../external/mbed-crypto/mbedcrypto.cmake)
 target_link_libraries(crypto-sp PRIVATE mbedcrypto)
 
diff --git a/deployments/crypto/opteesp/crypto_sp.c b/deployments/crypto/opteesp/crypto_sp.c
index ea60d1c..39039b3 100644
--- a/deployments/crypto/opteesp/crypto_sp.c
+++ b/deployments/crypto/opteesp/crypto_sp.c
@@ -46,7 +46,8 @@
 	/* Establish RPC session with secure storage SP */
 	storage_caller = ffarpc_caller_init(&ffarpc_caller);
 
-	if (!ffarpc_caller_discover(storage_uuid, storage_sp_ids, sizeof(storage_sp_ids)/sizeof(uint16_t)) ||
+	if (!ffarpc_caller_discover(storage_uuid, storage_sp_ids,
+								sizeof(storage_sp_ids)/sizeof(uint16_t)) ||
 		ffarpc_caller_open(&ffarpc_caller, storage_sp_ids[0], 0)) {
 		/*
 		 * Failed to establish session.  To allow the crypto service
@@ -59,7 +60,7 @@
 	}
 
 	/* Initialize the crypto service */
-	crypto_iface = mbed_crypto_provider_init(&crypto_provider, storage_caller);
+	crypto_iface = mbed_crypto_provider_init(&crypto_provider, storage_caller, NULL);
 
 	mbed_crypto_provider_register_serializer(&crypto_provider,
                     TS_RPC_ENCODING_PROTOBUF, pb_crypto_provider_serializer_instance());
diff --git a/deployments/deployment.cmake b/deployments/deployment.cmake
index 6543318..ca2a5e1 100644
--- a/deployments/deployment.cmake
+++ b/deployments/deployment.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -22,6 +22,7 @@
 # Common utilities used by the build system
 include(${TS_ROOT}/tools/cmake/common/Utils.cmake REQUIRED)
 include(${TS_ROOT}/tools/cmake/common/AddComponents.cmake REQUIRED)
+include(${TS_ROOT}/tools/cmake/common/AddPlatform.cmake REQUIRED)
 
 # Check build environment requirements are met
 ts_verify_build_env()
@@ -31,3 +32,26 @@
   "${TS_ROOT}"
   "${TS_ROOT}/components"
   )
+
+# Set platform provider root default to use if no commandline variable value has been specified.
+# The root path may be specified to allow an external project to provide platform definitions.
+if (DEFINED ENV{TS_PLATFORM_ROOT})
+  set(_default_platform_root ENV{TS_PLATFORM_ROOT})
+else()
+  set(_default_platform_root "${TS_ROOT}/platform/providers")
+endif()
+set(TS_PLATFORM_ROOT ${_default_platform_root} CACHE STRING "Platform provider path")
+
+# Set the default platform to use if no explict platform has been specified on the cmake commandline.
+if (DEFINED ENV{TS_PLATFORM})
+  set(_default_platform ENV{TS_PLATFORM})
+else()
+  set(_default_platform "ts/vanilla")
+endif()
+set(TS_PLATFORM ${_default_platform} CACHE STRING "Selected platform")
+
+# Custom property for defining platform feature dependencies based on components used in a deployment
+define_property(TARGET PROPERTY TS_PLATFORM_DRIVER_DEPENDENCIES
+  BRIEF_DOCS "List of platform driver interfaces used for a deployment."
+  FULL_DOCS "Used by the platform specific builder to specify a configuration for the built platform components."
+  )
\ No newline at end of file
diff --git a/deployments/libts/linux-pc/CMakeLists.txt b/deployments/libts/linux-pc/CMakeLists.txt
index 9c798ad..ff1e139 100644
--- a/deployments/libts/linux-pc/CMakeLists.txt
+++ b/deployments/libts/linux-pc/CMakeLists.txt
@@ -37,7 +37,7 @@
 		"components/service/locator/standalone"
 		"components/service/locator/standalone/services/crypto"
 		"components/service/crypto/provider/mbedcrypto"
-		"components/service/crypto/provider/mbedcrypto/entropy_source/mock"
+		"components/service/crypto/provider/mbedcrypto/entropy_adapter/linux"
 		"components/service/crypto/provider/serializer/protobuf"
 		"components/service/crypto/provider/serializer/packed-c"
 		"components/service/secure_storage/client/psa"