diff mbox series

[v2,14/21] cmd: fwu: align the command with metadata version 2

Message ID 20240212074712.3657076-15-sughosh.ganu@linaro.org
State New
Headers show
Series FWU: Migrate FWU metadata to version 2 | expand

Commit Message

Sughosh Ganu Feb. 12, 2024, 7:47 a.m. UTC
Make changes to the fwu_mdata_read command to have it align with the
metadata version 2.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since V1:
* Use the helper functions from the previous patch to access the
  image information in the metadata.

 cmd/fwu_mdata.c | 45 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/cmd/fwu_mdata.c b/cmd/fwu_mdata.c
index 5ecda455df..6d5ed7a187 100644
--- a/cmd/fwu_mdata.c
+++ b/cmd/fwu_mdata.c
@@ -16,6 +16,8 @@ 
 static void print_mdata(struct fwu_mdata *mdata)
 {
 	int i, j;
+	uint8_t num_banks;
+	uint16_t num_images;
 	struct fwu_image_entry *img_entry;
 	struct fwu_image_bank_info *img_info;
 
@@ -25,15 +27,22 @@  static void print_mdata(struct fwu_mdata *mdata)
 	printf("active_index: %#x\n", mdata->active_index);
 	printf("previous_active_index: %#x\n", mdata->previous_active_index);
 
+	num_banks = fwu_get_fw_desc(mdata)->num_banks;
+	num_images = fwu_get_fw_desc(mdata)->num_images;
+
+	for (i = 0; i < 4; i++)
+		printf("bank_state[%d]: %#x\n", i, mdata->bank_state[i]);
+
 	printf("\tImage Info\n");
-	for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
-		img_entry = &mdata->img_entry[i];
+
+	for (i = 0; i < num_images; i++) {
+		img_entry = fwu_img_entry_offset(mdata, i);
 		printf("\nImage Type Guid: %pUL\n",
-		       &img_entry->image_type_uuid);
-		printf("Location Guid: %pUL\n", &img_entry->location_uuid);
-		for (j = 0; j < CONFIG_FWU_NUM_BANKS; j++) {
-			img_info = &img_entry->img_bank_info[j];
-			printf("Image Guid:  %pUL\n", &img_info->image_uuid);
+		       &img_entry->image_type_guid);
+		printf("Location Guid: %pUL\n", &img_entry->location_guid);
+		for (j = 0; j < num_banks; j++) {
+			img_info = fwu_img_bank_info_offset(mdata, i, j);
+			printf("Image Guid:  %pUL\n", &img_info->image_guid);
 			printf("Image Acceptance: %s\n",
 			       img_info->accepted == 0x1 ? "yes" : "no");
 		}
@@ -43,19 +52,35 @@  static void print_mdata(struct fwu_mdata *mdata)
 int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag,
 		     int argc, char * const argv[])
 {
+	uint32_t mdata_size;
+	struct fwu_mdata *mdata = NULL;
 	int ret = CMD_RET_SUCCESS, res;
-	struct fwu_mdata mdata;
 
-	res = fwu_get_mdata(&mdata);
+	res = fwu_get_mdata_size(&mdata_size);
+	if (res) {
+		log_err("Unable to get FWU metadata size\n");
+		ret = CMD_RET_FAILURE;
+		goto out;
+	}
+
+	mdata = malloc(mdata_size);
+	if (!mdata) {
+		log_err("Unable to allocate memory for FWU metadata\n");
+		ret = CMD_RET_FAILURE;
+		goto out;
+	}
+
+	res = fwu_get_mdata(mdata);
 	if (res < 0) {
 		log_err("Unable to get valid FWU metadata\n");
 		ret = CMD_RET_FAILURE;
 		goto out;
 	}
 
-	print_mdata(&mdata);
+	print_mdata(mdata);
 
 out:
+	free(mdata);
 	return ret;
 }