blob: 3c8be576ac7ac509959cfe9c3df15549f329413a [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
Sughosh Ganu90ec2452024-03-22 16:27:27 +053016static void print_mdata(struct fwu_data *data)
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053017{
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");
Sughosh Ganu90ec2452024-03-22 16:27:27 +053023 printf("crc32: %#x\n", data->crc32);
24 printf("version: %#x\n", data->version);
25 printf("active_index: %#x\n", data->active_index);
26 printf("previous_active_index: %#x\n", data->previous_active_index);
27
28 if (data->version == 2) {
29 for (i = 0; i < 4; i++)
30 printf("bank_state[%d]: %#x\n",
31 i, data->bank_state[i]);
32 }
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053033
34 printf("\tImage Info\n");
35 for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
Sughosh Ganu90ec2452024-03-22 16:27:27 +053036 img_entry = &data->fwu_images[i];
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053037 printf("\nImage Type Guid: %pUL\n",
Sughosh Ganu90ec2452024-03-22 16:27:27 +053038 &img_entry->image_type_guid);
39 printf("Location Guid: %pUL\n", &img_entry->location_guid);
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053040 for (j = 0; j < CONFIG_FWU_NUM_BANKS; j++) {
41 img_info = &img_entry->img_bank_info[j];
Sughosh Ganu90ec2452024-03-22 16:27:27 +053042 printf("Image Guid: %pUL\n", &img_info->image_guid);
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053043 printf("Image Acceptance: %s\n",
44 img_info->accepted == 0x1 ? "yes" : "no");
45 }
46 }
47}
48
49int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag,
50 int argc, char * const argv[])
51{
Sughosh Ganu90ec2452024-03-22 16:27:27 +053052 struct fwu_data *data = fwu_get_data();
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053053
Sughosh Ganu90ec2452024-03-22 16:27:27 +053054 print_mdata(data);
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053055
Sughosh Ganu90ec2452024-03-22 16:27:27 +053056 return CMD_RET_SUCCESS;
Sughosh Ganu0f951fd2022-10-21 18:16:04 +053057}
58
59U_BOOT_CMD(
60 fwu_mdata_read, 1, 1, do_fwu_mdata_read,
61 "Read and print FWU metadata",
62 ""
63);