Add fwu deployment configuration for SP

Extends fwu deployment with a configuration for running the
update agent within an SP. To support FVP/Qemu based testing,
secure flash is implemented using a file residing on the host
PC, accessed using semihosting.

Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I216db494129d32822cb8e2011b0924fa1cc4e978
diff --git a/deployments/fwu/config/default-opteesp/CMakeLists.txt b/deployments/fwu/config/default-opteesp/CMakeLists.txt
new file mode 100644
index 0000000..3a00d45
--- /dev/null
+++ b/deployments/fwu/config/default-opteesp/CMakeLists.txt
@@ -0,0 +1,103 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
+
+# Set default platform.
+set(TS_PLATFORM "arm/fvp/fvp_base_revc-2xaemv8a" CACHE STRING "Target platform location.")
+include(../../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  The CMakeLists.txt for building the default fwu deployment for opteesp
+#
+#  Builds the fwu service provider for running in an SEL0 secure partition
+#  hosted by OPTEE in the role of SPM.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/opteesp/env.cmake)
+project(trusted-services LANGUAGES C ASM)
+add_executable(fwu)
+target_include_directories(fwu PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+set(SP_UUID_CANON "6823a838-1b06-470e-9774-0cce8bfb53fd")
+set(SP_HEAP_SIZE "32 * 1024" CACHE STRING "SP heap size in bytes")
+include(${TS_ROOT}/tools/cmake/common/TargetCompileDefinitions.cmake)
+set_target_uuids(
+	SP_UUID ${SP_UUID_CANON}
+	SP_NAME "fwu"
+)
+
+target_include_directories(fwu PRIVATE
+	${CMAKE_CURRENT_LIST_DIR}
+)
+
+#-------------------------------------------------------------------------------
+#  Configure trace output
+#
+#-------------------------------------------------------------------------------
+set(TRACE_PREFIX "FWU" CACHE STRING "Trace prefix")
+set(TRACE_LEVEL "TRACE_LEVEL_DEBUG" CACHE STRING "Trace level")
+
+#-------------------------------------------------------------------------------
+#  Deployment specific components
+#
+#-------------------------------------------------------------------------------
+add_components(TARGET "fwu"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"environments/opteesp"
+)
+
+include(../../env/commonsp/fwu_sp.cmake REQUIRED)
+include(../../infra/semihosted-block-store.cmake REQUIRED)
+include(../../fwu.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  Set target platform to provide drivers needed by the deployment
+#
+#-------------------------------------------------------------------------------
+add_platform(TARGET "fwu")
+
+#-------------------------------------------------------------------------------
+#  Deployment specific build options
+#-------------------------------------------------------------------------------
+target_compile_definitions(fwu PRIVATE
+	ARM64=1
+)
+
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+	target_compile_options(fwu PRIVATE
+		-std=c99
+	)
+
+endif()
+
+compiler_generate_stripped_elf(TARGET fwu NAME "${SP_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
+
+#-------------------------------------------------------------------------------
+#  Deployment specific install options
+#-------------------------------------------------------------------------------
+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()
+#TODO: api headers
+
+install(TARGETS fwu
+			PUBLIC_HEADER DESTINATION ${TS_ENV}/include
+			RUNTIME DESTINATION ${TS_ENV}/bin
+		)
+install(FILES ${STRIPPED_ELF} DESTINATION ${TS_ENV}/bin)
+
+get_property(_PROTO_FILES TARGET fwu PROPERTY PROTOBUF_FILES)
+install(FILES ${_PROTO_FILES} DESTINATION ${TS_ENV}/lib/protobuf)
+
+include(${TS_ROOT}/tools/cmake/common/ExportSp.cmake)
+export_sp(
+	SP_UUID_CANON ${SP_UUID_CANON}
+	SP_UUID_LE ${SP_UUID_LE}
+	SP_NAME "fwu"
+	MK_IN ${TS_ROOT}/environments/opteesp/sp.mk.in
+	DTS_IN ${CMAKE_CURRENT_LIST_DIR}/default_fwu.dts.in
+	JSON_IN ${TS_ROOT}/environments/opteesp/sp_pkg.json.in
+)
diff --git a/deployments/fwu/config/default-opteesp/default_fwu.dts.in b/deployments/fwu/config/default-opteesp/default_fwu.dts.in
new file mode 100644
index 0000000..b850174
--- /dev/null
+++ b/deployments/fwu/config/default-opteesp/default_fwu.dts.in
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+@DTS_TAG@
+
+@DTS_NODE@ {
+	compatible = "arm,ffa-manifest-1.0";
+	ffa-version = <0x00010000>; /* 31:16 - Major, 15:0 - Minor */
+	uuid = <@EXPORT_SP_UUID_DT@>;
+	description = "FWU";
+	execution-ctx-count = <1>;
+	exception-level = <1>; /* S-EL0 */
+	execution-state = <0>; /* AArch64 */
+	xlat-granule = <0>; /* 4KiB */
+	messaging-method = <3>; /* Direct messaging only */
+	elf-format = <1>;
+};
diff --git a/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h b/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h
new file mode 100644
index 0000000..66cd9f2
--- /dev/null
+++ b/deployments/fwu/config/default-opteesp/optee_sp_user_defines.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+ */
+
+#ifndef OPTEE_SP_USER_DEFINES_H
+#define OPTEE_SP_USER_DEFINES_H
+
+#define OPTEE_SP_FLAGS				0
+
+/* Provisioned stack size */
+#define OPTEE_SP_STACK_SIZE			(64 * 1024)
+
+#endif /* SP_HEADER_DEFINES_H */
diff --git a/deployments/fwu/config/default-sp/CMakeLists.txt b/deployments/fwu/config/default-sp/CMakeLists.txt
new file mode 100644
index 0000000..dcc62da
--- /dev/null
+++ b/deployments/fwu/config/default-sp/CMakeLists.txt
@@ -0,0 +1,97 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
+
+# Set default platform.
+set(TS_PLATFORM "arm/fvp/fvp_base_revc-2xaemv8a" CACHE STRING "Target platform location.")
+include(../../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  The CMakeLists.txt for building the fwu deployment for generic sp
+#  environment.
+#
+#  Builds the fwu service provider for running in an SEL0 secure
+#  partition hosted by any SPM.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/sp/env.cmake)
+set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type")
+project(trusted-services LANGUAGES C ASM)
+add_executable(fwu)
+target_include_directories(fwu PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+set(SP_NAME "fwu")
+set(SP_UUID_CANON "6823a838-1b06-470e-9774-0cce8bfb53fd")
+set(SP_UUID_LE "0x38a82368 0x0e47061b 0xce0c7497 0xfd53fb8b")
+set(SP_STACK_SIZE "64 * 1024" CACHE STRING "Stack size")
+set(SP_HEAP_SIZE "32 * 1024" CACHE STRING "Heap size")
+
+#-------------------------------------------------------------------------------
+#  Configure trace output
+#
+#-------------------------------------------------------------------------------
+set(TRACE_PREFIX "FWU" CACHE STRING "Trace prefix")
+set(TRACE_LEVEL "TRACE_LEVEL_DEBUG" CACHE STRING "Trace level")
+
+#-------------------------------------------------------------------------------
+#  Components that are specific to deployment in the sp environment.
+#
+#-------------------------------------------------------------------------------
+add_components(TARGET "fwu"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		environments/sp
+)
+
+include(../../env/commonsp/fwu_sp.cmake REQUIRED)
+include(../../infra/semihosted-block-store.cmake REQUIRED)
+include(../../fwu.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  Set target platform to provide drivers needed by the deployment
+#
+#-------------------------------------------------------------------------------
+add_platform(TARGET "fwu")
+
+#-------------------------------------------------------------------------------
+#  Deployment specific build options
+#-------------------------------------------------------------------------------
+target_compile_definitions(fwu PRIVATE
+	ARM64=1
+)
+
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+	target_compile_options(fwu PRIVATE
+		-std=c99
+	)
+
+endif()
+
+compiler_generate_binary_output(TARGET fwu NAME "${SP_UUID_CANON}.bin" SP_BINARY)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SP_UUID_CANON}.bin DESTINATION ${TS_ENV}/bin)
+
+include(${TS_ROOT}/tools/cmake/common/ExportMemoryRegionsToManifest.cmake REQUIRED)
+export_memory_regions_to_manifest(TARGET fwu NAME "${SP_UUID_CANON}_memory_regions.dtsi" RES EXPORT_MEMORY_REGIONS_DTSI)
+
+#-------------------------------------------------------------------------------
+#  Deployment specific install options
+#-------------------------------------------------------------------------------
+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 fwu
+			PUBLIC_HEADER DESTINATION ${TS_ENV}/include
+			RUNTIME DESTINATION ${TS_ENV}/bin
+		)
+
+include(${TS_ROOT}/tools/cmake/common/ExportSp.cmake)
+export_sp(
+	SP_UUID_CANON ${SP_UUID_CANON}
+	SP_UUID_LE ${SP_UUID_LE}
+	SP_NAME ${SP_NAME}
+	DTS_IN ${CMAKE_CURRENT_LIST_DIR}/default_${SP_NAME}.dts.in
+	DTS_MEM_REGIONS ${SP_UUID_CANON}_memory_regions.dtsi
+	JSON_IN ${TS_ROOT}/environments/sp/sp_pkg.json.in
+)
diff --git a/deployments/fwu/config/default-sp/default_fwu.dts.in b/deployments/fwu/config/default-sp/default_fwu.dts.in
new file mode 100644
index 0000000..dabba0b
--- /dev/null
+++ b/deployments/fwu/config/default-sp/default_fwu.dts.in
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+@DTS_TAG@
+
+@DTS_NODE@ {
+	compatible = "arm,ffa-manifest-1.0";
+	ffa-version = <0x00010000>; /* 31:16 - Major, 15:0 - Minor */
+	uuid = <@EXPORT_SP_UUID_DT@>;
+	description = "FWU";
+	execution-ctx-count = <1>;
+	exception-level = <1>; /* S-EL0 */
+	execution-state = <0>; /* AArch64 */
+	xlat-granule = <0>; /* 4KiB */
+	messaging-method = <3>; /* Direct messaging only */
+};