3967a7ca5a79b0dc47d9cd05e5549f8bed0d88c2
[oweals/u-boot.git] / cmd / x86 / hob.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2014-2015, Bin Meng <bmeng.cn@gmail.com>
4  */
5
6 #include <common.h>
7 #include <command.h>
8 #include <efi.h>
9 #include <asm/hob.h>
10
11 DECLARE_GLOBAL_DATA_PTR;
12
13 static char *hob_type[] = {
14         "reserved",
15         "Hand-off",
16         "Mem Alloc",
17         "Res Desc",
18         "GUID Ext",
19         "FV",
20         "CPU",
21         "Mem Pool",
22         "reserved",
23         "FV2",
24         "Load PEIM",
25         "Capsule",
26 };
27
28 static int do_hob(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
29 {
30         const struct hob_header *hdr;
31         uint type;
32         char *desc;
33         int i = 0;
34         efi_guid_t *guid;
35         char uuid[UUID_STR_LEN + 1];
36
37         hdr = gd->arch.hob_list;
38
39         printf("HOB list address: 0x%08x\n\n", (unsigned int)hdr);
40
41         printf("#  | Address  | Type      | Len  | ");
42         printf("%36s\n", "GUID");
43         printf("---|----------|-----------|------|-");
44         printf("------------------------------------\n");
45         while (!end_of_hob(hdr)) {
46                 printf("%02x | %08x | ", i, (unsigned int)hdr);
47                 type = hdr->type;
48                 if (type == HOB_TYPE_UNUSED)
49                         desc = "*Unused*";
50                 else if (type == HOB_TYPE_EOH)
51                         desc = "*EOH*";
52                 else if (type >= 0 && type <= ARRAY_SIZE(hob_type))
53                         desc = hob_type[type];
54                 else
55                         desc = "*Invalid*";
56                 printf("%-9s | %04x | ", desc, hdr->len);
57
58                 if (type == HOB_TYPE_MEM_ALLOC || type == HOB_TYPE_RES_DESC ||
59                     type == HOB_TYPE_GUID_EXT) {
60                         guid = (efi_guid_t *)(hdr + 1);
61                         uuid_bin_to_str(guid->b, uuid, UUID_STR_FORMAT_GUID);
62                         printf("%s", uuid);
63                 } else {
64                         printf("%36s", "Not Available");
65                 }
66                 printf("\n");
67                 hdr = get_next_hob(hdr);
68                 i++;
69         }
70
71         return 0;
72 }
73
74 U_BOOT_CMD(hob, 1, 1, do_hob,
75            "Print Hand-Off Block (HOB) information",
76            ""
77 );