blob: 68d2618ca49d27d98a9ac5d1a84ad9c7a675936f [file] [log] [blame]
Patrick Georgi55189c92020-05-10 20:09:31 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer6540ae52007-07-12 16:35:42 +00002
3#include "common.h"
4
5/* basename of this program, as reported by argv[0] */
Uwe Hermann6e565942008-03-01 19:06:32 +00006const char prog_name[] = "nvramtool";
Stefan Reinauer6540ae52007-07-12 16:35:42 +00007
8/* version of this program */
Stefan Reinauera67aab72008-09-27 10:08:28 +00009const char prog_version[] = "2.1";
Stefan Reinauer6540ae52007-07-12 16:35:42 +000010
11/****************************************************************************
12 * get_line_from_file
13 *
14 * Get a line of input from file 'f'. Store result in 'line' which is an
15 * array of 'line_buf_size' bytes.
16 ****************************************************************************/
Stefan Reinauer90b96b62010-01-13 21:00:23 +000017int get_line_from_file(FILE * f, char line[], int line_buf_size)
18{
19 if (fgets(line, line_buf_size, f) == NULL)
20 return LINE_EOF;
Stefan Reinauer6540ae52007-07-12 16:35:42 +000021
Stefan Reinauer90b96b62010-01-13 21:00:23 +000022 /* If the file contains a line that is too long, then it's best
Stefan Reinauer14e22772010-04-27 06:56:47 +000023 * to let the user know right away rather than passing back a
Stefan Reinauer90b96b62010-01-13 21:00:23 +000024 * truncated result that will lead to problems later on.
25 */
26 return (strlen(line) == ((size_t) (line_buf_size - 1))) ?
27 LINE_TOO_LONG : OK;
28}
Stefan Reinauer6540ae52007-07-12 16:35:42 +000029
30/****************************************************************************
31 * out_of_memory
32 *
33 * We ran out of memory. Print an error message and die.
34 ****************************************************************************/
Evgeny Zinoviev79f7fcc2020-01-11 01:26:54 +030035noreturn void out_of_memory(void)
Stefan Reinauer90b96b62010-01-13 21:00:23 +000036{
37 fprintf(stderr, "%s: Out of memory.\n", prog_name);
38 exit(1);
39}
Stefan Reinauer6540ae52007-07-12 16:35:42 +000040
41/****************************************************************************
42 * usage
43 *
44 * Write a usage message to 'outfile'. If 'outfile' is 'stderr' then exit
45 * with a value of 1. Otherwise exit with a value of 0.
46 ****************************************************************************/
Stefan Reinauer90b96b62010-01-13 21:00:23 +000047void usage(FILE * outfile)
48{
49 fprintf(outfile,
50 "Usage: %s [-y LAYOUT_FILE | -t] PARAMETER ...\n\n"
51 " Read/write coreboot parameters or show info from "
52 "coreboot table.\n\n"
53 " -y LAYOUT_FILE: Use CMOS layout specified by "
54 "LAYOUT_FILE.\n"
55 " -t: Use CMOS layout specified by CMOS option "
56 "table.\n"
Patrick Georgi202be7b2011-01-21 07:29:40 +000057 " -C CBFS_FILE: Use CBFS file for layout and CMOS data.\n"
58 " -D CMOS_FILE: Use CMOS file for CMOS data (overrides CMOS of -C).\n"
Stefan Reinauer90b96b62010-01-13 21:00:23 +000059 " [-n] -r NAME: Show parameter NAME. If -n is given, "
60 "show value only.\n"
61 " -e NAME: Show all possible values for parameter "
62 "NAME.\n"
63 " -a: Show names and values for all "
64 "parameters.\n"
65 " -w NAME=VALUE: Set parameter NAME to VALUE.\n"
66 " -p INPUT_FILE: Set parameters according to INPUT_FILE.\n"
67 " -i: Same as -p but file contents taken from "
68 "standard input.\n"
69 " -c [VALUE]: Show CMOS checksum or set checksum to "
70 "VALUE.\n"
71 " -l [ARG]: Show coreboot table info for ARG, or "
72 "all ARG choices.\n"
Vikram Narayanana8111cf2012-04-14 15:25:13 +053073 " -L OUTPUT_BIN Write CMOS layout file in binary format\n"
74 " -H OUTPUT_HDR Write CMOS layout file in header format\n"
Stefan Reinauer90b96b62010-01-13 21:00:23 +000075 " -d: Show low-level dump of coreboot table.\n"
76 " -Y: Show CMOS layout info.\n"
77 " -b OUTPUT_FILE: Dump CMOS memory contents to file.\n"
78 " -B INPUT_FILE: Write file contents to CMOS memory.\n"
79 " -x: Show hex dump of CMOS memory.\n"
80 " -X DUMPFILE: Show hex dump of CMOS dumpfile.\n"
81 " -v: Show version info for this program.\n"
82 " -h: Show this message.\n", prog_name);
83 exit(outfile == stderr);
84}