blob: 2dd30808bd109096f12146d58dc8b09659de2e57 [file] [log] [blame]
Park, Aiden7165fd52019-08-03 08:30:31 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2014-2015, Bin Meng <bmeng.cn@gmail.com>
4 */
5
Park, Aiden7165fd52019-08-03 08:30:31 +00006#include <command.h>
7#include <efi.h>
Simon Glassba06b3c2020-05-10 11:39:52 -06008#include <uuid.h>
Simon Glass401d1c42020-10-30 21:38:53 -06009#include <asm/global_data.h>
Park, Aiden7165fd52019-08-03 08:30:31 +000010#include <asm/hob.h>
Simon Glass10536ce2020-09-22 14:54:49 -060011#include <asm/fsp/fsp_hob.h>
Park, Aiden7165fd52019-08-03 08:30:31 +000012
13DECLARE_GLOBAL_DATA_PTR;
14
15static char *hob_type[] = {
16 "reserved",
17 "Hand-off",
18 "Mem Alloc",
19 "Res Desc",
20 "GUID Ext",
21 "FV",
22 "CPU",
23 "Mem Pool",
24 "reserved",
25 "FV2",
26 "Load PEIM",
27 "Capsule",
28};
29
Simon Glass51af1442020-09-22 14:54:50 -060030static char *res_type[] = {
31 "System",
32 "Memory-mapped I/O",
33 "I/O",
34 "Firmware device",
35 "Memory-mapped I/O port",
36 "Reserved",
37 "I/O reserved",
38};
39
Simon Glass10536ce2020-09-22 14:54:49 -060040static struct guid_name {
41 efi_guid_t guid;
42 const char *name;
43} guid_name[] = {
44 { FSP_HOB_RESOURCE_OWNER_TSEG_GUID, "TSEG" },
45 { FSP_HOB_RESOURCE_OWNER_FSP_GUID, "FSP" },
46 { FSP_HOB_RESOURCE_OWNER_SMM_PEI_SMRAM_GUID, "SMM PEI SMRAM" },
47 { FSP_NON_VOLATILE_STORAGE_HOB_GUID, "NVS" },
48 { FSP_VARIABLE_NV_DATA_HOB_GUID, "Variable NVS" },
49 { FSP_GRAPHICS_INFO_HOB_GUID, "Graphics info" },
50 { FSP_HOB_RESOURCE_OWNER_PCD_DATABASE_GUID1, "PCD database ea" },
51 { FSP_HOB_RESOURCE_OWNER_PCD_DATABASE_GUID2, "PCD database 9b" },
52 { FSP_HOB_RESOURCE_OWNER_PEIM_DXE_GUID, "PEIM Init DXE" },
53 { FSP_HOB_RESOURCE_OWNER_ALLOC_STACK_GUID, "Alloc stack" },
54 { FSP_HOB_RESOURCE_OWNER_SMBIOS_MEMORY_GUID, "SMBIOS memory" },
55 { {}, "zero-guid" },
56 {}
57};
58
59static const char *guid_to_name(const efi_guid_t *guid)
60{
61 struct guid_name *entry;
62
63 for (entry = guid_name; entry->name; entry++) {
64 if (!guidcmp(guid, &entry->guid))
65 return entry->name;
66 }
67
68 return NULL;
69}
70
Simon Glass51af1442020-09-22 14:54:50 -060071static void show_hob_details(const struct hob_header *hdr)
72{
73 const void *ptr = hdr;
74
75 switch (hdr->type) {
76 case HOB_TYPE_RES_DESC: {
77 const struct hob_res_desc *res = ptr;
78 const char *typename;
79
Bin Meng53094332021-07-31 16:45:28 +080080 typename = res->type >= RES_SYS_MEM && res->type <= RES_MAX_MEM_TYPE ?
Simon Glass51af1442020-09-22 14:54:50 -060081 res_type[res->type] : "unknown";
82
83 printf(" base = %08llx, len = %08llx, end = %08llx, type = %d (%s)\n\n",
84 res->phys_start, res->len, res->phys_start + res->len,
85 res->type, typename);
86 break;
87 }
88 }
89}
90
Simon Glass09140112020-05-10 11:40:03 -060091static int do_hob(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Park, Aiden7165fd52019-08-03 08:30:31 +000092{
93 const struct hob_header *hdr;
94 uint type;
95 char *desc;
96 int i = 0;
97 efi_guid_t *guid;
98 char uuid[UUID_STR_LEN + 1];
Simon Glass51af1442020-09-22 14:54:50 -060099 bool verbose = false;
Simon Glassd11544df2020-09-22 14:54:48 -0600100 int seq = -1; /* Show all by default */
Park, Aiden7165fd52019-08-03 08:30:31 +0000101
Simon Glassd11544df2020-09-22 14:54:48 -0600102 argc--;
103 argv++;
Simon Glass51af1442020-09-22 14:54:50 -0600104 if (argc) {
105 if (!strcmp("-v", *argv)) {
106 verbose = true;
107 argc--;
108 argv++;
109 }
110 if (argc)
111 seq = simple_strtol(*argv, NULL, 16);
112 }
Park, Aiden7165fd52019-08-03 08:30:31 +0000113 hdr = gd->arch.hob_list;
114
115 printf("HOB list address: 0x%08x\n\n", (unsigned int)hdr);
116
117 printf("# | Address | Type | Len | ");
118 printf("%36s\n", "GUID");
119 printf("---|----------|-----------|------|-");
120 printf("------------------------------------\n");
Simon Glassd11544df2020-09-22 14:54:48 -0600121 for (i = 0; !end_of_hob(hdr); i++, hdr = get_next_hob(hdr)) {
122 if (seq != -1 && seq != i)
123 continue;
Park, Aiden7165fd52019-08-03 08:30:31 +0000124 printf("%02x | %08x | ", i, (unsigned int)hdr);
125 type = hdr->type;
126 if (type == HOB_TYPE_UNUSED)
127 desc = "*Unused*";
128 else if (type == HOB_TYPE_EOH)
129 desc = "*EOH*";
130 else if (type >= 0 && type <= ARRAY_SIZE(hob_type))
131 desc = hob_type[type];
132 else
133 desc = "*Invalid*";
134 printf("%-9s | %04x | ", desc, hdr->len);
135
136 if (type == HOB_TYPE_MEM_ALLOC || type == HOB_TYPE_RES_DESC ||
137 type == HOB_TYPE_GUID_EXT) {
Simon Glass10536ce2020-09-22 14:54:49 -0600138 const char *name;
139
Park, Aiden7165fd52019-08-03 08:30:31 +0000140 guid = (efi_guid_t *)(hdr + 1);
Simon Glass10536ce2020-09-22 14:54:49 -0600141 name = guid_to_name(guid);
142 if (!name) {
143 uuid_bin_to_str(guid->b, uuid,
144 UUID_STR_FORMAT_GUID);
145 name = uuid;
146 }
147 printf("%36s", name);
Park, Aiden7165fd52019-08-03 08:30:31 +0000148 } else {
149 printf("%36s", "Not Available");
150 }
151 printf("\n");
Simon Glass51af1442020-09-22 14:54:50 -0600152 if (verbose)
153 show_hob_details(hdr);
Park, Aiden7165fd52019-08-03 08:30:31 +0000154 }
155
156 return 0;
157}
158
Simon Glass51af1442020-09-22 14:54:50 -0600159U_BOOT_CMD(hob, 3, 1, do_hob,
Bin Meng2ab1ffa2021-07-31 16:45:27 +0800160 "[-v] [seq] Print Hand-Off Block (HOB) information",
161 " -v - Show detailed HOB information where available\n"
162 " seq - Record # to show (all by default)"
Park, Aiden7165fd52019-08-03 08:30:31 +0000163);