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