Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 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> |
Simon Glass | ba06b3c | 2020-05-10 11:39:52 -0600 | [diff] [blame] | 9 | #include <uuid.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 11 | #include <asm/hob.h> |
Simon Glass | 10536ce | 2020-09-22 14:54:49 -0600 | [diff] [blame] | 12 | #include <asm/fsp/fsp_hob.h> |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | static char *hob_type[] = { |
| 17 | "reserved", |
| 18 | "Hand-off", |
| 19 | "Mem Alloc", |
| 20 | "Res Desc", |
| 21 | "GUID Ext", |
| 22 | "FV", |
| 23 | "CPU", |
| 24 | "Mem Pool", |
| 25 | "reserved", |
| 26 | "FV2", |
| 27 | "Load PEIM", |
| 28 | "Capsule", |
| 29 | }; |
| 30 | |
Simon Glass | 51af144 | 2020-09-22 14:54:50 -0600 | [diff] [blame] | 31 | static char *res_type[] = { |
| 32 | "System", |
| 33 | "Memory-mapped I/O", |
| 34 | "I/O", |
| 35 | "Firmware device", |
| 36 | "Memory-mapped I/O port", |
| 37 | "Reserved", |
| 38 | "I/O reserved", |
| 39 | }; |
| 40 | |
Simon Glass | 10536ce | 2020-09-22 14:54:49 -0600 | [diff] [blame] | 41 | static struct guid_name { |
| 42 | efi_guid_t guid; |
| 43 | const char *name; |
| 44 | } guid_name[] = { |
| 45 | { FSP_HOB_RESOURCE_OWNER_TSEG_GUID, "TSEG" }, |
| 46 | { FSP_HOB_RESOURCE_OWNER_FSP_GUID, "FSP" }, |
| 47 | { FSP_HOB_RESOURCE_OWNER_SMM_PEI_SMRAM_GUID, "SMM PEI SMRAM" }, |
| 48 | { FSP_NON_VOLATILE_STORAGE_HOB_GUID, "NVS" }, |
| 49 | { FSP_VARIABLE_NV_DATA_HOB_GUID, "Variable NVS" }, |
| 50 | { FSP_GRAPHICS_INFO_HOB_GUID, "Graphics info" }, |
| 51 | { FSP_HOB_RESOURCE_OWNER_PCD_DATABASE_GUID1, "PCD database ea" }, |
| 52 | { FSP_HOB_RESOURCE_OWNER_PCD_DATABASE_GUID2, "PCD database 9b" }, |
| 53 | { FSP_HOB_RESOURCE_OWNER_PEIM_DXE_GUID, "PEIM Init DXE" }, |
| 54 | { FSP_HOB_RESOURCE_OWNER_ALLOC_STACK_GUID, "Alloc stack" }, |
| 55 | { FSP_HOB_RESOURCE_OWNER_SMBIOS_MEMORY_GUID, "SMBIOS memory" }, |
| 56 | { {}, "zero-guid" }, |
| 57 | {} |
| 58 | }; |
| 59 | |
| 60 | static const char *guid_to_name(const efi_guid_t *guid) |
| 61 | { |
| 62 | struct guid_name *entry; |
| 63 | |
| 64 | for (entry = guid_name; entry->name; entry++) { |
| 65 | if (!guidcmp(guid, &entry->guid)) |
| 66 | return entry->name; |
| 67 | } |
| 68 | |
| 69 | return NULL; |
| 70 | } |
| 71 | |
Simon Glass | 51af144 | 2020-09-22 14:54:50 -0600 | [diff] [blame] | 72 | static void show_hob_details(const struct hob_header *hdr) |
| 73 | { |
| 74 | const void *ptr = hdr; |
| 75 | |
| 76 | switch (hdr->type) { |
| 77 | case HOB_TYPE_RES_DESC: { |
| 78 | const struct hob_res_desc *res = ptr; |
| 79 | const char *typename; |
| 80 | |
Bin Meng | 5309433 | 2021-07-31 16:45:28 +0800 | [diff] [blame] | 81 | typename = res->type >= RES_SYS_MEM && res->type <= RES_MAX_MEM_TYPE ? |
Simon Glass | 51af144 | 2020-09-22 14:54:50 -0600 | [diff] [blame] | 82 | res_type[res->type] : "unknown"; |
| 83 | |
| 84 | printf(" base = %08llx, len = %08llx, end = %08llx, type = %d (%s)\n\n", |
| 85 | res->phys_start, res->len, res->phys_start + res->len, |
| 86 | res->type, typename); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 92 | static int do_hob(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 93 | { |
| 94 | const struct hob_header *hdr; |
| 95 | uint type; |
| 96 | char *desc; |
| 97 | int i = 0; |
| 98 | efi_guid_t *guid; |
| 99 | char uuid[UUID_STR_LEN + 1]; |
Simon Glass | 51af144 | 2020-09-22 14:54:50 -0600 | [diff] [blame] | 100 | bool verbose = false; |
Simon Glass | d11544df | 2020-09-22 14:54:48 -0600 | [diff] [blame] | 101 | int seq = -1; /* Show all by default */ |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 102 | |
Simon Glass | d11544df | 2020-09-22 14:54:48 -0600 | [diff] [blame] | 103 | argc--; |
| 104 | argv++; |
Simon Glass | 51af144 | 2020-09-22 14:54:50 -0600 | [diff] [blame] | 105 | if (argc) { |
| 106 | if (!strcmp("-v", *argv)) { |
| 107 | verbose = true; |
| 108 | argc--; |
| 109 | argv++; |
| 110 | } |
| 111 | if (argc) |
| 112 | seq = simple_strtol(*argv, NULL, 16); |
| 113 | } |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 114 | hdr = gd->arch.hob_list; |
| 115 | |
| 116 | printf("HOB list address: 0x%08x\n\n", (unsigned int)hdr); |
| 117 | |
| 118 | printf("# | Address | Type | Len | "); |
| 119 | printf("%36s\n", "GUID"); |
| 120 | printf("---|----------|-----------|------|-"); |
| 121 | printf("------------------------------------\n"); |
Simon Glass | d11544df | 2020-09-22 14:54:48 -0600 | [diff] [blame] | 122 | for (i = 0; !end_of_hob(hdr); i++, hdr = get_next_hob(hdr)) { |
| 123 | if (seq != -1 && seq != i) |
| 124 | continue; |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 125 | printf("%02x | %08x | ", i, (unsigned int)hdr); |
| 126 | type = hdr->type; |
| 127 | if (type == HOB_TYPE_UNUSED) |
| 128 | desc = "*Unused*"; |
| 129 | else if (type == HOB_TYPE_EOH) |
| 130 | desc = "*EOH*"; |
| 131 | else if (type >= 0 && type <= ARRAY_SIZE(hob_type)) |
| 132 | desc = hob_type[type]; |
| 133 | else |
| 134 | desc = "*Invalid*"; |
| 135 | printf("%-9s | %04x | ", desc, hdr->len); |
| 136 | |
| 137 | if (type == HOB_TYPE_MEM_ALLOC || type == HOB_TYPE_RES_DESC || |
| 138 | type == HOB_TYPE_GUID_EXT) { |
Simon Glass | 10536ce | 2020-09-22 14:54:49 -0600 | [diff] [blame] | 139 | const char *name; |
| 140 | |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 141 | guid = (efi_guid_t *)(hdr + 1); |
Simon Glass | 10536ce | 2020-09-22 14:54:49 -0600 | [diff] [blame] | 142 | name = guid_to_name(guid); |
| 143 | if (!name) { |
| 144 | uuid_bin_to_str(guid->b, uuid, |
| 145 | UUID_STR_FORMAT_GUID); |
| 146 | name = uuid; |
| 147 | } |
| 148 | printf("%36s", name); |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 149 | } else { |
| 150 | printf("%36s", "Not Available"); |
| 151 | } |
| 152 | printf("\n"); |
Simon Glass | 51af144 | 2020-09-22 14:54:50 -0600 | [diff] [blame] | 153 | if (verbose) |
| 154 | show_hob_details(hdr); |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
Simon Glass | 51af144 | 2020-09-22 14:54:50 -0600 | [diff] [blame] | 160 | U_BOOT_CMD(hob, 3, 1, do_hob, |
Bin Meng | 2ab1ffa | 2021-07-31 16:45:27 +0800 | [diff] [blame] | 161 | "[-v] [seq] Print Hand-Off Block (HOB) information", |
| 162 | " -v - Show detailed HOB information where available\n" |
| 163 | " seq - Record # to show (all by default)" |
Park, Aiden | 7165fd5 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 164 | ); |