Integrate RPMB components into the build system

Add RPMB block storage to host libts, component-test build and
ts-service-test builds.

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: Ife45ea753476e9014334b2ccec698337cd719654
diff --git a/components/service/block_storage/config/ref/ref_partition_configurator.h b/components/service/block_storage/config/ref/ref_partition_configurator.h
index 4e15d54..0ca6b7f 100644
--- a/components/service/block_storage/config/ref/ref_partition_configurator.h
+++ b/components/service/block_storage/config/ref/ref_partition_configurator.h
@@ -25,7 +25,7 @@
  */
 
 #define REF_PARTITION_BACK_STORE_SIZE   (200)
-#define REF_PARTITION_BLOCK_SIZE        (512)
+#define REF_PARTITION_BLOCK_SIZE        (256)
 
 /* About the right size for PSA storage */
 #define REF_PARTITION_1_GUID            DISK_GUID_UNIQUE_PARTITION_PSA_ITS
diff --git a/components/service/block_storage/test/service/block_storage_service_tests.cpp b/components/service/block_storage/test/service/block_storage_service_tests.cpp
index fd82ba6..4b256a5 100644
--- a/components/service/block_storage/test/service/block_storage_service_tests.cpp
+++ b/components/service/block_storage/test/service/block_storage_service_tests.cpp
@@ -44,6 +44,7 @@
 	}
 
 	static const uint32_t LOCAL_CLIENT_ID = 1;
+	static const uint32_t SECTOR_SIZE = 512;
 
 	struct block_store *m_block_store;
 	struct uuid_octets m_partition_1_guid;
@@ -61,7 +62,8 @@
 		m_block_store, &m_partition_1_guid, &info);
 
 	LONGS_EQUAL(PSA_SUCCESS, status);
-	LONGS_EQUAL(REF_PARTITION_1_ENDING_LBA - REF_PARTITION_1_STARTING_LBA + 1, info.num_blocks);
+	LONGS_EQUAL(REF_PARTITION_1_ENDING_LBA - REF_PARTITION_1_STARTING_LBA + 1,
+		    info.num_blocks * info.block_size / SECTOR_SIZE);
 	LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
 	MEMCMP_EQUAL(m_partition_1_guid.octets,
 		info.partition_guid.octets, sizeof(info.partition_guid.octets));
@@ -71,7 +73,8 @@
 		m_block_store, &m_partition_2_guid, &info);
 
 	LONGS_EQUAL(PSA_SUCCESS, status);
-	LONGS_EQUAL(REF_PARTITION_2_ENDING_LBA - REF_PARTITION_2_STARTING_LBA + 1, info.num_blocks);
+	LONGS_EQUAL(REF_PARTITION_2_ENDING_LBA - REF_PARTITION_2_STARTING_LBA + 1,
+		    info.num_blocks * info.block_size / SECTOR_SIZE);
 	LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
 	MEMCMP_EQUAL(m_partition_2_guid.octets,
 		info.partition_guid.octets, sizeof(info.partition_guid.octets));
@@ -81,7 +84,8 @@
 		m_block_store, &m_partition_3_guid, &info);
 
 	LONGS_EQUAL(PSA_SUCCESS, status);
-	LONGS_EQUAL(REF_PARTITION_3_ENDING_LBA - REF_PARTITION_3_STARTING_LBA + 1, info.num_blocks);
+	LONGS_EQUAL(REF_PARTITION_3_ENDING_LBA - REF_PARTITION_3_STARTING_LBA + 1,
+		    info.num_blocks * info.block_size / SECTOR_SIZE);
 	LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
 	MEMCMP_EQUAL(m_partition_3_guid.octets,
 		info.partition_guid.octets, sizeof(info.partition_guid.octets));
@@ -91,7 +95,8 @@
 		m_block_store, &m_partition_4_guid, &info);
 
 	LONGS_EQUAL(PSA_SUCCESS, status);
-	LONGS_EQUAL(REF_PARTITION_4_ENDING_LBA - REF_PARTITION_4_STARTING_LBA + 1, info.num_blocks);
+	LONGS_EQUAL(REF_PARTITION_4_ENDING_LBA - REF_PARTITION_4_STARTING_LBA + 1,
+		    info.num_blocks * info.block_size / SECTOR_SIZE);
 	LONGS_EQUAL(REF_PARTITION_BLOCK_SIZE, info.block_size);
 	MEMCMP_EQUAL(m_partition_4_guid.octets,
 		info.partition_guid.octets, sizeof(info.partition_guid.octets));
@@ -181,12 +186,6 @@
 		MEMCMP_EQUAL(write_buffer, read_buffer, sizeof(write_buffer));
 	}
 
-	/* Write again to the first block - this should fail as it's not erased */
-	status = block_store_write(
-		m_block_store, LOCAL_CLIENT_ID, handle, 0,
-		0, write_buffer, sizeof(write_buffer), &num_written);
-	LONGS_EQUAL(PSA_ERROR_STORAGE_FAILURE, status);
-
 	/* Erase a set of blocks */
 	uint64_t erase_begin_lba = 0;
 	size_t erase_len = 3;
