1
/*****************************************************************************\
3
*****************************************************************************
4
* Copyright (C) 2002-2005 The Regents of the University of California.
5
* Produced at the Lawrence Livermore National Laboratory.
6
* Written by Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>
7
* and Stefan Reinauer <stepan@openbios.org>.
11
* This file is part of nvramtool, a utility for reading/writing coreboot
12
* parameters and displaying information from the coreboot table.
13
* For details, see http://coreboot.org/nvramtool.
15
* Please also read the file DISCLAIMER which is included in this software
18
* This program is free software; you can redistribute it and/or modify it
19
* under the terms of the GNU General Public License (as published by the
20
* Free Software Foundation) version 2, dated June 1991.
22
* This program is distributed in the hope that it will be useful, but
23
* WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
25
* conditions of the GNU General Public License for more details.
27
* You should have received a copy of the GNU General Public License along
28
* with this program; if not, write to the Free Software Foundation, Inc.,
29
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
30
\*****************************************************************************/
35
#include "coreboot_tables.h"
36
#include "ip_checksum.h"
39
#include "cmos_lowlevel.h"
42
typedef void (*lbtable_print_fn_t) (const struct lb_record *rec);
44
/* This structure represents an item in the coreboot table that may be
45
* displayed using the -l option.
50
const char *description;
51
const char *nofound_msg;
52
lbtable_print_fn_t print_fn;
57
{ unsigned long start; /* address of first byte of memory range */
58
unsigned long end; /* address of last byte of memory range */
62
static const struct lb_header * lbtable_scan (unsigned long start,
64
int *bad_header_count,
65
int *bad_table_count);
66
static void process_cmos_table (void);
67
static void get_cmos_checksum_info (void);
68
static void try_convert_checksum_layout (cmos_checksum_layout_t *layout);
69
static void try_add_cmos_table_enum (cmos_enum_t *cmos_enum);
70
static void try_add_cmos_table_entry (cmos_entry_t *cmos_entry);
71
static const struct lb_record * find_lbrec (uint32_t tag);
72
static const char * lbrec_tag_to_str (uint32_t tag);
73
static const struct cmos_entries * first_cmos_table_entry (void);
74
static const struct cmos_entries *
75
next_cmos_table_entry (const struct cmos_entries *last);
76
static const struct cmos_enums * first_cmos_table_enum (void);
77
static const struct cmos_enums * next_cmos_table_enum
78
(const struct cmos_enums *last);
79
static const struct lb_record * first_cmos_rec (uint32_t tag);
80
static const struct lb_record * next_cmos_rec (const struct lb_record *last,
82
static void memory_print_fn (const struct lb_record *rec);
83
static void mainboard_print_fn (const struct lb_record *rec);
84
static void cmos_opt_table_print_fn (const struct lb_record *rec);
85
static void print_option_record (const struct cmos_entries *cmos_entry);
86
static void print_enum_record (const struct cmos_enums *cmos_enum);
87
static void print_defaults_record (const struct cmos_defaults *cmos_defaults);
88
static void print_unknown_record (const struct lb_record *cmos_item);
89
static void option_checksum_print_fn (const struct lb_record *rec);
90
static void string_print_fn (const struct lb_record *rec);
91
static void uint64_to_hex_string (char str[], uint64_t n);
93
static const char memory_desc[] =
94
" This shows information about system memory.\n";
96
static const char mainboard_desc[] =
97
" This shows information about your mainboard.\n";
99
static const char version_desc[] =
100
" This shows coreboot version information.\n";
102
static const char extra_version_desc[] =
103
" This shows extra coreboot version information.\n";
105
static const char build_desc[] =
106
" This shows coreboot build information.\n";
108
static const char compile_time_desc[] =
109
" This shows when coreboot was compiled.\n";
111
static const char compile_by_desc[] =
112
" This shows who compiled coreboot.\n";
114
static const char compile_host_desc[] =
115
" This shows the name of the machine that compiled coreboot.\n";
117
static const char compile_domain_desc[] =
118
" This shows the domain name of the machine that compiled coreboot.\n";
120
static const char compiler_desc[] =
121
" This shows the name of the compiler used to build coreboot.\n";
123
static const char linker_desc[] =
124
" This shows the name of the linker used to build coreboot.\n";
126
static const char assembler_desc[] =
127
" This shows the name of the assembler used to build coreboot.\n";
129
static const char cmos_opt_table_desc[] =
130
" This does a low-level dump of the CMOS option table. The table "
132
" information about the layout of the values that coreboot stores in\n"
133
" nonvolatile RAM.\n";
135
static const char option_checksum_desc[] =
136
" This shows the location of the CMOS checksum and the area over which it "
140
static const char generic_nofound_msg[] =
141
"%s: Item %s not found in coreboot table.\n";
143
static const char nofound_msg_cmos_opt_table[] =
144
"%s: Item %s not found in coreboot table. Apparently, the "
145
"coreboot installed on this system was built without specifying "
146
"HAVE_OPTION_TABLE.\n";
148
static const char nofound_msg_option_checksum[] =
149
"%s: Item %s not found in coreboot table. Apparently, you are "
150
"using coreboot v1.\n";
152
/* This is the number of items from the coreboot table that may be displayed
153
* using the -l option.
155
#define NUM_LBTABLE_CHOICES 14
157
/* These represent the various items from the coreboot table that may be
158
* displayed using the -l option.
160
static const lbtable_choice_t lbtable_choices[NUM_LBTABLE_CHOICES] =
161
{ { LB_TAG_MEMORY, "memory",
162
memory_desc, generic_nofound_msg,
165
{ LB_TAG_MAINBOARD, "mainboard",
166
mainboard_desc, generic_nofound_msg,
169
{ LB_TAG_VERSION, "version",
170
version_desc, generic_nofound_msg,
173
{ LB_TAG_EXTRA_VERSION, "extra_version",
174
extra_version_desc, generic_nofound_msg,
177
{ LB_TAG_BUILD, "build",
178
build_desc, generic_nofound_msg,
181
{ LB_TAG_COMPILE_TIME, "compile_time",
182
compile_time_desc, generic_nofound_msg,
185
{ LB_TAG_COMPILE_BY, "compile_by",
186
compile_by_desc, generic_nofound_msg,
189
{ LB_TAG_COMPILE_HOST, "compile_host",
190
compile_host_desc, generic_nofound_msg,
193
{ LB_TAG_COMPILE_DOMAIN, "compile_domain",
194
compile_domain_desc, generic_nofound_msg,
197
{ LB_TAG_COMPILER, "compiler",
198
compiler_desc, generic_nofound_msg,
201
{ LB_TAG_LINKER, "linker",
202
linker_desc, generic_nofound_msg,
205
{ LB_TAG_ASSEMBLER, "assembler",
206
assembler_desc, generic_nofound_msg,
209
{ LB_TAG_CMOS_OPTION_TABLE, "cmos_opt_table",
210
cmos_opt_table_desc, nofound_msg_cmos_opt_table,
211
cmos_opt_table_print_fn
213
{ LB_TAG_OPTION_CHECKSUM, "option_checksum",
214
option_checksum_desc, nofound_msg_option_checksum,
215
option_checksum_print_fn
219
/* The coreboot table resides in low physical memory, which we access using
220
* /dev/mem. These are ranges of physical memory that should be scanned for a
224
#define NUM_MEM_RANGES 2
226
static const mem_range_t mem_ranges[NUM_MEM_RANGES] =
227
{ { 0x00000000, 0x00000fff },
228
{ 0x000f0000, 0x000fffff }
231
/* This is the number of bytes of physical memory to map, starting at physical
232
* address 0. This value must be large enough to contain all memory ranges
233
* specified in mem_ranges above plus the maximum possible size of the
234
* coreboot table (since the start of the table could potentially occur at
235
* the end of the last memory range).
237
static const size_t BYTES_TO_MAP = (1024 * 1024);
239
/* Pointer to low physical memory that we access by calling mmap() on
242
static const void *low_phys_mem;
244
/* Pointer to coreboot table. */
245
static const struct lb_header *lbtable = NULL;
247
/* The CMOS option table is located within the coreboot table. It tells us
248
* where the CMOS parameters are located in the nonvolatile RAM.
250
static const struct cmos_option_table *cmos_table = NULL;
252
static const hexdump_format_t format =
253
{ 12, 4, " ", " | ", " ", " | ", '.', NULL };
255
/****************************************************************************
258
* Convert a virtual address to a physical address. 'vaddr' is a virtual
259
* address in the address space of the current process. It points to
260
* somewhere in the chunk of memory that we mapped by calling mmap() on
261
* /dev/mem. This macro converts 'vaddr' to a physical address.
262
****************************************************************************/
263
#define vtophys(vaddr) (((unsigned long) vaddr) - \
264
((unsigned long) low_phys_mem))
266
/****************************************************************************
269
* Convert a physical address to a virtual address. 'paddr' is a physical
270
* address. This macro converts 'paddr' to a virtual address in the address
271
* space of the current process. The virtual to physical mapping was set up
272
* by calling mmap() on /dev/mem.
273
****************************************************************************/
274
#define phystov(paddr) (((unsigned long) low_phys_mem) + \
275
((unsigned long) paddr))
277
/****************************************************************************
280
* Find the coreboot table and set global variable lbtable to point to it.
281
****************************************************************************/
282
void get_lbtable (void)
283
{ int fd, i, bad_header_count, bad_table_count, bad_headers, bad_tables;
288
/* The coreboot table is located in low physical memory, which may be
289
* conveniently accessed by calling mmap() on /dev/mem.
292
if ((fd = open("/dev/mem", O_RDONLY, 0)) < 0)
293
{ fprintf(stderr, "%s: Can not open /dev/mem for reading: %s\n",
294
prog_name, strerror(errno));
298
if ((low_phys_mem = mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd, 0))
300
{ fprintf(stderr, "%s: Failed to mmap /dev/mem: %s\n", prog_name,
305
bad_header_count = 0;
308
for (i = 0; i < NUM_MEM_RANGES; i++)
309
{ lbtable = lbtable_scan(phystov(mem_ranges[i].start),
310
phystov(mem_ranges[i].end),
311
&bad_headers, &bad_tables);
314
return; /* success: we found it! */
316
bad_header_count += bad_headers;
317
bad_table_count += bad_tables;
321
"%s: coreboot table not found. coreboot does not appear to\n"
322
" be installed on this system. Scanning for the table "
324
" following results:\n\n"
325
" %d valid signatures were found with bad header "
327
" %d valid headers were found with bad table "
329
prog_name, bad_header_count, bad_table_count);
333
/****************************************************************************
334
* get_layout_from_cmos_table
336
* Find the CMOS table which is stored within the coreboot table and set the
337
* global variable cmos_table to point to it.
338
****************************************************************************/
339
void get_layout_from_cmos_table (void)
343
cmos_table = (const struct cmos_option_table *)
344
find_lbrec(LB_TAG_CMOS_OPTION_TABLE);
346
if ((cmos_table) == NULL)
348
"%s: CMOS option table not found in coreboot table. "
349
"Apparently, the coreboot installed on this system was "
350
"built without specifying HAVE_OPTION_TABLE.\n",
355
process_cmos_table();
356
get_cmos_checksum_info();
359
/****************************************************************************
362
* Do a low-level dump of the coreboot table.
363
****************************************************************************/
364
void dump_lbtable (void)
365
{ const char *p, *data;
366
uint32_t bytes_processed;
367
const struct lb_record *lbrec;
369
p = ((const char *) lbtable) + lbtable->header_bytes;
370
printf("Coreboot table at physical address 0x%lx:\n"
371
" signature: 0x%x (ASCII: %c%c%c%c)\n"
372
" header_bytes: 0x%x (decimal: %d)\n"
373
" header_checksum: 0x%x (decimal: %d)\n"
374
" table_bytes: 0x%x (decimal: %d)\n"
375
" table_checksum: 0x%x (decimal: %d)\n"
376
" table_entries: 0x%x (decimal: %d)\n\n",
377
vtophys(lbtable), *((uint32_t *) lbtable->signature),
378
lbtable->signature[0], lbtable->signature[1],lbtable->signature[2],
379
lbtable->signature[3], lbtable->header_bytes, lbtable->header_bytes,
380
lbtable->header_checksum, lbtable->header_checksum,
381
lbtable->table_bytes, lbtable->table_bytes, lbtable->table_checksum,
382
lbtable->table_checksum, lbtable->table_entries,
383
lbtable->table_entries);
385
if ((lbtable->table_bytes == 0) != (lbtable->table_entries == 0))
386
{ printf("Inconsistent values for table_bytes and table_entries!!!\n"
387
"They should be either both 0 or both nonzero.\n");
391
if (lbtable->table_bytes == 0)
392
{ printf("The coreboot table is empty!!!\n");
396
for (bytes_processed = 0; ; )
397
{ lbrec = (const struct lb_record *) &p[bytes_processed];
398
printf(" %s record at physical address 0x%lx:\n"
399
" tag: 0x%x (decimal: %d)\n"
400
" size: 0x%x (decimal: %d)\n"
402
lbrec_tag_to_str(lbrec->tag), vtophys(lbrec), lbrec->tag,
403
lbrec->tag, lbrec->size, lbrec->size);
405
data = ((const char *) lbrec) + sizeof(*lbrec);
406
hexdump(data, lbrec->size - sizeof(*lbrec), vtophys(data), stdout,
409
bytes_processed += lbrec->size;
411
if (bytes_processed >= lbtable->table_bytes)
418
/****************************************************************************
419
* list_lbtable_choices
421
* List names and informational blurbs for items from the coreboot table
422
* that may be displayed using the -l option.
423
****************************************************************************/
424
void list_lbtable_choices (void)
429
lbtable_choices[i].name, lbtable_choices[i].description);
431
if (++i >= NUM_LBTABLE_CHOICES)
438
/****************************************************************************
441
* Show the coreboot table item specified by 'item'.
442
****************************************************************************/
443
void list_lbtable_item (const char item[])
445
const struct lb_record *rec;
447
for (i = 0; i < NUM_LBTABLE_CHOICES; i++)
448
{ if (strcmp(item, lbtable_choices[i].name) == 0)
452
if (i == NUM_LBTABLE_CHOICES)
453
{ fprintf(stderr, "%s: Invalid coreboot table item %s.\n", prog_name,
458
if ((rec = find_lbrec(lbtable_choices[i].tag)) == NULL)
459
{ fprintf(stderr, lbtable_choices[i].nofound_msg, prog_name,
460
lbtable_choices[i].name);
464
lbtable_choices[i].print_fn(rec);
467
/****************************************************************************
470
* Scan the chunk of memory specified by 'start' and 'end' for a coreboot
471
* table. The first 4 bytes of the table are marked by the signature
472
* { 'L', 'B', 'I', 'O' }. 'start' and 'end' indicate the addresses of the
473
* first and last bytes of the chunk of memory to be scanned. For instance,
474
* values of 0x10000000 and 0x1000ffff for 'start' and 'end' specify a 64k
475
* chunk of memory starting at address 0x10000000. 'start' and 'end' are
476
* virtual addresses in the address space of the current process. They
477
* represent a chunk of memory obtained by calling mmap() on /dev/mem.
479
* If a coreboot table is found, return a pointer to it. Otherwise return
480
* NULL. On return, *bad_header_count and *bad_table_count are set as
484
* Indicates the number of times in which a valid signature was found
485
* but the header checksum was invalid.
488
* Indicates the number of times in which a header with a valid
489
* checksum was found but the table checksum was invalid.
490
****************************************************************************/
491
static const struct lb_header * lbtable_scan (unsigned long start,
493
int *bad_header_count,
494
int *bad_table_count)
495
{ static const char signature[] = { 'L', 'B', 'I', 'O' };
496
const struct lb_header *table;
500
assert(end >= start);
501
sig = (*((const uint32_t *) signature));
503
*bad_header_count = 0;
504
*bad_table_count = 0;
506
/* Look for signature. Table is aligned on 16-byte boundary. Therefore
507
* only check every fourth 32-bit memory word. As the loop is coded below,
508
* this function will behave in a reasonable manner for ALL possible values
509
* for 'start' and 'end': even weird boundary cases like 0x00000000 and
510
* 0xffffffff on a 32-bit architecture.
512
for (p = (const uint32_t *) start;
513
(((unsigned long) p) <= end) &&
514
((end - (unsigned long) p) >= (sizeof(uint32_t) - 1));
519
/* We found a valid signature. */
520
table = (const struct lb_header *) p;
522
/* validate header checksum */
523
if (compute_ip_checksum((void *) table, sizeof(*table)))
524
{ (*bad_header_count)++;
528
/* validate table checksum */
529
if (table->table_checksum !=
530
compute_ip_checksum(((char *) table) + sizeof(*table),
532
{ (*bad_table_count)++;
536
/* checksums are ok: we found it! */
543
/****************************************************************************
546
* Extract layout information from the CMOS option table and store it in our
547
* internal repository.
548
****************************************************************************/
549
static void process_cmos_table (void)
550
{ const struct cmos_enums *p;
551
const struct cmos_entries *q;
552
cmos_enum_t cmos_enum;
553
cmos_entry_t cmos_entry;
555
/* First add the enums. */
556
for (p = first_cmos_table_enum(); p != NULL; p = next_cmos_table_enum(p))
557
{ cmos_enum.config_id = p->config_id;
558
cmos_enum.value = p->value;
559
strncpy(cmos_enum.text, (char *)p->text, CMOS_MAX_TEXT_LENGTH);
560
cmos_enum.text[CMOS_MAX_TEXT_LENGTH] = '\0';
561
try_add_cmos_table_enum(&cmos_enum);
564
/* Now add the entries. We must add the entries after the enums because
565
* the entries are sanity checked against the enums as they are added.
567
for (q = first_cmos_table_entry(); q != NULL; q = next_cmos_table_entry(q))
568
{ cmos_entry.bit = q->bit;
569
cmos_entry.length = q->length;
573
cmos_entry.config = CMOS_ENTRY_ENUM;
577
cmos_entry.config = CMOS_ENTRY_HEX;
581
cmos_entry.config = CMOS_ENTRY_RESERVED;
585
cmos_entry.config = CMOS_ENTRY_STRING;
590
"%s: Entry in CMOS option table has unknown config "
591
"value.\n", prog_name);
595
cmos_entry.config_id = q->config_id;
596
strncpy(cmos_entry.name, (char *)q->name, CMOS_MAX_NAME_LENGTH);
597
cmos_entry.name[CMOS_MAX_NAME_LENGTH] = '\0';
598
try_add_cmos_table_entry(&cmos_entry);
602
/****************************************************************************
603
* get_cmos_checksum_info
605
* Get layout information for CMOS checksum.
606
****************************************************************************/
607
static void get_cmos_checksum_info (void)
608
{ const cmos_entry_t *e;
609
struct cmos_checksum *checksum;
610
cmos_checksum_layout_t layout;
611
unsigned index, index2;
613
checksum = (struct cmos_checksum *) find_lbrec(LB_TAG_OPTION_CHECKSUM);
615
if (checksum != NULL)
616
{ /* We are lucky. The coreboot table hints us to the checksum.
617
* We might have to check the type field here though.
619
layout.summed_area_start = checksum->range_start;
620
layout.summed_area_end = checksum->range_end;
621
layout.checksum_at = checksum->location;
622
try_convert_checksum_layout(&layout);
623
cmos_checksum_start = layout.summed_area_start;
624
cmos_checksum_end = layout.summed_area_end;
625
cmos_checksum_index = layout.checksum_at;
629
if ((e = find_cmos_entry(checksum_param_name)) == NULL)
632
/* If we get here, we are unlucky. The CMOS option table contains the
633
* location of the CMOS checksum. However, there is no information
634
* regarding which bytes of the CMOS area the checksum is computed over.
635
* Thus we have to hope our presets will be fine.
639
{ fprintf(stderr, "%s: Error: CMOS checksum is not byte-aligned.\n",
645
index2 = index + 1; /* The CMOS checksum occupies 16 bits. */
647
if (verify_cmos_byte_index(index) || verify_cmos_byte_index(index2))
648
{ fprintf(stderr, "%s: Error: CMOS checksum location out of range.\n",
653
if (((index >= cmos_checksum_start) && (index <= cmos_checksum_end)) ||
654
(((index2) >= cmos_checksum_start) && ((index2) <= cmos_checksum_end)))
655
{ fprintf(stderr, "%s: Error: CMOS checksum overlaps checksummed area.\n",
660
cmos_checksum_index = index;
663
/****************************************************************************
664
* try_convert_checksum_layout
666
* Perform sanity checking on CMOS checksum layout information and attempt to
667
* convert information from bit positions to byte positions. Return OK on
668
* success or an error code on failure.
669
****************************************************************************/
670
static void try_convert_checksum_layout (cmos_checksum_layout_t *layout)
671
{ switch (checksum_layout_to_bytes(layout))
675
case LAYOUT_SUMMED_AREA_START_NOT_ALIGNED:
677
"%s: CMOS checksummed area start is not byte-aligned.\n",
681
case LAYOUT_SUMMED_AREA_END_NOT_ALIGNED:
683
"%s: CMOS checksummed area end is not byte-aligned.\n",
687
case LAYOUT_CHECKSUM_LOCATION_NOT_ALIGNED:
689
"%s: CMOS checksum location is not byte-aligned.\n",
693
case LAYOUT_INVALID_SUMMED_AREA:
695
"%s: CMOS checksummed area end must be greater than "
696
"CMOS checksummed area start.\n",
700
case LAYOUT_CHECKSUM_OVERLAPS_SUMMED_AREA:
702
"%s: CMOS checksum overlaps checksummed area.\n",
706
case LAYOUT_SUMMED_AREA_OUT_OF_RANGE:
708
"%s: CMOS checksummed area out of range.\n",
712
case LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE:
714
"%s: CMOS checksum location out of range.\n",
725
/****************************************************************************
726
* try_add_cmos_table_enum
728
* Attempt to add a CMOS enum to our internal repository. Exit with an error
729
* message on failure.
730
****************************************************************************/
731
static void try_add_cmos_table_enum (cmos_enum_t *cmos_enum)
732
{ switch (add_cmos_enum(cmos_enum))
736
case LAYOUT_DUPLICATE_ENUM:
737
fprintf(stderr, "%s: Duplicate enum %s found in CMOS option "
738
"table.\n", prog_name, cmos_enum->text);
748
/****************************************************************************
749
* try_add_cmos_table_entry
751
* Attempt to add a CMOS entry to our internal repository. Exit with an
752
* error message on failure.
753
****************************************************************************/
754
static void try_add_cmos_table_entry (cmos_entry_t *cmos_entry)
755
{ const cmos_entry_t *conflict;
757
switch (add_cmos_entry(cmos_entry, &conflict))
761
case CMOS_AREA_OUT_OF_RANGE:
763
"%s: Bad CMOS option layout in CMOS option table entry "
764
"%s.\n", prog_name, cmos_entry->name);
767
case CMOS_AREA_TOO_WIDE:
769
"%s: Area too wide for CMOS option table entry %s.\n",
770
prog_name, cmos_entry->name);
773
case LAYOUT_ENTRY_OVERLAP:
775
"%s: CMOS option table entries %s and %s have overlapping "
776
"layouts.\n", prog_name, cmos_entry->name, conflict->name);
779
case LAYOUT_ENTRY_BAD_LENGTH:
780
/* Silently ignore entries with zero length. Although this should
781
* never happen in practice, we should handle the case in a
782
* reasonable manner just to be safe.
793
/****************************************************************************
796
* Find the record in the coreboot table that matches 'tag'. Return pointer
797
* to record on success or NULL if record not found.
798
****************************************************************************/
799
static const struct lb_record * find_lbrec (uint32_t tag)
801
uint32_t bytes_processed;
802
const struct lb_record *lbrec;
804
p = ((const char *) lbtable) + lbtable->header_bytes;
806
for (bytes_processed = 0;
807
bytes_processed < lbtable->table_bytes;
808
bytes_processed += lbrec->size)
809
{ lbrec = (const struct lb_record *) &p[bytes_processed];
811
if (lbrec->tag == tag)
818
/****************************************************************************
821
* Return a pointer to the string representation of the given coreboot table
823
****************************************************************************/
824
static const char * lbrec_tag_to_str (uint32_t tag)
826
{ case LB_TAG_UNUSED:
835
case LB_TAG_MAINBOARD:
841
case LB_TAG_EXTRA_VERSION:
842
return "EXTRA_VERSION";
847
case LB_TAG_COMPILE_TIME:
848
return "COMPILE_TIME";
850
case LB_TAG_COMPILE_BY:
853
case LB_TAG_COMPILE_HOST:
854
return "COMPILE_HOST";
856
case LB_TAG_COMPILE_DOMAIN:
857
return "COMPILE_DOMAIN";
859
case LB_TAG_COMPILER:
865
case LB_TAG_ASSEMBLER:
868
case LB_TAG_CMOS_OPTION_TABLE:
869
return "CMOS_OPTION_TABLE";
871
case LB_TAG_OPTION_CHECKSUM:
872
return "OPTION_CHECKSUM";
881
/****************************************************************************
882
* first_cmos_table_entry
884
* Return a pointer to the first entry in the CMOS table that represents a
885
* CMOS parameter. Return NULL if CMOS table is empty.
886
****************************************************************************/
887
static const struct cmos_entries * first_cmos_table_entry (void)
888
{ return (const struct cmos_entries *) first_cmos_rec(LB_TAG_OPTION); }
890
/****************************************************************************
891
* next_cmos_table_entry
893
* Return a pointer to the next entry after 'last' in the CMOS table that
894
* represents a CMOS parameter. Return NULL if there are no more parameters.
895
****************************************************************************/
896
static const struct cmos_entries *
897
next_cmos_table_entry (const struct cmos_entries *last)
898
{ return (const struct cmos_entries *)
899
next_cmos_rec((const struct lb_record *) last, LB_TAG_OPTION);
902
/****************************************************************************
903
* first_cmos_table_enum
905
* Return a pointer to the first entry in the CMOS table that represents a
906
* possible CMOS parameter value. Return NULL if the table does not contain
908
****************************************************************************/
909
static const struct cmos_enums * first_cmos_table_enum (void)
910
{ return (const struct cmos_enums *) first_cmos_rec(LB_TAG_OPTION_ENUM); }
912
/****************************************************************************
913
* next_cmos_table_enum
915
* Return a pointer to the next entry after 'last' in the CMOS table that
916
* represents a possible CMOS parameter value. Return NULL if there are no
917
* more parameter values.
918
****************************************************************************/
919
static const struct cmos_enums * next_cmos_table_enum
920
(const struct cmos_enums *last)
921
{ return (const struct cmos_enums *)
922
next_cmos_rec((const struct lb_record *) last, LB_TAG_OPTION_ENUM);
925
/****************************************************************************
928
* Return a pointer to the first entry in the CMOS table whose type matches
929
* 'tag'. Return NULL if CMOS table contains no such entry.
931
* Possible values for 'tag' are as follows:
933
* LB_TAG_OPTION: The entry represents a CMOS parameter.
934
* LB_TAG_OPTION_ENUM: The entry represents a possible value for a CMOS
935
* parameter of type 'enum'.
937
* The CMOS table tells us where in the nonvolatile RAM to look for CMOS
938
* parameter values and specifies their types as 'enum', 'hex', or
940
****************************************************************************/
941
static const struct lb_record * first_cmos_rec (uint32_t tag)
943
uint32_t bytes_processed, bytes_for_entries;
944
const struct lb_record *lbrec;
946
p = ((const char *) cmos_table) + cmos_table->header_length;
947
bytes_for_entries = cmos_table->size - cmos_table->header_length;
949
for (bytes_processed = 0;
950
bytes_processed < bytes_for_entries;
951
bytes_processed += lbrec->size)
952
{ lbrec = (const struct lb_record *) &p[bytes_processed];
954
if (lbrec->tag == tag)
961
/****************************************************************************
964
* Return a pointer to the next entry after 'last' in the CMOS table whose
965
* type matches 'tag'. Return NULL if the table contains no more entries of
967
****************************************************************************/
968
static const struct lb_record * next_cmos_rec (const struct lb_record *last,
971
uint32_t bytes_processed, bytes_for_entries, last_offset;
972
const struct lb_record *lbrec;
974
p = ((const char *) cmos_table) + cmos_table->header_length;
975
bytes_for_entries = cmos_table->size - cmos_table->header_length;
976
last_offset = ((const char *) last) - p;
978
for (bytes_processed = last_offset + last->size;
979
bytes_processed < bytes_for_entries;
980
bytes_processed += lbrec->size)
981
{ lbrec = (const struct lb_record *) &p[bytes_processed];
983
if (lbrec->tag == tag)
990
/****************************************************************************
993
* Display function for 'memory' item of coreboot table.
994
****************************************************************************/
995
static void memory_print_fn (const struct lb_record *rec)
996
{ char start_str[19], end_str[19], size_str[19];
997
const struct lb_memory *p;
998
const char *mem_type;
999
const struct lb_memory_range *ranges;
1000
uint64_t size, start, end;
1003
p = (const struct lb_memory *) rec;
1004
entries = (p->size - sizeof(*p)) / sizeof(p->map[0]);
1008
{ printf("No memory ranges were found.\n");
1013
{ switch (ranges[i].type)
1015
mem_type = "AVAILABLE";
1018
case LB_MEM_RESERVED:
1019
mem_type = "RESERVED";
1023
mem_type = "CONFIG_TABLE";
1027
mem_type = "UNKNOWN";
1031
size = unpack_lb64(ranges[i].size);
1032
start = unpack_lb64(ranges[i].start);
1033
end = start + size - 1;
1034
uint64_to_hex_string(start_str, start);
1035
uint64_to_hex_string(end_str, end);
1036
uint64_to_hex_string(size_str, size);
1037
printf("%s memory:\n"
1038
" from physical addresses %s to %s\n"
1039
" size is %s bytes (%lld in decimal)\n",
1040
mem_type, start_str, end_str, size_str,
1041
(unsigned long long) size);
1050
/****************************************************************************
1051
* mainboard_print_fn
1053
* Display function for 'mainboard' item of coreboot table.
1054
****************************************************************************/
1055
static void mainboard_print_fn (const struct lb_record *rec)
1056
{ const struct lb_mainboard *p;
1058
p = (const struct lb_mainboard *) rec;
1059
printf("Vendor: %s\n"
1060
"Part number: %s\n",
1061
&p->strings[p->vendor_idx],
1062
&p->strings[p->part_number_idx]);
1065
/****************************************************************************
1066
* cmos_opt_table_print_fn
1068
* Display function for 'cmos_opt_table' item of coreboot table.
1069
****************************************************************************/
1070
static void cmos_opt_table_print_fn (const struct lb_record *rec)
1072
const struct cmos_option_table *p;
1073
const struct lb_record *cmos_item;
1074
uint32_t bytes_processed, bytes_for_entries;
1077
p = (const struct cmos_option_table *) rec;
1078
q = ((const char *) p) + p->header_length;
1079
bytes_for_entries = p->size - p->header_length;
1081
printf("CMOS option table at physical address 0x%lx:\n"
1082
" tag: 0x%x (decimal: %d)\n"
1083
" size: 0x%x (decimal: %d)\n"
1084
" header_length: 0x%x (decimal: %d)\n\n",
1085
vtophys(p), p->tag, p->tag, p->size, p->size, p->header_length,
1088
if (p->header_length > p->size)
1089
{ printf("Header length for CMOS option table is greater than the size "
1090
"of the entire table including header!!!\n");
1094
if (bytes_for_entries == 0)
1095
{ printf("The CMOS option table is empty!!!\n");
1099
for (bytes_processed = 0; ; )
1100
{ cmos_item = (const struct lb_record *) &q[bytes_processed];
1102
switch (cmos_item->tag)
1103
{ case LB_TAG_OPTION:
1104
print_option_record((const struct cmos_entries *) cmos_item);
1107
case LB_TAG_OPTION_ENUM:
1108
print_enum_record((const struct cmos_enums *) cmos_item);
1111
case LB_TAG_OPTION_DEFAULTS:
1112
print_defaults_record((const struct cmos_defaults *) cmos_item);
1116
print_unknown_record(cmos_item);
1120
bytes_processed += cmos_item->size;
1122
if (bytes_processed >= bytes_for_entries)
1129
/****************************************************************************
1130
* print_option_record
1132
* Display "option" record from CMOS option table.
1133
****************************************************************************/
1134
static void print_option_record (const struct cmos_entries *cmos_entry)
1135
{ static const size_t S_BUFSIZE = 80;
1138
switch (cmos_entry->config)
1148
strcpy(s, "RESERVED");
1152
snprintf(s, S_BUFSIZE, "UNKNOWN: value is 0x%x (decimal: %d)",
1153
cmos_entry->config, cmos_entry->config);
1157
printf(" OPTION record at physical address 0x%lx:\n"
1158
" tag: 0x%x (decimal: %d)\n"
1159
" size: 0x%x (decimal: %d)\n"
1160
" bit: 0x%x (decimal: %d)\n"
1161
" length: 0x%x (decimal: %d)\n"
1163
" config_id: 0x%x (decimal: %d)\n"
1165
vtophys(cmos_entry), cmos_entry->tag, cmos_entry->tag,
1166
cmos_entry->size, cmos_entry->size, cmos_entry->bit,
1167
cmos_entry->bit, cmos_entry->length, cmos_entry->length, s,
1168
cmos_entry->config_id, cmos_entry->config_id, cmos_entry->name);
1171
/****************************************************************************
1174
* Display "enum" record from CMOS option table.
1175
****************************************************************************/
1176
static void print_enum_record (const struct cmos_enums *cmos_enum)
1177
{ printf(" ENUM record at physical address 0x%lx:\n"
1178
" tag: 0x%x (decimal: %d)\n"
1179
" size: 0x%x (decimal: %d)\n"
1180
" config_id: 0x%x (decimal: %d)\n"
1181
" value: 0x%x (decimal: %d)\n"
1183
vtophys(cmos_enum), cmos_enum->tag, cmos_enum->tag, cmos_enum->size,
1184
cmos_enum->size, cmos_enum->config_id, cmos_enum->config_id,
1185
cmos_enum->value, cmos_enum->value, cmos_enum->text);
1188
/****************************************************************************
1189
* print_defaults_record
1191
* Display "defaults" record from CMOS option table.
1192
****************************************************************************/
1193
static void print_defaults_record (const struct cmos_defaults *cmos_defaults)
1194
{ printf(" DEFAULTS record at physical address 0x%lx:\n"
1195
" tag: 0x%x (decimal: %d)\n"
1196
" size: 0x%x (decimal: %d)\n"
1197
" name_length: 0x%x (decimal: %d)\n"
1200
vtophys(cmos_defaults), cmos_defaults->tag, cmos_defaults->tag,
1201
cmos_defaults->size, cmos_defaults->size,
1202
cmos_defaults->name_length, cmos_defaults->name_length,
1203
cmos_defaults->name);
1204
hexdump(cmos_defaults->default_set, CMOS_IMAGE_BUFFER_SIZE,
1205
vtophys(cmos_defaults->default_set), stdout, &format);
1208
/****************************************************************************
1209
* print_unknown_record
1211
* Display record of unknown type from CMOS option table.
1212
****************************************************************************/
1213
static void print_unknown_record (const struct lb_record *cmos_item)
1216
printf(" UNKNOWN record at physical address 0x%lx:\n"
1217
" tag: 0x%x (decimal: %d)\n"
1218
" size: 0x%x (decimal: %d)\n"
1220
vtophys(cmos_item), cmos_item->tag, cmos_item->tag,
1221
cmos_item->size, cmos_item->size);
1222
data = ((const char *) cmos_item) + sizeof(*cmos_item);
1223
hexdump(data, cmos_item->size - sizeof(*cmos_item), vtophys(data), stdout,
1227
/****************************************************************************
1228
* option_checksum_print_fn
1230
* Display function for 'option_checksum' item of coreboot table.
1231
****************************************************************************/
1232
static void option_checksum_print_fn (const struct lb_record *rec)
1233
{ struct cmos_checksum *p;
1235
p = (struct cmos_checksum *) rec;
1236
printf("CMOS checksum from bit %d to bit %d\n"
1237
"at position %d is type %s.\n",
1238
p->range_start, p->range_end, p->location,
1239
(p->type == CHECKSUM_PCBIOS) ? "PC BIOS" : "NONE");
1242
/****************************************************************************
1245
* Display function for a generic item of coreboot table that simply
1246
* consists of a string.
1247
****************************************************************************/
1248
static void string_print_fn (const struct lb_record *rec)
1249
{ const struct lb_string *p;
1251
p = (const struct lb_string *) rec;
1252
printf("%s\n", p->string);
1255
/****************************************************************************
1256
* uint64_to_hex_string
1258
* Convert the 64-bit integer 'n' to its hexadecimal string representation,
1259
* storing the result in 's'. 's' must point to a buffer at least 19 bytes
1260
* long. The result is displayed with as many leading zeros as needed to
1261
* make a 16-digit hex number including a 0x prefix (example: the number 1
1262
* will be displayed as "0x0000000000000001").
1263
****************************************************************************/
1264
static void uint64_to_hex_string (char str[], uint64_t n)
1265
{ int chars_printed;
1270
/* Print the result right-justified with leading spaces in a
1271
* 16-character field. */
1272
chars_printed = sprintf(&str[2], "%016llx", (unsigned long long) n);
1273
assert(chars_printed == 16);