Add block storage standalone service context

To support service level testing of the block storage service, a
standalone service context has been added that constructs a
service provider with backend storage for testing via the standard
service RPC interface.

Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I866da635d0a6563cae9ed4de92f915107a5e3de5
diff --git a/components/service/locator/standalone/services/block-storage/block_storage_service_context.cpp b/components/service/locator/standalone/services/block-storage/block_storage_service_context.cpp
new file mode 100644
index 0000000..5173d9f
--- /dev/null
+++ b/components/service/locator/standalone/services/block-storage/block_storage_service_context.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+#include <cstring>
+#include "block_storage_service_context.h"
+
+block_storage_service_context::block_storage_service_context(const char *sn) :
+	standalone_service_context(sn),
+	m_block_storage_provider(),
+	m_ram_block_store(),
+	m_partitioned_block_store()
+{
+
+}
+
+block_storage_service_context::~block_storage_service_context()
+{
+
+}
+
+void block_storage_service_context::do_init()
+{
+	/* Initialize a ram_block_store to use as the back store */
+	struct uuid_octets back_store_guid;
+	memset(&back_store_guid, 0, sizeof(back_store_guid));
+
+	struct block_store *back_store = ram_block_store_init(
+		&m_ram_block_store,
+		&back_store_guid,
+		1000,
+		512);
+	assert(back_store);
+
+	/* Stack a partitioned_block_store over the back store */
+	struct block_store *front_store = partitioned_block_store_init(
+		&m_partitioned_block_store,
+		0,
+		&back_store_guid,
+		back_store);
+	assert(front_store);
+
+	/* Initialise the block storage service provider */
+	struct rpc_interface *rpc_iface = block_storage_provider_init(
+		&m_block_storage_provider,
+		front_store);
+	assert(rpc_iface);
+
+	standalone_service_context::set_rpc_interface(rpc_iface);
+}
+
+void block_storage_service_context::do_deinit()
+{
+	block_storage_provider_deinit(&m_block_storage_provider);
+	partitioned_block_store_deinit(&m_partitioned_block_store);
+	ram_block_store_deinit(&m_ram_block_store);
+}
diff --git a/components/service/locator/standalone/services/block-storage/block_storage_service_context.h b/components/service/locator/standalone/services/block-storage/block_storage_service_context.h
new file mode 100644
index 0000000..81a03dd
--- /dev/null
+++ b/components/service/locator/standalone/services/block-storage/block_storage_service_context.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef STANDALONE_BLOCK_STORAGE_SERVICE_CONTEXT_H
+#define STANDALONE_BLOCK_STORAGE_SERVICE_CONTEXT_H
+
+#include <service/locator/standalone/standalone_service_context.h>
+#include <rpc/direct/direct_caller.h>
+#include <service/block_storage/provider/block_storage_provider.h>
+#include <service/block_storage/block_store/device/ram/ram_block_store.h>
+#include <service/block_storage/block_store/partitioned/partitioned_block_store.h>
+
+class block_storage_service_context : public standalone_service_context
+{
+public:
+	block_storage_service_context(const char *sn);
+	virtual ~block_storage_service_context();
+
+private:
+
+	void do_init();
+	void do_deinit();
+
+	struct block_storage_provider m_block_storage_provider;
+	struct ram_block_store m_ram_block_store;
+	struct partitioned_block_store m_partitioned_block_store;
+};
+
+#endif /* STANDALONE_BLOCK_STORAGE_SERVICE_CONTEXT_H */
diff --git a/components/service/locator/standalone/services/block-storage/component.cmake b/components/service/locator/standalone/services/block-storage/component.cmake
new file mode 100644
index 0000000..68f258b
--- /dev/null
+++ b/components/service/locator/standalone/services/block-storage/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2022, 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}/block_storage_service_context.cpp"
+	)
diff --git a/components/service/locator/standalone/standalone_env.cpp b/components/service/locator/standalone/standalone_env.cpp
index 7f7ce13..c9d7ba1 100644
--- a/components/service/locator/standalone/standalone_env.cpp
+++ b/components/service/locator/standalone/standalone_env.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -10,6 +10,7 @@
 #include <service/locator/standalone/services/protected-storage/ps_service_context.h>
 #include <service/locator/standalone/services/test-runner/test_runner_service_context.h>
 #include <service/locator/standalone/services/attestation/attestation_service_context.h>
+#include <service/locator/standalone/services/block-storage/block_storage_service_context.h>
 #include <service/locator/standalone/services/smm-variable/smm_variable_service_context.h>
 #include "standalone_location_strategy.h"
 #include "standalone_service_registry.h"
@@ -31,6 +32,9 @@
 	static attestation_service_context attestation_context("sn:trustedfirmware.org:attestation:0");
 	standalone_service_registry::instance()->regsiter_service_instance(&attestation_context);
 
+	static block_storage_service_context block_storage_context("sn:trustedfirmware.org:block-storage:0");
+	standalone_service_registry::instance()->regsiter_service_instance(&block_storage_context);
+
 	static smm_variable_service_context smm_variable_context("sn:trustedfirmware.org:smm-variable:0");
 	standalone_service_registry::instance()->regsiter_service_instance(&smm_variable_context);
 
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index 532ae21..541dd35 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -52,6 +52,7 @@
 		"components/service/locator/standalone/services/protected-storage"
 		"components/service/locator/standalone/services/test-runner"
 		"components/service/locator/standalone/services/attestation"
+		"components/service/locator/standalone/services/block-storage"
 		"components/service/locator/standalone/services/smm-variable"
 		"components/service/discovery/client"
 		"components/service/discovery/provider"
diff --git a/deployments/libts/linux-pc/CMakeLists.txt b/deployments/libts/linux-pc/CMakeLists.txt
index 2fe21ec..1b76d4c 100644
--- a/deployments/libts/linux-pc/CMakeLists.txt
+++ b/deployments/libts/linux-pc/CMakeLists.txt
@@ -47,6 +47,7 @@
 		"components/service/locator/standalone/services/protected-storage"
 		"components/service/locator/standalone/services/test-runner"
 		"components/service/locator/standalone/services/attestation"
+		"components/service/locator/standalone/services/block-storage"
 		"components/service/locator/standalone/services/smm-variable"
 		"components/service/attestation/include"
 		"components/service/attestation/claims"
@@ -61,6 +62,12 @@
 		"components/service/attestation/key_mngr/local"
 		"components/service/attestation/provider"
 		"components/service/attestation/provider/serializer/packed-c"
+		"components/service/block_storage/block_store"
+		"components/service/block_storage/block_store/device"
+		"components/service/block_storage/block_store/device/ram"
+		"components/service/block_storage/block_store/partitioned"
+		"components/service/block_storage/provider"
+		"components/service/block_storage/provider/serializer/packed-c"
 		"components/service/crypto/provider"
 		"components/service/crypto/provider/serializer/protobuf"
 		"components/service/crypto/provider/serializer/packed-c"