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 <hexdump.h>
11 #include <log.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14
15 #include <linux/types.h>
16
print_mdata(struct fwu_data * data)17 static void print_mdata(struct fwu_data *data)
18 {
19 int i, j;
20 struct fwu_image_entry *img_entry;
21 struct fwu_image_bank_info *img_info;
22
23 printf("\tFWU Metadata\n");
24 printf("crc32: %#x\n", data->crc32);
25 printf("version: %#x\n", data->version);
26 printf("size: %#x\n", data->metadata_size);
27 printf("active_index: %#x\n", data->active_index);
28 printf("previous_active_index: %#x\n", data->previous_active_index);
29
30 if (data->version == 2) {
31 for (i = 0; i < 4; i++)
32 printf("bank_state[%d]: %#x\n",
33 i, data->bank_state[i]);
34 }
35
36 printf("\tImage Info\n");
37 for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
38 img_entry = &data->fwu_images[i];
39 printf("\nImage Type Guid: %pUL\n",
40 &img_entry->image_type_guid);
41 printf("Location Guid: %pUL\n", &img_entry->location_guid);
42 for (j = 0; j < CONFIG_FWU_NUM_BANKS; j++) {
43 img_info = &img_entry->img_bank_info[j];
44 printf("Image Guid: %pUL\n", &img_info->image_guid);
45 printf("Image Acceptance: %s\n",
46 img_info->accepted == 0x1 ? "yes" : "no");
47 }
48 }
49
50 if (data->version == 2) {
51 struct fwu_mdata *mdata = data->fwu_mdata;
52 struct fwu_fw_store_desc *desc;
53 void *end;
54 u32 diff;
55
56 /*
57 * fwu_mdata defines only header that's why taking it as array
58 * which exactly point to image description location
59 */
60 desc = (struct fwu_fw_store_desc *)&mdata[1];
61
62 /* Number of entries is taken from for loop - variable i */
63 end = &desc->img_entry[i];
64 debug("mdata %p, desc %p, end %p\n", mdata, desc, end);
65
66 diff = data->metadata_size - ((void *)end - (void *)mdata);
67 if (diff) {
68 printf("Custom fields covered by CRC len: 0x%x\n", diff);
69 print_hex_dump_bytes("CUSTOM ", DUMP_PREFIX_OFFSET,
70 end, diff);
71 }
72 }
73 }
74
do_fwu_mdata_read(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])75 int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag,
76 int argc, char * const argv[])
77 {
78 struct fwu_data *data = fwu_get_data();
79
80 print_mdata(data);
81
82 return CMD_RET_SUCCESS;
83 }
84
85 U_BOOT_CMD(
86 fwu_mdata_read, 1, 1, do_fwu_mdata_read,
87 "Read and print FWU metadata",
88 ""
89 );
90