Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1 | /*****************************************************************************\ |
Uwe Hermann | 6e56594 | 2008-03-01 19:06:32 +0000 | [diff] [blame] | 2 | * nvramtool.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 | * UCRL-CODE-2003-012 |
| 8 | * All rights reserved. |
| 9 | * |
Uwe Hermann | 6e56594 | 2008-03-01 19:06:32 +0000 | [diff] [blame] | 10 | * This file is part of nvramtool, a utility for reading/writing coreboot |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 11 | * parameters and displaying information from the coreboot table. |
Uwe Hermann | 6e56594 | 2008-03-01 19:06:32 +0000 | [diff] [blame] | 12 | * For details, see http://coreboot.org/nvramtool. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 13 | * |
| 14 | * Please also read the file DISCLAIMER which is included in this software |
| 15 | * distribution. |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or modify it |
| 18 | * under the terms of the GNU General Public License (as published by the |
| 19 | * Free Software Foundation) version 2, dated June 1991. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, but |
| 22 | * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and |
| 24 | * conditions of the GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License along |
| 27 | * with this program; if not, write to the Free Software Foundation, Inc., |
Stefan Reinauer | ac7a2d2 | 2009-09-23 21:53:25 +0000 | [diff] [blame] | 28 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 29 | \*****************************************************************************/ |
| 30 | |
| 31 | #include "common.h" |
| 32 | #include "opts.h" |
| 33 | #include "lbtable.h" |
| 34 | #include "layout.h" |
| 35 | #include "layout_file.h" |
| 36 | #include "input_file.h" |
| 37 | #include "cmos_ops.h" |
| 38 | #include "cmos_lowlevel.h" |
| 39 | #include "reg_expr.h" |
| 40 | #include "hexdump.h" |
| 41 | |
| 42 | typedef void (*op_fn_t) (void); |
| 43 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 44 | static void op_show_version(void); |
| 45 | static void op_show_usage(void); |
| 46 | static void op_lbtable_show_info(void); |
| 47 | static void op_lbtable_dump(void); |
| 48 | static void op_show_param_values(void); |
| 49 | static void op_cmos_show_one_param(void); |
| 50 | static void op_cmos_show_all_params(void); |
| 51 | static void op_cmos_set_one_param(void); |
| 52 | static void op_cmos_set_params_stdin(void); |
| 53 | static void op_cmos_set_params_file(void); |
| 54 | static void op_cmos_checksum(void); |
| 55 | static void op_show_layout(void); |
| 56 | static void op_write_cmos_dump(void); |
| 57 | static void op_read_cmos_dump(void); |
| 58 | static void op_show_cmos_hex_dump(void); |
| 59 | static void op_show_cmos_dumpfile(void); |
| 60 | static int list_one_param(const char name[], int show_name); |
| 61 | static int list_all_params(void); |
| 62 | static void list_param_enums(const char name[]); |
| 63 | static void set_one_param(const char name[], const char value[]); |
| 64 | static void set_params(FILE * f); |
| 65 | static void parse_assignment(char arg[], const char **name, const char **value); |
| 66 | static int list_cmos_entry(const cmos_entry_t * e, int show_name); |
| 67 | static uint16_t convert_checksum_value(const char value[]); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 68 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 69 | static const op_fn_t op_fns[] = { op_show_version, |
| 70 | op_show_usage, |
| 71 | op_lbtable_show_info, |
| 72 | op_lbtable_dump, |
| 73 | op_show_param_values, |
| 74 | op_cmos_show_one_param, |
| 75 | op_cmos_show_all_params, |
| 76 | op_cmos_set_one_param, |
| 77 | op_cmos_set_params_stdin, |
| 78 | op_cmos_set_params_file, |
| 79 | op_cmos_checksum, |
| 80 | op_show_layout, |
| 81 | op_write_cmos_dump, |
| 82 | op_read_cmos_dump, |
| 83 | op_show_cmos_hex_dump, |
| 84 | op_show_cmos_dumpfile |
| 85 | }; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 86 | |
| 87 | static const hexdump_format_t cmos_dump_format = |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 88 | { 16, 2, "", " | ", " ", " | ", '.', NULL }; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 89 | |
| 90 | /**************************************************************************** |
| 91 | * main |
| 92 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 93 | int main(int argc, char *argv[]) |
| 94 | { |
| 95 | cmos_layout_get_fn_t fn; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 96 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 97 | parse_nvramtool_args(argc, argv); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 98 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 99 | if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found) { |
| 100 | set_layout_filename(nvramtool_op_modifiers |
| 101 | [NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].param); |
| 102 | fn = get_layout_from_file; |
| 103 | } else |
| 104 | fn = get_layout_from_cmos_table; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 105 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 106 | register_cmos_layout_get_fn(fn); |
| 107 | op_fns[nvramtool_op.op] (); |
| 108 | return 0; |
| 109 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 110 | |
| 111 | /**************************************************************************** |
| 112 | * op_show_version |
| 113 | * |
| 114 | * -v |
| 115 | * |
| 116 | * Show version information for this program. |
| 117 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 118 | static void op_show_version(void) |
| 119 | { |
| 120 | printf("This is %s version %s.\n", prog_name, prog_version); |
| 121 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 122 | |
| 123 | /**************************************************************************** |
| 124 | * op_show_usage |
| 125 | * |
| 126 | * -h |
| 127 | * |
| 128 | * Show a usage message for this program. |
| 129 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 130 | static void op_show_usage(void) |
| 131 | { |
| 132 | usage(stdout); |
| 133 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 134 | |
| 135 | /**************************************************************************** |
| 136 | * op_lbtable_show_info |
| 137 | * |
| 138 | * -l [ARG] |
| 139 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 140 | * If ARG is present, show coreboot table information specified by ARG. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 141 | * Else show all possible values for ARG. |
| 142 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 143 | static void op_lbtable_show_info(void) |
| 144 | { |
| 145 | if (nvramtool_op.param == NULL) |
| 146 | list_lbtable_choices(); |
| 147 | else { |
| 148 | get_lbtable(); |
| 149 | list_lbtable_item(nvramtool_op.param); |
| 150 | } |
| 151 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 152 | |
| 153 | /**************************************************************************** |
| 154 | * op_lbtable_dump |
| 155 | * |
| 156 | * -d |
| 157 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 158 | * Do low-level dump of coreboot table. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 159 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 160 | static void op_lbtable_dump(void) |
| 161 | { |
| 162 | get_lbtable(); |
| 163 | dump_lbtable(); |
| 164 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 165 | |
| 166 | /**************************************************************************** |
| 167 | * op_show_param_values |
| 168 | * |
| 169 | * -e NAME option |
| 170 | * |
| 171 | * Show all possible values for parameter NAME. |
| 172 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 173 | static void op_show_param_values(void) |
| 174 | { |
| 175 | get_cmos_layout(); |
| 176 | list_param_enums(nvramtool_op.param); |
| 177 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 178 | |
| 179 | /**************************************************************************** |
| 180 | * op_cmos_show_one_param |
| 181 | * |
| 182 | * [-n] -r NAME |
| 183 | * |
| 184 | * Show parameter NAME. If -n is specified, show value only. Else show name |
| 185 | * and value. |
| 186 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 187 | static void op_cmos_show_one_param(void) |
| 188 | { |
| 189 | int result; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 190 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 191 | get_cmos_layout(); |
| 192 | result = list_one_param(nvramtool_op.param, |
| 193 | !nvramtool_op_modifiers |
| 194 | [NVRAMTOOL_MOD_SHOW_VALUE_ONLY].found); |
| 195 | cmos_checksum_verify(); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 196 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 197 | if (result) |
| 198 | exit(1); |
| 199 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 200 | |
| 201 | /**************************************************************************** |
| 202 | * op_cmos_show_all_params |
| 203 | * |
| 204 | * -a |
| 205 | * |
| 206 | * Show names and values for all parameters. |
| 207 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 208 | static void op_cmos_show_all_params(void) |
| 209 | { |
| 210 | int result; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 211 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 212 | get_cmos_layout(); |
| 213 | result = list_all_params(); |
| 214 | cmos_checksum_verify(); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 215 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 216 | if (result) |
| 217 | exit(1); |
| 218 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 219 | |
| 220 | /**************************************************************************** |
| 221 | * op_cmos_set_one_param |
| 222 | * |
| 223 | * -w NAME=VALUE |
| 224 | * |
| 225 | * Set parameter NAME to VALUE. |
| 226 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 227 | static void op_cmos_set_one_param(void) |
| 228 | { |
| 229 | const char *name, *value; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 230 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 231 | get_cmos_layout(); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 232 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 233 | /* Separate 'NAME=VALUE' syntax into two strings representing NAME and |
| 234 | * VALUE. |
| 235 | */ |
| 236 | parse_assignment(nvramtool_op.param, &name, &value); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 237 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 238 | set_one_param(name, value); |
| 239 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 240 | |
| 241 | /**************************************************************************** |
| 242 | * op_cmos_set_params_stdin |
| 243 | * |
| 244 | * -i |
| 245 | * |
| 246 | * Set parameters according to standard input. |
| 247 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 248 | static void op_cmos_set_params_stdin(void) |
| 249 | { |
| 250 | get_cmos_layout(); |
| 251 | set_params(stdin); |
| 252 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 253 | |
| 254 | /**************************************************************************** |
| 255 | * op_cmos_set_params_file |
| 256 | * |
| 257 | * -p INPUT_FILE |
| 258 | * |
| 259 | * Set parameters according to INPUT_FILE. |
| 260 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 261 | static void op_cmos_set_params_file(void) |
| 262 | { |
| 263 | FILE *f; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 264 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 265 | if ((f = fopen(nvramtool_op.param, "r")) == NULL) { |
| 266 | fprintf(stderr, "%s: Can not open file %s for reading: %s\n", |
| 267 | prog_name, nvramtool_op.param, strerror(errno)); |
| 268 | exit(1); |
| 269 | } |
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 | get_cmos_layout(); |
| 272 | set_params(f); |
| 273 | fclose(f); |
| 274 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 275 | |
| 276 | /**************************************************************************** |
| 277 | * op_cmos_checksum |
| 278 | * |
| 279 | * -c [VALUE] |
| 280 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 281 | * If VALUE is present, set coreboot CMOS checksum to VALUE. Else show |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 282 | * checksum value. |
| 283 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 284 | static void op_cmos_checksum(void) |
| 285 | { |
| 286 | uint16_t checksum; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 287 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 288 | get_cmos_layout(); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 289 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 290 | if (nvramtool_op.param == NULL) { |
| 291 | set_iopl(3); |
| 292 | checksum = cmos_checksum_read(); |
| 293 | set_iopl(0); |
| 294 | printf("0x%x\n", checksum); |
| 295 | } else { |
| 296 | checksum = convert_checksum_value(nvramtool_op.param); |
| 297 | set_iopl(3); |
| 298 | cmos_checksum_write(checksum); |
| 299 | set_iopl(0); |
| 300 | } |
| 301 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 302 | |
| 303 | /**************************************************************************** |
| 304 | * op_show_layout |
| 305 | * |
| 306 | * -Y |
| 307 | * |
| 308 | * Write CMOS layout information to standard output. |
| 309 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 310 | static void op_show_layout(void) |
| 311 | { |
| 312 | get_cmos_layout(); |
| 313 | write_cmos_layout(stdout); |
| 314 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 315 | |
| 316 | /**************************************************************************** |
| 317 | * op_write_cmos_dump |
| 318 | * |
| 319 | * -b OUTPUT_FILE |
| 320 | * |
| 321 | * Write the contents of CMOS memory to a binary file. |
| 322 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 323 | static void op_write_cmos_dump(void) |
| 324 | { |
| 325 | unsigned char data[CMOS_SIZE]; |
| 326 | FILE *f; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 327 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 328 | if ((f = fopen(nvramtool_op.param, "w")) == NULL) { |
| 329 | fprintf(stderr, "%s: Can not open file %s for writing: %s\n", |
| 330 | prog_name, nvramtool_op.param, strerror(errno)); |
| 331 | exit(1); |
| 332 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 333 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 334 | set_iopl(3); |
| 335 | cmos_read_all(data); |
| 336 | set_iopl(0); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 337 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 338 | if (fwrite(data, 1, CMOS_SIZE, f) != CMOS_SIZE) { |
| 339 | fprintf(stderr, "%s: Error writing CMOS data to file %s: %s\n", |
| 340 | prog_name, nvramtool_op.param, strerror(errno)); |
| 341 | exit(1); |
| 342 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 343 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 344 | fclose(f); |
| 345 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 346 | |
| 347 | /**************************************************************************** |
| 348 | * op_read_cmos_dump |
| 349 | * |
| 350 | * -B INPUT_FILE |
| 351 | * |
| 352 | * Read binary data from a file and write the data to CMOS memory. |
| 353 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 354 | static void op_read_cmos_dump(void) |
| 355 | { |
| 356 | unsigned char data[CMOS_SIZE]; |
| 357 | size_t nr_bytes; |
| 358 | FILE *f; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 359 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 360 | if ((f = fopen(nvramtool_op.param, "r")) == NULL) { |
| 361 | fprintf(stderr, "%s: Can not open file %s for reading: %s\n", |
| 362 | prog_name, nvramtool_op.param, strerror(errno)); |
| 363 | exit(1); |
| 364 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 365 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 366 | if ((nr_bytes = fread(data, 1, CMOS_SIZE, f)) != CMOS_SIZE) { |
| 367 | fprintf(stderr, |
| 368 | "%s: Error: Only able to read %d bytes of CMOS data " |
| 369 | "from file %s. CMOS data is unchanged.\n", prog_name, |
| 370 | (int)nr_bytes, nvramtool_op.param); |
| 371 | exit(1); |
| 372 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 373 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 374 | fclose(f); |
| 375 | set_iopl(3); |
| 376 | cmos_write_all(data); |
| 377 | set_iopl(0); |
| 378 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 379 | |
| 380 | /**************************************************************************** |
| 381 | * op_show_cmos_hex_dump |
| 382 | * |
| 383 | * -x |
| 384 | * |
| 385 | * Write a hex dump of CMOS memory to standard output. |
| 386 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 387 | static void op_show_cmos_hex_dump(void) |
| 388 | { |
| 389 | unsigned char data[CMOS_SIZE]; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 390 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 391 | set_iopl(3); |
| 392 | cmos_read_all(data); |
| 393 | set_iopl(0); |
| 394 | hexdump(data, CMOS_SIZE, 0, stdout, &cmos_dump_format); |
| 395 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 396 | |
| 397 | /**************************************************************************** |
| 398 | * op_show_cmos_dumpfile |
| 399 | * |
| 400 | * -X DUMP_FILE |
| 401 | * |
| 402 | * Read binary data from a file (presumably a CMOS dump file) and display a |
| 403 | * hex dump of the CMOS data from the file. |
| 404 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 405 | static void op_show_cmos_dumpfile(void) |
| 406 | { |
| 407 | unsigned char data[CMOS_SIZE]; |
| 408 | size_t nr_bytes; |
| 409 | FILE *f; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 410 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 411 | if ((f = fopen(nvramtool_op.param, "r")) == NULL) { |
| 412 | fprintf(stderr, "%s: Can not open file %s for reading: %s\n", |
| 413 | prog_name, nvramtool_op.param, strerror(errno)); |
| 414 | exit(1); |
| 415 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 416 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 417 | nr_bytes = fread(data, 1, CMOS_SIZE, f); |
| 418 | fclose(f); |
| 419 | hexdump(data, nr_bytes, 0, stdout, &cmos_dump_format); |
| 420 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 421 | |
| 422 | /**************************************************************************** |
| 423 | * list_one_param |
| 424 | * |
| 425 | * Attempt to list one CMOS parameter given by 'name'. 'show_name' is a |
| 426 | * boolean value indicating whether the parameter name should be displayed |
| 427 | * along with its value. Return 1 if error was encountered. Else return OK. |
| 428 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 429 | static int list_one_param(const char name[], int show_name) |
| 430 | { |
| 431 | const cmos_entry_t *e; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 432 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 433 | if (is_checksum_name(name) || ((e = find_cmos_entry(name)) == NULL)) { |
| 434 | fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name, |
| 435 | name); |
| 436 | exit(1); |
| 437 | } |
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 | if (e->config == CMOS_ENTRY_RESERVED) { |
| 440 | fprintf(stderr, "%s: Parameter %s is reserved.\n", prog_name, |
| 441 | name); |
| 442 | exit(1); |
| 443 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 444 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 445 | return (list_cmos_entry(e, show_name) != 0); |
| 446 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 447 | |
| 448 | /**************************************************************************** |
| 449 | * list_all_params |
| 450 | * |
| 451 | * Attempt to list all CMOS parameters. Return 1 if error was encountered. |
| 452 | * Else return OK. |
| 453 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 454 | static int list_all_params(void) |
| 455 | { |
| 456 | const cmos_entry_t *e; |
| 457 | int result; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 458 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 459 | result = OK; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 460 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 461 | for (e = first_cmos_entry(); e != NULL; e = next_cmos_entry(e)) { |
| 462 | if ((e->config == CMOS_ENTRY_RESERVED) |
| 463 | || is_checksum_name(e->name)) |
| 464 | continue; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 465 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 466 | if (list_cmos_entry(e, TRUE)) |
| 467 | result = 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 | return result; |
| 471 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 472 | |
| 473 | /**************************************************************************** |
| 474 | * list_param_enums |
| 475 | * |
| 476 | * List all possible values for CMOS parameter given by 'name'. |
| 477 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 478 | static void list_param_enums(const char name[]) |
| 479 | { |
| 480 | const cmos_entry_t *e; |
| 481 | const cmos_enum_t *p; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 482 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 483 | if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL) { |
| 484 | fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name, |
| 485 | name); |
| 486 | exit(1); |
| 487 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 488 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 489 | switch (e->config) { |
| 490 | case CMOS_ENTRY_ENUM: |
| 491 | for (p = first_cmos_enum_id(e->config_id); |
| 492 | p != NULL; p = next_cmos_enum_id(p)) |
| 493 | printf("%s\n", p->text); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 494 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 495 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 496 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 497 | case CMOS_ENTRY_HEX: |
| 498 | printf("Parameter %s requires a %u-bit unsigned integer.\n", |
| 499 | name, e->length); |
| 500 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 501 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 502 | case CMOS_ENTRY_STRING: |
| 503 | printf("Parameter %s requires a %u-byte string.\n", name, |
| 504 | e->length / 8); |
| 505 | break; |
Stefan Reinauer | a67aab7 | 2008-09-27 10:08:28 +0000 | [diff] [blame] | 506 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 507 | case CMOS_ENTRY_RESERVED: |
| 508 | printf("Parameter %s is reserved.\n", name); |
| 509 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 510 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 511 | default: |
| 512 | BUG(); |
| 513 | } |
| 514 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 515 | |
| 516 | /**************************************************************************** |
| 517 | * set_one_param |
| 518 | * |
| 519 | * Set the CMOS parameter given by 'name' to 'value'. The 'name' parameter |
| 520 | * is case-sensitive. If we are setting an enum parameter, then 'value' is |
| 521 | * interpreted as a case-sensitive string that must match the option name |
| 522 | * exactly. If we are setting a 'hex' parameter, then 'value' is treated as |
| 523 | * a string representation of an unsigned integer that may be specified in |
| 524 | * decimal, hex, or octal. |
| 525 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 526 | static void set_one_param(const char name[], const char value[]) |
| 527 | { |
| 528 | const cmos_entry_t *e; |
| 529 | unsigned long long n; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 530 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 531 | if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL) { |
| 532 | fprintf(stderr, "%s: CMOS parameter %s not found.", prog_name, |
| 533 | name); |
| 534 | exit(1); |
| 535 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 536 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 537 | switch (prepare_cmos_write(e, value, &n)) { |
| 538 | case OK: |
| 539 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 540 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 541 | case CMOS_OP_BAD_ENUM_VALUE: |
| 542 | fprintf(stderr, "%s: Bad value for parameter %s.", prog_name, |
| 543 | name); |
| 544 | goto fail; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 545 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 546 | case CMOS_OP_NEGATIVE_INT: |
| 547 | fprintf(stderr, |
| 548 | "%s: This program does not support assignment of negative " |
| 549 | "numbers to coreboot parameters.", prog_name); |
| 550 | goto fail; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 551 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 552 | case CMOS_OP_INVALID_INT: |
| 553 | fprintf(stderr, "%s: %s is not a valid integer.", prog_name, |
| 554 | value); |
| 555 | goto fail; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 556 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 557 | case CMOS_OP_RESERVED: |
| 558 | fprintf(stderr, |
| 559 | "%s: Can not modify reserved coreboot parameter %s.", |
| 560 | prog_name, name); |
| 561 | goto fail; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 562 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 563 | case CMOS_OP_VALUE_TOO_WIDE: |
| 564 | fprintf(stderr, |
| 565 | "%s: Can not write value %s to CMOS parameter %s that is " |
| 566 | "only %d bits wide.", prog_name, value, name, |
| 567 | e->length); |
| 568 | goto fail; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 569 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 570 | case CMOS_OP_NO_MATCHING_ENUM: |
| 571 | fprintf(stderr, |
| 572 | "%s: coreboot parameter %s has no matching enums.", |
| 573 | prog_name, name); |
| 574 | goto fail; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 575 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 576 | case CMOS_AREA_OUT_OF_RANGE: |
| 577 | fprintf(stderr, |
| 578 | "%s: The CMOS area specified by the layout info for " |
| 579 | "coreboot parameter %s is out of range.", prog_name, |
| 580 | name); |
| 581 | goto fail; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 582 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 583 | case CMOS_AREA_OVERLAPS_RTC: |
| 584 | fprintf(stderr, |
| 585 | "%s: The CMOS area specified by the layout info for " |
| 586 | "coreboot parameter %s overlaps the realtime clock area.", |
| 587 | prog_name, name); |
| 588 | goto fail; |
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 | case CMOS_AREA_TOO_WIDE: |
| 591 | fprintf(stderr, |
| 592 | "%s: The CMOS area specified by the layout info for " |
| 593 | "coreboot parameter %s is too wide.", prog_name, name); |
| 594 | goto fail; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 595 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 596 | default: |
| 597 | fprintf(stderr, |
| 598 | "%s: Unknown error encountered while attempting to modify " |
| 599 | "coreboot parameter %s.", prog_name, name); |
| 600 | goto fail; |
| 601 | } |
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 | /* write the value to nonvolatile RAM */ |
| 604 | set_iopl(3); |
| 605 | cmos_write(e, n); |
| 606 | cmos_checksum_write(cmos_checksum_compute()); |
| 607 | set_iopl(0); |
| 608 | return; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 609 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 610 | fail: |
| 611 | fprintf(stderr, " CMOS write not performed.\n"); |
| 612 | exit(1); |
| 613 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 614 | |
| 615 | /**************************************************************************** |
| 616 | * set_params |
| 617 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame] | 618 | * Set coreboot parameters according to the contents of file 'f'. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 619 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 620 | static void set_params(FILE * f) |
| 621 | { /* First process the input file. Then perform writes only if there were |
| 622 | * no problems processing the input. Either all values will be written |
| 623 | * successfully or no values will be written. |
| 624 | */ |
| 625 | do_cmos_writes(process_input_file(f)); |
| 626 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 627 | |
| 628 | /**************************************************************************** |
| 629 | * parse_assignment |
| 630 | * |
| 631 | * Parse the string 'arg' (which supposedly represents an assignment) into a |
| 632 | * NAME and a VALUE. If 'arg' does not conform to the proper assignment |
| 633 | * syntax, exit with a usage message. Otherwise, on return, 'arg' is broken |
| 634 | * into substrings representing NAME and VALUE, and *name and *value are set |
| 635 | * to point to these two substrings. |
| 636 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 637 | static void parse_assignment(char arg[], const char **name, const char **value) |
| 638 | { |
| 639 | static const size_t N_MATCHES = 4; |
| 640 | regmatch_t match[N_MATCHES]; |
| 641 | regex_t assignment; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 642 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 643 | compile_reg_exprs(REG_EXTENDED | REG_NEWLINE, 1, assignment_regex, |
| 644 | &assignment); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 645 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 646 | /* Does 'arg' conform to proper assignment syntax? If not, exit with a |
| 647 | * usage message. |
| 648 | */ |
| 649 | if (regexec(&assignment, arg, N_MATCHES, match, 0)) |
| 650 | usage(stderr); |
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 | /* Ok, we found a valid assignment. Break it into two strings |
| 653 | * representing NAME and VALUE. |
| 654 | */ |
| 655 | arg[match[1].rm_eo] = '\0'; |
| 656 | arg[match[2].rm_eo] = '\0'; |
| 657 | *name = &arg[match[1].rm_so]; |
| 658 | *value = &arg[match[2].rm_so]; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 659 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 660 | free_reg_exprs(1, &assignment); |
| 661 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 662 | |
| 663 | /**************************************************************************** |
| 664 | * list_cmos_entry |
| 665 | * |
| 666 | * Attempt to list the CMOS entry represented by 'e'. 'show_name' is a |
| 667 | * boolean value indicating whether the parameter name should be displayed |
| 668 | * along with its value. On success, return OK. On error, print an error |
| 669 | * message and return 1. |
| 670 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 671 | static int list_cmos_entry(const cmos_entry_t * e, int show_name) |
| 672 | { |
| 673 | const cmos_enum_t *p; |
| 674 | unsigned long long value; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 675 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 676 | /* sanity check CMOS entry */ |
| 677 | switch (prepare_cmos_read(e)) { |
| 678 | case OK: |
| 679 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 680 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 681 | case CMOS_OP_RESERVED: |
| 682 | BUG(); |
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 | case CMOS_AREA_OUT_OF_RANGE: |
| 685 | fprintf(stderr, |
| 686 | "%s: Can not read coreboot parameter %s because " |
| 687 | "layout info specifies out of range CMOS area.\n", |
| 688 | prog_name, e->name); |
| 689 | return 1; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 690 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 691 | case CMOS_AREA_OVERLAPS_RTC: |
| 692 | fprintf(stderr, |
| 693 | "%s: Can not read coreboot parameter %s because " |
| 694 | "layout info specifies CMOS area that overlaps realtime " |
| 695 | "clock area.\n", prog_name, e->name); |
| 696 | return 1; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 697 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 698 | case CMOS_AREA_TOO_WIDE: |
| 699 | fprintf(stderr, |
| 700 | "%s: Can not read coreboot parameter %s because " |
| 701 | "layout info specifies CMOS area that is too wide.\n", |
| 702 | prog_name, e->name); |
| 703 | return 1; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 704 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 705 | default: |
| 706 | fprintf(stderr, |
| 707 | "%s: Unknown error encountered while attempting to " |
| 708 | "read coreboot parameter %s\n", prog_name, e->name); |
| 709 | return 1; |
| 710 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 711 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 712 | /* read the value from CMOS */ |
| 713 | set_iopl(3); |
| 714 | value = cmos_read(e); |
| 715 | set_iopl(0); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 716 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 717 | /* display the value */ |
| 718 | switch (e->config) { |
| 719 | case CMOS_ENTRY_ENUM: |
| 720 | if ((p = find_cmos_enum(e->config_id, value)) == NULL) { |
| 721 | if (show_name) |
| 722 | printf("# Bad value -> %s = 0x%llx\n", e->name, |
| 723 | value); |
| 724 | else |
| 725 | printf("Bad value -> 0x%llx\n", value); |
| 726 | } else { |
| 727 | if (show_name) |
| 728 | printf("%s = %s\n", e->name, p->text); |
| 729 | else |
| 730 | printf("%s\n", p->text); |
| 731 | } |
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 | break; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 734 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 735 | case CMOS_ENTRY_HEX: |
| 736 | if (show_name) |
| 737 | printf("%s = 0x%llx\n", e->name, value); |
| 738 | else |
| 739 | printf("0x%llx\n", value); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 740 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 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 CMOS_ENTRY_STRING: |
| 744 | if (show_name) |
| 745 | printf("%s = %s\n", e->name, |
| 746 | (char *)(unsigned long)value); |
| 747 | else |
| 748 | printf("%s\n", (char *)(unsigned long)value); |
Stefan Reinauer | a67aab7 | 2008-09-27 10:08:28 +0000 | [diff] [blame] | 749 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 750 | free((void *)(unsigned long)value); |
Stefan Reinauer | a67aab7 | 2008-09-27 10:08:28 +0000 | [diff] [blame] | 751 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 752 | break; |
Stefan Reinauer | a67aab7 | 2008-09-27 10:08:28 +0000 | [diff] [blame] | 753 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 754 | case CMOS_ENTRY_RESERVED: |
| 755 | default: |
| 756 | BUG(); |
| 757 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 758 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 759 | return OK; |
| 760 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 761 | |
| 762 | /**************************************************************************** |
| 763 | * convert_checksum_value |
| 764 | * |
| 765 | * 'value' is the string representation of a checksum value that the user |
| 766 | * wishes to set using the -c option. Convert the string to a 16-bit |
| 767 | * unsigned integer and return the result. Exit with an error message if |
| 768 | * 'value' is invalid. |
| 769 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 770 | static uint16_t convert_checksum_value(const char value[]) |
| 771 | { |
| 772 | unsigned long n; |
| 773 | const char *p; |
| 774 | uint16_t result; |
| 775 | int negative; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 776 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 777 | for (p = value; isspace(*p); p++) ; |
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 | negative = (*p == '-'); |
| 780 | n = strtoul(value, (char **)&p, 0); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 781 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 782 | if (*p) { |
| 783 | fprintf(stderr, |
| 784 | "%s: Checksum value %s is not a valid integer.\n", |
| 785 | prog_name, value); |
| 786 | exit(1); |
| 787 | } |
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 | if (negative) { |
| 790 | fprintf(stderr, |
| 791 | "%s: Checksum must be an unsigned integer.\n", |
| 792 | prog_name); |
| 793 | exit(1); |
| 794 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 795 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 796 | result = (uint16_t) n; |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 797 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame^] | 798 | if (result != n) { |
| 799 | fprintf(stderr, |
| 800 | "%s: Checksum value must fit within 16 bits.\n", |
| 801 | prog_name); |
| 802 | exit(1); |
| 803 | } |
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 | return result; |
| 806 | } |