blob: 7ca2e13ae2f8b89b6987608a75c59775a4661993 [file] [log] [blame]
Simon Glasse1efad22021-03-15 18:00:24 +13001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
Simon Glasse1efad22021-03-15 18:00:24 +13007#include <asm/cb_sysinfo.h>
8#include <command.h>
9#include <console.h>
10#include <asm/global_data.h>
11
12DECLARE_GLOBAL_DATA_PTR;
13
14static void cbprompt(const char *name)
15{
16 for (; *name == '>'; name++)
17 puts(" ");
18 printf("%-12s: ", name);
19}
20
21static void print_dec(const char *name, int value)
22{
23 cbprompt(name);
24 printf(value > 9 ? "0d%d\n" : "%d\n", value);
25}
26
27static void print_hex(const char *name, int value)
28{
29 cbprompt(name);
30 printf("%x\n", value);
31}
32
33static void print_addr(const char *name, ulong value)
34{
35 cbprompt(name);
36 printf("%08lx\n", value);
37}
38
39static void print_addr64(const char *name, u64 value)
40{
41 cbprompt(name);
42 printf("%16llx\n", value);
43}
44
45static void print_ptr(const char *name, const void *value)
46{
47 cbprompt(name);
48 printf("%p\n", value);
49}
50
51static void print_str(const char *name, const char *value)
52{
53 if (value) {
54 cbprompt(name);
55 printf("%s\n", value);
56 }
57}
58
59static void print_idx(const char *name, uint idx, const u8 *strings)
60{
61 const char *ptr;
62
63 cbprompt(name);
64 ptr = (char *)strings + idx;
65 printf("%d: %s\n", idx, ptr ? ptr : "(unknown)");
66}
67
68static const char *const cb_mem_name[] = {
69 NULL,
70 "ram",
71 "reserved",
72 "acpi",
73 "nvs",
74 "unusable",
75 "vendor",
76};
77
78static const char *get_mem_name(int tag)
79{
80 if (tag >= CB_MEM_RAM && tag <= CB_MEM_VENDOR_RSVD)
81 return cb_mem_name[tag];
82
83 if (tag == CB_MEM_TABLE)
84 return "table";
85
86 return "(unknown)";
87}
88
89static const struct timestamp_id_to_name {
90 uint id;
91 const char *name;
92} timestamp_ids[] = {
93 /* Marker to report base_time */
94 { 0, "1st timestamp" },
95 { TS_START_ROMSTAGE, "start of romstage" },
96 { TS_BEFORE_INITRAM, "before ram initialization" },
97 { TS_AFTER_INITRAM, "after ram initialization" },
98 { TS_END_ROMSTAGE, "end of romstage" },
99 { TS_START_VBOOT, "start of verified boot" },
100 { TS_END_VBOOT, "end of verified boot" },
101 { TS_START_COPYRAM, "starting to load ramstage" },
102 { TS_END_COPYRAM, "finished loading ramstage" },
103 { TS_START_RAMSTAGE, "start of ramstage" },
104 { TS_START_BOOTBLOCK, "start of bootblock" },
105 { TS_END_BOOTBLOCK, "end of bootblock" },
106 { TS_START_COPYROM, "starting to load romstage" },
107 { TS_END_COPYROM, "finished loading romstage" },
108 { TS_START_ULZMA, "starting LZMA decompress (ignore for x86)" },
109 { TS_END_ULZMA, "finished LZMA decompress (ignore for x86)" },
110 { TS_START_ULZ4F, "starting LZ4 decompress (ignore for x86)" },
111 { TS_END_ULZ4F, "finished LZ4 decompress (ignore for x86)" },
112 { TS_DEVICE_ENUMERATE, "device enumeration" },
113 { TS_DEVICE_CONFIGURE, "device configuration" },
114 { TS_DEVICE_ENABLE, "device enable" },
115 { TS_DEVICE_INITIALIZE, "device initialization" },
116 { TS_DEVICE_DONE, "device setup done" },
117 { TS_CBMEM_POST, "cbmem post" },
118 { TS_WRITE_TABLES, "write tables" },
119 { TS_FINALIZE_CHIPS, "finalize chips" },
120 { TS_LOAD_PAYLOAD, "load payload" },
121 { TS_ACPI_WAKE_JUMP, "ACPI wake jump" },
122 { TS_SELFBOOT_JUMP, "selfboot jump" },
123
124 { TS_START_COPYVER, "starting to load verstage" },
125 { TS_END_COPYVER, "finished loading verstage" },
126 { TS_START_TPMINIT, "starting to initialize TPM" },
127 { TS_END_TPMINIT, "finished TPM initialization" },
128 { TS_START_VERIFY_SLOT, "starting to verify keyblock/preamble (RSA)" },
129 { TS_END_VERIFY_SLOT, "finished verifying keyblock/preamble (RSA)" },
130 { TS_START_HASH_BODY, "starting to verify body (load+SHA2+RSA) " },
131 { TS_DONE_LOADING, "finished loading body (ignore for x86)" },
132 { TS_DONE_HASHING, "finished calculating body hash (SHA2)" },
133 { TS_END_HASH_BODY, "finished verifying body signature (RSA)" },
134
135 { TS_START_COPYVPD, "starting to load Chrome OS VPD" },
136 { TS_END_COPYVPD_RO, "finished loading Chrome OS VPD (RO)" },
137 { TS_END_COPYVPD_RW, "finished loading Chrome OS VPD (RW)" },
138
139 { TS_U_BOOT_INITTED, "U-Boot start" },
140 { TS_RO_PARAMS_INIT, "RO parameter init" },
141 { TS_RO_VB_INIT, "RO vboot init" },
142 { TS_RO_VB_SELECT_FIRMWARE, "RO vboot select firmware" },
143 { TS_RO_VB_SELECT_AND_LOAD_KERNEL, "RO vboot select&load kernel" },
144 { TS_RW_VB_SELECT_AND_LOAD_KERNEL, "RW vboot select&load kernel" },
145 { TS_VB_SELECT_AND_LOAD_KERNEL, "vboot select&load kernel" },
146 { TS_VB_EC_VBOOT_DONE, "finished EC verification" },
147 { TS_VB_STORAGE_INIT_DONE, "finished storage device initialization" },
148 { TS_VB_READ_KERNEL_DONE, "finished reading kernel from disk" },
149 { TS_VB_VBOOT_DONE, "finished vboot kernel verification" },
150 { TS_KERNEL_DECOMPRESSION, "starting kernel decompression/relocation" },
151 { TS_START_KERNEL, "jumping to kernel" },
152 { TS_U_BOOT_START_KERNEL, "just before jump to kernel" },
153
154 /* Intel ME-related timestamps */
155 { TS_ME_INFORM_DRAM_WAIT, "waiting for ME acknowledgment of raminit"},
156 { TS_ME_INFORM_DRAM_DONE, "finished waiting for ME response"},
157
158 /* FSP-related timestamps */
159 { TS_FSP_MEMORY_INIT_START, "calling FspMemoryInit" },
160 { TS_FSP_MEMORY_INIT_END, "returning from FspMemoryInit" },
161 { TS_FSP_TEMP_RAM_EXIT_START, "calling FspTempRamExit" },
162 { TS_FSP_TEMP_RAM_EXIT_END, "returning from FspTempRamExit" },
163 { TS_FSP_SILICON_INIT_START, "calling FspSiliconInit" },
164 { TS_FSP_SILICON_INIT_END, "returning from FspSiliconInit" },
165 { TS_FSP_BEFORE_ENUMERATE, "calling FspNotify(AfterPciEnumeration)" },
166 { TS_FSP_AFTER_ENUMERATE,
167 "returning from FspNotify(AfterPciEnumeration)" },
168 { TS_FSP_BEFORE_FINALIZE, "calling FspNotify(ReadyToBoot)" },
169 { TS_FSP_AFTER_FINALIZE, "returning from FspNotify(ReadyToBoot)" },
170 { TS_FSP_BEFORE_END_OF_FIRMWARE, "calling FspNotify(EndOfFirmware)" },
171 { TS_FSP_AFTER_END_OF_FIRMWARE,
172 "returning from FspNotify(EndOfFirmware)" },
173};
174
175static const char *timestamp_name(uint32_t id)
176{
177 int i;
178
179 for (i = 0; i < ARRAY_SIZE(timestamp_ids); i++) {
180 if (timestamp_ids[i].id == id)
181 return timestamp_ids[i].name;
182 }
183
184 return "<unknown>";
185}
186
187static void show_table(struct sysinfo_t *info, bool verbose)
188{
189 struct cb_serial *ser = info->serial;
190 int i;
191
Simon Glass4a75a122023-07-25 15:37:06 -0600192 printf("Coreboot table at %lx, size %x, records %x (dec %d), decoded to %p",
193 gd->arch.coreboot_table, info->table_size, info->rec_count,
194 info->rec_count, info);
Simon Glasse1efad22021-03-15 18:00:24 +1300195 if (info->header)
196 printf(", forwarded to %p\n", info->header);
197 printf("\n");
198
199 print_dec("CPU KHz", info->cpu_khz);
200
201 print_addr("Serial I/O port", info->ser_ioport);
202 print_addr(">base", info->ser_base);
203 print_ptr(">pointer", ser);
204 if (ser) {
205 print_hex(">type", ser->type);
206 print_addr(">base", ser->baseaddr);
207 print_dec(">baud", ser->baud);
Simon Glass021f4442021-04-24 10:04:57 +1200208 print_hex(">regwidth", ser->regwidth);
Simon Glasse1efad22021-03-15 18:00:24 +1300209 print_dec(">input_hz", ser->input_hertz);
210 print_addr(">PCI addr", ser->uart_pci_addr);
211 }
212
213 print_dec("Mem ranges", info->n_memranges);
214 printf("%12s: %-11s || base || size\n", "id", "type");
215 for (i = 0; i < info->n_memranges; i++) {
216 const struct memrange *mr = &info->memrange[i];
217
218 printf("%12d: %02x:%-8s %016llx %016llx\n", i, mr->type,
219 get_mem_name(mr->type), mr->base, mr->size);
220 }
221 print_ptr("option_table", info->option_table);
222
223 print_hex("CMOS start", info->cmos_range_start);
224 if (info->cmos_range_start) {
225 print_hex(">CMOS end", info->cmos_range_end);
226 print_hex(">CMOS csum loc", info->cmos_checksum_location);
227 }
228
229 print_hex("VBNV start", info->vbnv_start);
230 print_hex("VBNV size", info->vbnv_size);
231
232 print_str("CB version", info->cb_version);
233 print_str(">Extra", info->extra_version);
234 print_str(">Build", info->build);
235 print_str(">Time", info->compile_time);
236 print_str(">By", info->compile_by);
237 print_str(">Host", info->compile_host);
238 print_str(">Domain", info->compile_domain);
239 print_str(">Compiler", info->compiler);
240 print_str(">Linker", info->linker);
241 print_str(">Assembler", info->assembler);
242
243 print_ptr("Framebuffer", info->framebuffer);
244 if (info->framebuffer) {
245 struct cb_framebuffer *fb = info->framebuffer;
246
247 print_addr64(">Phys addr", fb->physical_address);
248 print_dec(">X res", fb->x_resolution);
249 print_dec(">X res", fb->y_resolution);
250 print_hex(">Bytes / line", fb->bytes_per_line);
251 print_dec(">Bpp", fb->bits_per_pixel);
252 printf(" %-12s red %d/%d, green %d/%d, blue %d/%d, reserved %d/%d\n",
253 "pos/size", fb->red_mask_pos, fb->red_mask_size,
254 fb->green_mask_pos, fb->green_mask_size,
255 fb->blue_mask_pos, fb->blue_mask_size,
256 fb->reserved_mask_pos, fb->reserved_mask_size);
257 }
258
259 print_dec("GPIOs", info->num_gpios);
260 printf("%12s: %4s %12s %3s %s\n", "id", "port", "polarity", "val",
261 "name");
262 for (i = 0; i < info->num_gpios; i++) {
263 const struct cb_gpio *gpio = &info->gpios[i];
264 char portstr[4];
265
266 if (gpio->port == 0xffffffff)
267 strcpy(portstr, "-");
268 else
269 sprintf(portstr, "%x", gpio->port);
270 printf("%12d: %4s %12s %3d %s\n", i, portstr,
271 gpio->polarity == CB_GPIO_ACTIVE_LOW ? "active-low" :
272 "active-high", gpio->value, gpio->name);
273 }
274 print_dec("MACs", info->num_macs);
275 for (i = 0; i < info->num_macs; i++) {
276 const struct mac_address *mac = &info->macs[i];
277 int j;
278
279 printf("%12d: ", i);
280 for (j = 0; j < sizeof(mac->mac_addr); j++)
281 printf("%s%02x", j ? ":" : "", mac->mac_addr[j]);
282 printf("\n");
283 }
284 print_str(">Serial #", info->serialno);
285 print_ptr("Multiboot tab", info->mbtable);
286 print_ptr("CB header", info->header);
287 print_ptr("CB mainboard", info->mainboard);
288 if (info->mainboard) {
289 struct cb_mainboard *mb = info->mainboard;
290
291 print_idx(">vendor", mb->vendor_idx, mb->strings);
292 print_idx(">part_number", mb->part_number_idx, mb->strings);
293 }
294 print_ptr("vboot handoff", info->vboot_handoff);
295 print_hex(">size", info->vboot_handoff_size);
296 print_ptr(">vdat addr", info->vdat_addr);
297 print_hex(">size", info->vdat_size);
298
299 print_addr64("SMBIOS", info->smbios_start);
300 print_hex(">size", info->smbios_size);
301 print_hex("ROM MTRR", info->x86_rom_var_mtrr_index);
302
303 print_ptr("Tstamp table", info->tstamp_table);
304 if (verbose && info->tstamp_table) {
305 struct timestamp_table *ts = info->tstamp_table;
306
307 printf("%-12s", "Base_time");
308 print_grouped_ull(ts->base_time, 12);
309 printf("\n");
310 print_dec("Tick MHz", ts->tick_freq_mhz);
311 for (i = 0; i < ts->num_entries; i++) {
312 const struct timestamp_entry *tse;
313
314 tse = &ts->entries[i];
315 printf(" ");
316 print_grouped_ull(tse->entry_stamp, 12);
317 printf(" %s\n", timestamp_name(tse->entry_id));
318 }
319 }
320
321 print_ptr("CBmem cons", info->cbmem_cons);
322 if (info->cbmem_cons) {
323 struct cbmem_console *cons = info->cbmem_cons;
324 int i;
325
326 print_hex("Size", cons->size);
327 print_hex("Cursor", cons->cursor);
328 if (verbose) {
329 for (i = 0; i < cons->cursor; i++) {
330 int ch = cons->body[i];
331
332 putc(ch);
333
334 if (ch == '\n') {
335 /* check for ctrl-c to abort... */
336 if (ctrlc()) {
337 puts("Abort\n");
338 return;
339 }
340 printf(" ");
341 }
342 }
343 printf("\n");
344 }
345 }
346
347 print_ptr("MRC cache", info->mrc_cache);
348 print_ptr("ACPI GNVS", info->acpi_gnvs);
349 print_hex("Board ID", info->board_id);
350 print_hex("RAM code", info->ram_code);
351 print_ptr("WiFi calib", info->wifi_calibration);
352 print_addr64("Ramoops buff", info->ramoops_buffer);
353 print_hex(">size", info->ramoops_buffer_size);
354 print_hex("SF size", info->spi_flash.size);
355 print_hex("SF sector", info->spi_flash.sector_size);
356 print_hex("SF erase cmd", info->spi_flash.erase_cmd);
357
358 print_addr64("FMAP offset", info->fmap_offset);
359 print_addr64("CBFS offset", info->cbfs_offset);
360 print_addr64("CBFS size", info->cbfs_size);
361 print_addr64("Boot media size", info->boot_media_size);
362 print_addr64("MTC start", info->mtc_start);
363 print_hex("MTC size", info->mtc_size);
364
365 print_ptr("Chrome OS VPD", info->chromeos_vpd);
Simon Glasscf1f4bb2023-05-04 16:54:59 -0600366 print_ptr("RSDP", info->rsdp);
Simon Glassf35f7fa2023-05-04 16:55:06 -0600367 printf("%-12s: ", "Unimpl.");
368 if (info->unimpl_count) {
369 for (i = 0; i < info->unimpl_count; i++)
370 printf("%02x ", info->unimpl[i]);
371 printf("\n");
372 } else {
373 printf("(none)\n");
374 }
Simon Glasse1efad22021-03-15 18:00:24 +1300375}
376
377static int do_cbsysinfo(struct cmd_tbl *cmdtp, int flag, int argc,
378 char *const argv[])
379{
380 bool verbose = false;
381
382 if (argc > 1) {
383 if (!strcmp("-v", argv[1]))
384 verbose = true;
385 else
386 return CMD_RET_USAGE;
387 }
388
389 if (!gd->arch.coreboot_table) {
390 printf("No coreboot sysinfo table found\n");
391 return CMD_RET_FAILURE;
392 }
393 show_table(&lib_sysinfo, verbose);
394
395 return 0;
396}
397
398U_BOOT_CMD(
399 cbsysinfo, 2, 1, do_cbsysinfo,
400 "Show coreboot sysinfo table",
401 "[-v] Dumps out the contents of the sysinfo table. This only\n"
402 "works if U-Boot is booted from coreboot"
403);