xref: /openbmc/u-boot/cmd/x86/fsp.c (revision cbd2fba1)
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 <asm/fsp/fsp_support.h>
9 
10 DECLARE_GLOBAL_DATA_PTR;
11 
12 static char *hob_type[] = {
13 	"reserved",
14 	"Hand-off",
15 	"Mem Alloc",
16 	"Res Desc",
17 	"GUID Ext",
18 	"FV",
19 	"CPU",
20 	"Mem Pool",
21 	"reserved",
22 	"FV2",
23 	"Load PEIM",
24 	"Capsule",
25 };
26 
27 static int do_hdr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
28 {
29 	struct fsp_header *hdr = find_fsp_header();
30 	u32 img_addr = hdr->img_base;
31 	char *sign = (char *)&hdr->sign;
32 	int i;
33 
34 	printf("FSP    : binary 0x%08x, header 0x%08x\n",
35 	       CONFIG_FSP_ADDR, (int)hdr);
36 	printf("Header : sign ");
37 	for (i = 0; i < sizeof(hdr->sign); i++)
38 		printf("%c", *sign++);
39 	printf(", size %d, rev %d\n", hdr->hdr_len, hdr->hdr_rev);
40 	printf("Image  : rev ");
41 	if (hdr->hdr_rev == FSP_HEADER_REVISION_1) {
42 		printf("%d.%d",
43 		       (hdr->img_rev >> 8) & 0xff, hdr->img_rev & 0xff);
44 	} else {
45 		printf("%d.%d.%d.%d",
46 		       (hdr->img_rev >> 24) & 0xff, (hdr->img_rev >> 16) & 0xff,
47 		       (hdr->img_rev >> 8) & 0xff, hdr->img_rev & 0xff);
48 	}
49 	printf(", id ");
50 	for (i = 0; i < ARRAY_SIZE(hdr->img_id); i++)
51 		printf("%c", hdr->img_id[i]);
52 	printf(", addr 0x%08x, size %d\n", img_addr, hdr->img_size);
53 	if (hdr->hdr_rev == FSP_HEADER_REVISION_2) {
54 		printf("GFX    :%ssupported\n",
55 		       hdr->img_attr & FSP_ATTR_GRAPHICS_SUPPORT ? " " : " un");
56 	}
57 	printf("VPD    : addr 0x%08x, size %d\n",
58 	       hdr->cfg_region_off + img_addr, hdr->cfg_region_size);
59 	printf("\nNumber of APIs Supported : %d\n", hdr->api_num);
60 	printf("\tTempRamInit : 0x%08x\n", hdr->fsp_tempram_init + img_addr);
61 	printf("\tFspInit     : 0x%08x\n", hdr->fsp_init + img_addr);
62 	printf("\tFspNotify   : 0x%08x\n", hdr->fsp_notify + img_addr);
63 	if (hdr->hdr_rev == FSP_HEADER_REVISION_2) {
64 		printf("\tMemoryInit  : 0x%08x\n",
65 		       hdr->fsp_mem_init + img_addr);
66 		printf("\tTempRamExit : 0x%08x\n",
67 		       hdr->fsp_tempram_exit + img_addr);
68 		printf("\tSiliconInit : 0x%08x\n",
69 		       hdr->fsp_silicon_init + img_addr);
70 	}
71 
72 	return 0;
73 }
74 
75 static int do_hob(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
76 {
77 	const struct hob_header *hdr;
78 	uint type;
79 	char *desc;
80 	int i = 0;
81 
82 	hdr = gd->arch.hob_list;
83 
84 	printf("HOB list address: 0x%08x\n\n", (unsigned int)hdr);
85 
86 	printf("#  | Address  | Type      | Len  | ");
87 	printf("%42s\n", "GUID");
88 	printf("---|----------|-----------|------|-");
89 	printf("------------------------------------------\n");
90 	while (!end_of_hob(hdr)) {
91 		printf("%02x | %08x | ", i, (unsigned int)hdr);
92 		type = hdr->type;
93 		if (type == HOB_TYPE_UNUSED)
94 			desc = "*Unused*";
95 		else if (type == HOB_TYPE_EOH)
96 			desc = "*EOH*";
97 		else if (type >= 0 && type <= ARRAY_SIZE(hob_type))
98 			desc = hob_type[type];
99 		else
100 			desc = "*Invalid*";
101 		printf("%-9s | %04x | ", desc, hdr->len);
102 
103 		if (type == HOB_TYPE_MEM_ALLOC || type == HOB_TYPE_RES_DESC ||
104 		    type == HOB_TYPE_GUID_EXT) {
105 			struct efi_guid *guid = (struct efi_guid *)(hdr + 1);
106 			int j;
107 
108 			printf("%08x-%04x-%04x", guid->data1,
109 			       guid->data2, guid->data3);
110 			for (j = 0; j < ARRAY_SIZE(guid->data4); j++)
111 				printf("-%02x", guid->data4[j]);
112 		} else {
113 			printf("%42s", "Not Available");
114 		}
115 		printf("\n");
116 		hdr = get_next_hob(hdr);
117 		i++;
118 	}
119 
120 	return 0;
121 }
122 
123 static cmd_tbl_t fsp_commands[] = {
124 	U_BOOT_CMD_MKENT(hdr, 0, 1, do_hdr, "", ""),
125 	U_BOOT_CMD_MKENT(hob, 0, 1, do_hob, "", ""),
126 };
127 
128 static int do_fsp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
129 {
130 	cmd_tbl_t *fsp_cmd;
131 	int ret;
132 
133 	if (argc < 2)
134 		return CMD_RET_USAGE;
135 	fsp_cmd = find_cmd_tbl(argv[1], fsp_commands, ARRAY_SIZE(fsp_commands));
136 	argc -= 2;
137 	argv += 2;
138 	if (!fsp_cmd || argc > fsp_cmd->maxargs)
139 		return CMD_RET_USAGE;
140 
141 	ret = fsp_cmd->cmd(fsp_cmd, flag, argc, argv);
142 
143 	return cmd_process_error(fsp_cmd, ret);
144 }
145 
146 U_BOOT_CMD(
147 	fsp,	2,	1,	do_fsp,
148 	"Show Intel Firmware Support Package (FSP) related information",
149 	"hdr - Print FSP header information\n"
150 	"fsp hob - Print FSP Hand-Off Block (HOB) information"
151 );
152