libsp: Add build system files.

- Add opteesp deployment.
    This deployment builds libsp as a static library targeting aarch64
    SPs running under OP-TEE.
- Add inport and export interfaces for OP TEE-OS.
- Add opteesp environment files.
- Add shared CMake scripts including GCC compiler support.

Change-Id: Ie8643756d45d0d96822fd98c4c37e7264a7378a1
Signed-off-by: Gyorgy Szing <gyorgy.szing@arm.com>
diff --git a/deployments/deployment.cmake b/deployments/deployment.cmake
new file mode 100644
index 0000000..6543318
--- /dev/null
+++ b/deployments/deployment.cmake
@@ -0,0 +1,33 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#[===[.rst:
+  The base deployment CMake file
+  ------------------------------
+
+  Contains common CMake definitions that are used by concrete deployments.
+  This file should be included first by a concrete deployment's CMakeLists.txt.
+#]===]
+
+# Sets TS-ROOT which is used as the reference directory for everything contained within the project
+get_filename_component(TS_ROOT "${CMAKE_CURRENT_LIST_DIR}/../" ABSOLUTE CACHE PATH "Trusted Services root directory.")
+
+# Replicate TS_ROOT as environment variable to allow access from child CMake contexts
+set(ENV{TS_ROOT} "${TS_ROOT}")
+
+# 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)
+
+# Check build environment requirements are met
+ts_verify_build_env()
+
+# Project wide include directories
+set(TOP_LEVEL_INCLUDE_DIRS
+  "${TS_ROOT}"
+  "${TS_ROOT}/components"
+  )
diff --git a/deployments/libsp/opteesp/CMakeLists.txt b/deployments/libsp/opteesp/CMakeLists.txt
new file mode 100644
index 0000000..00f10d5
--- /dev/null
+++ b/deployments/libsp/opteesp/CMakeLists.txt
@@ -0,0 +1,132 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  The CMakeLists.txt for building the libsp deployment for opteesp
+#
+#  Used for building the libsp library that provides FFA related functons
+#  for applications deployed in a secure partition.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/opteesp/env.cmake)
+
+file(READ "${CMAKE_CURRENT_LIST_DIR}/version.txt" LIBSP_VERSION)
+project(trusted-services
+			VERSION
+				${LIBSP_VERSION}
+			 LANGUAGES
+				C ASM
+		)
+
+add_library(sp STATIC)
+
+# Include SP DEV KIT interface
+set(SP_DEV_KIT_INC_DIR ${CMAKE_CURRENT_LIST_DIR})
+list(APPEND CMAKE_MODULE_PATH "${TS_ROOT}/external/Spdevkit")
+find_package(Spdevkit COMPONENTS interface)
+
+target_link_libraries(sp PUBLIC ${SP_DEV_KIT_LIBRARIES})
+
+
+add_components(TARGET "sp"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		components/messaging/ffa/libsp
+		components/common/utils
+)
+
+target_compile_definitions("sp" PRIVATE
+	ARM64=1
+)
+
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+	target_compile_options("sp" PRIVATE
+		-fdiagnostics-show-option
+		-fpic
+		-gdwarf-2
+		-mstrict-align
+		-O0
+		-std=gnu99
+	)
+endif()
+
+######################################## install
+if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+	set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
+endif()
+
+install(
+	TARGETS
+		sp
+	EXPORT
+		LibspTargets
+	ARCHIVE	DESTINATION
+		lib
+	PUBLIC_HEADER DESTINATION
+		include
+	COMPONENT
+		libsp
+)
+
+#These would install the spdevkit content.
+#install(FILES $<TARGET_PROPERTY:sp_devkit_ifc,INTERFACE_LINK_LIBRARIES> DESTINATION lib)
+#install(FILES $<TARGET_PROPERTY:sp_devkit_ifc,INTERFACE_INCLUDE_DIRECTORIES>/ DESTINATION include)
+### Create a config file package.
+set(ConfigPackageLocation lib/cmake/libsp)
+
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+	"${CMAKE_CURRENT_BINARY_DIR}/LibspConfigVersion.cmake"
+	VERSION "1.0.0"
+	COMPATIBILITY SameMajorVersion
+)
+
+# Create targets file.
+export(
+	EXPORT
+		LibspTargets
+	FILE
+		"${CMAKE_CURRENT_BINARY_DIR}/LibspTargets.cmake"
+	NAMESPACE
+		libsp::
+)
+
+# Finalize config file.
+configure_package_config_file(
+		LibspConfig.cmake.in
+		"${CMAKE_CURRENT_BINARY_DIR}/LibspConfig.cmake"
+	PATH_VARS
+
+	INSTALL_DESTINATION
+		${ConfigPackageLocation}
+)
+
+install(
+	EXPORT
+		LibspTargets
+	FILE
+		LibspTargets.cmake
+	NAMESPACE
+		libsp::
+	DESTINATION
+		${ConfigPackageLocation}
+	COMPONENT
+		libsp
+)
+
+# install config and version files
+install(
+	FILES
+		"${CMAKE_CURRENT_BINARY_DIR}/LibspConfig.cmake"
+		"${CMAKE_CURRENT_BINARY_DIR}/LibspConfigVersion.cmake"
+		"${TS_ROOT}/external/Spdevkit/FindSpdevkit.cmake"
+	DESTINATION
+		${ConfigPackageLocation}
+	COMPONENT
+		libsp
+)
diff --git a/deployments/libsp/opteesp/LibspConfig.cmake.in b/deployments/libsp/opteesp/LibspConfig.cmake.in
new file mode 100644
index 0000000..cd8d0d6
--- /dev/null
+++ b/deployments/libsp/opteesp/LibspConfig.cmake.in
@@ -0,0 +1,16 @@
+#
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+@PACKAGE_INIT@
+
+# Any user of the lib will depend on spdevkit. Use our find module to get access to it.
+find_package(Spdevkit
+	 COMPONENTS LIBUTIL
+	 PATHS ${CMAKE_CURRENT_LIST_DIR}
+	 NO_DEFAULT_PATH
+	 REQUIRED)
+
+include("${CMAKE_CURRENT_LIST_DIR}/LibspTargets.cmake")
diff --git a/deployments/libsp/opteesp/version.txt b/deployments/libsp/opteesp/version.txt
new file mode 100644
index 0000000..afaf360
--- /dev/null
+++ b/deployments/libsp/opteesp/version.txt
@@ -0,0 +1 @@
+1.0.0
\ No newline at end of file
diff --git a/environments/opteesp/ExportSp.cmake b/environments/opteesp/ExportSp.cmake
new file mode 100644
index 0000000..3040bd0
--- /dev/null
+++ b/environments/opteesp/ExportSp.cmake
@@ -0,0 +1,20 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+foreach(_var IN ITEMS EXPORT_SP_NAME EXPORT_SP_UUID)
+	if(NOT DEFINED ${_var})
+		message(FATAL_ERROR
+				"Input variable ${_var} is undefined! Please define it"
+				"using set(${_var} ...) before including this file.")
+	endif()
+endforeach()
+
+configure_file(${CMAKE_CURRENT_LIST_DIR}/sp.mk.in ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk @ONLY NEWLINE_STYLE UNIX)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk DESTINATION lib/make)
+
+unset(EXPORT_SP_NAME)
+unset(EXPORT_SP_UUID)
diff --git a/environments/opteesp/component.cmake b/environments/opteesp/component.cmake
new file mode 100644
index 0000000..d840249
--- /dev/null
+++ b/environments/opteesp/component.cmake
@@ -0,0 +1,14 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+if (NOT DEFINED TGT)
+	message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+	"${CMAKE_CURRENT_LIST_DIR}/libsp_entry.c"
+	)
diff --git a/environments/opteesp/default_toolchain_file.cmake b/environments/opteesp/default_toolchain_file.cmake
new file mode 100644
index 0000000..76c78d7
--- /dev/null
+++ b/environments/opteesp/default_toolchain_file.cmake
@@ -0,0 +1,22 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#GNUARM v8 and v9 compilers use a different triplet.
+if(NOT DEFINED ENV{CROSS_COMPILE})
+	set(CROSS_COMPILE "aarch64-elf-;aarch64-none-elf-;aarch64-linux-gnu-" CACHE STRING "List of GCC prefix triplets to use.")
+endif()
+
+set(CMAKE_CROSSCOMPILING True)
+set(CMAKE_SYSTEM_NAME Generic)
+set(CMAKE_SYSTEM_PROCESSOR arm)
+set(CMAKE_POSITION_INDEPENDENT_CODE True)
+
+#set(CMAKE_C_FLAGS_INIT --specs=nosys.specs)
+#set(CMAKE_CXX_FLAGS_INIT --specs=nosys.specs)
+#set(CMAKE_EXE_LINKER_FLAGS_INIT --specs=nosys.specs)
+
+include($ENV{TS_ROOT}/tools/cmake/compiler/GCC.cmake REQUIRED)
diff --git a/environments/opteesp/env.cmake b/environments/opteesp/env.cmake
new file mode 100644
index 0000000..1a5c670
--- /dev/null
+++ b/environments/opteesp/env.cmake
@@ -0,0 +1,23 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+#  Environment file for deployments to opteesp.  This is a cross-compiled
+#  enviroment where built executables run within secure partitions
+#  with optee acting as the secure partition manager.
+#-------------------------------------------------------------------------------
+set(TS_ENV "opteesp" CACHE STRING "Environment identifier")
+
+# Default to using the base toolcahin file for the enviroment
+set(TS_BASE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/default_toolchain_file.cmake" CACHE STRING "Base toolchainfile")
+
+# Replicate in environment variable for access from child cmake contexts
+set(ENV{TS_BASE_TOOLCHAIN_FILE} "${TS_BASE_TOOLCHAIN_FILE}")
+
+# Set toolchain files to use
+set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/default_toolchain_file.cmake" CACHE STRING "Toolchain file")
+set(TS_EXTERNAL_LIB_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" CACHE STRING "External lib Toolchain file")
diff --git a/environments/opteesp/libsp_entry.c b/environments/opteesp/libsp_entry.c
new file mode 100644
index 0000000..92c046c
--- /dev/null
+++ b/environments/opteesp/libsp_entry.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "ffa_internal_api.h"
+#include "optee_sp_internal_api.h"
+#include "sp_api.h"
+
+void __noreturn optee_sp_entry(uintptr_t a0, uintptr_t a1, uintptr_t a2,
+			 uintptr_t a3)
+{
+	(void)a1;
+	(void)a2;
+	(void)a3;
+
+	sp_main((struct ffa_init_info *)a0);
+}
+
+void optee_sp_log_puts(const char *str)
+{
+	(void)str;
+}
+
+void __noreturn optee_sp_panic(void)
+{
+	while (1)
+		;
+}
diff --git a/environments/opteesp/sp.mk.in b/environments/opteesp/sp.mk.in
new file mode 100644
index 0000000..fd1bd13
--- /dev/null
+++ b/environments/opteesp/sp.mk.in
@@ -0,0 +1,16 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+ifeq (,${TS_INSTALL_PREFIX})
+    $(error TS_INSTALL_PREFIX is not defined!)
+endif
+
+ifeq (,${@EXPORT_SP_UUID@-included})
+@EXPORT_SP_UUID@-included=y
+endif
+
+OPTEE_OS_COMMON_EXTRA_FLAGS+=EARLY_TA_PATHS+=${TS_INSTALL_PREFIX}/bin/@EXPORT_SP_UUID@.stripped.elf
diff --git a/external/Spdevkit/FindSpdevkit.cmake b/external/Spdevkit/FindSpdevkit.cmake
new file mode 100644
index 0000000..4a5df37
--- /dev/null
+++ b/external/Spdevkit/FindSpdevkit.cmake
@@ -0,0 +1,180 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#[===[.rst:
+  Abstraction to interface to SP DEV KIT.
+  ---------------------------------------
+
+  SP DEV KIT is a component generated by the OP-TEE OS build and defines the
+  FF-A SP interface for the OS to SPs.
+
+  This file provides the following functionality:
+	- creates a static library to easy building the SP side component of the
+	  SP DEV KIT. This library will be properly configured with transitive
+	  dependencies to apply the needed compiler configurations to the
+	  target linking against it.
+	- defines a function to allow configuration of the linking phase of the
+	  executable target. (See: :command:`sp_dev_kit_configure_linking`)
+
+  Inputs:
+  ``SP_DEV_KIT_DIR``
+  A cmake or environment variable specifying the location of the SP DEV KIT.
+  This is mandatory.
+
+  ``SP_DEV_KIT_INC_DIR``
+  The SP DEV KIT depends on some header files living in the SP. This variable
+  must be set to an include path giving access to these headers.
+
+  Outputs:
+  :command:sp_dev_kit_configure_linking()
+
+  :variable:`SP_DEV_KIT_LIBRARIES`
+
+#]===]
+
+# Store SP DEV KIT location to cache.
+# If a cmake variable exist, use it as is.
+# If not, try to copy over the value from the environment.
+if(NOT DEFINED SP_DEV_KIT_DIR AND NOT DEFINED ENV{SP_DEV_KIT_DIR})
+	message(FATAL_ERROR "'SP_DEV_KIT_DIR' is not defined.")
+endif()
+set(SP_DEV_KIT_DIR $ENV{SP_DEV_KIT_DIR} CACHE STRING "SP dev kit from original OP-TEE build system")
+
+if (DEFINED ENV{SP_DEV_KIT_DIR} AND NOT SP_DEV_KIT_DIR STREQUAL "$ENV{SP_DEV_KIT_DIR}")
+	message(WARNING "Suspicious settings: the value of SP_DEV_KIT_DIR in the environment is not matching cmakes settings!")
+endif()
+
+# Find the directories inside SP DEV KIT. This gives more flexibility than when using static settings.
+find_path (SP_DEV_KIT_SRC_DIR
+	NAMES
+		sp_header.c
+	PATHS
+		${SP_DEV_KIT_DIR}
+	PATH_SUFFIXES
+		"src"
+	NO_DEFAULT_PATH
+	REQUIRED
+	DOC
+		"SP DEV KIT source directory"
+	)
+
+find_path (SP_DEV_KIT_INCLUDE_DIR
+	NAMES
+		ffa.h atomic.h compiler.h
+	PATHS
+		${SP_DEV_KIT_DIR}
+	PATH_SUFFIXES
+		"include"
+	NO_DEFAULT_PATH
+	REQUIRED
+	DOC
+		"SP DEV KIT include directory"
+	)
+
+find_path (SP_DEV_KIT_LIB_DIR
+	NAMES
+		${CMAKE_STATIC_LIBRARY_PREFIX}utils${CMAKE_STATIC_LIBRARY_SUFFIX} libutils.a utils.a utils.lib libutils.link_libraries
+	PATHS
+		${SP_DEV_KIT_DIR}
+	PATH_SUFFIXES
+		"lib"
+	NO_DEFAULT_PATH
+	REQUIRED
+	DOC
+		"SP DEV KIT library directory"
+	)
+
+#[===[.rst:
+.. cmake:variable:: SP_DEV_KIT_LIBRARIES
+
+  List of libraries forming the SP DEV KIT interface.
+
+#]===]
+
+# Create an imported target for libutils.a
+add_library(spdevkit::libutils STATIC IMPORTED)
+set_target_properties(spdevkit::libutils PROPERTIES
+	INTERFACE_INCLUDE_DIRECTORIES "${SP_DEV_KIT_INCLUDE_DIR}"
+	INTERFACE_LINK_LIBRARIES "${SP_DEV_KIT_LIB_DIR}/libutils.a"
+	IMPORTED_LOCATION "${SP_DEV_KIT_LIB_DIR}/libutils.a"
+)
+list(APPEND SP_DEV_KIT_LIBRARIES spdevkit::libutils)
+
+if (NOT Spdevkit_FIND_COMPONENTS OR "SP_HEADER" IN_LIST Spdevkit_FIND_COMPONENTS)
+	if (NOT DEFINED SP_DEV_KIT_INC_DIR)
+		message(FATAL_ERROR "Mandatory input variable 'SP_DEV_KIT_INC_DIR' is not defined.")
+	endif()
+
+	# Define a static library to compile the SP side source files and to
+	# capture dependencies (settings).
+	add_library(sp_header STATIC
+		${SP_DEV_KIT_SRC_DIR}/sp_assert.c
+		${SP_DEV_KIT_SRC_DIR}/sp_entry.c
+		${SP_DEV_KIT_SRC_DIR}/sp_header.c
+		${SP_DEV_KIT_SRC_DIR}/sp_trace.c
+		)
+
+	target_include_directories(sp_header
+							PRIVATE
+								${SP_DEV_KIT_INC_DIR}
+							)
+
+	target_link_libraries(sp_header PRIVATE spdevkit::libutils)
+	add_library(spdevkit::sp_header ALIAS sp_header)
+	list(APPEND SP_DEV_KIT_LIBRARIES spdevkit::sp_header)
+endif()
+
+#[===[.rst:
+.. cmake:command:: sp_dev_kit_configure_linking
+
+  .. code-block:: cmake
+
+    sp_dev_kit_configure_linking(TARGET <executable target> DEFINES <list of pre-processor macros>)
+
+  Connect an executable target to SP DEV KIT link requirements:
+	- add rules to run the linker command file trough the pre-processor if needed
+	- configure the target to use the linker command file
+	- link SP DEV KIT libraries to the target
+
+  Inputs:
+
+  ``TARGET``
+  Mandatory. The name of an already defined executable target (add_executable())
+
+  ``DEFINES``
+  Optional. Macro definitions for the pre-processing step.
+
+#]===]
+function(sp_dev_kit_configure_linking)
+	set(options  )
+	set(oneValueArgs TARGET)
+	set(multiValueArgs DEFINES)
+	cmake_parse_arguments(MY_PARAMS "${options}" "${oneValueArgs}"
+						"${multiValueArgs}" ${ARGN} )
+
+	if(NOT DEFINED MY_PARAMS_TARGET)
+		message(FATAL_ERROR "sp_dev_kit_configure_linking: mandatory parameter TARGET not defined!")
+	endif()
+
+	if(NOT DEFINED MY_PARAMS_DEFINES)
+		set(MY_PARAMS_DEFINES "")
+	endif()
+
+	compiler_preprocess_file(
+		SRC ${SP_DEV_KIT_DIR}/src/sp.ld.S
+		DST ${CMAKE_BINARY_DIR}/sp.ld
+		DEFINES ${MY_PARAMS_DEFINES}
+	)
+
+	add_custom_target(${MY_PARAMS_TARGET}-pplscript DEPENDS ${CMAKE_BINARY_DIR}/sp.ld)
+	add_dependencies(${MY_PARAMS_TARGET} ${MY_PARAMS_TARGET}-pplscript)
+
+	target_link_options(${MY_PARAMS_TARGET} PRIVATE
+		-T${CMAKE_BINARY_DIR}/sp.ld
+	)
+endfunction()
+
diff --git a/tools/cmake/common/AddComponents.cmake b/tools/cmake/common/AddComponents.cmake
new file mode 100644
index 0000000..07978bb
--- /dev/null
+++ b/tools/cmake/common/AddComponents.cmake
@@ -0,0 +1,60 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#[===[.rst:
+Add build components to the current build.
+------------------------------------------
+
+#]===]
+
+
+#[===[.rst:
+.. cmake:command:: add_components
+
+	.. code:: cmake
+
+		add_components(TARGET <target name> COMPONENTS <list of component directories>)
+
+	INPUTS:
+
+	``BASE_DIR``
+	If defined components are include relative to this directory. If nor paths must be
+	relative to CMAKE_SOURCE_DIR or be absolute.
+
+	``TARGET``
+	The name of an already defined target to add components to.
+
+	``COMPONENTS``
+	List of components relative to :cmake:variable:`CMAKE_SOURCE_DIR`
+
+#]===]
+
+function(add_components)
+	set(options  )
+	set(oneValueArgs TARGET BASE_DIR)
+	set(multiValueArgs COMPONENTS)
+	cmake_parse_arguments(MY_PARAMS "${options}" "${oneValueArgs}"
+						"${multiValueArgs}" ${ARGN} )
+
+	if(NOT DEFINED MY_PARAMS_TARGET)
+		message(FATAL_ERROR "add_component: mandatory parameter TARGET not defined!")
+	endif()
+	if(NOT DEFINED MY_PARAMS_COMPONENTS)
+		message(FATAL_ERROR "add_component: mandatory parameter COMPONENTS not defined!")
+	endif()
+	if(DEFINED MY_PARAMS_BASE_DIR AND NOT MY_PARAMS_BASE_DIR MATCHES ".*/$")
+		set(MY_PARAMS_BASE_DIR "${MY_PARAMS_BASE_DIR}/")
+	endif()
+
+	set(TGT ${MY_PARAMS_TARGET} CACHE STRING "")
+	foreach(_comp IN ITEMS ${MY_PARAMS_COMPONENTS})
+		set(_file ${MY_PARAMS_BASE_DIR}${_comp}/component.cmake)
+		include(${_file})
+		set(CMAKE_CONFIGURE_DEPENDS ${_file})
+	endforeach()
+	unset(TGT CACHE)
+endfunction()
diff --git a/tools/cmake/common/ExportLibrary.cmake b/tools/cmake/common/ExportLibrary.cmake
new file mode 100644
index 0000000..670f318
--- /dev/null
+++ b/tools/cmake/common/ExportLibrary.cmake
@@ -0,0 +1,72 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#[===[.rst:
+.. cmake:command:: export_library
+
+	.. code:: cmake
+
+		export_library(TARGET LIB_NAME INTERFACE_FILES)
+
+	INPUTS:
+
+	``TARGET``
+	The name of an already defined target that corresponds to the library.
+
+	``LIB_NAME``
+	The name of the library.
+
+	``INTERFACE_FILES``
+	List of header files to declare the library's public interface.
+
+#]===]
+function(export_library)
+	set(options  )
+	set(oneValueArgs TARGET LIB_NAME)
+	set(multiValueArgs INTERFACE_FILES)
+	cmake_parse_arguments(MY_PARAMS "${options}" "${oneValueArgs}"
+						"${multiValueArgs}" ${ARGN} )
+
+	if(NOT DEFINED MY_PARAMS_TARGET)
+		message(FATAL_ERROR "export_library: mandatory parameter TARGET not defined!")
+	endif()
+	if(NOT DEFINED MY_PARAMS_LIB_NAME)
+		message(FATAL_ERROR "export_library: mandatory parameter LIB_NAME not defined!")
+	endif()
+
+	# Set default install location if none specified
+	if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+		set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
+	endif()
+
+	# Specify export name and destinations for install
+	install(
+		TARGETS ${MY_PARAMS_TARGET}
+		EXPORT ${MY_PARAMS_LIB_NAME}_targets
+		ARCHIVE
+			DESTINATION lib
+		LIBRARY
+			DESTINATION lib
+		PUBLIC_HEADER
+			DESTINATION include
+	)
+
+	# Install library header files files
+	install(
+		FILES ${MY_PARAMS_INTERFACE_FILES}
+		DESTINATION include
+	)
+
+	# Install the export details
+	install(
+		EXPORT ${MY_PARAMS_LIB_NAME}_targets
+		FILE ${MY_PARAMS_LIB_NAME}_targets.cmake
+		NAMESPACE ${MY_PARAMS_LIB_NAME}::
+		DESTINATION lib/cmake
+		COMPONENT ${MY_PARAMS_LIB_NAME}
+	)
+endfunction()
diff --git a/tools/cmake/common/Utils.cmake b/tools/cmake/common/Utils.cmake
new file mode 100644
index 0000000..c889320
--- /dev/null
+++ b/tools/cmake/common/Utils.cmake
@@ -0,0 +1,51 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#[===[.rst:
+Misc utilities
+--------------
+#]===]
+
+include_guard(DIRECTORY)
+
+#[===[.rst:
+.. cmake:command:: check_args
+
+  .. code-block:: cmake
+
+    check_args(func_name REQ_ARG1 REQ_ARG2)
+
+  Helper macro for argument checking in functions. First argument *func_name* is
+  the name of the function, other arguments are the names of the required
+  arguments to that function. The macro iterates through the list, and prints
+  and error message if not all arguments are defined.
+
+#]===]
+macro(check_args)
+	set(_argv "${ARGV}")
+	list(SUBLIST _argv 0 1 _func)
+	list(SUBLIST _argv 1 -1 _args)
+	foreach(_arg IN LISTS _args)
+		if (NOT DEFINED _MY_PARAMS_${_arg})
+			message(FATAL_ERROR "${_func}(): mandatory parameter '${_arg}' missing.")
+		endif()
+	endforeach()
+endmacro()
+
+# Verify MSYS environment.
+function(ts_verify_build_env)
+    if (WIN32)
+        #On MSYS2 64 bit builds do not work. Verify environment.
+        execute_process(COMMAND uname -s
+                        OUTPUT_VARIABLE _os_name)
+        #If uname is present we assume MSYS environment and the os name must
+        #contain MING32.
+        if(_os_name STREQUAL "" AND NOT _os_name MATCHES ".*MINGW32.*")
+            message(FATAL_ERROR "This seems to be a 64 bit MINGW shell, which has issues. Please run the 32bit version.")
+        endif()
+    endif()
+endFunction()
diff --git a/tools/cmake/compiler/GCC.cmake b/tools/cmake/compiler/GCC.cmake
new file mode 100644
index 0000000..d061d11
--- /dev/null
+++ b/tools/cmake/compiler/GCC.cmake
@@ -0,0 +1,240 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2019-2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#[===[.rst:
+Compiler abstraction for GCC
+----------------------------
+
+.. cmake:variable:: CROSS_COMPILE
+
+	A ';' separated GCC prefix triplets to use when searching for the cross-compiler.
+	(i.e. ``aarch64-none-elf;aarch64-elf``).
+	The variable can be set on the command line with ``-DCROSS_COMPILE=<value>`` or in the
+	environment. If both is specified, command line takes precedence.
+
+#]===]
+
+include_guard(DIRECTORY)
+
+if(NOT CROSS_COMPILE AND NOT DEFINED ENV{CROSS_COMPILE})
+	message(FATAL_ERROR "'CROSS_COMPILE' is not defined. Set if to the gcc pferix triplet, ie. cmake <..>-DCROSS_COMPILE=aarch64-elf-")
+endif()
+
+set(CROSS_COMPILE $ENV{CROSS_COMPILE} CACHE STRING "Prefix of the cross-compiler commands")
+
+#Generate a list of tool names to look for. Store the result in CMAKE_<lang>_COMPILER.
+function(gcc_find_tool NAME LANG)
+	string(REGEX REPLACE "([^;]+);" "\\1${NAME};\\1${NAME}.exe;" _gcc_names "${CROSS_COMPILE};")
+	find_program(_cross_compile_gcc NAMES ${_gcc_names} REQUIRED)
+	if (NOT _cross_compile_gcc)
+		string(REPLACE ";" " " _msg "${_gcc_names}")
+		message(FATAL_ERROR "Failed to find ${NAME} with the names: ${_msg}")
+	endif()
+	set(CMAKE_${LANG}_COMPILER ${_cross_compile_gcc} CACHE STRING "${LANG} compiler executable.")
+endfunction()
+
+gcc_find_tool(gcc C)
+gcc_find_tool(g++ CXX)
+
+#Official solution to disable compiler checks
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+
+#By default when INTERFACE_INCUDES of libraryes linked to an exe are treated
+#as system includes. gcc-arm-8.2-2019.01-i686-mingw32-aarch64-elf (gcc 8.2.1) will
+#set C linkage o these files, which will result in compilation errors for C++ projects.
+#This setting fixes that.
+set(CMAKE_NO_SYSTEM_FROM_IMPORTED True)
+
+#[===[.rst:
+.. cmake:command:: compiler_preprocess_file
+
+  .. code-block:: cmake
+
+    compiler_preprocess_file(SRC file.c DST file_pp.c)
+    compiler_preprocess_file(SRC file.c DST file_pp.c
+                             DEFINES USE_LIB INCLUDES include/lib)
+
+  Run the preprocessor on a file and save the output to another file. Optionally
+  provide defines and include paths to the preprocessor.
+
+  Inputs:
+
+  ``SRC``
+    Name of the source file to preprocess.
+
+  ``DST``
+    Where to write the preprocessed output.
+
+  ``DEFINES`` (multi, optional)
+    Definitions for the preprocessor.
+
+  ``INCLUDES`` (multi, optional)
+    Include paths for the preprocessor.
+
+#]===]
+function(compiler_preprocess_file)
+	set(_OPTIONS_ARGS)
+	set(_ONE_VALUE_ARGS SRC DST)
+	set(_MULTI_VALUE_ARGS DEFINES INCLUDES)
+	cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
+
+	check_args(compiler_preprocess_file SRC DST)
+
+	set(_flags "")
+	if(_MY_PARAMS_DEFINES)
+		list(TRANSFORM _MY_PARAMS_DEFINES PREPEND -D)
+		list(APPEND _flags ${_MY_PARAMS_DEFINES})
+	endif()
+	if(_MY_PARAMS_INCLUDES)
+		list(TRANSFORM _MY_PARAMS_INCLUDES PREPEND -I)
+		list(APPEND _flags ${_MY_PARAMS_INCLUDES})
+	endif()
+
+	add_custom_command(
+		DEPENDS ${_MY_PARAMS_SRC} OUTPUT ${_MY_PARAMS_DST}
+		COMMAND ${CMAKE_C_COMPILER} -E -P -x assembler-with-cpp ${_flags}
+				${_MY_PARAMS_SRC} -o ${_MY_PARAMS_DST}
+	)
+endfunction()
+
+#[===[.rst:
+.. cmake:command:: compiler_set_linker_script
+
+  .. code-block:: cmake
+
+    compiler_set_linker_script(TARGET foo FILE foo.ld.S)
+    compiler_set_linker_script(TARGET foo FILE foo.ld.S DEF USE_LIB INC include/lib)
+
+  Set linker script for a target. The function adds an LDFLAG using the
+  toolchain specific syntax to the TARGET_linker_script group, which is applied
+  onto the target by the caller function. FILE will be preprocessed, optionally
+  defines and/or includes can be provided using DEF/INC arguments.
+
+  Inputs:
+
+  ``TARGET``
+    Name of the target.
+
+  ``FILE``
+    Linker script file for the target.
+
+  ``DEF`` (multi, optional)
+    Defines for the linker script preprocessor.
+
+  ``INC`` (multi, optional)
+    Include paths for the linker script preprocessor.
+
+#]===]
+function(compiler_set_linker_script)
+	set(_OPTIONS_ARGS)
+	set(_ONE_VALUE_ARGS TARGET FILE)
+	set(_MULTI_VALUE_ARGS DEF INC)
+	cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
+
+	check_args(compiler_set_linker_script TARGET FILE)
+
+	get_filename_component(_src "${_MY_PARAMS_FILE}" ABSOLUTE)
+	get_filename_component(_src_ext "${_MY_PARAMS_FILE}" EXT)
+	set(_dst "${CMAKE_BINARY_DIR}/${_MY_PARAMS_TARGET}.ld")
+
+	if(NOT ("${_src_ext}" STREQUAL ".ld" OR "${_src_ext}" STREQUAL ".ld.S"))
+		message(WARNING "compiler_set_linker_script(): extension mismatch '${_src}'")
+	endif()
+
+	compiler_preprocess_file(
+		SRC ${_src}
+		DST ${_dst}
+		DEFINES ${_MY_PARAMS_DEF} __LINKER__
+		INCLUDES ${_MY_PARAMS_INC}
+	)
+
+	add_custom_target("${_MY_PARAMS_TARGET}_ld" DEPENDS "${_dst}")
+	add_dependencies("${_MY_PARAMS_TARGET}" "${_MY_PARAMS_TARGET}_ld")
+
+	group_add(NAME "${_MY_PARAMS_TARGET}_linker_script" TYPE CONFIG KEY "LINK_DEPENDS" VAL "${_dst}")
+	group_add(NAME "${_MY_PARAMS_TARGET}_linker_script" TYPE LDFLAG KEY "-Wl,--script" VAL "${_dst}")
+endfunction()
+
+#[===[.rst:
+.. cmake:command:: compiler_generate_binary_output
+
+  .. code-block:: cmake
+
+    compiler_generate_binary_output(TARGET <name> RES <var>)
+
+  Generate binary output for the target. The function converts the output
+  executable into bin file using toolchain specific syntax.
+
+  Inputs:
+
+  ``TARGET``
+    Name of the target.
+
+  Outputs:
+
+  ``RES``
+    Full patch to output file.
+
+#]===]
+function(compiler_generate_binary_output)
+	set(options)
+	set(oneValueArgs TARGET)
+	set(multiValueArgs)
+	cmake_parse_arguments(MY "${options}" "${oneValueArgs}"
+						"${multiValueArgs}" ${ARGN} )
+	add_custom_command(
+		TARGET ${MY_TARGET} POST_BUILD
+		COMMAND ${CMAKE_OBJCOPY} -O binary
+				$<TARGET_FILE:${MY_TARGET}>
+				$<TARGET_FILE_DIR:${MY_TARGET}>/${MY_TARGET}.bin)
+	if (MY_RES)
+		set(${MY_RES} $<TARGET_FILE_DIR:${MY_TARGET}>/${MY_TARGET}.bin PARENT_SCOPE)
+	endif()
+
+endfunction()
+
+#[===[.rst:
+.. cmake:command:: compiler_generate_stripped_elf
+
+  .. code-block:: cmake
+
+    compiler_generate_stripped_elf(TARGET foo NAME foo.stripped.elf RES var)
+
+  Strip all symbols that are not needed for relocation processing and return the location
+  of the result.
+
+  Inputs:
+
+  ``TARGET``
+    Name of the target.
+
+  ``NAME``
+    Name of output file
+
+  Outputs:
+
+  ``RES``
+    Name of variable to store the full path of the stripped executable.
+
+#]===]
+
+function(compiler_generate_stripped_elf)
+	set(options)
+	set(oneValueArgs TARGET NAME RES)
+	set(multiValueArgs)
+	cmake_parse_arguments(MY "${options}" "${oneValueArgs}"
+						"${multiValueArgs}" ${ARGN} )
+
+	add_custom_command(
+		TARGET ${MY_TARGET} POST_BUILD
+		COMMAND ${CMAKE_OBJCOPY} --strip-unneeded
+				$<TARGET_FILE:${MY_TARGET}>
+				$<TARGET_FILE_DIR:${MY_TARGET}>/${MY_NAME})
+	if (MY_RES)
+		set(${MY_RES} $<TARGET_FILE_DIR:${MY_TARGET}>/${MY_NAME} PARENT_SCOPE)
+	endif()
+endfunction()