Restructure fwu-app deployment

Change fwu-app deployment to be more consistent to existing
deployments:
  - change fwu-app to be a dedicated deployment instead of a
    configuration of an SP.  Change the name to "fwu-tool".
	Change the name of the executable to the same.
  - delete posix environment and:
      - move posix trace implementation to linux-pc environment
	  - move deployment specific files to the deployment directory
  - move fwu-app common files from components/service/fwu/app to
    the new deployment, under src/app

Change-Id: Icf68d39bda34092807f33256f540389cd82d0a46
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/components/service/fwu/app/fwu_app.cpp b/components/app/fwu-tool/app/fwu_app.cpp
similarity index 100%
rename from components/service/fwu/app/fwu_app.cpp
rename to components/app/fwu-tool/app/fwu_app.cpp
diff --git a/components/service/fwu/app/fwu_app.h b/components/app/fwu-tool/app/fwu_app.h
similarity index 100%
rename from components/service/fwu/app/fwu_app.h
rename to components/app/fwu-tool/app/fwu_app.h
diff --git a/components/service/fwu/app/metadata_reader.cpp b/components/app/fwu-tool/app/metadata_reader.cpp
similarity index 100%
rename from components/service/fwu/app/metadata_reader.cpp
rename to components/app/fwu-tool/app/metadata_reader.cpp
diff --git a/components/service/fwu/app/metadata_reader.h b/components/app/fwu-tool/app/metadata_reader.h
similarity index 100%
rename from components/service/fwu/app/metadata_reader.h
rename to components/app/fwu-tool/app/metadata_reader.h
diff --git a/components/service/fwu/app/metadata_v1_reader.cpp b/components/app/fwu-tool/app/metadata_v1_reader.cpp
similarity index 100%
rename from components/service/fwu/app/metadata_v1_reader.cpp
rename to components/app/fwu-tool/app/metadata_v1_reader.cpp
diff --git a/components/service/fwu/app/metadata_v2_reader.cpp b/components/app/fwu-tool/app/metadata_v2_reader.cpp
similarity index 100%
rename from components/service/fwu/app/metadata_v2_reader.cpp
rename to components/app/fwu-tool/app/metadata_v2_reader.cpp
diff --git a/deployments/fwu/env/posix/cmd_print_image_dir.cpp b/components/app/fwu-tool/cmd_print_image_dir.cpp
similarity index 100%
rename from deployments/fwu/env/posix/cmd_print_image_dir.cpp
rename to components/app/fwu-tool/cmd_print_image_dir.cpp
diff --git a/deployments/fwu/env/posix/cmd_print_image_dir.h b/components/app/fwu-tool/cmd_print_image_dir.h
similarity index 86%
rename from deployments/fwu/env/posix/cmd_print_image_dir.h
rename to components/app/fwu-tool/cmd_print_image_dir.h
index 7ae2e01..6a8f91e 100644
--- a/deployments/fwu/env/posix/cmd_print_image_dir.h
+++ b/components/app/fwu-tool/cmd_print_image_dir.h
@@ -8,7 +8,7 @@
 #ifndef CMD_PRINT_IMAGE_DIR_H
 #define CMD_PRINT_IMAGE_DIR_H
 
-#include "service/fwu/app/fwu_app.h"
+#include "app/fwu_app.h"
 
 void cmd_print_image_dir(fwu_app &app);
 
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v1.cpp b/components/app/fwu-tool/cmd_print_metadata_v1.cpp
similarity index 100%
rename from deployments/fwu/env/posix/cmd_print_metadata_v1.cpp
rename to components/app/fwu-tool/cmd_print_metadata_v1.cpp
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v1.h b/components/app/fwu-tool/cmd_print_metadata_v1.h
similarity index 87%
rename from deployments/fwu/env/posix/cmd_print_metadata_v1.h
rename to components/app/fwu-tool/cmd_print_metadata_v1.h
index c31ec68..83ac756 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v1.h
+++ b/components/app/fwu-tool/cmd_print_metadata_v1.h
@@ -8,7 +8,7 @@
 #ifndef CMD_PRINT_METADATA_V1_H
 #define CMD_PRINT_METADATA_V1_H
 
