From 5344d7d0580ca7f2f2569f388dd6e3cd17a372f2 Mon Sep 17 00:00:00 2001
From: Harsimran Singh Tungal <harsimransingh.tungal@arm.com>
Date: Thu, 6 Feb 2025 10:26:04 +0000
Subject: [PATCH 3/8] Corstone1000: Define PSA FWU image mapping structure

This commit involves following changes

1. Define PSA FWU image mapping structure for Corstone-1000.
This structure is responsible to map specific image guid with
component number.
To enable platform-specific handling, service_proxy_factory.c now
conditionally selects the appropriate image mapping
based on PLATFORM_IS_FVP. This ensures that both FVP and MPS3
platforms use the correct GUID and firmware update configuration.

2. Rename RSS to RSE

Upstream-Status: Pending
Signed-off-by: Harsimran Singh Tungal <harsimransingh.tungal@arm.com>
Signed-off-by: Ali Can Ozaslan <ali.oezaslan@arm.com>
---
 .../infra/corstone1000/corstone1000_config.h  | 28 +++++++++++++++++++
 .../corstone1000/service_proxy_factory.c      | 25 +++++++++++++----
 2 files changed, 48 insertions(+), 5 deletions(-)
 create mode 100644 deployments/se-proxy/infra/corstone1000/corstone1000_config.h

diff --git a/deployments/se-proxy/infra/corstone1000/corstone1000_config.h b/deployments/se-proxy/infra/corstone1000/corstone1000_config.h
new file mode 100644
index 00000000..319401f3
--- /dev/null
+++ b/deployments/se-proxy/infra/corstone1000/corstone1000_config.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2025, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef CORSTONE1000_CONFIG_H
+#define CORSTONE1000_CONFIG_H
+
+#define FWU_IMAGE_COUNT 1
+
+/* Maximum payload size to be transferred at once to Secure Enclave */
+#define MAX_PAYLOAD_SIZE 4096
+
+#define CORSTONE1000_FVP_FULL_CAPSULE_UUID  \
+{ 0x4e, 0x3a, 0x9f, 0x98, 0xe0, 0x46, 0xd0, 0x4c, 0x98, 0x77, 0xa2, 0x5c, 0x70, 0xc0, 0x13, 0x29, }
+
+#define CORSTONE1000_MPS3_FULL_CAPSULE_UUID  \
+{ 0xd1, 0x65, 0x18, 0xdf, 0xfb, 0x90, 0x59, 0x4d, 0x9c, 0x38, 0xc9, 0xf2, 0xc1, 0xbb, 0xa8, 0xcc, }
+
+/* Image indexes in the UEFI capsule */
+enum fwu_image_index
+{
+	FWU_IMAGE_INDEX_FULL_CAPSULE = 1,
+};
+
+#endif /* CORSTONE1000_CONFIG_H */
diff --git a/deployments/se-proxy/infra/corstone1000/service_proxy_factory.c b/deployments/se-proxy/infra/corstone1000/service_proxy_factory.c
index ef91efe0..6e5f1221 100644
--- a/deployments/se-proxy/infra/corstone1000/service_proxy_factory.c
+++ b/deployments/se-proxy/infra/corstone1000/service_proxy_factory.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2021-2025, Arm Limited and Contributors. All rights reserved.
  * Copyright (c) 2021-2023, Linaro Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
@@ -19,6 +19,7 @@
 #include <service/secure_storage/frontend/secure_storage_provider/secure_storage_provider.h>
 #include "service/secure_storage/frontend/secure_storage_provider/secure_storage_uuid.h"
 #include <trace.h>
+#include "corstone1000_config.h"
 
 /* backends */
 #include <service/crypto/backend/psa_ipc/crypto_ipc_backend.h>
@@ -27,6 +28,20 @@
 
 static const struct rpc_uuid dummy_uuid = { 0 };
 
+static const struct psa_fwu_m_image_mapping img_mapping[FWU_IMAGE_COUNT] = {
+#if PLATFORM_IS_FVP
+	{
+		.uuid = CORSTONE1000_FVP_FULL_CAPSULE_UUID,
+		.component = FWU_IMAGE_INDEX_FULL_CAPSULE
+	},
+#else
+	{
+		.uuid = CORSTONE1000_MPS3_FULL_CAPSULE_UUID,
+		.component = FWU_IMAGE_INDEX_FULL_CAPSULE
+	},
+#endif
+};
+
 struct rpc_service_interface *attest_proxy_create(void)
 {
 	struct rpc_service_interface *attest_iface = NULL;
@@ -141,20 +156,20 @@ struct rpc_service_interface *fwu_proxy_create(void)
 	static struct fwu_provider fwu_provider = { 0 };
 
 	/* Static objects for proxy instance */
-	static struct rpc_caller_interface rss_comms = { 0 };
+	static struct rpc_caller_interface rse_comms = { 0 };
 	static struct rpc_caller_session rpc_session = { 0 };
 
-	rpc_status = rss_comms_caller_init(&rss_comms);
+	rpc_status = rse_comms_caller_init(&rse_comms);
 	if (rpc_status != RPC_SUCCESS)
 		return NULL;
 
-	rpc_status = rpc_caller_session_open(&rpc_session, &rss_comms, &dummy_uuid, 0, 0);
+	rpc_status = rpc_caller_session_open(&rpc_session, &rse_comms, &dummy_uuid, 0, 0);
 	if (rpc_status != RPC_SUCCESS)
 		return NULL;
 
-	agent = psa_fwu_m_update_agent_init(NULL, 0, 4096);
 	if (psa_fwu_ipc_init(&rpc_session) != PSA_SUCCESS)
 		return NULL;
+	agent = psa_fwu_m_update_agent_init(img_mapping, FWU_IMAGE_COUNT, MAX_PAYLOAD_SIZE);
 
 	return fwu_provider_init(&fwu_provider, agent);
 }
-- 
2.25.1

