blob: 5b5a2e4d1cda4a4b14bf80fa44c58a621c2f78a0 [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>
Michal Simek19892ed2025-03-21 11:25:48 +010010#include <hexdump.h>
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053011#include <log.h>
12#include <stdio.h>
13#include <stdlib.h>
14
15#include <linux/types.h>
16
Sughosh Ganu90ec2452024-03-22 16:27:27 +053017static void print_mdata(struct fwu_data *data)
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053018{
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");
Sughosh Ganu90ec2452024-03-22 16:27:27 +053024 printf("crc32: %#x\n", data->crc32);
25 printf("version: %#x\n", data->version);
Michal Simekd8d53db2024-06-05 16:58:27 +020026 printf("size: %#x\n", data->metadata_size);
Sughosh Ganu90ec2452024-03-22 16:27:27 +053027 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 }
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053035
36 printf("\tImage Info\n");
37 for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
Sughosh Ganu90ec2452024-03-22 16:27:27 +053038 img_entry = &data->fwu_images[i];
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053039 printf("\nImage Type Guid: %pUL\n",
Sughosh Ganu90ec2452024-03-22 16:27:27 +053040 &img_entry->image_type_guid);
41 printf("Location Guid: %pUL\n", &img_entry->location_guid);
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053042 for (j = 0; j < CONFIG_FWU_NUM_BANKS; j++) {
43 img_info = &img_entry->img_bank_info[j];
Sughosh Ganu90ec2452024-03-22 16:27:27 +053044 printf("Image Guid: %pUL\n", &img_info->image_guid);
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053045 printf("Image Acceptance: %s\n",
46 img_info->accepted == 0x1 ? "yes" : "no");
47 }
48 }
Michal Simek19892ed2025-03-21 11:25:48 +010049
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 }
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053073}
74
75int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag,
76 int argc, char * const argv[])
77{
Sughosh Ganu90ec2452024-03-22 16:27:27 +053078 struct fwu_data *data = fwu_get_data();
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053079
Sughosh Ganu90ec2452024-03-22 16:27:27 +053080 print_mdata(data);
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053081
Sughosh Ganu90ec2452024-03-22 16:27:27 +053082 return CMD_RET_SUCCESS;
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053083}
84
85U_BOOT_CMD(
86 fwu_mdata_read, 1, 1, do_fwu_mdata_read,
87 "Read and print FWU metadata",
88 ""
89);