Add reference partition configurator
Adds a component to set-up a reference storage partition configuration
to support test. Real block store deployments will use a dynamic
configuration loaded from a GPT or some other source.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I54ab14fb1dc3196c3485bbeb3f94169c7d0bc78e
diff --git a/components/service/block_storage/config/ref/component.cmake b/components/service/block_storage/config/ref/component.cmake
new file mode 100644
index 0000000..b03b1c2
--- /dev/null
+++ b/components/service/block_storage/config/ref/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}/ref_partition_configurator.c"
+ )
diff --git a/components/service/block_storage/config/ref/ref_partition_configurator.c b/components/service/block_storage/config/ref/ref_partition_configurator.c
new file mode 100644
index 0000000..c880afd
--- /dev/null
+++ b/components/service/block_storage/config/ref/ref_partition_configurator.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <assert.h>
+#include <stddef.h>
+#include "ref_partition_configurator.h"
+
+bool ref_partition_configure(struct partitioned_block_store *subject)
+{
+ struct uuid_octets guid;
+
+ size_t parsed_uuid_len =
+ uuid_parse_to_octets(REF_PARTITION_1_GUID, guid.octets, sizeof(guid.octets));
+ assert(parsed_uuid_len);
+ bool is_success = partitioned_block_store_add_partition(
+ subject,
+ &guid,
+ REF_PARTITION_1_STARTING_LBA,
+ REF_PARTITION_1_ENDING_LBA,
+ 0, NULL);
+
+ if (!is_success)
+ return false;
+
+ parsed_uuid_len =
+ uuid_parse_to_octets(REF_PARTITION_2_GUID, guid.octets, sizeof(guid.octets));
+ assert(parsed_uuid_len);
+ is_success = partitioned_block_store_add_partition(
+ subject,
+ &guid,
+ REF_PARTITION_2_STARTING_LBA,
+ REF_PARTITION_2_ENDING_LBA,
+ 0, NULL);
+
+ if (!is_success)
+ return false;
+
+ parsed_uuid_len =
+ uuid_parse_to_octets(REF_PARTITION_3_GUID, guid.octets, sizeof(guid.octets));
+ assert(parsed_uuid_len);
+ is_success = partitioned_block_store_add_partition(
+ subject,
+ &guid,
+ REF_PARTITION_3_STARTING_LBA,
+ REF_PARTITION_3_ENDING_LBA,
+ 0, NULL);
+
+ if (!is_success)
+ return false;
+
+ parsed_uuid_len =
+ uuid_parse_to_octets(REF_PARTITION_4_GUID, guid.octets, sizeof(guid.octets));
+ assert(parsed_uuid_len);
+ is_success = partitioned_block_store_add_partition(
+ subject,
+ &guid,
+ REF_PARTITION_4_STARTING_LBA,
+ REF_PARTITION_4_ENDING_LBA,
+ 0, NULL);
+
+ return is_success;
+}
diff --git a/components/service/block_storage/config/ref/ref_partition_configurator.h b/components/service/block_storage/config/ref/ref_partition_configurator.h
new file mode 100644
index 0000000..81aa108
--- /dev/null
+++ b/components/service/block_storage/config/ref/ref_partition_configurator.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef REF_PARTITION_CONFIGURATOR_H
+#define REF_PARTITION_CONFIGURATOR_H
+
+#include <stdbool.h>
+#include "service/block_storage/block_store/partitioned/partitioned_block_store.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * To support test, a reference storage partition configuration is used with
+ * a set of different sized partitions. The total backend block store size
+ * is kept as small as possible to allow the reference configuration to be
+ * used with a ram backed store in environments where available memory is
+ * constrained.
+ */
+
+#define REF_PARTITION_BACK_STORE_SIZE (200)
+#define REF_PARTITION_BLOCK_SIZE (512)
+
+/* About the right size for PSA storage */
+#define REF_PARTITION_1_GUID "92f7d53b-127e-432b-815c-9a95b80d69b7"
+#define REF_PARTITION_1_STARTING_LBA (0)
+#define REF_PARTITION_1_ENDING_LBA (95)
+
+/* Also about the right size for PSA storage */
+#define REF_PARTITION_2_GUID "701456da-9b50-49b2-9722-47510f851ccd"
+#define REF_PARTITION_2_STARTING_LBA (96)
+#define REF_PARTITION_2_ENDING_LBA (191)
+
+#define REF_PARTITION_3_GUID "c39ef8a6-ec97-4883-aa64-025f40f7d922"
+#define REF_PARTITION_3_STARTING_LBA (192)
+#define REF_PARTITION_3_ENDING_LBA (195)
+
+#define REF_PARTITION_4_GUID "c3d82065-58f3-4fcb-a8fc-772434bfc91d"
+#define REF_PARTITION_4_STARTING_LBA (196)
+#define REF_PARTITION_4_ENDING_LBA (199)
+
+/**
+ * \brief Configures a partitioned_block_store with the reference configuration
+ *
+ * \param[in] subject The subject partitioned_block_store
+ */
+bool ref_partition_configure(struct partitioned_block_store *subject);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* REF_PARTITION_CONFIGURATOR_H */
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
index 5173d9f..4629cd7 100644
--- 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
@@ -6,6 +6,8 @@
#include <assert.h>
#include <cstring>
+#include "service/block_storage/config/ref/ref_partition_configurator.h"
+#include "service/block_storage/provider/serializer/packed-c/packedc_block_storage_serializer.h"
#include "block_storage_service_context.h"
block_storage_service_context::block_storage_service_context(const char *sn) :
@@ -31,8 +33,8 @@
struct block_store *back_store = ram_block_store_init(
&m_ram_block_store,
&back_store_guid,
- 1000,
- 512);
+ REF_PARTITION_BACK_STORE_SIZE,
+ REF_PARTITION_BLOCK_SIZE);
assert(back_store);
/* Stack a partitioned_block_store over the back store */
@@ -43,12 +45,20 @@
back_store);
assert(front_store);
+ /* Use the reference partition configuration */
+ ref_partition_configure(&m_partitioned_block_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);
+ block_storage_provider_register_serializer(
+ &m_block_storage_provider,
+ TS_RPC_ENCODING_PACKED_C,
+ packedc_block_storage_serializer_instance());
+
standalone_service_context::set_rpc_interface(rpc_iface);
}
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index 541dd35..d5edf4f 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -86,6 +86,7 @@
"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/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 1b76d4c..e034e80 100644
--- a/deployments/libts/linux-pc/CMakeLists.txt
+++ b/deployments/libts/linux-pc/CMakeLists.txt
@@ -31,6 +31,7 @@
COMPONENTS
"components/rpc/direct"
"components/common/tlv"
+ "components/common/uuid"
"components/common/endian"
"components/common/utils"
"components/common/trace"
@@ -68,6 +69,7 @@
"components/service/block_storage/block_store/partitioned"
"components/service/block_storage/provider"
"components/service/block_storage/provider/serializer/packed-c"
+ "components/service/block_storage/config/ref"
"components/service/crypto/provider"
"components/service/crypto/provider/serializer/protobuf"
"components/service/crypto/provider/serializer/packed-c"