Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 1 | /*****************************************************************************\ |
| 2 | * common.c |
| 3 | * $Id: common.c,v 1.3 2006/01/24 00:25:40 dsp_llnl Exp $ |
| 4 | ***************************************************************************** |
| 5 | * Copyright (C) 2002-2005 The Regents of the University of California. |
| 6 | * Produced at the Lawrence Livermore National Laboratory. |
| 7 | * Written by Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>. |
| 8 | * UCRL-CODE-2003-012 |
| 9 | * All rights reserved. |
| 10 | * |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame^] | 11 | * This file is part of lxbios, a utility for reading/writing coreboot |
| 12 | * parameters and displaying information from the coreboot table. |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 13 | * For details, see <http://www.llnl.gov/linux/lxbios/>. |
| 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., |
| 29 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 30 | \*****************************************************************************/ |
| 31 | |
| 32 | #include "common.h" |
| 33 | |
| 34 | /* basename of this program, as reported by argv[0] */ |
| 35 | const char prog_name[] = "lxbios"; |
| 36 | |
| 37 | /* version of this program */ |
| 38 | const char prog_version[] = "2.0.1"; |
| 39 | |
| 40 | /**************************************************************************** |
| 41 | * get_line_from_file |
| 42 | * |
| 43 | * Get a line of input from file 'f'. Store result in 'line' which is an |
| 44 | * array of 'line_buf_size' bytes. |
| 45 | ****************************************************************************/ |
| 46 | int get_line_from_file (FILE *f, char line[], int line_buf_size) |
| 47 | { if (fgets(line, line_buf_size, f) == NULL) |
| 48 | return LINE_EOF; |
| 49 | |
| 50 | /* If the file contains a line that is too long, then it's best to let the |
| 51 | * user know right away rather than passing back a truncated result that |
| 52 | * will lead to problems later on. |
| 53 | */ |
| 54 | return (strlen(line) == ((size_t) (line_buf_size - 1))) ? |
| 55 | LINE_TOO_LONG : OK; |
| 56 | } |
| 57 | |
| 58 | /**************************************************************************** |
| 59 | * out_of_memory |
| 60 | * |
| 61 | * We ran out of memory. Print an error message and die. |
| 62 | ****************************************************************************/ |
| 63 | void out_of_memory (void) |
| 64 | { fprintf(stderr, "%s: Out of memory.\n", prog_name); |
| 65 | exit(1); |
| 66 | } |
| 67 | |
| 68 | /**************************************************************************** |
| 69 | * usage |
| 70 | * |
| 71 | * Write a usage message to 'outfile'. If 'outfile' is 'stderr' then exit |
| 72 | * with a value of 1. Otherwise exit with a value of 0. |
| 73 | ****************************************************************************/ |
| 74 | void usage (FILE *outfile) |
| 75 | { fprintf(outfile, |
| 76 | "Usage: %s [-y LAYOUT_FILE | -t] PARAMETER ...\n\n" |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame^] | 77 | " Read/write coreboot parameters or show info from " |
| 78 | "coreboot table.\n\n" |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 79 | " -y LAYOUT_FILE: Use CMOS layout specified by " |
| 80 | "LAYOUT_FILE.\n" |
| 81 | " -t: Use CMOS layout specified by CMOS option " |
| 82 | "table.\n" |
| 83 | " [-n] -r NAME: Show parameter NAME. If -n is given, " |
| 84 | "show value only.\n" |
| 85 | " -e NAME: Show all possible values for parameter " |
| 86 | "NAME.\n" |
| 87 | " -a: Show names and values for all " |
| 88 | "parameters.\n" |
| 89 | " -w NAME=VALUE: Set parameter NAME to VALUE.\n" |
| 90 | " -p INPUT_FILE: Set parameters according to INPUT_FILE.\n" |
| 91 | " -i: Same as -p but file contents taken from " |
| 92 | "standard input.\n" |
| 93 | " -c [VALUE]: Show CMOS checksum or set checksum to " |
| 94 | "VALUE.\n" |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame^] | 95 | " -l [ARG]: Show coreboot table info for ARG, or " |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 96 | "all ARG choices.\n" |
Stefan Reinauer | f527e70 | 2008-01-18 15:33:49 +0000 | [diff] [blame^] | 97 | " -d: Show low-level dump of coreboot table.\n" |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 98 | " -Y: Show CMOS layout info.\n" |
| 99 | " -b OUTPUT_FILE: Dump CMOS memory contents to file.\n" |
| 100 | " -B INPUT_FILE: Write file contents to CMOS memory.\n" |
| 101 | " -x: Show hex dump of CMOS memory.\n" |
| 102 | " -X DUMPFILE: Show hex dump of CMOS dumpfile.\n" |
| 103 | " -v: Show version info for this program.\n" |
| 104 | " -h: Show this message.\n", prog_name); |
| 105 | exit(outfile == stderr); |
| 106 | } |