-#include "service/fwu/app/fwu_app.h"
+#include "app/fwu_app.h"
 
 void cmd_print_metadata_v1(fwu_app &app);
 
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v2.cpp b/components/app/fwu-tool/cmd_print_metadata_v2.cpp
similarity index 100%
rename from deployments/fwu/env/posix/cmd_print_metadata_v2.cpp
rename to components/app/fwu-tool/cmd_print_metadata_v2.cpp
diff --git a/deployments/fwu/env/posix/cmd_print_metadata_v2.h b/components/app/fwu-tool/cmd_print_metadata_v2.h
similarity index 87%
rename from deployments/fwu/env/posix/cmd_print_metadata_v2.h
rename to components/app/fwu-tool/cmd_print_metadata_v2.h
index 5377212..fc25886 100644
--- a/deployments/fwu/env/posix/cmd_print_metadata_v2.h
+++ b/components/app/fwu-tool/cmd_print_metadata_v2.h
@@ -8,7 +8,7 @@
 #ifndef CMD_PRINT_METADATA_V2_H
 #define CMD_PRINT_METADATA_V2_H
 
-#include "service/fwu/app/fwu_app.h"
+#include "app/fwu_app.h"
 
 void cmd_print_metadata_v2(fwu_app &app);
 
diff --git a/deployments/fwu/env/posix/cmd_update_image.cpp b/components/app/fwu-tool/cmd_update_image.cpp
similarity index 100%
rename from deployments/fwu/env/posix/cmd_update_image.cpp
rename to components/app/fwu-tool/cmd_update_image.cpp
diff --git a/deployments/fwu/env/posix/cmd_update_image.h b/components/app/fwu-tool/cmd_update_image.h
similarity index 89%
rename from deployments/fwu/env/posix/cmd_update_image.h
rename to components/app/fwu-tool/cmd_update_image.h
index 7091bd2..20f71bc 100644
--- a/deployments/fwu/env/posix/cmd_update_image.h
+++ b/components/app/fwu-tool/cmd_update_image.h
@@ -10,7 +10,7 @@
 
 #include <string>
 
-#include "service/fwu/app/fwu_app.h"
+#include "app/fwu_app.h"
 
 int cmd_update_image(fwu_app &app, const std::string &img_type_uuid,
 		     const std::string &img_filename);
diff --git a/deployments/fwu/env/posix/fwu-posix.cmake b/components/app/fwu-tool/component.cmake
similarity index 75%
rename from deployments/fwu/env/posix/fwu-posix.cmake
rename to components/app/fwu-tool/component.cmake
index 8818fb4..73a8524 100644
--- a/deployments/fwu/env/posix/fwu-posix.cmake
+++ b/components/app/fwu-tool/component.cmake
@@ -9,25 +9,30 @@
 # of the fwu service.
 #-------------------------------------------------------------------------------
 
+if (NOT DEFINED TGT)
+	message(FATAL_ERROR "Mandatory parameter TGT is not defined.")
+endif()
 #-------------------------------------------------------------------------------
 # Common components for fwu posix deployments
 #
 #-------------------------------------------------------------------------------
