From 03f0a1ac1450223ff2aa9be116e918230371048e Mon Sep 17 00:00:00 2001
From: Vishnu Banavath <vishnu.banavath@arm.com>
Date: Fri, 17 Dec 2021 19:50:25 +0000
Subject: [PATCH 17/27] efi_firmware: add get_image_info for corstone1000

This change is to populate get_image_info which eventually
will be populated in ESRT table

Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com>
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Upstream-Status: Pending [Not submitted to upstream yet]
---
 lib/efi_loader/efi_firmware.c | 72 ++++++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index 93e2b01c07a6..0a38a96351ff 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -18,11 +18,69 @@
 
 #define FMP_PAYLOAD_HDR_SIGNATURE	SIGNATURE_32('M', 'S', 'S', '1')
 
+#if CONFIG_IS_ENABLED(TARGET_CORSTONE1000)
+#define EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID \
+	EFI_GUID(0xe2bb9c06, 0x70e9, 0x4b14, 0x97, 0xa3, \
+		 0x5a, 0x79, 0x13, 0x17, 0x6e, 0x3f)
+
+ const efi_guid_t efi_firmware_image_type_uboot_raw =
+				EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID;
+
+static efi_status_t efi_corstone1000_img_info_get (
+	efi_uintn_t *image_info_size,
+	struct efi_firmware_image_descriptor *image_info,
+	u32 *descriptor_version,
+	u8 *descriptor_count,
+	efi_uintn_t *descriptor_size,
+	u32 *package_version,
+	u16 **package_version_name,
+	const efi_guid_t *image_type)
+{
+	int i = 0;
+
+	*image_info_size = sizeof(*image_info);
+	*descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;
+	*descriptor_count = 1;//dfu_num;
+	*descriptor_size = sizeof(*image_info);
+	if (package_version)
+		*package_version = 0xffffffff; /* not supported */
+	if(package_version_name)
+		*package_version_name = NULL; /* not supported */
+
+	if(image_info == NULL) {
+		log_warning("image_info is null\n");
+		return EFI_BUFFER_TOO_SMALL;
+	}
+
+	image_info[i].image_index = i;
+	image_info[i].image_type_id = *image_type;
+	image_info[i].image_id = 0;
+	image_info[i].image_id_name = "wic";
+	image_info[i].version = 1;
+	image_info[i].version_name = NULL;
+	image_info[i].size = 0x1000;
+	image_info[i].attributes_supported = IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
+					     IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
+	image_info[i].attributes_setting = IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;
+	/* Check if the capsule authentication is enabled */
+	if (IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE))
+		image_info[0].attributes_setting |=
+			IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
+	image_info[i].lowest_supported_image_version = 0;
+	image_info[i].last_attempt_version = 0;
+	image_info[i].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;
+	image_info[i].hardware_instance = 1;
+	image_info[i].dependencies = NULL;
+
+	return EFI_SUCCESS;
+}
+#endif
+
 /**
  * struct fmp_payload_header - EDK2 header for the FMP payload
  *
  * This structure describes the header which is preprended to the
- * FMP payload by the edk2 capsule generation scripts.
+ * FMP payload by the edk1 capsule generation scripts.
  *
  * @signature:			Header signature used to identify the header
  * @header_size:		Size of the structure
@@ -286,10 +344,18 @@ efi_status_t EFIAPI efi_firmware_get_image_info(
 	     !descriptor_size || !package_version || !package_version_name))
 		return EFI_EXIT(EFI_INVALID_PARAMETER);
 
+#if CONFIG_IS_ENABLED(TARGET_CORSTONE1000)
+	ret = efi_corstone1000_img_info_get(image_info_size, image_info,
+			       descriptor_version, descriptor_count,
+			       descriptor_size,
+			       package_version, package_version_name,
+			       &efi_firmware_image_type_uboot_raw);
+#else
 	ret = efi_fill_image_desc_array(image_info_size, image_info,
 					descriptor_version, descriptor_count,
 					descriptor_size, package_version,
 					package_version_name);
+#endif
 
 	return EFI_EXIT(ret);
 }
@@ -415,6 +481,10 @@ efi_status_t EFIAPI efi_firmware_raw_set_image(
 		}
 	}
 
+#if CONFIG_IS_ENABLED(TARGET_CORSTONE1000)
+	return EFI_EXIT(EFI_SUCCESS);
+#endif
+
 	if (dfu_write_by_alt(image_index - 1, (void *)image, image_size,
 			     NULL, NULL))
 		return EFI_EXIT(EFI_DEVICE_ERROR);
-- 
2.39.1

