Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1 | /*****************************************************************************\ |
| 2 | * lbtable.c |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 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>. |
| 8 | * UCRL-CODE-2003-012 |
| 9 | * All rights reserved. |
| 10 | * |
Uwe Hermann | 6e56594 | 2008-03-01 19:06:32 +0000 | [diff] [blame] | 11 | * This file is part of nvramtool, a utility for reading/writing coreboot |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 12 | * parameters and displaying information from the coreboot table. |
Uwe Hermann | 6e56594 | 2008-03-01 19:06:32 +0000 | [diff] [blame] | 13 | * For details, see http://coreboot.org/nvramtool. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 14 | * |
| 15 | * Please also read the file DISCLAIMER which is included in this software |
| 16 | * distribution. |
| 17 | * |
| 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. |
| 21 | * |
| 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. |
| 26 | * |
| 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., |
Stefan Reinauer | ac7a2d2 | 2009-09-23 21:53:25 +0000 | [diff] [blame] | 29 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 30 | \*****************************************************************************/ |
| 31 | |
Stefan Reinauer | 297b91c | 2008-09-18 14:49:33 +0000 | [diff] [blame] | 32 | #include <string.h> |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 33 | #include <sys/mman.h> |
| 34 | #include "common.h" |
Stefan Reinauer | 7223ab7 | 2008-01-18 16:17:44 +0000 | [diff] [blame] | 35 | #include "coreboot_tables.h" |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 36 | #include "ip_checksum.h" |
| 37 | #include "lbtable.h" |
| 38 | #include "layout.h" |
| 39 | #include "cmos_lowlevel.h" |
| 40 | #include "hexdump.h" |
| 41 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 42 | typedef void (*lbtable_print_fn_t) (const struct lb_record * rec); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 43 | |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 44 | /* This structure represents an item in the coreboot table that may be |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 45 | * displayed using the -l option. |
| 46 | */ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 47 | typedef struct { |
| 48 | uint32_t tag; |
| 49 | const char *name; |
| 50 | const char *description; |
| 51 | const char *nofound_msg; |
| 52 | lbtable_print_fn_t print_fn; |
| 53 | } lbtable_choice_t; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 54 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 55 | typedef struct { |
| 56 | unsigned long start; /* address of first byte of memory range */ |
| 57 | unsigned long end; /* address of last byte of memory range */ |
| 58 | } mem_range_t; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 59 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 60 | static const struct lb_header *lbtable_scan(unsigned long start, |
| 61 | unsigned long end, |
| 62 | int *bad_header_count, |
| 63 | int *bad_table_count); |
| 64 | static void process_cmos_table(void); |
| 65 | static void get_cmos_checksum_info(void); |
| 66 | static void try_convert_checksum_layout(cmos_checksum_layout_t * layout); |
| 67 | static void try_add_cmos_table_enum(cmos_enum_t * cmos_enum); |
| 68 | static void try_add_cmos_table_entry(cmos_entry_t * cmos_entry); |
| 69 | static const struct lb_record *find_lbrec(uint32_t tag); |
| 70 | static const char *lbrec_tag_to_str(uint32_t tag); |
| 71 | static const struct cmos_entries *first_cmos_table_entry(void); |
| 72 | static const struct cmos_entries *next_cmos_table_entry(const struct |
| 73 | cmos_entries *last); |
| 74 | static const struct cmos_enums *first_cmos_table_enum(void); |
| 75 | static const struct cmos_enums *next_cmos_table_enum |
| 76 | (const struct cmos_enums *last); |
| 77 | static const struct lb_record *first_cmos_rec(uint32_t tag); |
| 78 | static const struct lb_record *next_cmos_rec(const struct lb_record *last, |
| 79 | uint32_t tag); |
| 80 | static void memory_print_fn(const struct lb_record *rec); |
| 81 | static void mainboard_print_fn(const struct lb_record *rec); |
| 82 | static void cmos_opt_table_print_fn(const struct lb_record *rec); |
| 83 | static void print_option_record(const struct cmos_entries *cmos_entry); |
| 84 | static void print_enum_record(const struct cmos_enums *cmos_enum); |
| 85 | static void print_defaults_record(const struct cmos_defaults *cmos_defaults); |
| 86 | static void print_unknown_record(const struct lb_record *cmos_item); |
| 87 | static void option_checksum_print_fn(const struct lb_record *rec); |
| 88 | static void string_print_fn(const struct lb_record *rec); |
| 89 | static void uint64_to_hex_string(char str[], uint64_t n); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 90 | |
| 91 | static const char memory_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 92 | " This shows information about system memory.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 93 | |
| 94 | static const char mainboard_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 95 | " This shows information about your mainboard.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 96 | |
| 97 | static const char version_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 98 | " This shows coreboot version information.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 99 | |
| 100 | static const char extra_version_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 101 | " This shows extra coreboot version information.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 102 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 103 | static const char build_desc[] = " This shows coreboot build information.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 104 | |
| 105 | static const char compile_time_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 106 | " This shows when coreboot was compiled.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 107 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 108 | static const char compile_by_desc[] = " This shows who compiled coreboot.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 109 | |
| 110 | static const char compile_host_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 111 | " This shows the name of the machine that compiled coreboot.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 112 | |
| 113 | static const char compile_domain_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 114 | " This shows the domain name of the machine that compiled coreboot.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 115 | |
| 116 | static const char compiler_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 117 | " This shows the name of the compiler used to build coreboot.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 118 | |
| 119 | static const char linker_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 120 | " This shows the name of the linker used to build coreboot.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 121 | |
| 122 | static const char assembler_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 123 | " This shows the name of the assembler used to build coreboot.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 124 | |
| 125 | static const char cmos_opt_table_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 126 | " This does a low-level dump of the CMOS option table. The table " |
| 127 | "contains\n" |
| 128 | " information about the layout of the values that coreboot stores in\n" |
| 129 | " nonvolatile RAM.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 130 | |
| 131 | static const char option_checksum_desc[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 132 | " This shows the location of the CMOS checksum and the area over which it " |
| 133 | "is\n" " calculated.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 134 | |
| 135 | static const char generic_nofound_msg[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 136 | "%s: Item %s not found in coreboot table.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 137 | |
| 138 | static const char nofound_msg_cmos_opt_table[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 139 | "%s: Item %s not found in coreboot table. Apparently, the " |
| 140 | "coreboot installed on this system was built without specifying " |
| 141 | "CONFIG_HAVE_OPTION_TABLE.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 142 | |
| 143 | static const char nofound_msg_option_checksum[] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 144 | "%s: Item %s not found in coreboot table. Apparently, you are " |
| 145 | "using coreboot v1.\n"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 146 | |
Stefan Reinauer | 764fe40 | 2009-03-17 14:39:36 +0000 | [diff] [blame] | 147 | int fd; |
| 148 | |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 149 | /* This is the number of items from the coreboot table that may be displayed |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 150 | * using the -l option. |
| 151 | */ |
| 152 | #define NUM_LBTABLE_CHOICES 14 |
| 153 | |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 154 | /* These represent the various items from the coreboot table that may be |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 155 | * displayed using the -l option. |
| 156 | */ |
| 157 | static const lbtable_choice_t lbtable_choices[NUM_LBTABLE_CHOICES] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 158 | { {LB_TAG_MEMORY, "memory", |
| 159 | memory_desc, generic_nofound_msg, |
| 160 | memory_print_fn}, |
| 161 | {LB_TAG_MAINBOARD, "mainboard", |
| 162 | mainboard_desc, generic_nofound_msg, |
| 163 | mainboard_print_fn}, |
| 164 | {LB_TAG_VERSION, "version", |
| 165 | version_desc, generic_nofound_msg, |
| 166 | string_print_fn}, |
| 167 | {LB_TAG_EXTRA_VERSION, "extra_version", |
| 168 | extra_version_desc, generic_nofound_msg, |
| 169 | string_print_fn}, |
| 170 | {LB_TAG_BUILD, "build", |
| 171 | build_desc, generic_nofound_msg, |
| 172 | string_print_fn}, |
| 173 | {LB_TAG_COMPILE_TIME, "compile_time", |
| 174 | compile_time_desc, generic_nofound_msg, |
| 175 | string_print_fn}, |
| 176 | {LB_TAG_COMPILE_BY, "compile_by", |
| 177 | compile_by_desc, generic_nofound_msg, |
| 178 | string_print_fn}, |
| 179 | {LB_TAG_COMPILE_HOST, "compile_host", |
| 180 | compile_host_desc, generic_nofound_msg, |
| 181 | string_print_fn}, |
| 182 | {LB_TAG_COMPILE_DOMAIN, "compile_domain", |
| 183 | compile_domain_desc, generic_nofound_msg, |
| 184 | string_print_fn}, |
| 185 | {LB_TAG_COMPILER, "compiler", |
| 186 | compiler_desc, generic_nofound_msg, |
| 187 | string_print_fn}, |
| 188 | {LB_TAG_LINKER, "linker", |
| 189 | linker_desc, generic_nofound_msg, |
| 190 | string_print_fn}, |
| 191 | {LB_TAG_ASSEMBLER, "assembler", |
| 192 | assembler_desc, generic_nofound_msg, |
| 193 | string_print_fn}, |
| 194 | {LB_TAG_CMOS_OPTION_TABLE, "cmos_opt_table", |
| 195 | cmos_opt_table_desc, nofound_msg_cmos_opt_table, |
| 196 | cmos_opt_table_print_fn}, |
| 197 | {LB_TAG_OPTION_CHECKSUM, "option_checksum", |
| 198 | option_checksum_desc, nofound_msg_option_checksum, |
| 199 | option_checksum_print_fn} |
| 200 | }; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 201 | |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 202 | /* The coreboot table resides in low physical memory, which we access using |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 203 | * /dev/mem. These are ranges of physical memory that should be scanned for a |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 204 | * coreboot table. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 205 | */ |
| 206 | |
| 207 | #define NUM_MEM_RANGES 2 |
| 208 | |
| 209 | static const mem_range_t mem_ranges[NUM_MEM_RANGES] = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 210 | { {0x00000000, 0x00000fff}, |
| 211 | {0x000f0000, 0x000fffff} |
| 212 | }; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 213 | |
| 214 | /* This is the number of bytes of physical memory to map, starting at physical |
| 215 | * address 0. This value must be large enough to contain all memory ranges |
| 216 | * specified in mem_ranges above plus the maximum possible size of the |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 217 | * coreboot table (since the start of the table could potentially occur at |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 218 | * the end of the last memory range). |
| 219 | */ |
| 220 | static const size_t BYTES_TO_MAP = (1024 * 1024); |
| 221 | |
| 222 | /* Pointer to low physical memory that we access by calling mmap() on |
| 223 | * /dev/mem. |
| 224 | */ |
| 225 | static const void *low_phys_mem; |
Stefan Reinauer | 764fe40 | 2009-03-17 14:39:36 +0000 | [diff] [blame] | 226 | static unsigned long low_phys_base = 0; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 227 | |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 228 | /* Pointer to coreboot table. */ |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 229 | static const struct lb_header *lbtable = NULL; |
| 230 | |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 231 | /* The CMOS option table is located within the coreboot table. It tells us |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 232 | * where the CMOS parameters are located in the nonvolatile RAM. |
| 233 | */ |
| 234 | static const struct cmos_option_table *cmos_table = NULL; |
| 235 | |
| 236 | static const hexdump_format_t format = |
Patrick Georgi | 024ec85 | 2011-01-18 12:14:08 +0000 | [diff] [blame] | 237 | { 12, 4, " ", " | ", " ", " | ", '.' }; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 238 | |
| 239 | /**************************************************************************** |
| 240 | * vtophys |
| 241 | * |
| 242 | * Convert a virtual address to a physical address. 'vaddr' is a virtual |
| 243 | * address in the address space of the current process. It points to |
| 244 | * somewhere in the chunk of memory that we mapped by calling mmap() on |
| 245 | * /dev/mem. This macro converts 'vaddr' to a physical address. |
| 246 | ****************************************************************************/ |
| 247 | #define vtophys(vaddr) (((unsigned long) vaddr) - \ |
Stefan Reinauer | 764fe40 | 2009-03-17 14:39:36 +0000 | [diff] [blame] | 248 | ((unsigned long) low_phys_mem) + low_phys_base) |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 249 | |
| 250 | /**************************************************************************** |
| 251 | * phystov |
| 252 | * |
| 253 | * Convert a physical address to a virtual address. 'paddr' is a physical |
| 254 | * address. This macro converts 'paddr' to a virtual address in the address |
| 255 | * space of the current process. The virtual to physical mapping was set up |
| 256 | * by calling mmap() on /dev/mem. |
| 257 | ****************************************************************************/ |
| 258 | #define phystov(paddr) (((unsigned long) low_phys_mem) + \ |
Stefan Reinauer | 764fe40 | 2009-03-17 14:39:36 +0000 | [diff] [blame] | 259 | ((unsigned long) paddr) - low_phys_base) |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 260 | |
| 261 | /**************************************************************************** |
| 262 | * get_lbtable |
| 263 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 264 | * Find the coreboot table and set global variable lbtable to point to it. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 265 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 266 | void get_lbtable(void) |
| 267 | { |
| 268 | int i, bad_header_count, bad_table_count, bad_headers, bad_tables; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 269 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 270 | if (lbtable != NULL) |
| 271 | return; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 272 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 273 | /* The coreboot table is located in low physical memory, which may be |
| 274 | * conveniently accessed by calling mmap() on /dev/mem. |
| 275 | */ |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 276 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 277 | if ((fd = open("/dev/mem", O_RDONLY, 0)) < 0) { |
| 278 | fprintf(stderr, "%s: Can not open /dev/mem for reading: %s\n", |
| 279 | prog_name, strerror(errno)); |
| 280 | exit(1); |
| 281 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 282 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 283 | if ((low_phys_mem = |
| 284 | mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd, 0)) |
| 285 | == MAP_FAILED) { |
| 286 | fprintf(stderr, "%s: Failed to mmap /dev/mem: %s\n", prog_name, |
| 287 | strerror(errno)); |
| 288 | exit(1); |
| 289 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 290 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 291 | bad_header_count = 0; |
| 292 | bad_table_count = 0; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 293 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 294 | for (i = 0; i < NUM_MEM_RANGES; i++) { |
| 295 | lbtable = lbtable_scan(phystov(mem_ranges[i].start), |
| 296 | phystov(mem_ranges[i].end), |
| 297 | &bad_headers, &bad_tables); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 298 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 299 | if (lbtable != NULL) |
| 300 | return; /* success: we found it! */ |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 301 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 302 | bad_header_count += bad_headers; |
| 303 | bad_table_count += bad_tables; |
| 304 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 305 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 306 | fprintf(stderr, |
| 307 | "%s: coreboot table not found. coreboot does not appear to\n" |
| 308 | " be installed on this system. Scanning for the table " |
| 309 | "produced the\n" |
| 310 | " following results:\n\n" |
| 311 | " %d valid signatures were found with bad header " |
| 312 | "checksums.\n" |
| 313 | " %d valid headers were found with bad table " |
| 314 | "checksums.\n", prog_name, bad_header_count, bad_table_count); |
| 315 | exit(1); |
| 316 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 317 | |
| 318 | /**************************************************************************** |
| 319 | * get_layout_from_cmos_table |
| 320 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 321 | * Find the CMOS table which is stored within the coreboot table and set the |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 322 | * global variable cmos_table to point to it. |
| 323 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 324 | void get_layout_from_cmos_table(void) |
| 325 | { |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 326 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 327 | get_lbtable(); |
| 328 | cmos_table = (const struct cmos_option_table *) |
| 329 | find_lbrec(LB_TAG_CMOS_OPTION_TABLE); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 330 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 331 | if ((cmos_table) == NULL) { |
| 332 | fprintf(stderr, |
| 333 | "%s: CMOS option table not found in coreboot table. " |
| 334 | "Apparently, the coreboot installed on this system was " |
| 335 | "built without specifying CONFIG_HAVE_OPTION_TABLE.\n", |
| 336 | prog_name); |
| 337 | exit(1); |
| 338 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 339 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 340 | process_cmos_table(); |
| 341 | get_cmos_checksum_info(); |
| 342 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 343 | |
| 344 | /**************************************************************************** |
| 345 | * dump_lbtable |
| 346 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 347 | * Do a low-level dump of the coreboot table. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 348 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 349 | void dump_lbtable(void) |
| 350 | { |
| 351 | const char *p, *data; |
| 352 | uint32_t bytes_processed; |
| 353 | const struct lb_record *lbrec; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 354 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 355 | p = ((const char *)lbtable) + lbtable->header_bytes; |
| 356 | printf("Coreboot table at physical address 0x%lx:\n" |
| 357 | " signature: 0x%x (ASCII: %c%c%c%c)\n" |
| 358 | " header_bytes: 0x%x (decimal: %d)\n" |
| 359 | " header_checksum: 0x%x (decimal: %d)\n" |
| 360 | " table_bytes: 0x%x (decimal: %d)\n" |
| 361 | " table_checksum: 0x%x (decimal: %d)\n" |
| 362 | " table_entries: 0x%x (decimal: %d)\n\n", |
Patrick Georgi | 2601697 | 2011-01-18 12:12:47 +0000 | [diff] [blame] | 363 | vtophys(lbtable), lbtable->signature32, |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 364 | lbtable->signature[0], lbtable->signature[1], |
| 365 | lbtable->signature[2], lbtable->signature[3], |
| 366 | lbtable->header_bytes, lbtable->header_bytes, |
| 367 | lbtable->header_checksum, lbtable->header_checksum, |
| 368 | lbtable->table_bytes, lbtable->table_bytes, |
| 369 | lbtable->table_checksum, lbtable->table_checksum, |
| 370 | lbtable->table_entries, lbtable->table_entries); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 371 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 372 | if ((lbtable->table_bytes == 0) != (lbtable->table_entries == 0)) { |
| 373 | printf |
| 374 | ("Inconsistent values for table_bytes and table_entries!!!\n" |
| 375 | "They should be either both 0 or both nonzero.\n"); |
| 376 | return; |
| 377 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 378 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 379 | if (lbtable->table_bytes == 0) { |
| 380 | printf("The coreboot table is empty!!!\n"); |
| 381 | return; |
| 382 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 383 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 384 | for (bytes_processed = 0;;) { |
| 385 | lbrec = (const struct lb_record *)&p[bytes_processed]; |
| 386 | printf(" %s record at physical address 0x%lx:\n" |
| 387 | " tag: 0x%x (decimal: %d)\n" |
| 388 | " size: 0x%x (decimal: %d)\n" |
| 389 | " data:\n", |
| 390 | lbrec_tag_to_str(lbrec->tag), vtophys(lbrec), lbrec->tag, |
| 391 | lbrec->tag, lbrec->size, lbrec->size); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 392 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 393 | data = ((const char *)lbrec) + sizeof(*lbrec); |
| 394 | hexdump(data, lbrec->size - sizeof(*lbrec), vtophys(data), |
| 395 | stdout, &format); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 396 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 397 | bytes_processed += lbrec->size; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 398 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 399 | if (bytes_processed >= lbtable->table_bytes) |
| 400 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 401 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 402 | printf("\n"); |
| 403 | } |
| 404 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 405 | |
| 406 | /**************************************************************************** |
| 407 | * list_lbtable_choices |
| 408 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 409 | * List names and informational blurbs for items from the coreboot table |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 410 | * that may be displayed using the -l option. |
| 411 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 412 | void list_lbtable_choices(void) |
| 413 | { |
| 414 | int i; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 415 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 416 | for (i = 0;;) { |
| 417 | printf("%s:\n%s", |
| 418 | lbtable_choices[i].name, lbtable_choices[i].description); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 419 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 420 | if (++i >= NUM_LBTABLE_CHOICES) |
| 421 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 422 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 423 | printf("\n"); |
| 424 | } |
| 425 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 426 | |
| 427 | /**************************************************************************** |
| 428 | * list_lbtable_item |
| 429 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 430 | * Show the coreboot table item specified by 'item'. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 431 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 432 | void list_lbtable_item(const char item[]) |
| 433 | { |
| 434 | int i; |
| 435 | const struct lb_record *rec; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 436 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 437 | for (i = 0; i < NUM_LBTABLE_CHOICES; i++) { |
| 438 | if (strcmp(item, lbtable_choices[i].name) == 0) |
| 439 | break; |
| 440 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 441 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 442 | if (i == NUM_LBTABLE_CHOICES) { |
| 443 | fprintf(stderr, "%s: Invalid coreboot table item %s.\n", |
| 444 | prog_name, item); |
| 445 | exit(1); |
| 446 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 447 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 448 | if ((rec = find_lbrec(lbtable_choices[i].tag)) == NULL) { |
| 449 | fprintf(stderr, lbtable_choices[i].nofound_msg, prog_name, |
| 450 | lbtable_choices[i].name); |
| 451 | exit(1); |
| 452 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 453 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 454 | lbtable_choices[i].print_fn(rec); |
| 455 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 456 | |
| 457 | /**************************************************************************** |
| 458 | * lbtable_scan |
| 459 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 460 | * Scan the chunk of memory specified by 'start' and 'end' for a coreboot |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 461 | * table. The first 4 bytes of the table are marked by the signature |
| 462 | * { 'L', 'B', 'I', 'O' }. 'start' and 'end' indicate the addresses of the |
| 463 | * first and last bytes of the chunk of memory to be scanned. For instance, |
| 464 | * values of 0x10000000 and 0x1000ffff for 'start' and 'end' specify a 64k |
| 465 | * chunk of memory starting at address 0x10000000. 'start' and 'end' are |
| 466 | * virtual addresses in the address space of the current process. They |
| 467 | * represent a chunk of memory obtained by calling mmap() on /dev/mem. |
| 468 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 469 | * If a coreboot table is found, return a pointer to it. Otherwise return |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 470 | * NULL. On return, *bad_header_count and *bad_table_count are set as |
| 471 | * follows: |
| 472 | * |
| 473 | * *bad_header_count: |
| 474 | * Indicates the number of times in which a valid signature was found |
| 475 | * but the header checksum was invalid. |
| 476 | * |
| 477 | * *bad_table_count: |
| 478 | * Indicates the number of times in which a header with a valid |
| 479 | * checksum was found but the table checksum was invalid. |
| 480 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 481 | static const struct lb_header *lbtable_scan(unsigned long start, |
| 482 | unsigned long end, |
| 483 | int *bad_header_count, |
| 484 | int *bad_table_count) |
| 485 | { |
Patrick Georgi | 2601697 | 2011-01-18 12:12:47 +0000 | [diff] [blame] | 486 | static const char signature[4] = { 'L', 'B', 'I', 'O' }; |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 487 | const struct lb_header *table; |
| 488 | const struct lb_forward *forward; |
| 489 | const uint32_t *p; |
| 490 | uint32_t sig; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 491 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 492 | assert(end >= start); |
Patrick Georgi | 2601697 | 2011-01-18 12:12:47 +0000 | [diff] [blame] | 493 | memcpy(&sig, signature, sizeof(sig)); |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 494 | table = NULL; |
| 495 | *bad_header_count = 0; |
| 496 | *bad_table_count = 0; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 497 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 498 | /* Look for signature. Table is aligned on 16-byte boundary. Therefore |
| 499 | * only check every fourth 32-bit memory word. As the loop is coded below, |
| 500 | * this function will behave in a reasonable manner for ALL possible values |
| 501 | * for 'start' and 'end': even weird boundary cases like 0x00000000 and |
| 502 | * 0xffffffff on a 32-bit architecture. |
| 503 | */ |
| 504 | for (p = (const uint32_t *)start; |
| 505 | (((unsigned long)p) <= end) && |
| 506 | ((end - (unsigned long)p) >= (sizeof(uint32_t) - 1)); p += 4) { |
| 507 | if (*p != sig) |
| 508 | continue; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 509 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 510 | /* We found a valid signature. */ |
| 511 | table = (const struct lb_header *)p; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 512 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 513 | /* validate header checksum */ |
| 514 | if (compute_ip_checksum((void *)table, sizeof(*table))) { |
| 515 | (*bad_header_count)++; |
| 516 | continue; |
| 517 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 518 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 519 | /* validate table checksum */ |
| 520 | if (table->table_checksum != |
| 521 | compute_ip_checksum(((char *)table) + sizeof(*table), |
| 522 | table->table_bytes)) { |
| 523 | (*bad_table_count)++; |
| 524 | continue; |
| 525 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 526 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 527 | /* checksums are ok: we found it! */ |
| 528 | /* But it may just be a forwarding table, so look if there's a forwarder */ |
| 529 | lbtable = table; |
| 530 | forward = (struct lb_forward *)find_lbrec(LB_TAG_FORWARD); |
| 531 | lbtable = NULL; |
Stefan Reinauer | 764fe40 | 2009-03-17 14:39:36 +0000 | [diff] [blame] | 532 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 533 | if (forward) { |
| 534 | uint64_t new_phys = forward->forward; |
Stefan Reinauer | 764fe40 | 2009-03-17 14:39:36 +0000 | [diff] [blame] | 535 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 536 | new_phys &= ~(getpagesize() - 1); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 537 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 538 | munmap((void *)low_phys_mem, BYTES_TO_MAP); |
| 539 | if ((low_phys_mem = |
| 540 | mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd, |
| 541 | (off_t) new_phys)) == MAP_FAILED) { |
| 542 | fprintf(stderr, |
| 543 | "%s: Failed to mmap /dev/mem: %s\n", |
| 544 | prog_name, strerror(errno)); |
| 545 | exit(1); |
| 546 | } |
| 547 | low_phys_base = new_phys; |
| 548 | table = |
| 549 | lbtable_scan(phystov(low_phys_base), |
| 550 | phystov(low_phys_base + BYTES_TO_MAP), |
| 551 | bad_header_count, bad_table_count); |
| 552 | } |
| 553 | return table; |
| 554 | } |
| 555 | |
| 556 | return NULL; |
| 557 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 558 | |
| 559 | /**************************************************************************** |
| 560 | * process_cmos_table |
| 561 | * |
| 562 | * Extract layout information from the CMOS option table and store it in our |
| 563 | * internal repository. |
| 564 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 565 | static void process_cmos_table(void) |
| 566 | { |
| 567 | const struct cmos_enums *p; |
| 568 | const struct cmos_entries *q; |
| 569 | cmos_enum_t cmos_enum; |
| 570 | cmos_entry_t cmos_entry; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 571 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 572 | /* First add the enums. */ |
| 573 | for (p = first_cmos_table_enum(); p != NULL; |
| 574 | p = next_cmos_table_enum(p)) { |
| 575 | cmos_enum.config_id = p->config_id; |
| 576 | cmos_enum.value = p->value; |
| 577 | strncpy(cmos_enum.text, (char *)p->text, CMOS_MAX_TEXT_LENGTH); |
| 578 | cmos_enum.text[CMOS_MAX_TEXT_LENGTH] = '\0'; |
| 579 | try_add_cmos_table_enum(&cmos_enum); |
| 580 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 581 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 582 | /* Now add the entries. We must add the entries after the enums because |
| 583 | * the entries are sanity checked against the enums as they are added. |
| 584 | */ |
| 585 | for (q = first_cmos_table_entry(); q != NULL; |
| 586 | q = next_cmos_table_entry(q)) { |
| 587 | cmos_entry.bit = q->bit; |
| 588 | cmos_entry.length = q->length; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 589 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 590 | switch (q->config) { |
| 591 | case 'e': |
| 592 | cmos_entry.config = CMOS_ENTRY_ENUM; |
| 593 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 594 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 595 | case 'h': |
| 596 | cmos_entry.config = CMOS_ENTRY_HEX; |
| 597 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 598 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 599 | case 'r': |
| 600 | cmos_entry.config = CMOS_ENTRY_RESERVED; |
| 601 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 602 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 603 | case 's': |
| 604 | cmos_entry.config = CMOS_ENTRY_STRING; |
| 605 | break; |
Stefan Reinauer | a67aab7 | 2008-09-27 10:08:28 +0000 | [diff] [blame] | 606 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 607 | default: |
| 608 | fprintf(stderr, |
| 609 | "%s: Entry in CMOS option table has unknown config " |
| 610 | "value.\n", prog_name); |
| 611 | exit(1); |
| 612 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 613 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 614 | cmos_entry.config_id = q->config_id; |
| 615 | strncpy(cmos_entry.name, (char *)q->name, CMOS_MAX_NAME_LENGTH); |
| 616 | cmos_entry.name[CMOS_MAX_NAME_LENGTH] = '\0'; |
| 617 | try_add_cmos_table_entry(&cmos_entry); |
| 618 | } |
| 619 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 620 | |
| 621 | /**************************************************************************** |
| 622 | * get_cmos_checksum_info |
| 623 | * |
| 624 | * Get layout information for CMOS checksum. |
| 625 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 626 | static void get_cmos_checksum_info(void) |
| 627 | { |
| 628 | const cmos_entry_t *e; |
| 629 | struct cmos_checksum *checksum; |
| 630 | cmos_checksum_layout_t layout; |
| 631 | unsigned index, index2; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 632 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 633 | checksum = (struct cmos_checksum *)find_lbrec(LB_TAG_OPTION_CHECKSUM); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 634 | |
Patrick Georgi | 0d4f653 | 2011-01-21 07:04:05 +0000 | [diff] [blame] | 635 | if (checksum == NULL) { |
| 636 | checksum = (struct cmos_checksum *)next_cmos_rec((const struct lb_record *)first_cmos_table_enum(), LB_TAG_OPTION_CHECKSUM); |
| 637 | } |
| 638 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 639 | if (checksum != NULL) { /* We are lucky. The coreboot table hints us to the checksum. |
| 640 | * We might have to check the type field here though. |
| 641 | */ |
| 642 | layout.summed_area_start = checksum->range_start; |
| 643 | layout.summed_area_end = checksum->range_end; |
| 644 | layout.checksum_at = checksum->location; |
| 645 | try_convert_checksum_layout(&layout); |
| 646 | cmos_checksum_start = layout.summed_area_start; |
| 647 | cmos_checksum_end = layout.summed_area_end; |
| 648 | cmos_checksum_index = layout.checksum_at; |
| 649 | return; |
| 650 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 651 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 652 | if ((e = find_cmos_entry(checksum_param_name)) == NULL) |
| 653 | return; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 654 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 655 | /* If we get here, we are unlucky. The CMOS option table contains the |
| 656 | * location of the CMOS checksum. However, there is no information |
| 657 | * regarding which bytes of the CMOS area the checksum is computed over. |
| 658 | * Thus we have to hope our presets will be fine. |
| 659 | */ |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 660 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 661 | if (e->bit % 8) { |
| 662 | fprintf(stderr, |
| 663 | "%s: Error: CMOS checksum is not byte-aligned.\n", |
| 664 | prog_name); |
| 665 | exit(1); |
| 666 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 667 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 668 | index = e->bit / 8; |
| 669 | index2 = index + 1; /* The CMOS checksum occupies 16 bits. */ |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 670 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 671 | if (verify_cmos_byte_index(index) || verify_cmos_byte_index(index2)) { |
| 672 | fprintf(stderr, |
| 673 | "%s: Error: CMOS checksum location out of range.\n", |
| 674 | prog_name); |
| 675 | exit(1); |
| 676 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 677 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 678 | if (((index >= cmos_checksum_start) && (index <= cmos_checksum_end)) || |
| 679 | (((index2) >= cmos_checksum_start) |
| 680 | && ((index2) <= cmos_checksum_end))) { |
| 681 | fprintf(stderr, |
| 682 | "%s: Error: CMOS checksum overlaps checksummed area.\n", |
| 683 | prog_name); |
| 684 | exit(1); |
| 685 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 686 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 687 | cmos_checksum_index = index; |
| 688 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 689 | |
| 690 | /**************************************************************************** |
| 691 | * try_convert_checksum_layout |
| 692 | * |
| 693 | * Perform sanity checking on CMOS checksum layout information and attempt to |
| 694 | * convert information from bit positions to byte positions. Return OK on |
| 695 | * success or an error code on failure. |
| 696 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 697 | static void try_convert_checksum_layout(cmos_checksum_layout_t * layout) |
| 698 | { |
| 699 | switch (checksum_layout_to_bytes(layout)) { |
| 700 | case OK: |
| 701 | return; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 702 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 703 | case LAYOUT_SUMMED_AREA_START_NOT_ALIGNED: |
| 704 | fprintf(stderr, |
| 705 | "%s: CMOS checksummed area start is not byte-aligned.\n", |
| 706 | prog_name); |
| 707 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 708 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 709 | case LAYOUT_SUMMED_AREA_END_NOT_ALIGNED: |
| 710 | fprintf(stderr, |
| 711 | "%s: CMOS checksummed area end is not byte-aligned.\n", |
| 712 | prog_name); |
| 713 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 714 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 715 | case LAYOUT_CHECKSUM_LOCATION_NOT_ALIGNED: |
| 716 | fprintf(stderr, |
| 717 | "%s: CMOS checksum location is not byte-aligned.\n", |
| 718 | prog_name); |
| 719 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 720 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 721 | case LAYOUT_INVALID_SUMMED_AREA: |
| 722 | fprintf(stderr, |
| 723 | "%s: CMOS checksummed area end must be greater than " |
| 724 | "CMOS checksummed area start.\n", prog_name); |
| 725 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 726 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 727 | case LAYOUT_CHECKSUM_OVERLAPS_SUMMED_AREA: |
| 728 | fprintf(stderr, |
| 729 | "%s: CMOS checksum overlaps checksummed area.\n", |
| 730 | prog_name); |
| 731 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 732 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 733 | case LAYOUT_SUMMED_AREA_OUT_OF_RANGE: |
| 734 | fprintf(stderr, |
| 735 | "%s: CMOS checksummed area out of range.\n", prog_name); |
| 736 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 737 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 738 | case LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE: |
| 739 | fprintf(stderr, |
| 740 | "%s: CMOS checksum location out of range.\n", |
| 741 | prog_name); |
| 742 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 743 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 744 | default: |
| 745 | BUG(); |
| 746 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 747 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 748 | exit(1); |
| 749 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 750 | |
| 751 | /**************************************************************************** |
| 752 | * try_add_cmos_table_enum |
| 753 | * |
| 754 | * Attempt to add a CMOS enum to our internal repository. Exit with an error |
| 755 | * message on failure. |
| 756 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 757 | static void try_add_cmos_table_enum(cmos_enum_t * cmos_enum) |
| 758 | { |
| 759 | switch (add_cmos_enum(cmos_enum)) { |
| 760 | case OK: |
| 761 | return; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 762 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 763 | case LAYOUT_DUPLICATE_ENUM: |
| 764 | fprintf(stderr, "%s: Duplicate enum %s found in CMOS option " |
| 765 | "table.\n", prog_name, cmos_enum->text); |
| 766 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 767 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 768 | default: |
| 769 | BUG(); |
| 770 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 771 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 772 | exit(1); |
| 773 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 774 | |
| 775 | /**************************************************************************** |
| 776 | * try_add_cmos_table_entry |
| 777 | * |
| 778 | * Attempt to add a CMOS entry to our internal repository. Exit with an |
| 779 | * error message on failure. |
| 780 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 781 | static void try_add_cmos_table_entry(cmos_entry_t * cmos_entry) |
| 782 | { |
| 783 | const cmos_entry_t *conflict; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 784 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 785 | switch (add_cmos_entry(cmos_entry, &conflict)) { |
| 786 | case OK: |
| 787 | return; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 788 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 789 | case CMOS_AREA_OUT_OF_RANGE: |
| 790 | fprintf(stderr, |
| 791 | "%s: Bad CMOS option layout in CMOS option table entry " |
| 792 | "%s.\n", prog_name, cmos_entry->name); |
| 793 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 794 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 795 | case CMOS_AREA_TOO_WIDE: |
| 796 | fprintf(stderr, |
| 797 | "%s: Area too wide for CMOS option table entry %s.\n", |
| 798 | prog_name, cmos_entry->name); |
| 799 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 800 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 801 | case LAYOUT_ENTRY_OVERLAP: |
| 802 | fprintf(stderr, |
| 803 | "%s: CMOS option table entries %s and %s have overlapping " |
| 804 | "layouts.\n", prog_name, cmos_entry->name, |
| 805 | conflict->name); |
| 806 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 807 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 808 | case LAYOUT_ENTRY_BAD_LENGTH: |
| 809 | /* Silently ignore entries with zero length. Although this should |
| 810 | * never happen in practice, we should handle the case in a |
| 811 | * reasonable manner just to be safe. |
| 812 | */ |
| 813 | return; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 814 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 815 | default: |
| 816 | BUG(); |
| 817 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 818 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 819 | exit(1); |
| 820 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 821 | |
| 822 | /**************************************************************************** |
| 823 | * find_lbrec |
| 824 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 825 | * Find the record in the coreboot table that matches 'tag'. Return pointer |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 826 | * to record on success or NULL if record not found. |
| 827 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 828 | static const struct lb_record *find_lbrec(uint32_t tag) |
| 829 | { |
| 830 | const char *p; |
| 831 | uint32_t bytes_processed; |
| 832 | const struct lb_record *lbrec; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 833 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 834 | p = ((const char *)lbtable) + lbtable->header_bytes; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 835 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 836 | for (bytes_processed = 0; |
| 837 | bytes_processed < lbtable->table_bytes; |
| 838 | bytes_processed += lbrec->size) { |
| 839 | lbrec = (const struct lb_record *)&p[bytes_processed]; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 840 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 841 | if (lbrec->tag == tag) |
| 842 | return lbrec; |
| 843 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 844 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 845 | return NULL; |
| 846 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 847 | |
| 848 | /**************************************************************************** |
| 849 | * lbrec_tag_to_str |
| 850 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 851 | * Return a pointer to the string representation of the given coreboot table |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 852 | * tag. |
| 853 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 854 | static const char *lbrec_tag_to_str(uint32_t tag) |
| 855 | { |
| 856 | switch (tag) { |
| 857 | case LB_TAG_UNUSED: |
| 858 | return "UNUSED"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 859 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 860 | case LB_TAG_MEMORY: |
| 861 | return "MEMORY"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 862 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 863 | case LB_TAG_HWRPB: |
| 864 | return "HWRPB"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 865 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 866 | case LB_TAG_MAINBOARD: |
| 867 | return "MAINBOARD"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 868 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 869 | case LB_TAG_VERSION: |
| 870 | return "VERSION"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 871 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 872 | case LB_TAG_EXTRA_VERSION: |
| 873 | return "EXTRA_VERSION"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 874 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 875 | case LB_TAG_BUILD: |
| 876 | return "BUILD"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 877 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 878 | case LB_TAG_COMPILE_TIME: |
| 879 | return "COMPILE_TIME"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 880 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 881 | case LB_TAG_COMPILE_BY: |
| 882 | return "COMPILE_BY"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 883 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 884 | case LB_TAG_COMPILE_HOST: |
| 885 | return "COMPILE_HOST"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 886 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 887 | case LB_TAG_COMPILE_DOMAIN: |
| 888 | return "COMPILE_DOMAIN"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 889 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 890 | case LB_TAG_COMPILER: |
| 891 | return "COMPILER"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 892 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 893 | case LB_TAG_LINKER: |
| 894 | return "LINKER"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 895 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 896 | case LB_TAG_ASSEMBLER: |
| 897 | return "ASSEMBLER"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 898 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 899 | case LB_TAG_SERIAL: |
| 900 | return "SERIAL"; |
Stefan Reinauer | 764fe40 | 2009-03-17 14:39:36 +0000 | [diff] [blame] | 901 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 902 | case LB_TAG_CONSOLE: |
| 903 | return "CONSOLE"; |
Stefan Reinauer | 764fe40 | 2009-03-17 14:39:36 +0000 | [diff] [blame] | 904 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 905 | case LB_TAG_FORWARD: |
| 906 | return "FORWARD"; |
Stefan Reinauer | 764fe40 | 2009-03-17 14:39:36 +0000 | [diff] [blame] | 907 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 908 | case LB_TAG_CMOS_OPTION_TABLE: |
| 909 | return "CMOS_OPTION_TABLE"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 910 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 911 | case LB_TAG_OPTION_CHECKSUM: |
| 912 | return "OPTION_CHECKSUM"; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 913 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 914 | default: |
| 915 | break; |
| 916 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 917 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 918 | return "UNKNOWN"; |
| 919 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 920 | |
| 921 | /**************************************************************************** |
| 922 | * first_cmos_table_entry |
| 923 | * |
| 924 | * Return a pointer to the first entry in the CMOS table that represents a |
| 925 | * CMOS parameter. Return NULL if CMOS table is empty. |
| 926 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 927 | static const struct cmos_entries *first_cmos_table_entry(void) |
| 928 | { |
| 929 | return (const struct cmos_entries *)first_cmos_rec(LB_TAG_OPTION); |
| 930 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 931 | |
| 932 | /**************************************************************************** |
| 933 | * next_cmos_table_entry |
| 934 | * |
| 935 | * Return a pointer to the next entry after 'last' in the CMOS table that |
| 936 | * represents a CMOS parameter. Return NULL if there are no more parameters. |
| 937 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 938 | static const struct cmos_entries *next_cmos_table_entry(const struct |
| 939 | cmos_entries *last) |
| 940 | { |
| 941 | return (const struct cmos_entries *) |
| 942 | next_cmos_rec((const struct lb_record *)last, LB_TAG_OPTION); |
| 943 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 944 | |
| 945 | /**************************************************************************** |
| 946 | * first_cmos_table_enum |
| 947 | * |
| 948 | * Return a pointer to the first entry in the CMOS table that represents a |
| 949 | * possible CMOS parameter value. Return NULL if the table does not contain |
| 950 | * any such entries. |
| 951 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 952 | static const struct cmos_enums *first_cmos_table_enum(void) |
| 953 | { |
| 954 | return (const struct cmos_enums *)first_cmos_rec(LB_TAG_OPTION_ENUM); |
| 955 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 956 | |
| 957 | /**************************************************************************** |
| 958 | * next_cmos_table_enum |
| 959 | * |
| 960 | * Return a pointer to the next entry after 'last' in the CMOS table that |
| 961 | * represents a possible CMOS parameter value. Return NULL if there are no |
| 962 | * more parameter values. |
| 963 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 964 | static const struct cmos_enums *next_cmos_table_enum |
| 965 | (const struct cmos_enums *last) { |
| 966 | return (const struct cmos_enums *) |
| 967 | next_cmos_rec((const struct lb_record *)last, LB_TAG_OPTION_ENUM); |
| 968 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 969 | |
| 970 | /**************************************************************************** |
| 971 | * first_cmos_rec |
| 972 | * |
| 973 | * Return a pointer to the first entry in the CMOS table whose type matches |
| 974 | * 'tag'. Return NULL if CMOS table contains no such entry. |
| 975 | * |
| 976 | * Possible values for 'tag' are as follows: |
| 977 | * |
| 978 | * LB_TAG_OPTION: The entry represents a CMOS parameter. |
| 979 | * LB_TAG_OPTION_ENUM: The entry represents a possible value for a CMOS |
| 980 | * parameter of type 'enum'. |
| 981 | * |
| 982 | * The CMOS table tells us where in the nonvolatile RAM to look for CMOS |
| 983 | * parameter values and specifies their types as 'enum', 'hex', or |
| 984 | * 'reserved'. |
| 985 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 986 | static const struct lb_record *first_cmos_rec(uint32_t tag) |
| 987 | { |
| 988 | const char *p; |
| 989 | uint32_t bytes_processed, bytes_for_entries; |
| 990 | const struct lb_record *lbrec; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 991 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 992 | p = ((const char *)cmos_table) + cmos_table->header_length; |
| 993 | bytes_for_entries = cmos_table->size - cmos_table->header_length; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 994 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 995 | for (bytes_processed = 0; |
| 996 | bytes_processed < bytes_for_entries; |
| 997 | bytes_processed += lbrec->size) { |
| 998 | lbrec = (const struct lb_record *)&p[bytes_processed]; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 999 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1000 | if (lbrec->tag == tag) |
| 1001 | return lbrec; |
| 1002 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1003 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1004 | return NULL; |
| 1005 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1006 | |
| 1007 | /**************************************************************************** |
| 1008 | * next_cmos_rec |
| 1009 | * |
| 1010 | * Return a pointer to the next entry after 'last' in the CMOS table whose |
| 1011 | * type matches 'tag'. Return NULL if the table contains no more entries of |
| 1012 | * this type. |
| 1013 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1014 | static const struct lb_record *next_cmos_rec(const struct lb_record *last, |
| 1015 | uint32_t tag) |
| 1016 | { |
| 1017 | const char *p; |
| 1018 | uint32_t bytes_processed, bytes_for_entries, last_offset; |
| 1019 | const struct lb_record *lbrec; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1020 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1021 | p = ((const char *)cmos_table) + cmos_table->header_length; |
| 1022 | bytes_for_entries = cmos_table->size - cmos_table->header_length; |
| 1023 | last_offset = ((const char *)last) - p; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1024 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1025 | for (bytes_processed = last_offset + last->size; |
| 1026 | bytes_processed < bytes_for_entries; |
| 1027 | bytes_processed += lbrec->size) { |
| 1028 | lbrec = (const struct lb_record *)&p[bytes_processed]; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1029 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1030 | if (lbrec->tag == tag) |
| 1031 | return lbrec; |
| 1032 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1033 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1034 | return NULL; |
| 1035 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1036 | |
| 1037 | /**************************************************************************** |
| 1038 | * memory_print_fn |
| 1039 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 1040 | * Display function for 'memory' item of coreboot table. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1041 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1042 | static void memory_print_fn(const struct lb_record *rec) |
| 1043 | { |
| 1044 | char start_str[19], end_str[19], size_str[19]; |
| 1045 | const struct lb_memory *p; |
| 1046 | const char *mem_type; |
| 1047 | const struct lb_memory_range *ranges; |
| 1048 | uint64_t size, start, end; |
| 1049 | int i, entries; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1050 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1051 | p = (const struct lb_memory *)rec; |
| 1052 | entries = (p->size - sizeof(*p)) / sizeof(p->map[0]); |
| 1053 | ranges = p->map; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1054 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1055 | if (entries == 0) { |
| 1056 | printf("No memory ranges were found.\n"); |
| 1057 | return; |
| 1058 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1059 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1060 | for (i = 0;;) { |
| 1061 | switch (ranges[i].type) { |
| 1062 | case LB_MEM_RAM: |
| 1063 | mem_type = "AVAILABLE"; |
| 1064 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1065 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1066 | case LB_MEM_RESERVED: |
| 1067 | mem_type = "RESERVED"; |
| 1068 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1069 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1070 | case LB_MEM_TABLE: |
| 1071 | mem_type = "CONFIG_TABLE"; |
| 1072 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1073 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1074 | default: |
| 1075 | mem_type = "UNKNOWN"; |
| 1076 | break; |
| 1077 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1078 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1079 | size = unpack_lb64(ranges[i].size); |
| 1080 | start = unpack_lb64(ranges[i].start); |
| 1081 | end = start + size - 1; |
| 1082 | uint64_to_hex_string(start_str, start); |
| 1083 | uint64_to_hex_string(end_str, end); |
| 1084 | uint64_to_hex_string(size_str, size); |
| 1085 | printf("%s memory:\n" |
| 1086 | " from physical addresses %s to %s\n" |
| 1087 | " size is %s bytes (%lld in decimal)\n", |
| 1088 | mem_type, start_str, end_str, size_str, |
| 1089 | (unsigned long long)size); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1090 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1091 | if (++i >= entries) |
| 1092 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1093 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1094 | printf("\n"); |
| 1095 | } |
| 1096 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1097 | |
| 1098 | /**************************************************************************** |
| 1099 | * mainboard_print_fn |
| 1100 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 1101 | * Display function for 'mainboard' item of coreboot table. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1102 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1103 | static void mainboard_print_fn(const struct lb_record *rec) |
| 1104 | { |
| 1105 | const struct lb_mainboard *p; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1106 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1107 | p = (const struct lb_mainboard *)rec; |
| 1108 | printf("Vendor: %s\n" |
| 1109 | "Part number: %s\n", |
| 1110 | &p->strings[p->vendor_idx], &p->strings[p->part_number_idx]); |
| 1111 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1112 | |
| 1113 | /**************************************************************************** |
| 1114 | * cmos_opt_table_print_fn |
| 1115 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 1116 | * Display function for 'cmos_opt_table' item of coreboot table. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1117 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1118 | static void cmos_opt_table_print_fn(const struct lb_record *rec) |
| 1119 | { |
| 1120 | const struct cmos_option_table *p; |
| 1121 | const struct lb_record *cmos_item; |
| 1122 | uint32_t bytes_processed, bytes_for_entries; |
| 1123 | const char *q; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1124 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1125 | p = (const struct cmos_option_table *)rec; |
| 1126 | q = ((const char *)p) + p->header_length; |
| 1127 | bytes_for_entries = p->size - p->header_length; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1128 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1129 | printf("CMOS option table at physical address 0x%lx:\n" |
| 1130 | " tag: 0x%x (decimal: %d)\n" |
| 1131 | " size: 0x%x (decimal: %d)\n" |
| 1132 | " header_length: 0x%x (decimal: %d)\n\n", |
| 1133 | vtophys(p), p->tag, p->tag, p->size, p->size, p->header_length, |
| 1134 | p->header_length); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1135 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1136 | if (p->header_length > p->size) { |
| 1137 | printf |
| 1138 | ("Header length for CMOS option table is greater than the size " |
| 1139 | "of the entire table including header!!!\n"); |
| 1140 | return; |
| 1141 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1142 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1143 | if (bytes_for_entries == 0) { |
| 1144 | printf("The CMOS option table is empty!!!\n"); |
| 1145 | return; |
| 1146 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1147 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1148 | for (bytes_processed = 0;;) { |
| 1149 | cmos_item = (const struct lb_record *)&q[bytes_processed]; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1150 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1151 | switch (cmos_item->tag) { |
| 1152 | case LB_TAG_OPTION: |
| 1153 | print_option_record((const struct cmos_entries *) |
| 1154 | cmos_item); |
| 1155 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1156 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1157 | case LB_TAG_OPTION_ENUM: |
| 1158 | print_enum_record((const struct cmos_enums *)cmos_item); |
| 1159 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1160 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1161 | case LB_TAG_OPTION_DEFAULTS: |
| 1162 | print_defaults_record((const struct cmos_defaults *) |
| 1163 | cmos_item); |
| 1164 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1165 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1166 | default: |
| 1167 | print_unknown_record(cmos_item); |
| 1168 | break; |
| 1169 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1170 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1171 | bytes_processed += cmos_item->size; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1172 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1173 | if (bytes_processed >= bytes_for_entries) |
| 1174 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1175 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1176 | printf("\n"); |
| 1177 | } |
| 1178 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1179 | |
| 1180 | /**************************************************************************** |
| 1181 | * print_option_record |
| 1182 | * |
| 1183 | * Display "option" record from CMOS option table. |
| 1184 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1185 | static void print_option_record(const struct cmos_entries *cmos_entry) |
| 1186 | { |
| 1187 | static const size_t S_BUFSIZE = 80; |
| 1188 | char s[S_BUFSIZE]; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1189 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1190 | switch (cmos_entry->config) { |
| 1191 | case 'e': |
| 1192 | strcpy(s, "ENUM"); |
| 1193 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1194 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1195 | case 'h': |
| 1196 | strcpy(s, "HEX"); |
| 1197 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1198 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1199 | case 'r': |
| 1200 | strcpy(s, "RESERVED"); |
| 1201 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1202 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1203 | default: |
| 1204 | snprintf(s, S_BUFSIZE, "UNKNOWN: value is 0x%x (decimal: %d)", |
| 1205 | cmos_entry->config, cmos_entry->config); |
| 1206 | break; |
| 1207 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1208 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1209 | printf(" OPTION record at physical address 0x%lx:\n" |
| 1210 | " tag: 0x%x (decimal: %d)\n" |
| 1211 | " size: 0x%x (decimal: %d)\n" |
| 1212 | " bit: 0x%x (decimal: %d)\n" |
| 1213 | " length: 0x%x (decimal: %d)\n" |
| 1214 | " config: %s\n" |
| 1215 | " config_id: 0x%x (decimal: %d)\n" |
| 1216 | " name: %s\n", |
| 1217 | vtophys(cmos_entry), cmos_entry->tag, cmos_entry->tag, |
| 1218 | cmos_entry->size, cmos_entry->size, cmos_entry->bit, |
| 1219 | cmos_entry->bit, cmos_entry->length, cmos_entry->length, s, |
| 1220 | cmos_entry->config_id, cmos_entry->config_id, cmos_entry->name); |
| 1221 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1222 | |
| 1223 | /**************************************************************************** |
| 1224 | * print_enum_record |
| 1225 | * |
| 1226 | * Display "enum" record from CMOS option table. |
| 1227 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1228 | static void print_enum_record(const struct cmos_enums *cmos_enum) |
| 1229 | { |
| 1230 | printf(" ENUM record at physical address 0x%lx:\n" |
| 1231 | " tag: 0x%x (decimal: %d)\n" |
| 1232 | " size: 0x%x (decimal: %d)\n" |
| 1233 | " config_id: 0x%x (decimal: %d)\n" |
| 1234 | " value: 0x%x (decimal: %d)\n" |
| 1235 | " text: %s\n", |
| 1236 | vtophys(cmos_enum), cmos_enum->tag, cmos_enum->tag, |
| 1237 | cmos_enum->size, cmos_enum->size, cmos_enum->config_id, |
| 1238 | cmos_enum->config_id, cmos_enum->value, cmos_enum->value, |
| 1239 | cmos_enum->text); |
| 1240 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1241 | |
| 1242 | /**************************************************************************** |
| 1243 | * print_defaults_record |
| 1244 | * |
| 1245 | * Display "defaults" record from CMOS option table. |
| 1246 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1247 | static void print_defaults_record(const struct cmos_defaults *cmos_defaults) |
| 1248 | { |
| 1249 | printf(" DEFAULTS record at physical address 0x%lx:\n" |
| 1250 | " tag: 0x%x (decimal: %d)\n" |
| 1251 | " size: 0x%x (decimal: %d)\n" |
| 1252 | " name_length: 0x%x (decimal: %d)\n" |
| 1253 | " name: %s\n" |
| 1254 | " default_set:\n", |
| 1255 | vtophys(cmos_defaults), cmos_defaults->tag, cmos_defaults->tag, |
| 1256 | cmos_defaults->size, cmos_defaults->size, |
| 1257 | cmos_defaults->name_length, cmos_defaults->name_length, |
| 1258 | cmos_defaults->name); |
| 1259 | hexdump(cmos_defaults->default_set, CMOS_IMAGE_BUFFER_SIZE, |
| 1260 | vtophys(cmos_defaults->default_set), stdout, &format); |
| 1261 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1262 | |
| 1263 | /**************************************************************************** |
| 1264 | * print_unknown_record |
| 1265 | * |
| 1266 | * Display record of unknown type from CMOS option table. |
| 1267 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1268 | static void print_unknown_record(const struct lb_record *cmos_item) |
| 1269 | { |
| 1270 | const char *data; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1271 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1272 | printf(" UNKNOWN record at physical address 0x%lx:\n" |
| 1273 | " tag: 0x%x (decimal: %d)\n" |
| 1274 | " size: 0x%x (decimal: %d)\n" |
| 1275 | " data:\n", |
| 1276 | vtophys(cmos_item), cmos_item->tag, cmos_item->tag, |
| 1277 | cmos_item->size, cmos_item->size); |
| 1278 | data = ((const char *)cmos_item) + sizeof(*cmos_item); |
| 1279 | hexdump(data, cmos_item->size - sizeof(*cmos_item), vtophys(data), |
| 1280 | stdout, &format); |
| 1281 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1282 | |
| 1283 | /**************************************************************************** |
| 1284 | * option_checksum_print_fn |
| 1285 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 1286 | * Display function for 'option_checksum' item of coreboot table. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1287 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1288 | static void option_checksum_print_fn(const struct lb_record *rec) |
| 1289 | { |
| 1290 | struct cmos_checksum *p; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1291 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1292 | p = (struct cmos_checksum *)rec; |
| 1293 | printf("CMOS checksum from bit %d to bit %d\n" |
| 1294 | "at position %d is type %s.\n", |
| 1295 | p->range_start, p->range_end, p->location, |
| 1296 | (p->type == CHECKSUM_PCBIOS) ? "PC BIOS" : "NONE"); |
| 1297 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1298 | |
| 1299 | /**************************************************************************** |
| 1300 | * string_print_fn |
| 1301 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 1302 | * Display function for a generic item of coreboot table that simply |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1303 | * consists of a string. |
| 1304 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1305 | static void string_print_fn(const struct lb_record *rec) |
| 1306 | { |
| 1307 | const struct lb_string *p; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1308 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1309 | p = (const struct lb_string *)rec; |
| 1310 | printf("%s\n", p->string); |
| 1311 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1312 | |
| 1313 | /**************************************************************************** |
| 1314 | * uint64_to_hex_string |
| 1315 | * |
| 1316 | * Convert the 64-bit integer 'n' to its hexadecimal string representation, |
| 1317 | * storing the result in 's'. 's' must point to a buffer at least 19 bytes |
| 1318 | * long. The result is displayed with as many leading zeros as needed to |
| 1319 | * make a 16-digit hex number including a 0x prefix (example: the number 1 |
| 1320 | * will be displayed as "0x0000000000000001"). |
| 1321 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1322 | static void uint64_to_hex_string(char str[], uint64_t n) |
| 1323 | { |
| 1324 | int chars_printed; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1325 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1326 | str[0] = '0'; |
| 1327 | str[1] = 'x'; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1328 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 1329 | /* Print the result right-justified with leading spaces in a |
| 1330 | * 16-character field. */ |
| 1331 | chars_printed = sprintf(&str[2], "%016llx", (unsigned long long)n); |
| 1332 | assert(chars_printed == 16); |
| 1333 | } |