diff --git a/components/service/locator/linux/ffa/linuxffa_location_strategy.c b/components/service/locator/linux/ffa/linuxffa_location_strategy.c
index d49c077..a904876 100644
--- a/components/service/locator/linux/ffa/linuxffa_location_strategy.c
+++ b/components/service/locator/linux/ffa/linuxffa_location_strategy.c
@@ -12,6 +12,7 @@
 #include "components/service/block_storage/provider/block_storage_uuid.h"
 #include "components/service/crypto/provider/crypto_uuid.h"
 #include "components/service/fwu/provider/fwu_uuid.h"
+#include "components/service/rpmb/provider/rpmb_uuid.h"
 #include "components/service/secure_storage/frontend/secure_storage_provider/secure_storage_uuid.h"
 #include "components/service/test_runner/provider/test_runner_uuid.h"
 #include <stddef.h>
@@ -66,6 +67,7 @@
 		{"attestation",                 {.uuid = TS_PSA_ATTESTATION_SERVICE_UUID}},
 		{"block-storage",               {.uuid = TS_BLOCK_STORAGE_SERVICE_UUID}},
 		{"fwu",                         {.uuid = TS_FWU_SERVICE_UUID}},
+		{"rpmb",			{.uuid = TS_RPMB_SERVICE_UUID}},
 		{NULL,                          {.uuid = {0}}}
 	};
 
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 87f5346..56f91db 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
@@ -7,7 +7,7 @@
 #include <assert.h>
 #include <cstring>
 #include "service/block_storage/provider/serializer/packed-c/packedc_block_storage_serializer.h"
-#include "service/block_storage/factory/ref_ram_gpt/block_store_factory.h"
+#include "service/block_storage/factory/rpmb/block_store_factory.h"
 #include "block_storage_service_context.h"
 
 block_storage_service_context::block_storage_service_context(const char *sn) :
@@ -26,7 +26,7 @@
 void block_storage_service_context::do_init()
 {
 	/* Create backend block store */
-	m_block_store = ref_ram_gpt_block_store_factory_create();
+	m_block_store = rpmb_block_store_factory_create();
 	assert(m_block_store);
 
 	/* Initialise the block storage service provider */
@@ -44,5 +44,5 @@
 void block_storage_service_context::do_deinit()
 {
 	block_storage_provider_deinit(&m_block_storage_provider);
-	ref_ram_gpt_block_store_factory_destroy(m_block_store);
+	rpmb_block_store_factory_destroy(m_block_store);
 }
diff --git a/components/service/locator/standalone/standalone_env.cpp b/components/service/locator/standalone/standalone_env.cpp
index 9ca80d4..438fc7e 100644
--- a/components/service/locator/standalone/standalone_env.cpp
+++ b/components/service/locator/standalone/standalone_env.cpp
@@ -13,6 +13,7 @@
 #include <service/locator/standalone/services/block-storage/block_storage_service_context.h>
 #include <service/locator/standalone/services/fwu/fwu_service_context.h>
 #include <service/locator/standalone/services/smm-variable/smm_variable_service_context.h>
+#include <service/locator/standalone/services/rpmb/rpmb_service_context.h>
 #include "standalone_location_strategy.h"
 #include "standalone_service_registry.h"
 
@@ -46,5 +47,8 @@
 	static smm_variable_service_context smm_variable_context("sn:trustedfirmware.org:smm-variable:0");
 	standalone_service_registry::instance()->regsiter_service_instance(&smm_variable_context);
 
+	static rpmb_service_context rpmb_context("sn:trustedfirmware.org:rpmb:0");
+	standalone_service_registry::instance()->regsiter_service_instance(&rpmb_context);
+
 	service_locator_register_strategy(standalone_location_strategy());
 }
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index a8718f0..b55706f 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -64,6 +64,7 @@
 		"components/service/locator/standalone/services/attestation"
 		"components/service/locator/standalone/services/block-storage"
 		"components/service/locator/standalone/services/fwu"
+		"components/service/locator/standalone/services/rpmb"
 		"components/service/locator/standalone/services/smm-variable"
 		"components/service/attestation/include"
 		"components/service/attestation/claims"
@@ -91,6 +92,7 @@
 		"components/service/block_storage/block_store/device/null"
 		"components/service/block_storage/block_store/device/file"
 		"components/service/block_storage/block_store/device/file/test"
+		"components/service/block_storage/block_store/device/rpmb"
 		"components/service/block_storage/block_store/client"
 		"components/service/block_storage/block_store/partitioned"
 		"components/service/block_storage/block_store/partitioned/test"
@@ -101,6 +103,7 @@
 		"components/service/block_storage/factory/ref_ram"
 		"components/service/block_storage/factory/ref_ram_gpt"
 		"components/service/block_storage/factory/client"