-add_components(TARGET "fwu"
+add_components(TARGET ${TGT}
 	BASE_DIR ${TS_ROOT}
 	COMPONENTS
-		"environments/posix"
 		"components/common/crc32/native"
 		"components/common/trace"
 		"components/common/utils"
-		"components/service/fwu/app"
 )
 
-target_sources(fwu PRIVATE
+target_sources(${TGT} PRIVATE
 	${CMAKE_CURRENT_LIST_DIR}/fwu_main.cpp
 	${CMAKE_CURRENT_LIST_DIR}/cmd_update_image.cpp
 	${CMAKE_CURRENT_LIST_DIR}/cmd_print_image_dir.cpp
 	${CMAKE_CURRENT_LIST_DIR}/cmd_print_metadata_v1.cpp
 	${CMAKE_CURRENT_LIST_DIR}/cmd_print_metadata_v2.cpp
 	${CMAKE_CURRENT_LIST_DIR}/print_uuid.cpp
+	${CMAKE_CURRENT_LIST_DIR}/app/fwu_app.cpp
+	${CMAKE_CURRENT_LIST_DIR}/app/metadata_reader.cpp
+	${CMAKE_CURRENT_LIST_DIR}/app/metadata_v1_reader.cpp
+	${CMAKE_CURRENT_LIST_DIR}/app/metadata_v2_reader.cpp
 )
\ No newline at end of file
diff --git a/deployments/fwu/env/posix/fwu_main.cpp b/components/app/fwu-tool/fwu_main.cpp
similarity index 98%
rename from deployments/fwu/env/posix/fwu_main.cpp
rename to components/app/fwu-tool/fwu_main.cpp
index 88bac76..ef0fe10 100644
--- a/deployments/fwu/env/posix/fwu_main.cpp
+++ b/components/app/fwu-tool/fwu_main.cpp
@@ -16,7 +16,7 @@
 #include "cmd_print_metadata_v2.h"
 #include "cmd_update_image.h"
 #include "common/uuid/uuid.h"
-#include "service/fwu/app/fwu_app.h"
+#include "app/fwu_app.h"
 
 static bool option_selected(const char *option_switch, int argc, char *argv[]);
 
diff --git a/deployments/fwu/env/posix/print_uuid.cpp b/components/app/fwu-tool/print_uuid.cpp
similarity index 100%
rename from deployments/fwu/env/posix/print_uuid.cpp
rename to components/app/fwu-tool/print_uuid.cpp
diff --git a/deployments/fwu/env/posix/print_uuid.h b/components/app/fwu-tool/print_uuid.h
similarity index 100%
rename from deployments/fwu/env/posix/print_uuid.h
rename to components/app/fwu-tool/print_uuid.h
diff --git a/components/service/fwu/app/component.cmake b/components/service/fwu/app/component.cmake
deleted file mode 100644
index 7b9e5ab..0000000
--- a/components/service/fwu/app/component.cmake
+++ /dev/null
@@ -1,16 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2023, 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}/fwu_app.cpp"
-	"${CMAKE_CURRENT_LIST_DIR}/metadata_reader.cpp"
-	"${CMAKE_CURRENT_LIST_DIR}/metadata_v1_reader.cpp"
-	"${CMAKE_CURRENT_LIST_DIR}/metadata_v2_reader.cpp"
-	)
diff --git a/deployments/fwu-tool/file-block-store.cmake b/deployments/fwu-tool/file-block-store.cmake
new file mode 100644
index 0000000..ea1590b
--- /dev/null
+++ b/deployments/fwu-tool/file-block-store.cmake
@@ -0,0 +1,33 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Lists components that provide an infrastructure layer for the block-storage
+# service provider that uses a ram-backed block store, partitioned by default
+# using the 'ref' configuration. This infrastructure is intended for test
+# purposes.
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+	message(FATAL_ERROR "Mandatory parameter TGT is not defined.")
+endif()
+
+#-------------------------------------------------------------------------------
+# Infrastructure components
+#
+#-------------------------------------------------------------------------------
+add_components(TARGET ${TGT}
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"components/media/disk"
+		"components/media/volume"
+		"components/media/volume/base_io_dev"
+		"components/media/volume/block_volume"
+		"components/media/volume/factory/single_flash"
+		"components/service/block_storage/block_store"
+		"components/service/block_storage/block_store/device"
+		"components/service/block_storage/block_store/device/file"
+		"components/service/block_storage/block_store/partitioned"
+		"components/service/block_storage/factory/file"
+		"components/service/block_storage/config/gpt"
+)
\ No newline at end of file
diff --git a/deployments/fwu-tool/fwu.cmake b/deployments/fwu-tool/fwu.cmake
new file mode 100644
index 0000000..d9cac39
--- /dev/null
+++ b/deployments/fwu-tool/fwu.cmake
@@ -0,0 +1,55 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Common components used for any deployment of the fwu service provider.
+#-------------------------------------------------------------------------------
+
+if (NOT DEFINED TGT)
+	message(FATAL_ERROR "Mandatory parameter TGT is not defined.")
+endif()
+
+#-------------------------------------------------------------------------------
+#  Components common to all deployments
+#
+#-------------------------------------------------------------------------------
+add_components(TARGET ${TGT}
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"components/app/fwu-tool"
+		"components/common/uuid"
+		"components/common/endian"
+		"components/media/disk/gpt_iterator"
+		"components/media/volume/index"
+		"components/service/common/include"
+		"components/service/fwu/agent"
+		"components/service/fwu/config"
+		"components/service/fwu/config/gpt"
+		"components/service/fwu/fw_store/banked"
+		"components/service/fwu/fw_store/banked/metadata_serializer/v1"
+		"components/service/fwu/fw_store/banked/metadata_serializer/v2"
+		"components/service/fwu/installer"
+		"components/service/fwu/installer/raw"
+		"components/service/fwu/installer/copy"
+		"components/service/fwu/installer/factory/default"
+		"components/service/fwu/inspector/direct"
+)
+
+#################################################################
+
+target_include_directories(${TGT} PRIVATE
+	${TS_ROOT}
+	${TS_ROOT}/components
+)
+
+#-------------------------------------------------------------------------------
+#  Define install content.
+#
+#-------------------------------------------------------------------------------
+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 ${TGT}
+		RUNTIME DESTINATION ${TS_ENV}/bin
+		PUBLIC_HEADER DESTINATION ${TS_ENV}/include)
diff --git a/deployments/fwu/config/fwu-app-linux-pc/CMakeLists.txt b/deployments/fwu-tool/linux-pc/CMakeLists.txt
similarity index 78%
rename from deployments/fwu/config/fwu-app-linux-pc/CMakeLists.txt
rename to deployments/fwu-tool/linux-pc/CMakeLists.txt
index 416ee01..e0948c0 100644
--- a/deployments/fwu/config/fwu-app-linux-pc/CMakeLists.txt
+++ b/deployments/fwu-tool/linux-pc/CMakeLists.txt
@@ -5,23 +5,24 @@
 #
 #-------------------------------------------------------------------------------
 cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
