blob: f04af27de63203581b58b93e7588a27d7bdc6ecd [file] [log] [blame]
Sughosh Ganu0f951fd2022-10-21 18:16:04 +05301/* 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
16static 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
43int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag,
44 int argc, char * const argv[])
45{
46 struct udevice *dev;
47 int ret = CMD_RET_SUCCESS, res;
48 struct fwu_mdata mdata = { 0 };
49
50 if (uclass_get_device(UCLASS_FWU_MDATA, 0, &dev) || !dev) {
51 log_err("Unable to get FWU metadata device\n");
52 return CMD_RET_FAILURE;
53 }
54
55 res = fwu_check_mdata_validity();
56 if (res < 0) {
57 log_err("FWU Metadata check failed\n");
58 ret = CMD_RET_FAILURE;
59 goto out;
60 }
61
62 res = fwu_get_mdata(dev, &mdata);
63 if (res < 0) {
64 log_err("Unable to get valid FWU metadata\n");
65 ret = CMD_RET_FAILURE;
66 goto out;
67 }
68
69 print_mdata(&mdata);
70
71out:
72 return ret;
73}
74
75U_BOOT_CMD(
76 fwu_mdata_read, 1, 1, do_fwu_mdata_read,
77 "Read and print FWU metadata",
78 ""
79);