162716ebbSBin Meng /*
262716ebbSBin Meng * Copyright (C) 2014-2015, Bin Meng <bmeng.cn@gmail.com>
362716ebbSBin Meng *
462716ebbSBin Meng * SPDX-License-Identifier: GPL-2.0+
562716ebbSBin Meng */
662716ebbSBin Meng
762716ebbSBin Meng #include <common.h>
862716ebbSBin Meng #include <command.h>
962716ebbSBin Meng #include <asm/fsp/fsp_support.h>
1062716ebbSBin Meng
1162716ebbSBin Meng DECLARE_GLOBAL_DATA_PTR;
1262716ebbSBin Meng
1362716ebbSBin Meng static char *hob_type[] = {
1462716ebbSBin Meng "reserved",
1562716ebbSBin Meng "Hand-off",
1662716ebbSBin Meng "Mem Alloc",
1762716ebbSBin Meng "Res Desc",
1862716ebbSBin Meng "GUID Ext",
1962716ebbSBin Meng "FV",
2062716ebbSBin Meng "CPU",
2162716ebbSBin Meng "Mem Pool",
2262716ebbSBin Meng "reserved",
2362716ebbSBin Meng "FV2",
2462716ebbSBin Meng "Load PEIM",
2562716ebbSBin Meng "Capsule",
2662716ebbSBin Meng };
2762716ebbSBin Meng
do_hdr(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])28010921aeSBin Meng static int do_hdr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
29010921aeSBin Meng {
30010921aeSBin Meng struct fsp_header *hdr = find_fsp_header();
31010921aeSBin Meng u32 img_addr = hdr->img_base;
32010921aeSBin Meng char *sign = (char *)&hdr->sign;
33010921aeSBin Meng int i;
34010921aeSBin Meng
35010921aeSBin Meng printf("FSP : binary 0x%08x, header 0x%08x\n",
36010921aeSBin Meng CONFIG_FSP_ADDR, (int)hdr);
37010921aeSBin Meng printf("Header : sign ");
38010921aeSBin Meng for (i = 0; i < sizeof(hdr->sign); i++)
39010921aeSBin Meng printf("%c", *sign++);
40010921aeSBin Meng printf(", size %d, rev %d\n", hdr->hdr_len, hdr->hdr_rev);
41010921aeSBin Meng printf("Image : rev %d.%d, id ",
42010921aeSBin Meng (hdr->img_rev >> 8) & 0xff, hdr->img_rev & 0xff);
43010921aeSBin Meng for (i = 0; i < ARRAY_SIZE(hdr->img_id); i++)
44010921aeSBin Meng printf("%c", hdr->img_id[i]);
45010921aeSBin Meng printf(", addr 0x%08x, size %d\n", img_addr, hdr->img_size);
46010921aeSBin Meng printf("VPD : addr 0x%08x, size %d\n",
47010921aeSBin Meng hdr->cfg_region_off + img_addr, hdr->cfg_region_size);
48010921aeSBin Meng printf("\nNumber of APIs Supported : %d\n", hdr->api_num);
49010921aeSBin Meng printf("\tTempRamInit : 0x%08x\n", hdr->fsp_tempram_init + img_addr);
50010921aeSBin Meng printf("\tFspInit : 0x%08x\n", hdr->fsp_init + img_addr);
51010921aeSBin Meng printf("\tFspNotify : 0x%08x\n", hdr->fsp_notify + img_addr);
52010921aeSBin Meng
53010921aeSBin Meng return 0;
54010921aeSBin Meng }
55010921aeSBin Meng
do_hob(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])5662716ebbSBin Meng static int do_hob(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
5762716ebbSBin Meng {
5862716ebbSBin Meng const struct hob_header *hdr;
5962716ebbSBin Meng uint type;
6062716ebbSBin Meng char *desc;
6162716ebbSBin Meng int i = 0;
6262716ebbSBin Meng
6362716ebbSBin Meng hdr = gd->arch.hob_list;
6462716ebbSBin Meng
6562716ebbSBin Meng printf("HOB list address: 0x%08x\n\n", (unsigned int)hdr);
6662716ebbSBin Meng
6762716ebbSBin Meng printf("# | Address | Type | Len | ");
6862716ebbSBin Meng printf("%42s\n", "GUID");
6962716ebbSBin Meng printf("---|----------|-----------|------|-");
7062716ebbSBin Meng printf("------------------------------------------\n");
7162716ebbSBin Meng while (!end_of_hob(hdr)) {
72*59fb7fbdSBin Meng printf("%02x | %08x | ", i, (unsigned int)hdr);
7362716ebbSBin Meng type = hdr->type;
7462716ebbSBin Meng if (type == HOB_TYPE_UNUSED)
7562716ebbSBin Meng desc = "*Unused*";
7662716ebbSBin Meng else if (type == HOB_TYPE_EOH)
7762716ebbSBin Meng desc = "*EOH*";
7862716ebbSBin Meng else if (type >= 0 && type <= ARRAY_SIZE(hob_type))
7962716ebbSBin Meng desc = hob_type[type];
8062716ebbSBin Meng else
8162716ebbSBin Meng desc = "*Invalid*";
82*59fb7fbdSBin Meng printf("%-9s | %04x | ", desc, hdr->len);
8362716ebbSBin Meng
8462716ebbSBin Meng if (type == HOB_TYPE_MEM_ALLOC || type == HOB_TYPE_RES_DESC ||
8562716ebbSBin Meng type == HOB_TYPE_GUID_EXT) {
8662716ebbSBin Meng struct efi_guid *guid = (struct efi_guid *)(hdr + 1);
8762716ebbSBin Meng int j;
8862716ebbSBin Meng
8962716ebbSBin Meng printf("%08x-%04x-%04x", guid->data1,
9062716ebbSBin Meng guid->data2, guid->data3);
9162716ebbSBin Meng for (j = 0; j < ARRAY_SIZE(guid->data4); j++)
9262716ebbSBin Meng printf("-%02x", guid->data4[j]);
9362716ebbSBin Meng } else {
9462716ebbSBin Meng printf("%42s", "Not Available");
9562716ebbSBin Meng }
9662716ebbSBin Meng printf("\n");
9762716ebbSBin Meng hdr = get_next_hob(hdr);
9862716ebbSBin Meng i++;
9962716ebbSBin Meng }
10062716ebbSBin Meng
10162716ebbSBin Meng return 0;
10262716ebbSBin Meng }
10362716ebbSBin Meng
10462716ebbSBin Meng static cmd_tbl_t fsp_commands[] = {
105010921aeSBin Meng U_BOOT_CMD_MKENT(hdr, 0, 1, do_hdr, "", ""),
10662716ebbSBin Meng U_BOOT_CMD_MKENT(hob, 0, 1, do_hob, "", ""),
10762716ebbSBin Meng };
10862716ebbSBin Meng
do_fsp(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])10962716ebbSBin Meng static int do_fsp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
11062716ebbSBin Meng {
11162716ebbSBin Meng cmd_tbl_t *fsp_cmd;
11262716ebbSBin Meng int ret;
11362716ebbSBin Meng
11462716ebbSBin Meng if (argc < 2)
11562716ebbSBin Meng return CMD_RET_USAGE;
11662716ebbSBin Meng fsp_cmd = find_cmd_tbl(argv[1], fsp_commands, ARRAY_SIZE(fsp_commands));
11762716ebbSBin Meng argc -= 2;
11862716ebbSBin Meng argv += 2;
11962716ebbSBin Meng if (!fsp_cmd || argc > fsp_cmd->maxargs)
12062716ebbSBin Meng return CMD_RET_USAGE;
12162716ebbSBin Meng
12262716ebbSBin Meng ret = fsp_cmd->cmd(fsp_cmd, flag, argc, argv);
12362716ebbSBin Meng
12462716ebbSBin Meng return cmd_process_error(fsp_cmd, ret);
12562716ebbSBin Meng }
12662716ebbSBin Meng
12762716ebbSBin Meng U_BOOT_CMD(
12862716ebbSBin Meng fsp, 2, 1, do_fsp,
12962716ebbSBin Meng "Show Intel Firmware Support Package (FSP) related information",
130010921aeSBin Meng "hdr - Print FSP header information\n"
131010921aeSBin Meng "fsp hob - Print FSP Hand-Off Block (HOB) information"
13262716ebbSBin Meng );
133