diff mbox series

[13/18] cmd: fwu: Align the command with metadata version 2

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

Commit Message

Sughosh Ganu Jan. 22, 2024, 11:54 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>
---
 cmd/fwu_mdata.c | 43 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/cmd/fwu_mdata.c b/cmd/fwu_mdata.c
index 5ecda455df..7d99b8287f 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 = mdata->fw_desc[0].num_banks;
+	num_images = mdata->fw_desc[0].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 = &mdata->fw_desc[0].img_entry[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_entry->image_type_guid);
+		printf("Location Guid: %pUL\n", &img_entry->location_guid);
+		for (j = 0; j < num_banks; j++) {
 			img_info = &img_entry->img_bank_info[j];
-			printf("Image Guid:  %pUL\n", &img_info->image_uuid);
+			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;
 }