+		"components/service/block_storage/factory/rpmb"
 		"components/service/fwu/agent"
 		"components/service/fwu/fw_store/banked"
 		"components/service/fwu/fw_store/banked/metadata_serializer/v1"
@@ -160,6 +163,17 @@
 		"components/service/crypto/test/service/extension/key_derivation"
 		"components/service/crypto/test/service/extension/key_derivation/packed-c"
 		"components/service/crypto/test/protocol"
+		"components/service/rpmb/backend"
+		"components/service/rpmb/backend/emulated"
+		"components/service/rpmb/backend/mock"
+		"components/service/rpmb/backend/mock/test"
+		"components/service/rpmb/client"
+		"components/service/rpmb/frontend"
+		"components/service/rpmb/frontend/platform/default"
+		"components/service/rpmb/frontend/platform/mock"
+		"components/service/rpmb/frontend/platform/mock/test"
+		"components/service/rpmb/frontend/test"
+		"components/service/rpmb/provider"
 		"components/service/secure_storage/include"
 		"components/service/secure_storage/frontend/psa/its"
 		"components/service/secure_storage/frontend/psa/its/test"
diff --git a/deployments/libts/linux-pc/CMakeLists.txt b/deployments/libts/linux-pc/CMakeLists.txt
index 60d0995..2660a78 100644
--- a/deployments/libts/linux-pc/CMakeLists.txt
+++ b/deployments/libts/linux-pc/CMakeLists.txt
@@ -46,6 +46,9 @@
 	EXPORT_PUBLIC_INTERFACE_FWU_SERVICE_CONTEXT
 )
 
+# Enable RPMB authentication key write for host tests
+set(RPMB_WRITE_KEY TRUE CACHE BOOL "Enable RPMB Authentication Key Write")
+
 #-------------------------------------------------------------------------------
 #  Components that are specific to deployment in the linux-pc environment.
 #
@@ -75,6 +78,7 @@
 		"components/service/locator/standalone/services/attestation"
 		"components/service/locator/standalone/services/block-storage"
 		"components/service/locator/standalone/services/fwu"
+		"components/service/locator/standalone/services/rpmb"
 		"components/service/locator/standalone/services/smm-variable"
 		"components/service/attestation/include"
 		"components/service/attestation/claims"
@@ -92,6 +96,7 @@
 		"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/device/rpmb"
 		"components/service/block_storage/block_store/partitioned"
 		"components/service/block_storage/block_store/client"
 		"components/service/block_storage/provider"
@@ -100,6 +105,7 @@
 		"components/service/block_storage/config/ref"
 		"components/service/block_storage/factory/ref_ram_gpt"
 		"components/service/block_storage/factory/client"
+		"components/service/block_storage/factory/rpmb"
 		"components/service/crypto/provider"
 		"components/service/crypto/provider/serializer/protobuf"
 		"components/service/crypto/provider/serializer/packed-c"
@@ -116,6 +122,12 @@
 		"components/service/crypto/factory/full"
 		"components/service/crypto/backend/mbedcrypto"
 		"components/service/crypto/backend/mbedcrypto/trng_adapter/linux"
+		"components/service/rpmb/backend"
+		"components/service/rpmb/backend/emulated"
+		"components/service/rpmb/client"
+		"components/service/rpmb/frontend"
+		"components/service/rpmb/frontend/platform/default"
+		"components/service/rpmb/provider"
 		"components/service/secure_storage/include"
 		"components/service/secure_storage/frontend/psa/its"
 		"components/service/secure_storage/frontend/secure_storage_provider"
diff --git a/deployments/ts-service-test/linux-pc/CMakeLists.txt b/deployments/ts-service-test/linux-pc/CMakeLists.txt
index 8e59483..b0cd912 100644
--- a/deployments/ts-service-test/linux-pc/CMakeLists.txt
+++ b/deployments/ts-service-test/linux-pc/CMakeLists.txt
@@ -111,6 +111,8 @@
 		"components/service/fwu/test/fwu_dut_factory/remote_sim"
 		"components/service/fwu/test/metadata_fetcher/volume"
 		"components/service/fwu/test/ref_scenarios"
+		"components/service/rpmb/backend/emulated"
+		"components/service/rpmb/provider"
 		"components/media/volume"
 		"components/media/volume/index"
 		"components/media/volume/base_io_dev"
diff --git a/deployments/ts-service-test/ts-service-test.cmake b/deployments/ts-service-test/ts-service-test.cmake
index 8cefe30..925cedd 100644
--- a/deployments/ts-service-test/ts-service-test.cmake
+++ b/deployments/ts-service-test/ts-service-test.cmake
@@ -53,6 +53,10 @@
 		"components/service/attestation/client/psa"
 		"components/service/attestation/client/provision"
 		"components/service/attestation/test/service"
+		"components/service/rpmb/backend"
+		"components/service/rpmb/client"
+		"components/service/rpmb/frontend"
+		"components/service/rpmb/frontend/platform/default"
 		"protocols/service/crypto/protobuf"
 		"protocols/service/crypto/packed-c"
 		"components/service/secure_storage/include"