coreboot/util/nvramtool/common.c
<<
>>
Prefs
   1/*****************************************************************************\
   2 * common.c
   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 *
  10 *  This file is part of nvramtool, a utility for reading/writing coreboot
  11 *  parameters and displaying information from the coreboot table.
  12 *  For details, see http://coreboot.org/nvramtool.
  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.,
  28 *  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  29\*****************************************************************************/
  30
  31#include "common.h"
  32
  33/* basename of this program, as reported by argv[0] */
  34const char prog_name[] = "nvramtool";
  35
  36/* version of this program */
  37const char prog_version[] = "2.1";
  38
  39/****************************************************************************
  40 * get_line_from_file
  41 *
  42 * Get a line of input from file 'f'.  Store result in 'line' which is an
  43 * array of 'line_buf_size' bytes.
  44 ****************************************************************************/
  45int get_line_from_file(FILE * f, char line[], int line_buf_size)
  46{
  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
  51         * to let the user know right away rather than passing back a
  52         * truncated result that 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 ****************************************************************************/
  63void out_of_memory(void)
  64{
  65        fprintf(stderr, "%s: Out of memory.\n", prog_name);
  66        exit(1);
  67}
  68
  69/****************************************************************************
  70 * usage
  71 *
  72 * Write a usage message to 'outfile'.  If 'outfile' is 'stderr' then exit
  73 * with a value of 1.  Otherwise exit with a value of 0.
  74 ****************************************************************************/
  75void usage(FILE * outfile)
  76{
  77        fprintf(outfile,
  78                "Usage: %s [-y LAYOUT_FILE | -t] PARAMETER ...\n\n"
  79                "       Read/write coreboot parameters or show info from "
  80                "coreboot table.\n\n"
  81                "       -y LAYOUT_FILE: Use CMOS layout specified by "
  82                "LAYOUT_FILE.\n"
  83                "       -t:             Use CMOS layout specified by CMOS option "
  84                "table.\n"
  85                "       -C CBFS_FILE:   Use CBFS file for layout and CMOS data.\n"
  86                "       -D CMOS_FILE:   Use CMOS file for CMOS data (overrides CMOS of -C).\n"
  87                "       [-n] -r NAME:   Show parameter NAME.  If -n is given, "
  88                "show value only.\n"
  89                "       -e NAME:        Show all possible values for parameter "
  90                "NAME.\n"
  91                "       -a:             Show names and values for all "
  92                "parameters.\n"
  93                "       -w NAME=VALUE:  Set parameter NAME to VALUE.\n"
  94                "       -p INPUT_FILE:  Set parameters according to INPUT_FILE.\n"
  95                "       -i:             Same as -p but file contents taken from "
  96                "standard input.\n"
  97                "       -c [VALUE]:     Show CMOS checksum or set checksum to "
  98                "VALUE.\n"
  99                "       -l [ARG]:       Show coreboot table info for ARG, or "
 100                "all ARG choices.\n"
 101                "       -d:             Show low-level dump of coreboot table.\n"
 102                "       -Y:             Show CMOS layout info.\n"
 103                "       -b OUTPUT_FILE: Dump CMOS memory contents to file.\n"
 104                "       -B INPUT_FILE:  Write file contents to CMOS memory.\n"
 105                "       -x:             Show hex dump of CMOS memory.\n"
 106                "       -X DUMPFILE:    Show hex dump of CMOS dumpfile.\n"
 107                "       -v:             Show version info for this program.\n"
 108                "       -h:             Show this message.\n", prog_name);
 109        exit(outfile == stderr);
 110}
 111
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.