-include(../../../deployment.cmake REQUIRED)
+include(../../deployment.cmake REQUIRED)
 
 #-------------------------------------------------------------------------------
-# The CMakeLists.txt for building the fwu deployment for linux-pc
+# The CMakeLists.txt for building the fwu-tool deployment for linux-pc
 #
 # This configuration builds the FWU update agent into a command-line app
 # that can be used to apply updates to disk image files.
 #-------------------------------------------------------------------------------
 project(trusted-services LANGUAGES CXX C)
-add_executable(fwu)
-target_include_directories(fwu PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+add_executable(fwu-tool)
+set(TGT "fwu-tool")
+target_include_directories(fwu-tool PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
 
 #-------------------------------------------------------------------------------
 #  Configure trace output for command-line app
 #
 #-------------------------------------------------------------------------------
-set(TRACE_PREFIX "FWU" CACHE STRING "Trace prefix")
+set(TRACE_PREFIX "fwu-tool" CACHE STRING "Trace prefix")
 set(TRACE_LEVEL "TRACE_LEVEL_DEBUG" CACHE STRING "Trace level")
 
 #-------------------------------------------------------------------------------
@@ -30,7 +31,7 @@
 #-------------------------------------------------------------------------------
 
 # Scale number of partitions for pretty complicated fw images
-target_compile_definitions("fwu" PRIVATE
+target_compile_definitions(${TGT} PRIVATE
     PARTITIONED_BLOCK_STORE_MAX_PARTITIONS=24)
 
 #-------------------------------------------------------------------------------
@@ -38,18 +39,21 @@
 #
 #-------------------------------------------------------------------------------
 include(${TS_ROOT}/environments/linux-pc/env.cmake)
+add_components(TARGET ${TGT}
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS "environments/linux-pc"
+)
 
 #-------------------------------------------------------------------------------
 #  External project source-level dependencies
 #
 #-------------------------------------------------------------------------------
 include(${TS_ROOT}/external/tf_a/tf-a.cmake)
-add_tfa_dependency(TARGET "fwu")
+add_tfa_dependency(TARGET ${TGT})
 
 #-------------------------------------------------------------------------------
 #  Deployment specific components
 #
 #-------------------------------------------------------------------------------
-include(../../env/posix/fwu-posix.cmake REQUIRED)
-include(../../fwu.cmake REQUIRED)
-include(../../infra/file-block-store.cmake REQUIRED)
+include(../fwu.cmake REQUIRED)
+include(../file-block-store.cmake REQUIRED)
diff --git a/environments/posix/component.cmake b/environments/linux-pc/component.cmake
similarity index 100%
rename from environments/posix/component.cmake
rename to environments/linux-pc/component.cmake
diff --git a/environments/posix/posix_trace.c b/environments/linux-pc/posix_trace.c
similarity index 100%
rename from environments/posix/posix_trace.c
rename to environments/linux-pc/posix_trace.c