mtd: nand: raw: atmel: Add error handling when rb-gpios missing
[platform/kernel/u-boot.git] / cmd / fwu_mdata.c
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2022, Linaro Limited
4  */
5
6 #include <command.h>
7 #include <dm.h>
8 #include <fwu.h>
9 #include <fwu_mdata.h>
10 #include <log.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 #include <linux/types.h>
15
16 static void print_mdata(struct fwu_mdata *mdata)
17 {
18         int i, j;
19         struct fwu_image_entry *img_entry;
20         struct fwu_image_bank_info *img_info;
21
22         printf("\tFWU Metadata\n");
23         printf("crc32: %#x\n", mdata->crc32);
24         printf("version: %#x\n", mdata->version);
25         printf("active_index: %#x\n", mdata->active_index);
26         printf("previous_active_index: %#x\n", mdata->previous_active_index);
27
28         printf("\tImage Info\n");
29         for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
30                 img_entry = &mdata->img_entry[i];
31                 printf("\nImage Type Guid: %pUL\n",
32                        &img_entry->image_type_uuid);
33                 printf("Location Guid: %pUL\n", &img_entry->location_uuid);
34                 for (j = 0; j < CONFIG_FWU_NUM_BANKS; j++) {
35                         img_info = &img_entry->img_bank_info[j];
36                         printf("Image Guid:  %pUL\n", &img_info->image_uuid);
37                         printf("Image Acceptance: %s\n",
38                                img_info->accepted == 0x1 ? "yes" : "no");
39                 }
40         }
41 }
42
43 int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag,
44                      int argc, char * const argv[])
45 {
46         int ret = CMD_RET_SUCCESS, res;
47         struct fwu_mdata mdata;
48
49         res = fwu_get_mdata(&mdata);
50         if (res < 0) {
51                 log_err("Unable to get valid FWU metadata\n");
52                 ret = CMD_RET_FAILURE;
53                 goto out;
54         }
55
56         print_mdata(&mdata);
57
58 out:
59         return ret;
60 }
61
62 U_BOOT_CMD(
63         fwu_mdata_read, 1,      1,      do_fwu_mdata_read,
64         "Read and print FWU metadata",
65         ""
66 );