2020-05-10 20:09:31 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2007-07-12 18:35:42 +02:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
/* basename of this program, as reported by argv[0] */
|
2008-03-01 20:06:32 +01:00
|
|
|
const char prog_name[] = "nvramtool";
|
2007-07-12 18:35:42 +02:00
|
|
|
|
|
|
|
/* version of this program */
|
2008-09-27 12:08:28 +02:00
|
|
|
const char prog_version[] = "2.1";
|
2007-07-12 18:35:42 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* get_line_from_file
|
|
|
|
*
|
|
|
|
* Get a line of input from file 'f'. Store result in 'line' which is an
|
|
|
|
* array of 'line_buf_size' bytes.
|
|
|
|
****************************************************************************/
|
2010-01-13 22:00:23 +01:00
|
|
|
int get_line_from_file(FILE * f, char line[], int line_buf_size)
|
|
|
|
{
|
|
|
|
if (fgets(line, line_buf_size, f) == NULL)
|
|
|
|
return LINE_EOF;
|
2007-07-12 18:35:42 +02:00
|
|
|
|
2010-01-13 22:00:23 +01:00
|
|
|
/* If the file contains a line that is too long, then it's best
|
2010-04-27 08:56:47 +02:00
|
|
|
* to let the user know right away rather than passing back a
|
2010-01-13 22:00:23 +01:00
|
|
|
* truncated result that will lead to problems later on.
|
|
|
|
*/
|
|
|
|
return (strlen(line) == ((size_t) (line_buf_size - 1))) ?
|
|
|
|
LINE_TOO_LONG : OK;
|
|
|
|
}
|
2007-07-12 18:35:42 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* out_of_memory
|
|
|
|
*
|
|
|
|
* We ran out of memory. Print an error message and die.
|
|
|
|
****************************************************************************/
|
2020-01-10 23:26:54 +01:00
|
|
|
noreturn void out_of_memory(void)
|
2010-01-13 22:00:23 +01:00
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: Out of memory.\n", prog_name);
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-07-12 18:35:42 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* usage
|
|
|
|
*
|
|
|
|
* Write a usage message to 'outfile'. If 'outfile' is 'stderr' then exit
|
|
|
|
* with a value of 1. Otherwise exit with a value of 0.
|
|
|
|
****************************************************************************/
|
2010-01-13 22:00:23 +01:00
|
|
|
void usage(FILE * outfile)
|
|
|
|
{
|
|
|
|
fprintf(outfile,
|
|
|
|
"Usage: %s [-y LAYOUT_FILE | -t] PARAMETER ...\n\n"
|
|
|
|
" Read/write coreboot parameters or show info from "
|
|
|
|
"coreboot table.\n\n"
|
|
|
|
" -y LAYOUT_FILE: Use CMOS layout specified by "
|
|
|
|
"LAYOUT_FILE.\n"
|
|
|
|
" -t: Use CMOS layout specified by CMOS option "
|
|
|
|
"table.\n"
|
2011-01-21 08:29:40 +01:00
|
|
|
" -C CBFS_FILE: Use CBFS file for layout and CMOS data.\n"
|
|
|
|
" -D CMOS_FILE: Use CMOS file for CMOS data (overrides CMOS of -C).\n"
|
2010-01-13 22:00:23 +01:00
|
|
|
" [-n] -r NAME: Show parameter NAME. If -n is given, "
|
|
|
|
"show value only.\n"
|
|
|
|
" -e NAME: Show all possible values for parameter "
|
|
|
|
"NAME.\n"
|
|
|
|
" -a: Show names and values for all "
|
|
|
|
"parameters.\n"
|
|
|
|
" -w NAME=VALUE: Set parameter NAME to VALUE.\n"
|
|
|
|
" -p INPUT_FILE: Set parameters according to INPUT_FILE.\n"
|
|
|
|
" -i: Same as -p but file contents taken from "
|
|
|
|
"standard input.\n"
|
|
|
|
" -c [VALUE]: Show CMOS checksum or set checksum to "
|
|
|
|
"VALUE.\n"
|
|
|
|
" -l [ARG]: Show coreboot table info for ARG, or "
|
|
|
|
"all ARG choices.\n"
|
2012-04-14 11:55:13 +02:00
|
|
|
" -L OUTPUT_BIN Write CMOS layout file in binary format\n"
|
|
|
|
" -H OUTPUT_HDR Write CMOS layout file in header format\n"
|
2010-01-13 22:00:23 +01:00
|
|
|
" -d: Show low-level dump of coreboot table.\n"
|
|
|
|
" -Y: Show CMOS layout info.\n"
|
|
|
|
" -b OUTPUT_FILE: Dump CMOS memory contents to file.\n"
|
|
|
|
" -B INPUT_FILE: Write file contents to CMOS memory.\n"
|
|
|
|
" -x: Show hex dump of CMOS memory.\n"
|
|
|
|
" -X DUMPFILE: Show hex dump of CMOS dumpfile.\n"
|
|
|
|
" -v: Show version info for this program.\n"
|
|
|
|
" -h: Show this message.\n", prog_name);
|
|
|
|
exit(outfile == stderr);
|
|
|
|
}
|