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/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