blob: 5ecda455df6e1b3f852850d5ce4a36b85f810e26 [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{
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053046 int ret = CMD_RET_SUCCESS, res;
Jassi Brara1df12f2023-03-06 17:18:41 -060047 struct fwu_mdata mdata;
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053048
Jassi Brarf7522552023-03-06 17:18:48 -060049 res = fwu_get_mdata(&mdata);
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053050 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
58out:
59 return ret;
60}
61
62U_BOOT_CMD(
63 fwu_mdata_read, 1, 1, do_fwu_mdata_read,
64 "Read and print FWU metadata",
65 ""
66);