Integrate block_store backend into PS standalone service context

The standalone service context for the Protected Storage service
has been modified to use the Secure Flash Store with a block store
backend. This makes service testing in the linux_pc environment
closer to testing on real hardware by including block_storage
components in the service deployment.

Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: Ib7ed3e323958b4948a80526c2163cc8b55d4ed74
diff --git a/components/service/locator/standalone/services/protected-storage/ps_service_context.cpp b/components/service/locator/standalone/services/protected-storage/ps_service_context.cpp
index cda49f6..476f510 100644
--- a/components/service/locator/standalone/services/protected-storage/ps_service_context.cpp
+++ b/components/service/locator/standalone/services/protected-storage/ps_service_context.cpp
@@ -1,15 +1,19 @@
 /*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
 #include "ps_service_context.h"
+#include "service/block_storage/factory/client/block_store_factory.h"
+#include "service/block_storage/config/ref/ref_partition_configurator.h"
+#include "service/secure_storage/backend/secure_flash_store/secure_flash_store.h"
 
 ps_service_context::ps_service_context(const char *sn) :
-    standalone_service_context(sn),
-    m_storage_provider(),
-    m_mock_store()
+	standalone_service_context(sn),
+	m_storage_provider(),
+	m_sfs_flash_adapter(),
+	m_block_store(NULL)
 {
 
 }
@@ -21,14 +25,36 @@
 
 void ps_service_context::do_init()
 {
-    struct storage_backend *storage_backend = mock_store_init(&m_mock_store);
-    struct rpc_interface *storage_ep = secure_storage_provider_init(&m_storage_provider, storage_backend);
+	struct uuid_octets guid;
+	const struct sfs_flash_info_t *flash_info = NULL;
 
-    standalone_service_context::set_rpc_interface(storage_ep);
+	uuid_parse_to_octets(REF_PARTITION_2_GUID, guid.octets, sizeof(guid.octets));
+
+	m_block_store = client_block_store_factory_create(
+		"sn:trustedfirmware.org:block-storage:0");
+
+	psa_status_t status = sfs_flash_block_store_adapter_init(
+		&m_sfs_flash_adapter,
+		0,
+		m_block_store,
+		&guid,
+		MIN_FLASH_BLOCK_SIZE,
+		MAX_NUM_FILES,
+		&flash_info);
+
+	if (status == PSA_SUCCESS) {
+
+		struct storage_backend *storage_backend = sfs_init(flash_info);
+		struct rpc_interface *storage_ep = secure_storage_provider_init(
+			&m_storage_provider, storage_backend);
+
+		standalone_service_context::set_rpc_interface(storage_ep);
+	}
 }
 
 void ps_service_context::do_deinit()
 {
-    secure_storage_provider_deinit(&m_storage_provider);
-    mock_store_deinit(&m_mock_store);
+	secure_storage_provider_deinit(&m_storage_provider);
+	client_block_store_factory_destroy(m_block_store);
+	m_block_store = NULL;
 }
diff --git a/components/service/locator/standalone/services/protected-storage/ps_service_context.h b/components/service/locator/standalone/services/protected-storage/ps_service_context.h
index 2e3c46e..81d5c46 100644
--- a/components/service/locator/standalone/services/protected-storage/ps_service_context.h
+++ b/components/service/locator/standalone/services/protected-storage/ps_service_context.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -9,21 +9,26 @@
 
 #include <service/locator/standalone/standalone_service_context.h>
 #include <service/secure_storage/frontend/secure_storage_provider/secure_storage_provider.h>
-#include <service/secure_storage/backend/mock_store/mock_store.h>
+#include <service/secure_storage/backend/secure_flash_store/flash/block_store_adapter/sfs_flash_block_store_adapter.h>
+#include <service/block_storage/block_store/block_store.h>
 
 class ps_service_context : public standalone_service_context
 {
 public:
-    ps_service_context(const char *sn);
-    virtual ~ps_service_context();
+	ps_service_context(const char *sn);
+	virtual ~ps_service_context();
 
 private:
 
-    void do_init();
-    void do_deinit();
+	void do_init();
+	void do_deinit();
 
-    struct secure_storage_provider m_storage_provider;
-    struct mock_store m_mock_store;
+	static const size_t MAX_NUM_FILES = 10;
+	static const size_t MIN_FLASH_BLOCK_SIZE = 4096;
+
+	struct secure_storage_provider m_storage_provider;
+	struct sfs_flash_block_store_adapter m_sfs_flash_adapter;
+	struct block_store *m_block_store;
 };
 
 #endif /* STANDALONE_PS_SERVICE_CONTEXT_H */
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index b2ca483..b5b87aa 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -82,12 +82,14 @@
 		"components/service/block_storage/block_store/device/ram"
 		"components/service/block_storage/block_store/device/ram/test"
 		"components/service/block_storage/block_store/device/null"
+		"components/service/block_storage/block_store/client"
 		"components/service/block_storage/block_store/partitioned"
 		"components/service/block_storage/block_store/partitioned/test"
 		"components/service/block_storage/provider"
 		"components/service/block_storage/provider/serializer/packed-c"
 		"components/service/block_storage/config/ref"
 		"components/service/block_storage/factory/ref_ram"
+		"components/service/block_storage/factory/client"
 		"components/service/crypto/client/cpp"
 		"components/service/crypto/client/cpp/protocol/protobuf"
 		"components/service/crypto/client/cpp/protocol/packed-c"
diff --git a/deployments/libts/linux-pc/CMakeLists.txt b/deployments/libts/linux-pc/CMakeLists.txt
index 832983b..54ec44e 100644
--- a/deployments/libts/linux-pc/CMakeLists.txt
+++ b/deployments/libts/linux-pc/CMakeLists.txt
@@ -67,10 +67,12 @@
 		"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/block_store/client"
 		"components/service/block_storage/provider"
 		"components/service/block_storage/provider/serializer/packed-c"
 		"components/service/block_storage/config/ref"
 		"components/service/block_storage/factory/ref_ram"
+		"components/service/block_storage/factory/client"
 		"components/service/crypto/provider"
 		"components/service/crypto/provider/serializer/protobuf"
 		"components/service/crypto/provider/serializer/packed-c"
@@ -93,6 +95,10 @@
 		"components/service/secure_storage/backend/secure_storage_client"
 		"components/service/secure_storage/backend/mock_store"
 		"components/service/secure_storage/backend/null_store"
+		"components/service/secure_storage/backend/secure_flash_store"
+		"components/service/secure_storage/backend/secure_flash_store/flash_fs"
+		"components/service/secure_storage/backend/secure_flash_store/flash"
+		"components/service/secure_storage/backend/secure_flash_store/flash/block_store_adapter"
 		"components/service/test_runner/provider"
 		"components/service/test_runner/provider/serializer/packed-c"
 		"components/service/test_runner/provider/backend/mock"