indent all of nvramtool to make it fit into coreboot's

coding style

Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Stefan Reinauer <stepan@coresystems.de>



git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5007 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Stefan Reinauer 2010-01-13 21:00:23 +00:00 committed by Stefan Reinauer
parent 766db7ea09
commit 90b96b68e0
24 changed files with 3252 additions and 3076 deletions

View File

@ -36,11 +36,10 @@
#include "common.h"
#include "cmos_lowlevel.h"
typedef struct
{ unsigned byte_index;
typedef struct {
unsigned byte_index;
unsigned bit_offset;
}
cmos_bit_op_location_t;
} cmos_bit_op_location_t;
static unsigned cmos_bit_op_strategy(unsigned bit, unsigned bits_left,
cmos_bit_op_location_t * where);
@ -61,7 +60,9 @@ static void put_bits (unsigned char value, unsigned bit, unsigned nr_bits,
****************************************************************************/
static inline unsigned char get_bits(unsigned long long value, unsigned bit,
unsigned nr_bits)
{ return (value >> bit) & ((unsigned char) ((1 << nr_bits) - 1)); }
{
return (value >> bit) & ((unsigned char)((1 << nr_bits) - 1));
}
/****************************************************************************
* put_bits
@ -73,7 +74,10 @@ static inline unsigned char get_bits (unsigned long long value, unsigned bit,
****************************************************************************/
static inline void put_bits(unsigned char value, unsigned bit,
unsigned nr_bits, unsigned long long *result)
{ *result += ((unsigned long long)(value & ((unsigned char) ((1 << nr_bits) - 1)))) << bit; }
{
*result += ((unsigned long long)(value &
((unsigned char)((1 << nr_bits) - 1)))) << bit;
}
/****************************************************************************
* cmos_read
@ -83,7 +87,8 @@ static inline void put_bits (unsigned char value, unsigned bit,
* process must be set appropriately.
****************************************************************************/
unsigned long long cmos_read(const cmos_entry_t * e)
{ cmos_bit_op_location_t where;
{
cmos_bit_op_location_t where;
unsigned bit = e->bit, length = e->length;
unsigned next_bit, bits_left, nr_bits;
unsigned long long result = 0;
@ -92,26 +97,30 @@ unsigned long long cmos_read (const cmos_entry_t *e)
assert(!verify_cmos_op(bit, length, e->config));
result = 0;
if (e->config == CMOS_ENTRY_STRING)
{ char *newstring = calloc(1, (length+7)/8);
if (e->config == CMOS_ENTRY_STRING) {
char *newstring = calloc(1, (length + 7) / 8);
unsigned usize = (8 * sizeof(unsigned long long));
if(!newstring) { out_of_memory(); }
if (!newstring) {
out_of_memory();
}
for (next_bit = 0, bits_left = length;
bits_left;
next_bit += nr_bits, bits_left -= nr_bits)
{ nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left>usize?usize:bits_left, &where);
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
nr_bits = cmos_bit_op_strategy(bit + next_bit,
bits_left > usize ? usize : bits_left, &where);
value = cmos_read_bits(&where, nr_bits);
put_bits(value, next_bit % usize, nr_bits, &((unsigned long long *)newstring)[next_bit/usize]);
put_bits(value, next_bit % usize, nr_bits,
&((unsigned long long *)newstring)[next_bit /
usize]);
result = (unsigned long)newstring;
}
}
else
{ for (next_bit = 0, bits_left = length;
bits_left;
next_bit += nr_bits, bits_left -= nr_bits)
{ nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left, &where);
} else {
for (next_bit = 0, bits_left = length;
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
nr_bits =
cmos_bit_op_strategy(bit + next_bit, bits_left,
&where);
value = cmos_read_bits(&where, nr_bits);
put_bits(value, next_bit, nr_bits, &result);
}
@ -128,30 +137,34 @@ unsigned long long cmos_read (const cmos_entry_t *e)
* appropriately.
****************************************************************************/
void cmos_write(const cmos_entry_t * e, unsigned long long value)
{ cmos_bit_op_location_t where;
{
cmos_bit_op_location_t where;
unsigned bit = e->bit, length = e->length;
unsigned next_bit, bits_left, nr_bits;
assert(!verify_cmos_op(bit, length, e->config));
if (e->config == CMOS_ENTRY_STRING)
{ unsigned long long *data = (unsigned long long *)(unsigned long)value;
if (e->config == CMOS_ENTRY_STRING) {
unsigned long long *data =
(unsigned long long *)(unsigned long)value;
unsigned usize = (8 * sizeof(unsigned long long));
for (next_bit = 0, bits_left = length;
bits_left;
next_bit += nr_bits, bits_left -= nr_bits)
{ nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left>usize?usize:bits_left, &where);
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
nr_bits = cmos_bit_op_strategy(bit + next_bit,
bits_left > usize ? usize : bits_left,
&where);
value = data[next_bit / usize];
cmos_write_bits(&where, nr_bits, get_bits(value, next_bit % usize, nr_bits));
cmos_write_bits(&where, nr_bits,
get_bits(value, next_bit % usize, nr_bits));
}
}
else
{ for (next_bit = 0, bits_left = length;
bits_left;
next_bit += nr_bits, bits_left -= nr_bits)
{ nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left, &where);
cmos_write_bits(&where, nr_bits, get_bits(value, next_bit, nr_bits));
} else {
for (next_bit = 0, bits_left = length;
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
nr_bits = cmos_bit_op_strategy(bit + next_bit,
bits_left, &where);
cmos_write_bits(&where, nr_bits,
get_bits(value, next_bit, nr_bits));
}
}
}
@ -167,16 +180,16 @@ void cmos_write (const cmos_entry_t *e, unsigned long long value)
* real time clock.
****************************************************************************/
unsigned char cmos_read_byte(unsigned index)
{ unsigned short port_0, port_1;
{
unsigned short port_0, port_1;
assert(!verify_cmos_byte_index(index));
if (index < 128)
{ port_0 = 0x70;
if (index < 128) {
port_0 = 0x70;
port_1 = 0x71;
}
else
{ port_0 = 0x72;
} else {
port_0 = 0x72;
port_1 = 0x73;
}
@ -195,16 +208,16 @@ unsigned char cmos_read_byte (unsigned index)
* affect its functioning.
****************************************************************************/
void cmos_write_byte(unsigned index, unsigned char value)
{ unsigned short port_0, port_1;
{
unsigned short port_0, port_1;
assert(!verify_cmos_byte_index(index));
if (index < 128)
{ port_0 = 0x70;
if (index < 128) {
port_0 = 0x70;
port_1 = 0x71;
}
else
{ port_0 = 0x72;
} else {
port_0 = 0x72;
port_1 = 0x73;
}
@ -219,7 +232,8 @@ void cmos_write_byte (unsigned index, unsigned char value)
* 'data' are set to zero since this corresponds to the real time clock area.
****************************************************************************/
void cmos_read_all(unsigned char data[])
{ unsigned i;
{
unsigned i;
for (i = 0; i < CMOS_RTC_AREA_SIZE; i++)
data[i] = 0;
@ -236,7 +250,8 @@ void cmos_read_all (unsigned char data[])
* area.
****************************************************************************/
void cmos_write_all(unsigned char data[])
{ unsigned i;
{
unsigned i;
for (i = CMOS_RTC_AREA_SIZE; i < CMOS_SIZE; i++)
cmos_write_byte(i, data[i]);
@ -260,32 +275,24 @@ void set_iopl (int level)
assert((level >= 0) && (level <= 3));
#if defined(__FreeBSD__)
if (level == 0)
{
if (io_fd != -1)
{
if (level == 0) {
if (io_fd != -1) {
close(io_fd);
io_fd = -1;
}
}
else
{
if (io_fd == -1)
{
} else {
if (io_fd == -1) {
io_fd = open("/dev/io", O_RDWR);
if (io_fd < 0)
{
if (io_fd < 0) {
perror("/dev/io");
exit(1);
}
}
}
#else
if (iopl(level))
{ fprintf(stderr,
"%s: iopl() system call failed. You must be root to do "
"this.\n",
prog_name);
if (iopl(level)) {
fprintf(stderr, "%s: iopl() system call failed. "
"You must be root to do this.\n", prog_name);
exit(1);
}
#endif
@ -301,7 +308,8 @@ void set_iopl (int level)
* no problems were encountered, return OK. Else return an error code.
****************************************************************************/
int verify_cmos_op(unsigned bit, unsigned length, cmos_entry_config_t config)
{ if ((bit >= (8 * CMOS_SIZE)) || ((bit + length) > (8 * CMOS_SIZE)))
{
if ((bit >= (8 * CMOS_SIZE)) || ((bit + length) > (8 * CMOS_SIZE)))
return CMOS_AREA_OUT_OF_RANGE;
if (bit < (8 * CMOS_RTC_AREA_SIZE))
@ -324,7 +332,8 @@ int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config)
****************************************************************************/
static unsigned cmos_bit_op_strategy(unsigned bit, unsigned bits_left,
cmos_bit_op_location_t * where)
{ unsigned max_bits;
{
unsigned max_bits;
where->byte_index = bit >> 3;
where->bit_offset = bit & 0x07;
@ -340,7 +349,8 @@ static unsigned cmos_bit_op_strategy (unsigned bit, unsigned bits_left,
****************************************************************************/
static unsigned char cmos_read_bits(const cmos_bit_op_location_t * where,
unsigned nr_bits)
{ return (cmos_read_byte(where->byte_index) >> where->bit_offset) &
{
return (cmos_read_byte(where->byte_index) >> where->bit_offset) &
((unsigned char)((1 << nr_bits) - 1));
}
@ -352,10 +362,11 @@ static unsigned char cmos_read_bits (const cmos_bit_op_location_t *where,
****************************************************************************/
static void cmos_write_bits(const cmos_bit_op_location_t * where,
unsigned nr_bits, unsigned char value)
{ unsigned char n, mask;
{
unsigned char n, mask;
if (nr_bits == 8)
{ cmos_write_byte(where->byte_index, value);
if (nr_bits == 8) {
cmos_write_byte(where->byte_index, value);
return;
}

View File

@ -57,6 +57,8 @@ int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config);
* return 0.
****************************************************************************/
static inline int verify_cmos_byte_index(unsigned index)
{ return (index < CMOS_RTC_AREA_SIZE) || (index >= CMOS_SIZE); }
{
return (index < CMOS_RTC_AREA_SIZE) || (index >= CMOS_SIZE);
}
#endif /* NVRAMTOOL_CMOS_LOWLEVEL_H */

View File

@ -40,7 +40,8 @@ static int prepare_cmos_op_common (const cmos_entry_t *e);
* Perform a few checks common to both reads and writes.
****************************************************************************/
static int prepare_cmos_op_common(const cmos_entry_t * e)
{ int result;
{
int result;
if (e->config == CMOS_ENTRY_RESERVED)
/* Access to reserved parameters is not permitted. */
@ -61,13 +62,14 @@ static int prepare_cmos_op_common (const cmos_entry_t *e)
* code. Else return OK.
****************************************************************************/
int prepare_cmos_read(const cmos_entry_t * e)
{ int result;
{
int result;
if ((result = prepare_cmos_op_common(e)) != OK)
return result;
switch (e->config)
{ case CMOS_ENTRY_ENUM:
switch (e->config) {
case CMOS_ENTRY_ENUM:
case CMOS_ENTRY_HEX:
case CMOS_ENTRY_STRING:
break;
@ -89,7 +91,8 @@ int prepare_cmos_read (const cmos_entry_t *e)
****************************************************************************/
int prepare_cmos_write(const cmos_entry_t * e, const char value_str[],
unsigned long long *value)
{ const cmos_enum_t *q;
{
const cmos_enum_t *q;
unsigned long long out;
const char *p;
char *memory;
@ -98,13 +101,12 @@ int prepare_cmos_write (const cmos_entry_t *e, const char value_str[],
if ((result = prepare_cmos_op_common(e)) != OK)
return result;
switch (e->config)
{ case CMOS_ENTRY_ENUM:
switch (e->config) {
case CMOS_ENTRY_ENUM:
/* Make sure the user's input corresponds to a valid option. */
for (q = first_cmos_enum_id(e->config_id), found_one = 0;
q != NULL;
q = next_cmos_enum_id(q))
{ found_one = 1;
q != NULL; q = next_cmos_enum_id(q)) {
found_one = 1;
if (!strncmp(q->text, value_str, CMOS_MAX_TEXT_LENGTH))
break;
@ -120,8 +122,8 @@ int prepare_cmos_write (const cmos_entry_t *e, const char value_str[],
break;
case CMOS_ENTRY_HEX:
/* See if the first character of 'value_str' (excluding any initial
* whitespace) is a minus sign.
/* See if the first character of 'value_str' (excluding
* any initial whitespace) is a minus sign.
*/
for (p = value_str; isspace(*p); p++) ;
negative = (*p == '-');
@ -131,9 +133,9 @@ int prepare_cmos_write (const cmos_entry_t *e, const char value_str[],
if (*p)
return CMOS_OP_INVALID_INT;
/* If we get this far, the user specified a valid integer. However
* we do not currently support the use of negative numbers as CMOS
* parameter values.
/* If we get this far, the user specified a valid integer.
* However we do not currently support the use of negative
* numbers as CMOS parameter values.
*/
if (negative)
return CMOS_OP_NEGATIVE_INT;
@ -153,8 +155,7 @@ int prepare_cmos_write (const cmos_entry_t *e, const char value_str[],
BUG();
}
if ((e->length < (8 * sizeof(*value))) &&
(out >= (1ull << e->length)))
if ((e->length < (8 * sizeof(*value))) && (out >= (1ull << e->length)))
return CMOS_OP_VALUE_TOO_WIDE;
*value = out;
@ -168,7 +169,8 @@ int prepare_cmos_write (const cmos_entry_t *e, const char value_str[],
* this value.
****************************************************************************/
uint16_t cmos_checksum_read(void)
{ uint16_t lo, hi;
{
uint16_t lo, hi;
/* The checksum is stored in a big-endian format. */
hi = cmos_read_byte(cmos_checksum_index);
@ -183,7 +185,8 @@ uint16_t cmos_checksum_read (void)
* 'checksum'.
****************************************************************************/
void cmos_checksum_write(uint16_t checksum)
{ unsigned char lo, hi;
{
unsigned char lo, hi;
/* The checksum is stored in a big-endian format. */
hi = (unsigned char)(checksum >> 8);
@ -199,7 +202,8 @@ void cmos_checksum_write (uint16_t checksum)
* CMOS and return this checksum.
****************************************************************************/
uint16_t cmos_checksum_compute(void)
{ unsigned i, sum;
{
unsigned i, sum;
sum = 0;
@ -216,15 +220,16 @@ uint16_t cmos_checksum_compute (void)
* valid then print warning message and exit.
****************************************************************************/
void cmos_checksum_verify(void)
{ uint16_t computed, actual;
{
uint16_t computed, actual;
set_iopl(3);
computed = cmos_checksum_compute();
actual = cmos_checksum_read();
set_iopl(0);
if (computed != actual)
{ fprintf(stderr, "%s: Warning: Coreboot CMOS checksum is bad.\n",
if (computed != actual) {
fprintf(stderr, "%s: Warning: Coreboot CMOS checksum is bad.\n",
prog_name);
exit(1);
}

View File

@ -43,12 +43,13 @@ const char prog_version[] = "2.1";
* array of 'line_buf_size' bytes.
****************************************************************************/
int get_line_from_file(FILE * f, char line[], int line_buf_size)
{ if (fgets(line, line_buf_size, f) == NULL)
{
if (fgets(line, line_buf_size, f) == NULL)
return LINE_EOF;
/* If the file contains a line that is too long, then it's best to let the
* user know right away rather than passing back a truncated result that
* will lead to problems later on.
/* If the file contains a line that is too long, then it's best
* to let the user know right away rather than passing back a
* truncated result that will lead to problems later on.
*/
return (strlen(line) == ((size_t) (line_buf_size - 1))) ?
LINE_TOO_LONG : OK;
@ -60,7 +61,8 @@ int get_line_from_file (FILE *f, char line[], int line_buf_size)
* We ran out of memory. Print an error message and die.
****************************************************************************/
void out_of_memory(void)
{ fprintf(stderr, "%s: Out of memory.\n", prog_name);
{
fprintf(stderr, "%s: Out of memory.\n", prog_name);
exit(1);
}
@ -71,7 +73,8 @@ void out_of_memory (void)
* with a value of 1. Otherwise exit with a value of 0.
****************************************************************************/
void usage(FILE * outfile)
{ fprintf(outfile,
{
fprintf(outfile,
"Usage: %s [-y LAYOUT_FILE | -t] PARAMETER ...\n\n"
" Read/write coreboot parameters or show info from "
"coreboot table.\n\n"

View File

@ -73,10 +73,7 @@ static inline struct lb_uint64 pack_lb64(uint64_t value)
return result;
}
struct lb_header
{
struct lb_header {
uint8_t signature[4]; /* LBIO */
uint32_t header_bytes;
uint32_t header_checksum;
@ -184,7 +181,6 @@ struct cmos_entries {
variable length int aligned */
};
/* cmos enumerations record
This record is variable length. The text field may be
shorter than CMOS_MAX_TEXT_LENGTH.
@ -228,6 +224,4 @@ struct cmos_checksum {
#define CHECKSUM_PCBIOS 1
};
#endif /* COREBOOT_TABLES_H */

View File

@ -67,7 +67,8 @@ static void charprint (FILE *outfile, unsigned char byte,
*--------------------------------------------------------------------------*/
void hexdump(const void *mem, int bytes, uint64_t addrprint_start,
FILE * outfile, const hexdump_format_t * format)
{ int bytes_left, index, i;
{
int bytes_left, index, i;
const unsigned char *p;
is_printable_fn_t is_printable_fn;
@ -83,21 +84,22 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
p = (const unsigned char *)mem;
index = 0;
/* Each iteration handles one full line of output. When loop terminates,
* the number of remaining bytes to display (if any) will not be enough to
* fill an entire line.
/* Each iteration handles one full line of output. When loop
* terminates, the number of remaining bytes to display (if any)
* will not be enough to fill an entire line.
*/
for (bytes_left = bytes;
bytes_left >= format->bytes_per_line;
bytes_left -= format->bytes_per_line)
{ /* print start address for current line */
bytes_left -= format->bytes_per_line) {
/* print start address for current line */
fprintf(outfile, format->indent);
addrprint(outfile, addrprint_start + index, format->addrprint_width);
addrprint(outfile, addrprint_start + index,
format->addrprint_width);
fprintf(outfile, format->sep1);
/* display the bytes in hex */
for (i = 0; ; )
{ hexprint(outfile, p[index++]);
for (i = 0;;) {
hexprint(outfile, p[index++]);
if (++i >= format->bytes_per_line)
break;
@ -125,16 +127,16 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
fprintf(outfile, format->sep1);
/* display bytes for last line in hex */
for (i = 0; i < bytes_left; i++)
{ hexprint(outfile, p[index++]);
for (i = 0; i < bytes_left; i++) {
hexprint(outfile, p[index++]);
fprintf(outfile, format->sep2);
}
index -= bytes_left;
/* pad the rest of the hex byte area with spaces */
for (; ; )
{ fprintf(outfile, " ");
for (;;) {
fprintf(outfile, " ");
if (++i >= format->bytes_per_line)
break;
@ -146,7 +148,8 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
/* display bytes for last line as characters */
for (i = 0; i < bytes_left; i++)
charprint(outfile, p[index++], format->nonprintable, is_printable_fn);
charprint(outfile, p[index++], format->nonprintable,
is_printable_fn);
/* pad the rest of the character area with spaces */
for (; i < format->bytes_per_line; i++)
@ -170,7 +173,9 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
* Return 1 if the input character is printable. Otherwise return 0.
*--------------------------------------------------------------------------*/
int default_is_printable_fn(unsigned char c)
{ return (c >= 0x20) && (c <= 0x7e); }
{
return (c >= 0x20) && (c <= 0x7e);
}
/*--------------------------------------------------------------------------
* addrprint
@ -184,7 +189,8 @@ int default_is_printable_fn (unsigned char c)
* Must be a value from 1 to 8.
*--------------------------------------------------------------------------*/
static void addrprint(FILE * outfile, uint64_t address, int width)
{ char s[17];
{
char s[17];
int i;
/* force the user's input to be valid */
@ -196,11 +202,11 @@ static void addrprint (FILE *outfile, uint64_t address, int width)
/* convert address to string */
sprintf(s, "%016llx", (unsigned long long)address);
/* write it out, with colons separating consecutive 16-bit chunks of the
* address
/* write it out, with colons separating consecutive 16-bit
* chunks of the address
*/
for (i = 16 - (2 * width); ; )
{ fprintf(outfile, "%c", s[i]);
for (i = 16 - (2 * width);;) {
fprintf(outfile, "%c", s[i]);
if (++i >= 16)
break;
@ -220,8 +226,9 @@ static void addrprint (FILE *outfile, uint64_t address, int width)
* byte: the byte to display
*--------------------------------------------------------------------------*/
static void hexprint(FILE * outfile, unsigned char byte)
{ static const char tbl[] =
{ '0', '1', '2', '3', '4', '5', '6', '7',
{
static const char tbl[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
@ -244,4 +251,6 @@ static void hexprint (FILE *outfile, unsigned char byte)
static void charprint(FILE * outfile, unsigned char byte,
unsigned char nonprintable,
is_printable_fn_t is_printable_fn)
{ fprintf(outfile, "%c", is_printable_fn(byte) ? byte : nonprintable); }
{
fprintf(outfile, "%c", is_printable_fn(byte) ? byte : nonprintable);
}

View File

@ -81,8 +81,8 @@ typedef int (*is_printable_fn_t) (unsigned char c);
* printable. A value of NULL will cause
* default_is_printable_fn to be used.
*--------------------------------------------------------------------------*/
typedef struct
{ int bytes_per_line;
typedef struct {
int bytes_per_line;
int addrprint_width;
const char *indent;
const char *sep1;
@ -90,8 +90,7 @@ typedef struct
const char *sep3;
unsigned char nonprintable;
is_printable_fn_t is_printable_fn;
}
hexdump_format_t;
} hexdump_format_t;
/*--------------------------------------------------------------------------
* hexdump

View File

@ -42,10 +42,7 @@ static unsigned long long try_prepare_cmos_write (const cmos_entry_t *e,
/* matches either a blank line or a comment line */
static const char blank_or_comment_regex[] =
/* a blank line */
"(^[[:space:]]+$)"
"|" /* or ... */
"(^[[:space:]]+$)" "|" /* or ... */
/* a line consisting of: optional whitespace followed by */
"(^[[:space:]]*"
/* a '#' character and optionally, additional characters */
@ -95,18 +92,16 @@ cmos_write_t * process_input_file (FILE *f)
&blank_or_comment, assignment_regex, &assignment);
/* each iteration processes one line from input file */
for (line_num = 1;
get_input_file_line(f, line, LINE_BUF_SIZE) == OK;
line_num++)
{ /* skip comments and blank lines */
for (line_num = 1; get_input_file_line(f, line, LINE_BUF_SIZE) == OK; line_num++) { /* skip comments and blank lines */
if (!regexec(&blank_or_comment, line, 0, NULL, 0))
continue;
/* Is this a valid assignment line? If not, then it's a syntax
* error.
*/
if (regexec(&assignment, line, N_MATCHES, match, 0))
{ fprintf(stderr, "%s: Syntax error on line %d of input file.\n",
if (regexec(&assignment, line, N_MATCHES, match, 0)) {
fprintf(stderr,
"%s: Syntax error on line %d of input file.\n",
prog_name, line_num);
exit(1);
}
@ -120,8 +115,10 @@ cmos_write_t * process_input_file (FILE *f)
value = &line[match[2].rm_so];
/* now look up the coreboot parameter name */
if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL)
{ fprintf(stderr, "%s: Error on line %d of input file: CMOS parameter "
if (is_checksum_name(name)
|| (e = find_cmos_entry(name)) == NULL) {
fprintf(stderr,
"%s: Error on line %d of input file: CMOS parameter "
"%s not found.\n", prog_name, line_num, name);
exit(1);
}
@ -157,12 +154,13 @@ cmos_write_t * process_input_file (FILE *f)
* we go.
****************************************************************************/
void do_cmos_writes(cmos_write_t * list)
{ cmos_write_t *item;
{
cmos_write_t *item;
set_iopl(3);
while (list != NULL)
{ cmos_entry_t e;
while (list != NULL) {
cmos_entry_t e;
item = list;
e.bit = item->bit;
e.length = item->length;
@ -184,15 +182,17 @@ void do_cmos_writes (cmos_write_t *list)
* error.
****************************************************************************/
static int get_input_file_line(FILE * f, char line[], int line_buf_size)
{ switch (get_line_from_file(f, line, line_buf_size))
{ case OK:
{
switch (get_line_from_file(f, line, line_buf_size)) {
case OK:
return OK;
case LINE_EOF:
return LINE_EOF;
case LINE_TOO_LONG:
fprintf(stderr, "%s: Error on line %d of input file: Maximum line "
fprintf(stderr,
"%s: Error on line %d of input file: Maximum line "
"length exceeded. Max is %d characters.\n", prog_name,
line_num, line_buf_size - 2);
break;
@ -214,61 +214,71 @@ static int get_input_file_line (FILE *f, char line[], int line_buf_size)
****************************************************************************/
static unsigned long long try_prepare_cmos_write(const cmos_entry_t * e,
const char value_str[])
{ unsigned long long value;
{
unsigned long long value;
switch (prepare_cmos_write(e, value_str, &value))
{ case OK:
switch (prepare_cmos_write(e, value_str, &value)) {
case OK:
return value;
case CMOS_OP_BAD_ENUM_VALUE:
fprintf(stderr, "%s: Error on line %d of input file: Bad value for "
fprintf(stderr,
"%s: Error on line %d of input file: Bad value for "
"parameter %s.", prog_name, line_num, e->name);
break;
case CMOS_OP_NEGATIVE_INT:
fprintf(stderr, "%s: Error on line %d of input file: This program "
fprintf(stderr,
"%s: Error on line %d of input file: This program "
"does not support assignment of negative numbers to "
"coreboot parameters.", prog_name, line_num);
break;
case CMOS_OP_INVALID_INT:
fprintf(stderr, "%s: Error on line %d of input file: %s is not a "
fprintf(stderr,
"%s: Error on line %d of input file: %s is not a "
"valid integer.", prog_name, line_num, value_str);
break;
case CMOS_OP_RESERVED:
fprintf(stderr, "%s: Error on line %d of input file: Can not modify "
fprintf(stderr,
"%s: Error on line %d of input file: Can not modify "
"reserved coreboot parameter %s.", prog_name, line_num,
e->name);
break;
case CMOS_OP_VALUE_TOO_WIDE:
fprintf(stderr, "%s: Error on line %d of input file: Can not write "
fprintf(stderr,
"%s: Error on line %d of input file: Can not write "
"value %s to CMOS parameter %s that is only %d bits wide.",
prog_name, line_num, value_str, e->name, e->length);
break;
case CMOS_OP_NO_MATCHING_ENUM:
fprintf(stderr, "%s: coreboot parameter %s has no matching enums.",
fprintf(stderr,
"%s: coreboot parameter %s has no matching enums.",
prog_name, e->name);
break;
case CMOS_AREA_OUT_OF_RANGE:
fprintf(stderr, "%s: The CMOS area specified by the layout info for "
fprintf(stderr,
"%s: The CMOS area specified by the layout info for "
"coreboot parameter %s is out of range.", prog_name,
e->name);
break;
case CMOS_AREA_OVERLAPS_RTC:
fprintf(stderr, "%s: The CMOS area specified by the layout info for "
fprintf(stderr,
"%s: The CMOS area specified by the layout info for "
"coreboot parameter %s overlaps the realtime clock area.",
prog_name, e->name);
break;
case CMOS_AREA_TOO_WIDE:
fprintf(stderr, "%s: The CMOS area specified by the layout info for "
"coreboot parameter %s is too wide.",
prog_name, e->name);
fprintf(stderr,
"%s: The CMOS area specified by the layout info for "
"coreboot parameter %s is too wide.", prog_name,
e->name);
break;
default:

View File

@ -36,13 +36,13 @@
typedef struct cmos_write_t cmos_write_t;
/* This represents a pending CMOS write operation. When changing multiple
* CMOS parameter values, we first represent the changes as a list of pending
* write operations. This allows us to sanity check all write operations
* before any of them are performed.
/* This represents a pending CMOS write operation. When changing
* multiple CMOS parameter values, we first represent the changes as a
* list of pending write operations. This allows us to sanity check all
* write operations before any of them are performed.
*/
struct cmos_write_t
{ unsigned bit;
struct cmos_write_t {
unsigned bit;
unsigned length;
cmos_entry_config_t config;
unsigned long long value;

View File

@ -34,15 +34,15 @@
typedef struct cmos_entry_item_t cmos_entry_item_t;
struct cmos_entry_item_t
{ cmos_entry_t item;
struct cmos_entry_item_t {
cmos_entry_t item;
cmos_entry_item_t *next;
};
typedef struct cmos_enum_item_t cmos_enum_item_t;
struct cmos_enum_item_t
{ cmos_enum_t item;
struct cmos_enum_item_t {
cmos_enum_t item;
cmos_enum_item_t *next;
};
@ -101,7 +101,9 @@ static cmos_layout_get_fn_t cmos_layout_get_fn = default_cmos_layout_get_fn;
****************************************************************************/
static inline int entries_overlap(const cmos_entry_t * p,
const cmos_entry_t * q)
{ return areas_overlap(p->bit, p->length, q->bit, q->length); }
{
return areas_overlap(p->bit, p->length, q->bit, q->length);
}
/****************************************************************************
* cmos_entry_to_const_item
@ -109,8 +111,8 @@ static inline int entries_overlap (const cmos_entry_t *p,
* Return a pointer to the cmos_entry_item_t that 'p' is embedded within.
****************************************************************************/
static inline const cmos_entry_item_t *cmos_entry_to_const_item
(const cmos_entry_t *p)
{ static const cmos_entry_t *pos = &((cmos_entry_item_t *) 0)->item;
(const cmos_entry_t * p) {
static const cmos_entry_t *pos = &((cmos_entry_item_t *) 0)->item;
unsigned long offset, address;
offset = (unsigned long)pos;
@ -124,8 +126,8 @@ static inline const cmos_entry_item_t * cmos_entry_to_const_item
* Return a pointer to the cmos_enum_item_t that 'p' is embedded within.
****************************************************************************/
static inline const cmos_enum_item_t *cmos_enum_to_const_item
(const cmos_enum_t *p)
{ static const cmos_enum_t *pos = &((cmos_enum_item_t *) 0)->item;
(const cmos_enum_t * p) {
static const cmos_enum_t *pos = &((cmos_enum_item_t *) 0)->item;
unsigned long offset, address;
offset = (unsigned long)pos;
@ -140,7 +142,9 @@ static inline const cmos_enum_item_t * cmos_enum_to_const_item
* information.
****************************************************************************/
void register_cmos_layout_get_fn(cmos_layout_get_fn_t fn)
{ cmos_layout_get_fn = fn; }
{
cmos_layout_get_fn = fn;
}
/****************************************************************************
* get_cmos_layout
@ -148,7 +152,9 @@ void register_cmos_layout_get_fn (cmos_layout_get_fn_t fn)
* Retrieve CMOS layout information and store it in our internal repository.
****************************************************************************/
void get_cmos_layout(void)
{ cmos_layout_get_fn(); }
{
cmos_layout_get_fn();
}
/****************************************************************************
* add_cmos_entry
@ -159,20 +165,22 @@ void get_cmos_layout (void)
* will be set to point to the overlapping entry.
****************************************************************************/
int add_cmos_entry(const cmos_entry_t * e, const cmos_entry_t ** conflict)
{ cmos_entry_item_t *item, *prev, *new_entry;
{
cmos_entry_item_t *item, *prev, *new_entry;
*conflict = NULL;
if (e->length < 1)
return LAYOUT_ENTRY_BAD_LENGTH;
if ((new_entry = (cmos_entry_item_t *) malloc(sizeof(*new_entry))) == NULL)
if ((new_entry =
(cmos_entry_item_t *) malloc(sizeof(*new_entry))) == NULL)
out_of_memory();
new_entry->item = *e;
if (cmos_entry_list == NULL)
{ new_entry->next = NULL;
if (cmos_entry_list == NULL) {
new_entry->next = NULL;
cmos_entry_list = new_entry;
return OK;
}
@ -184,9 +192,9 @@ int add_cmos_entry (const cmos_entry_t *e, const cmos_entry_t **conflict)
(item != NULL) && (item->item.bit < e->bit);
prev = item, item = item->next) ;
if (prev == NULL)
{ if (entries_overlap(e, &cmos_entry_list->item))
{ *conflict = &cmos_entry_list->item;
if (prev == NULL) {
if (entries_overlap(e, &cmos_entry_list->item)) {
*conflict = &cmos_entry_list->item;
goto fail;
}
@ -195,13 +203,13 @@ int add_cmos_entry (const cmos_entry_t *e, const cmos_entry_t **conflict)
return OK;
}
if (entries_overlap(&prev->item, e))
{ *conflict = &prev->item;
if (entries_overlap(&prev->item, e)) {
*conflict = &prev->item;
goto fail;
}
if ((item != NULL) && entries_overlap(e, &item->item))
{ *conflict = &item->item;
if ((item != NULL) && entries_overlap(e, &item->item)) {
*conflict = &item->item;
goto fail;
}
@ -221,10 +229,11 @@ fail:
* entry or NULL if entry not found.
****************************************************************************/
const cmos_entry_t *find_cmos_entry(const char name[])
{ cmos_entry_item_t *item;
{
cmos_entry_item_t *item;
for (item = cmos_entry_list; item != NULL; item = item->next)
{ if (!strcmp(item->item.name, name))
for (item = cmos_entry_list; item != NULL; item = item->next) {
if (!strcmp(item->item.name, name))
return &item->item;
}
@ -238,7 +247,9 @@ const cmos_entry_t * find_cmos_entry (const char name[])
* empty.
****************************************************************************/
const cmos_entry_t *first_cmos_entry(void)
{ return (cmos_entry_list == NULL) ? NULL : &cmos_entry_list->item; }
{
return (cmos_entry_list == NULL) ? NULL : &cmos_entry_list->item;
}
/****************************************************************************
* next_cmos_entry
@ -247,7 +258,8 @@ const cmos_entry_t * first_cmos_entry (void)
* entries.
****************************************************************************/
const cmos_entry_t *next_cmos_entry(const cmos_entry_t * last)
{ const cmos_entry_item_t *last_item, *next_item;
{
const cmos_entry_item_t *last_item, *next_item;
last_item = cmos_entry_to_const_item(last);
next_item = last_item->next;
@ -261,35 +273,36 @@ const cmos_entry_t * next_cmos_entry (const cmos_entry_t *last)
* information. Return OK on success or an error code on failure.
****************************************************************************/
int add_cmos_enum(const cmos_enum_t * e)
{ cmos_enum_item_t *item, *prev, *new_enum;
{
cmos_enum_item_t *item, *prev, *new_enum;
if ((new_enum = (cmos_enum_item_t *) malloc(sizeof(*new_enum))) == NULL)
out_of_memory();
new_enum->item = *e;
if (cmos_enum_list == NULL)
{ new_enum->next = NULL;
if (cmos_enum_list == NULL) {
new_enum->next = NULL;
cmos_enum_list = new_enum;
return OK;
}
/* The list of enums is sorted in ascending order, first by 'config_id' and
* then by 'value'. Look for the first enum whose 'config_id' field
* matches 'e'.
/* The list of enums is sorted in ascending order, first by
* 'config_id' and then by 'value'. Look for the first enum
* whose 'config_id' field matches 'e'.
*/
for (item = cmos_enum_list, prev = NULL;
(item != NULL) && (item->item.config_id < e->config_id);
prev = item, item = item->next) ;
if (item == NULL)
{ new_enum->next = NULL;
if (item == NULL) {
new_enum->next = NULL;
prev->next = new_enum;
return OK;
}
if (item->item.config_id > e->config_id)
{ new_enum->next = item;
if (item->item.config_id > e->config_id) {
new_enum->next = item;
if (prev == NULL)
cmos_enum_list = new_enum;
@ -299,22 +312,23 @@ int add_cmos_enum (const cmos_enum_t *e)
return OK;
}
/* List already contains at least one enum whose 'config_id' matches 'e'.
* Now find proper place to insert 'e' based on 'value'.
/* List already contains at least one enum whose 'config_id'
* matches 'e'. Now find proper place to insert 'e' based on
* 'value'.
*/
while (item->item.value < e->value)
{ prev = item;
while (item->item.value < e->value) {
prev = item;
item = item->next;
if ((item == NULL) || (item->item.config_id != e->config_id))
{ new_enum->next = item;
if ((item == NULL) || (item->item.config_id != e->config_id)) {
new_enum->next = item;
prev->next = new_enum;
return OK;
}
}
if (item->item.value == e->value)
{ free(new_enum);
if (item->item.value == e->value) {
free(new_enum);
return LAYOUT_DUPLICATE_ENUM;
}
@ -334,15 +348,15 @@ int add_cmos_enum (const cmos_enum_t *e)
* Search for an enum that matches 'config_id' and 'value'. If found, return
* a pointer to the mathcing enum. Else return NULL.
****************************************************************************/
const cmos_enum_t * find_cmos_enum (unsigned config_id,
unsigned long long value)
{ const cmos_enum_item_t *item;
const cmos_enum_t *find_cmos_enum(unsigned config_id, unsigned long long value)
{
const cmos_enum_item_t *item;
if ((item = find_first_cmos_enum_id(config_id)) == NULL)
return NULL;
while (item->item.value < value)
{ item = item->next;
while (item->item.value < value) {
item = item->next;
if ((item == NULL) || (item->item.config_id != config_id))
return NULL;
@ -358,7 +372,9 @@ const cmos_enum_t * find_cmos_enum (unsigned config_id,
* empty.
****************************************************************************/
const cmos_enum_t *first_cmos_enum(void)
{ return (cmos_enum_list == NULL) ? NULL : &cmos_enum_list->item; }
{
return (cmos_enum_list == NULL) ? NULL : &cmos_enum_list->item;
}
/****************************************************************************
* next_cmos_enum
@ -367,7 +383,8 @@ const cmos_enum_t * first_cmos_enum (void)
* enums.
****************************************************************************/
const cmos_enum_t *next_cmos_enum(const cmos_enum_t * last)
{ const cmos_enum_item_t *last_item, *next_item;
{
const cmos_enum_item_t *last_item, *next_item;
last_item = cmos_enum_to_const_item(last);
next_item = last_item->next;
@ -381,7 +398,8 @@ const cmos_enum_t * next_cmos_enum (const cmos_enum_t *last)
* 'config_id' or NULL if there are no matching enums.
****************************************************************************/
const cmos_enum_t *first_cmos_enum_id(unsigned config_id)
{ const cmos_enum_item_t *item;
{
const cmos_enum_item_t *item;
item = find_first_cmos_enum_id(config_id);
return (item == NULL) ? NULL : &item->item;
@ -394,7 +412,8 @@ const cmos_enum_t * first_cmos_enum_id (unsigned config_id)
* 'config_id' field of 'last' or NULL if there are no more matching enums.
****************************************************************************/
const cmos_enum_t *next_cmos_enum_id(const cmos_enum_t * last)
{ const cmos_enum_item_t *item;
{
const cmos_enum_item_t *item;
item = cmos_enum_to_const_item(last)->next;
return ((item == NULL) || (item->item.config_id != last->config_id)) ?
@ -408,7 +427,9 @@ const cmos_enum_t * next_cmos_enum_id (const cmos_enum_t *last)
* checksum. Else return 0.
****************************************************************************/
int is_checksum_name(const char name[])
{ return !strcmp(name, checksum_param_name); }
{
return !strcmp(name, checksum_param_name);
}
/****************************************************************************
* checksum_layout_to_bytes
@ -419,7 +440,8 @@ int is_checksum_name (const char name[])
* a sanity check fails.
****************************************************************************/
int checksum_layout_to_bytes(cmos_checksum_layout_t * layout)
{ unsigned start, end, index;
{
unsigned start, end, index;
start = layout->summed_area_start;
end = layout->summed_area_end;
@ -465,7 +487,8 @@ int checksum_layout_to_bytes (cmos_checksum_layout_t *layout)
* in bytes. Convert this information to bit positions.
****************************************************************************/
void checksum_layout_to_bits(cmos_checksum_layout_t * layout)
{ layout->summed_area_start *= 8;
{
layout->summed_area_start *= 8;
layout->summed_area_end = (layout->summed_area_end * 8) + 7;
layout->checksum_at *= 8;
}
@ -478,7 +501,9 @@ void checksum_layout_to_bits (cmos_checksum_layout_t *layout)
* retrieve layout information.
****************************************************************************/
static void default_cmos_layout_get_fn(void)
{ BUG(); }
{
BUG();
}
/****************************************************************************
* areas_overlap
@ -487,7 +512,8 @@ static void default_cmos_layout_get_fn (void)
****************************************************************************/
static int areas_overlap(unsigned area_0_start, unsigned area_0_length,
unsigned area_1_start, unsigned area_1_length)
{ unsigned area_0_end, area_1_end;
{
unsigned area_0_end, area_1_end;
area_0_end = area_0_start + area_0_length - 1;
area_1_end = area_1_start + area_1_length - 1;
@ -501,7 +527,8 @@ static int areas_overlap (unsigned area_0_start, unsigned area_0_length,
* 'config_id'. Return NULL if there is no matching enum.
****************************************************************************/
static const cmos_enum_item_t *find_first_cmos_enum_id(unsigned config_id)
{ cmos_enum_item_t *item;
{
cmos_enum_item_t *item;
for (item = cmos_enum_list;
(item != NULL) && (item->item.config_id < config_id);

View File

@ -45,44 +45,40 @@
#define LAYOUT_SUMMED_AREA_OUT_OF_RANGE (LAYOUT_RESULT_START + 8)
#define LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE (LAYOUT_RESULT_START + 9)
typedef enum
{ CMOS_ENTRY_ENUM,
typedef enum {
CMOS_ENTRY_ENUM,
CMOS_ENTRY_HEX,
CMOS_ENTRY_STRING,
CMOS_ENTRY_RESERVED
}
cmos_entry_config_t;
} cmos_entry_config_t;
/* This represents a CMOS parameter. */
typedef struct
{ unsigned bit;
typedef struct {
unsigned bit;
unsigned length;
cmos_entry_config_t config;
unsigned config_id;
char name[CMOS_MAX_NAME_LENGTH + 1];
}
cmos_entry_t;
} cmos_entry_t;
/* This represents a possible value for a CMOS parameter of type
* CMOS_ENTRY_ENUM.
*/
typedef struct
{ unsigned config_id;
typedef struct {
unsigned config_id;
unsigned long long value;
char text[CMOS_MAX_TEXT_LENGTH + 1];
}
cmos_enum_t;
} cmos_enum_t;
/* This represents the location of the CMOS checksum and the area over which
* it is computed. Depending on the context, the values may be represented as
* either bit positions or byte positions.
/* This represents the location of the CMOS checksum and the area over
* which it is computed. Depending on the context, the values may be
* represented as either bit positions or byte positions.
*/
typedef struct
{ unsigned summed_area_start; /* first checksummed location */
typedef struct {
unsigned summed_area_start; /* first checksummed location */
unsigned summed_area_end; /* last checksummed location */
unsigned checksum_at; /* location of checksum */
}
cmos_checksum_layout_t;
} cmos_checksum_layout_t;
extern const char checksum_param_name[];
@ -101,8 +97,7 @@ const cmos_entry_t * find_cmos_entry (const char name[]);
const cmos_entry_t *first_cmos_entry(void);
const cmos_entry_t *next_cmos_entry(const cmos_entry_t * last);
int add_cmos_enum(const cmos_enum_t * e);
const cmos_enum_t * find_cmos_enum (unsigned config_id,
unsigned long long value);
const cmos_enum_t *find_cmos_enum(unsigned config_id, unsigned long long value);
const cmos_enum_t *first_cmos_enum(void);
const cmos_enum_t *next_cmos_enum(const cmos_enum_t * last);
const cmos_enum_t *first_cmos_enum_id(unsigned config_id);

View File

@ -62,10 +62,7 @@ static unsigned long do_string_to_unsigned_long (const char str[],
/* matches either a blank line or a comment line */
static const char blank_or_comment_regex[] =
/* a blank line */
"(^[[:space:]]+$)"
"|" /* or ... */
"(^[[:space:]]+$)" "|" /* or ... */
/* a line consisting of: optional whitespace followed by */
"(^[[:space:]]*"
/* a '#' character and optionally, additional characters */
@ -195,7 +192,9 @@ static const char *layout_filename = NULL;
* Set the name of the file we will obtain CMOS layout information from.
****************************************************************************/
void set_layout_filename(const char filename[])
{ layout_filename = filename; }
{
layout_filename = filename;
}
/****************************************************************************
* get_layout_from_file
@ -203,12 +202,14 @@ void set_layout_filename (const char filename[])
* Read CMOS layout information from the user-specified CMOS layout file.
****************************************************************************/
void get_layout_from_file(void)
{ FILE *f;
{
FILE *f;
assert(layout_filename != NULL);
if ((f = fopen(layout_filename, "r")) == NULL)
{ fprintf(stderr, "%s: Can not open CMOS layout file %s for reading: "
if ((f = fopen(layout_filename, "r")) == NULL) {
fprintf(stderr,
"%s: Can not open CMOS layout file %s for reading: "
"%s\n", prog_name, layout_filename, strerror(errno));
exit(1);
}
@ -224,26 +225,26 @@ void get_layout_from_file (void)
* format that CMOS layout files adhere to.
****************************************************************************/
void write_cmos_layout(FILE * f)
{ const cmos_entry_t *cmos_entry;
{
const cmos_entry_t *cmos_entry;
const cmos_enum_t *cmos_enum;
cmos_checksum_layout_t layout;
fprintf(f, "entries\n");
for (cmos_entry = first_cmos_entry();
cmos_entry != NULL;
cmos_entry = next_cmos_entry(cmos_entry))
fprintf(f, "%u %u %c %u %s\n", cmos_entry->bit, cmos_entry->length,
cmos_entry != NULL; cmos_entry = next_cmos_entry(cmos_entry))
fprintf(f, "%u %u %c %u %s\n", cmos_entry->bit,
cmos_entry->length,
cmos_entry_char_value(cmos_entry->config),
cmos_entry->config_id, cmos_entry->name);
fprintf(f, "\nenumerations\n");
for (cmos_enum = first_cmos_enum();
cmos_enum != NULL;
cmos_enum = next_cmos_enum(cmos_enum))
fprintf(f, "%u %llu %s\n", cmos_enum->config_id, cmos_enum->value,
cmos_enum->text);
cmos_enum != NULL; cmos_enum = next_cmos_enum(cmos_enum))
fprintf(f, "%u %llu %s\n", cmos_enum->config_id,
cmos_enum->value, cmos_enum->text);
layout.summed_area_start = cmos_checksum_start;
layout.summed_area_end = cmos_checksum_end;
@ -260,7 +261,8 @@ void write_cmos_layout (FILE *f)
* repository.
****************************************************************************/
static void process_layout_file(FILE * f)
{ compile_reg_exprs(REG_EXTENDED | REG_NEWLINE, 7,
{
compile_reg_exprs(REG_EXTENDED | REG_NEWLINE, 7,
blank_or_comment_regex, &blank_or_comment_expr,
start_entries_regex, &start_entries_expr,
entries_line_regex, &entries_line_expr,
@ -271,15 +273,16 @@ static void process_layout_file (FILE *f)
line_num = 1;
skip_past_start(f);
/* Skip past all entries. We will process these later when we make a
* second pass through the file.
/* Skip past all entries. We will process these later when we
* make a second pass through the file.
*/
while (!process_entry(f, 1)) ;
/* Process all enums, adding them to our internal repository as we go. */
/* Process all enums, adding them to our internal repository as
* we go. */
if (process_enum(f, 0))
{ fprintf(stderr, "%s: Error: CMOS layout file contains no "
if (process_enum(f, 0)) {
fprintf(stderr, "%s: Error: CMOS layout file contains no "
"enumerations.\n", prog_name);
exit(1);
}
@ -292,14 +295,16 @@ static void process_layout_file (FILE *f)
skip_past_start(f);
/* Process all entries, adding them to the repository as we go. We must
* add the entries after the enums, even though they appear in the layout
* file before the enums. This is because the entries are sanity checked
* against the enums as they are added.
/* Process all entries, adding them to the repository as we go.
* We must add the entries after the enums, even though they
* appear in the layout file before the enums. This is because
* the entries are sanity checked against the enums as they are
* added.
*/
if (process_entry(f, 0))
{ fprintf(stderr, "%s: Error: CMOS layout file contains no entries.\n",
if (process_entry(f, 0)) {
fprintf(stderr,
"%s: Error: CMOS layout file contains no entries.\n",
prog_name);
exit(1);
}
@ -312,8 +317,8 @@ static void process_layout_file (FILE *f)
/* Process CMOS checksum info. */
process_checksum_info(f);
/* See if there are any lines left to process. If so, verify that they are
* all either blank lines or comments.
/* See if there are any lines left to process. If so, verify
* that they are all either blank lines or comments.
*/
skip_remaining_lines(f);
@ -329,11 +334,12 @@ static void process_layout_file (FILE *f)
* Skip past the line that marks the start of the "entries" section.
****************************************************************************/
static void skip_past_start(FILE * f)
{ char line[LINE_BUF_SIZE];
{
char line[LINE_BUF_SIZE];
for (; ; line_num++)
{ if (get_layout_file_line(f, line, LINE_BUF_SIZE))
{ fprintf(stderr,
for (;; line_num++) {
if (get_layout_file_line(f, line, LINE_BUF_SIZE)) {
fprintf(stderr,
"%s: \"entries\" line not found in CMOS layout file.\n",
prog_name);
exit(1);
@ -345,7 +351,8 @@ static void skip_past_start (FILE *f)
if (!regexec(&start_entries_expr, line, 0, NULL, 0))
break;
fprintf(stderr, "%s: Syntax error on line %d of CMOS layout file. "
fprintf(stderr,
"%s: Syntax error on line %d of CMOS layout file. "
"\"entries\" line expected.\n", prog_name, line_num);
exit(1);
}
@ -361,7 +368,8 @@ static void skip_past_start (FILE *f)
* Return 1 if there are no more entries.
****************************************************************************/
static int process_entry(FILE * f, int skip_add)
{ static const size_t N_MATCHES = 6;
{
static const size_t N_MATCHES = 6;
char line[LINE_BUF_SIZE];
regmatch_t match[N_MATCHES];
cmos_entry_t cmos_entry;
@ -369,9 +377,9 @@ static int process_entry (FILE *f, int skip_add)
result = 1;
for (; ; line_num++)
{ if (get_layout_file_line(f, line, LINE_BUF_SIZE))
{ fprintf(stderr,
for (;; line_num++) {
if (get_layout_file_line(f, line, LINE_BUF_SIZE)) {
fprintf(stderr,
"%s: Unexpected end of CMOS layout file reached while "
"reading \"entries\" section.\n", prog_name);
exit(1);
@ -380,9 +388,10 @@ static int process_entry (FILE *f, int skip_add)
if (!regexec(&blank_or_comment_expr, line, 0, NULL, 0))
continue;
if (regexec(&entries_line_expr, line, N_MATCHES, match, 0))
{ if (regexec(&start_enums_expr, line, 0, NULL, 0))
{ fprintf(stderr, "%s: Syntax error on line %d of CMOS layout "
if (regexec(&entries_line_expr, line, N_MATCHES, match, 0)) {
if (regexec(&start_enums_expr, line, 0, NULL, 0)) {
fprintf(stderr,
"%s: Syntax error on line %d of CMOS layout "
"file.\n", prog_name, line_num);
exit(1);
}
@ -400,9 +409,9 @@ static int process_entry (FILE *f, int skip_add)
line[match[3].rm_eo] = '\0';
line[match[4].rm_eo] = '\0';
line[match[5].rm_eo] = '\0';
create_entry(&cmos_entry, &line[match[1].rm_so], &line[match[2].rm_so],
&line[match[3].rm_so], &line[match[4].rm_so],
&line[match[5].rm_so]);
create_entry(&cmos_entry, &line[match[1].rm_so],
&line[match[2].rm_so], &line[match[3].rm_so],
&line[match[4].rm_so], &line[match[5].rm_so]);
try_add_layout_file_entry(&cmos_entry);
break;
}
@ -419,7 +428,8 @@ static int process_entry (FILE *f, int skip_add)
* and processed. Return 1 if there are no more enumerations.
****************************************************************************/
static int process_enum(FILE * f, int skip_add)
{ static const size_t N_MATCHES = 4;
{
static const size_t N_MATCHES = 4;
char line[LINE_BUF_SIZE];
regmatch_t match[N_MATCHES];
cmos_enum_t cmos_enum;
@ -427,20 +437,22 @@ static int process_enum (FILE *f, int skip_add)
result = 1;
for (; ; line_num++)
{ if (get_layout_file_line(f, line, LINE_BUF_SIZE))
{ fprintf(stderr,
for (;; line_num++) {
if (get_layout_file_line(f, line, LINE_BUF_SIZE)) {
fprintf(stderr,
"%s: Unexpected end of CMOS layout file reached while "
"reading \"enumerations\" section.\n", prog_name);
"reading \"enumerations\" section.\n",
prog_name);
exit(1);
}
if (!regexec(&blank_or_comment_expr, line, 0, NULL, 0))
continue;
if (regexec(&enums_line_expr, line, N_MATCHES, match, 0))
{ if (regexec(&start_checksums_expr, line, 0, NULL, 0))
{ fprintf(stderr, "%s: Syntax error on line %d of CMOS layout "
if (regexec(&enums_line_expr, line, N_MATCHES, match, 0)) {
if (regexec(&start_checksums_expr, line, 0, NULL, 0)) {
fprintf(stderr,
"%s: Syntax error on line %d of CMOS layout "
"file.\n", prog_name, line_num);
exit(1);
}
@ -456,8 +468,8 @@ static int process_enum (FILE *f, int skip_add)
line[match[1].rm_eo] = '\0';
line[match[2].rm_eo] = '\0';
line[match[3].rm_eo] = '\0';
create_enum(&cmos_enum, &line[match[1].rm_so], &line[match[2].rm_so],
&line[match[3].rm_so]);
create_enum(&cmos_enum, &line[match[1].rm_so],
&line[match[2].rm_so], &line[match[3].rm_so]);
try_add_cmos_enum(&cmos_enum);
break;
}
@ -472,13 +484,14 @@ static int process_enum (FILE *f, int skip_add)
* Get line conatining CMOS checksum information.
****************************************************************************/
static void process_checksum_info(FILE * f)
{ static const size_t N_MATCHES = 4;
{
static const size_t N_MATCHES = 4;
char line[LINE_BUF_SIZE];
regmatch_t match[N_MATCHES];
for (; ; line_num++)
{ if (get_layout_file_line(f, line, LINE_BUF_SIZE))
{ fprintf(stderr,
for (;; line_num++) {
if (get_layout_file_line(f, line, LINE_BUF_SIZE)) {
fprintf(stderr,
"%s: Unexpected end of CMOS layout file reached while "
"reading \"checksums\" section.\n", prog_name);
exit(1);
@ -487,10 +500,11 @@ static void process_checksum_info (FILE *f)
if (!regexec(&blank_or_comment_expr, line, 0, NULL, 0))
continue;
if (regexec(&checksum_line_expr, line, N_MATCHES, match, 0))
{ fprintf(stderr, "%s: Syntax error on line %d of CMOS layout "
"file. \"checksum\" line expected.\n", prog_name,
line_num);
if (regexec(&checksum_line_expr, line, N_MATCHES, match, 0)) {
fprintf(stderr,
"%s: Syntax error on line %d of CMOS layout "
"file. \"checksum\" line expected.\n",
prog_name, line_num);
exit(1);
}
@ -511,13 +525,14 @@ static void process_checksum_info (FILE *f)
* that contains anything other than comments and whitespace.
****************************************************************************/
static void skip_remaining_lines(FILE * f)
{ char line[LINE_BUF_SIZE];
{
char line[LINE_BUF_SIZE];
for (line_num++;
get_layout_file_line(f, line, LINE_BUF_SIZE) == OK;
line_num++)
{ if (regexec(&blank_or_comment_expr, line, 0, NULL, 0))
{ fprintf(stderr, "%s: Syntax error on line %d of CMOS layout file: "
get_layout_file_line(f, line, LINE_BUF_SIZE) == OK; line_num++) {
if (regexec(&blank_or_comment_expr, line, 0, NULL, 0)) {
fprintf(stderr,
"%s: Syntax error on line %d of CMOS layout file: "
"Only comments and/or whitespace allowed after "
"\"checksum\" line.\n", prog_name, line_num);
exit(1);
@ -535,14 +550,15 @@ static void create_entry (cmos_entry_t *cmos_entry,
const char start_bit_str[], const char length_str[],
const char config_str[], const char config_id_str[],
const char name_str[])
{ cmos_entry->bit = string_to_unsigned(start_bit_str, "start-bit");
{
cmos_entry->bit = string_to_unsigned(start_bit_str, "start-bit");
cmos_entry->length = string_to_unsigned(length_str, "length");
if (config_str[1] != '\0')
goto bad_config_str;
switch (config_str[0])
{ case 'e':
switch (config_str[0]) {
case 'e':
cmos_entry->config = CMOS_ENTRY_ENUM;
break;
@ -564,8 +580,9 @@ static void create_entry (cmos_entry_t *cmos_entry,
cmos_entry->config_id = string_to_unsigned(config_id_str, "config-ID");
if (strlen(name_str) >= CMOS_MAX_NAME_LENGTH)
{ fprintf(stderr, "%s: Error on line %d of CMOS layout file: name too "
if (strlen(name_str) >= CMOS_MAX_NAME_LENGTH) {
fprintf(stderr,
"%s: Error on line %d of CMOS layout file: name too "
"long (max length is %d).\n", prog_name, line_num,
CMOS_MAX_NAME_LENGTH - 1);
exit(1);
@ -575,7 +592,8 @@ static void create_entry (cmos_entry_t *cmos_entry,
return;
bad_config_str:
fprintf(stderr, "%s: Error on line %d of CMOS layout file: 'e', 'h', or "
fprintf(stderr,
"%s: Error on line %d of CMOS layout file: 'e', 'h', or "
"'r' expected for config value.\n", prog_name, line_num);
exit(1);
}
@ -587,26 +605,30 @@ bad_config_str:
* an error message on failure.
****************************************************************************/
static void try_add_layout_file_entry(const cmos_entry_t * cmos_entry)
{ const cmos_entry_t *conflict;
{
const cmos_entry_t *conflict;
switch (add_cmos_entry(cmos_entry, &conflict))
{ case OK:
switch (add_cmos_entry(cmos_entry, &conflict)) {
case OK:
return;
case CMOS_AREA_OUT_OF_RANGE:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. Area "
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. Area "
"covered by entry %s is out of range.\n", prog_name,
line_num, cmos_entry->name);
break;
case CMOS_AREA_TOO_WIDE:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. Area "
"covered by entry %s is too wide.\n", prog_name, line_num,
cmos_entry->name);
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. Area "
"covered by entry %s is too wide.\n", prog_name,
line_num, cmos_entry->name);
break;
case LAYOUT_ENTRY_OVERLAP:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. Layouts "
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. Layouts "
"overlap for entries %s and %s.\n", prog_name, line_num,
cmos_entry->name, conflict->name);
break;
@ -633,11 +655,13 @@ static void try_add_layout_file_entry (const cmos_entry_t *cmos_entry)
****************************************************************************/
static void create_enum(cmos_enum_t * cmos_enum, const char id_str[],
const char value_str[], const char text_str[])
{ cmos_enum->config_id = string_to_unsigned(id_str, "ID");
{
cmos_enum->config_id = string_to_unsigned(id_str, "ID");
cmos_enum->value = string_to_unsigned_long(value_str, "value");
if (strlen(text_str) >= CMOS_MAX_TEXT_LENGTH)
{ fprintf(stderr, "%s: Error on line %d of CMOS layout file: text too "
if (strlen(text_str) >= CMOS_MAX_TEXT_LENGTH) {
fprintf(stderr,
"%s: Error on line %d of CMOS layout file: text too "
"long (max length is %d).\n", prog_name, line_num,
CMOS_MAX_TEXT_LENGTH - 1);
exit(1);
@ -653,8 +677,9 @@ static void create_enum (cmos_enum_t *cmos_enum, const char id_str[],
* an error message on failure.
****************************************************************************/
static void try_add_cmos_enum(const cmos_enum_t * cmos_enum)
{ switch (add_cmos_enum(cmos_enum))
{ case OK:
{
switch (add_cmos_enum(cmos_enum)) {
case OK:
return;
case LAYOUT_DUPLICATE_ENUM:
@ -678,7 +703,8 @@ static void try_add_cmos_enum (const cmos_enum_t *cmos_enum)
****************************************************************************/
static void set_checksum_info(const char start_str[], const char end_str[],
const char index_str[])
{ cmos_checksum_layout_t layout;
{
cmos_checksum_layout_t layout;
/* These are bit positions that we want to convert to byte positions. */
layout.summed_area_start =
@ -688,48 +714,57 @@ static void set_checksum_info (const char start_str[], const char end_str[],
layout.checksum_at =
string_to_unsigned(index_str, "CMOS checksum location");
switch (checksum_layout_to_bytes(&layout))
{ case OK:
switch (checksum_layout_to_bytes(&layout)) {
case OK:
break;
case LAYOUT_SUMMED_AREA_START_NOT_ALIGNED:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS "
"checksummed area start is not byte-aligned.\n", prog_name,
line_num);
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. CMOS "
"checksummed area start is not byte-aligned.\n",
prog_name, line_num);
goto fail;
case LAYOUT_SUMMED_AREA_END_NOT_ALIGNED:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS "
"checksummed area end is not byte-aligned.\n", prog_name,
line_num);
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. CMOS "
"checksummed area end is not byte-aligned.\n",
prog_name, line_num);
goto fail;
case LAYOUT_CHECKSUM_LOCATION_NOT_ALIGNED:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS "
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. CMOS "
"checksum location is not byte-aligned.\n", prog_name,
line_num);
goto fail;
case LAYOUT_INVALID_SUMMED_AREA:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS "
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. CMOS "
"checksummed area end must be greater than CMOS checksummed "
"area start.\n", prog_name, line_num);
goto fail;
case LAYOUT_CHECKSUM_OVERLAPS_SUMMED_AREA:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS "
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. CMOS "
"checksum overlaps checksummed area.\n", prog_name,
line_num);
goto fail;
case LAYOUT_SUMMED_AREA_OUT_OF_RANGE:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS "
"checksummed area out of range.\n", prog_name, line_num);
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. CMOS "
"checksummed area out of range.\n", prog_name,
line_num);
goto fail;
case LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS "
"checksum location out of range.\n", prog_name, line_num);
fprintf(stderr,
"%s: Error on line %d of CMOS layout file. CMOS "
"checksum location out of range.\n", prog_name,
line_num);
goto fail;
default:
@ -751,8 +786,9 @@ fail:
* Return the character representation of 'config'.
****************************************************************************/
static char cmos_entry_char_value(cmos_entry_config_t config)
{ switch (config)
{ case CMOS_ENTRY_ENUM:
{
switch (config) {
case CMOS_ENTRY_ENUM:
return 'e';
case CMOS_ENTRY_HEX:
@ -779,17 +815,19 @@ static char cmos_entry_char_value (cmos_entry_config_t config)
* failure.
****************************************************************************/
static int get_layout_file_line(FILE * f, char line[], int line_buf_size)
{ switch (get_line_from_file(f, line, line_buf_size))
{ case OK:
{
switch (get_line_from_file(f, line, line_buf_size)) {
case OK:
return OK;
case LINE_EOF:
return LINE_EOF;
case LINE_TOO_LONG:
fprintf(stderr, "%s: Error on line %d of CMOS layout file: Maximum "
"line length exceeded. Max is %d characters.\n", prog_name,
line_num, line_buf_size - 2);
fprintf(stderr,
"%s: Error on line %d of CMOS layout file: Maximum "
"line length exceeded. Max is %d characters.\n",
prog_name, line_num, line_buf_size - 2);
break;
}
@ -803,16 +841,18 @@ static int get_layout_file_line (FILE *f, char line[], int line_buf_size)
* Convert the string 'str' to an unsigned and return the result.
****************************************************************************/
static unsigned string_to_unsigned(const char str[], const char str_name[])
{ unsigned long n;
{
unsigned long n;
unsigned z;
n = do_string_to_unsigned_long(str, str_name, "");
if ((z = (unsigned) n) != n)
{ /* This could happen on an architecture in which sizeof(unsigned) <
* sizeof(unsigned long).
if ((z = (unsigned)n) != n) {
/* This could happen on an architecture in which
* sizeof(unsigned) < sizeof(unsigned long).
*/
fprintf(stderr, "%s: Error on line %d of CMOS layout file: %s value is "
fprintf(stderr,
"%s: Error on line %d of CMOS layout file: %s value is "
"out of range.\n", prog_name, line_num, str_name);
exit(1);
}
@ -827,7 +867,9 @@ static unsigned string_to_unsigned (const char str[], const char str_name[])
****************************************************************************/
static unsigned long string_to_unsigned_long(const char str[],
const char str_name[])
{ return do_string_to_unsigned_long(str, str_name, " long"); }
{
return do_string_to_unsigned_long(str, str_name, " long");
}
/****************************************************************************
* do_string_to_unsigned_long
@ -838,15 +880,17 @@ static unsigned long string_to_unsigned_long (const char str[],
static unsigned long do_string_to_unsigned_long(const char str[],
const char str_name[],
const char blurb[])
{ unsigned long n;
{
unsigned long n;
char *p;
n = strtoul(str, &p, 0);
if (*p != '\0')
{ fprintf(stderr, "%s: Error on line %d of CMOS layout file: %s is not a "
"valid unsigned%s integer.\n", prog_name,
line_num, str_name, blurb);
if (*p != '\0') {
fprintf(stderr,
"%s: Error on line %d of CMOS layout file: %s is not a "
"valid unsigned%s integer.\n", prog_name, line_num,
str_name, blurb);
exit(1);
}

View File

@ -44,20 +44,18 @@ typedef void (*lbtable_print_fn_t) (const struct lb_record *rec);
/* This structure represents an item in the coreboot table that may be
* displayed using the -l option.
*/
typedef struct
{ uint32_t tag;
typedef struct {
uint32_t tag;
const char *name;
const char *description;
const char *nofound_msg;
lbtable_print_fn_t print_fn;
}
lbtable_choice_t;
} lbtable_choice_t;
typedef struct
{ unsigned long start; /* address of first byte of memory range */
typedef struct {
unsigned long start; /* address of first byte of memory range */
unsigned long end; /* address of last byte of memory range */
}
mem_range_t;
} mem_range_t;
static const struct lb_header *lbtable_scan(unsigned long start,
unsigned long end,
@ -71,8 +69,8 @@ static void try_add_cmos_table_entry (cmos_entry_t *cmos_entry);
static const struct lb_record *find_lbrec(uint32_t tag);
static const char *lbrec_tag_to_str(uint32_t tag);
static const struct cmos_entries *first_cmos_table_entry(void);
static const struct cmos_entries *
next_cmos_table_entry (const struct cmos_entries *last);
static const struct cmos_entries *next_cmos_table_entry(const struct
cmos_entries *last);
static const struct cmos_enums *first_cmos_table_enum(void);
static const struct cmos_enums *next_cmos_table_enum
(const struct cmos_enums *last);
@ -102,14 +100,12 @@ static const char version_desc[] =
static const char extra_version_desc[] =
" This shows extra coreboot version information.\n";
static const char build_desc[] =
" This shows coreboot build information.\n";
static const char build_desc[] = " This shows coreboot build information.\n";
static const char compile_time_desc[] =
" This shows when coreboot was compiled.\n";
static const char compile_by_desc[] =
" This shows who compiled coreboot.\n";
static const char compile_by_desc[] = " This shows who compiled coreboot.\n";
static const char compile_host_desc[] =
" This shows the name of the machine that compiled coreboot.\n";
@ -134,8 +130,7 @@ static const char cmos_opt_table_desc[] =
static const char option_checksum_desc[] =
" This shows the location of the CMOS checksum and the area over which it "
"is\n"
" calculated.\n";
"is\n" " calculated.\n";
static const char generic_nofound_msg[] =
"%s: Item %s not found in coreboot table.\n";
@ -162,60 +157,46 @@ int fd;
static const lbtable_choice_t lbtable_choices[NUM_LBTABLE_CHOICES] =
{ {LB_TAG_MEMORY, "memory",
memory_desc, generic_nofound_msg,
memory_print_fn
},
memory_print_fn},
{LB_TAG_MAINBOARD, "mainboard",
mainboard_desc, generic_nofound_msg,
mainboard_print_fn
},
mainboard_print_fn},
{LB_TAG_VERSION, "version",
version_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_EXTRA_VERSION, "extra_version",
extra_version_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_BUILD, "build",
build_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_COMPILE_TIME, "compile_time",
compile_time_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_COMPILE_BY, "compile_by",
compile_by_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_COMPILE_HOST, "compile_host",
compile_host_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_COMPILE_DOMAIN, "compile_domain",
compile_domain_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_COMPILER, "compiler",
compiler_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_LINKER, "linker",
linker_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_ASSEMBLER, "assembler",
assembler_desc, generic_nofound_msg,
string_print_fn
},
string_print_fn},
{LB_TAG_CMOS_OPTION_TABLE, "cmos_opt_table",
cmos_opt_table_desc, nofound_msg_cmos_opt_table,
cmos_opt_table_print_fn
},
cmos_opt_table_print_fn},
{LB_TAG_OPTION_CHECKSUM, "option_checksum",
option_checksum_desc, nofound_msg_option_checksum,
option_checksum_print_fn
}
option_checksum_print_fn}
};
/* The coreboot table resides in low physical memory, which we access using
@ -283,7 +264,8 @@ static const hexdump_format_t format =
* Find the coreboot table and set global variable lbtable to point to it.
****************************************************************************/
void get_lbtable(void)
{ int i, bad_header_count, bad_table_count, bad_headers, bad_tables;
{
int i, bad_header_count, bad_table_count, bad_headers, bad_tables;
if (lbtable != NULL)
return;
@ -292,15 +274,16 @@ void get_lbtable (void)
* conveniently accessed by calling mmap() on /dev/mem.
*/
if ((fd = open("/dev/mem", O_RDONLY, 0)) < 0)
{ fprintf(stderr, "%s: Can not open /dev/mem for reading: %s\n",
if ((fd = open("/dev/mem", O_RDONLY, 0)) < 0) {
fprintf(stderr, "%s: Can not open /dev/mem for reading: %s\n",
prog_name, strerror(errno));
exit(1);
}
if ((low_phys_mem = mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd, 0))
== MAP_FAILED)
{ fprintf(stderr, "%s: Failed to mmap /dev/mem: %s\n", prog_name,
if ((low_phys_mem =
mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd, 0))
== MAP_FAILED) {
fprintf(stderr, "%s: Failed to mmap /dev/mem: %s\n", prog_name,
strerror(errno));
exit(1);
}
@ -308,8 +291,8 @@ void get_lbtable (void)
bad_header_count = 0;
bad_table_count = 0;
for (i = 0; i < NUM_MEM_RANGES; i++)
{ lbtable = lbtable_scan(phystov(mem_ranges[i].start),
for (i = 0; i < NUM_MEM_RANGES; i++) {
lbtable = lbtable_scan(phystov(mem_ranges[i].start),
phystov(mem_ranges[i].end),
&bad_headers, &bad_tables);
@ -328,8 +311,7 @@ void get_lbtable (void)
" %d valid signatures were found with bad header "
"checksums.\n"
" %d valid headers were found with bad table "
"checksums.\n",
prog_name, bad_header_count, bad_table_count);
"checksums.\n", prog_name, bad_header_count, bad_table_count);
exit(1);
}
@ -346,8 +328,8 @@ void get_layout_from_cmos_table (void)
cmos_table = (const struct cmos_option_table *)
find_lbrec(LB_TAG_CMOS_OPTION_TABLE);
if ((cmos_table) == NULL)
{ fprintf(stderr,
if ((cmos_table) == NULL) {
fprintf(stderr,
"%s: CMOS option table not found in coreboot table. "
"Apparently, the coreboot installed on this system was "
"built without specifying CONFIG_HAVE_OPTION_TABLE.\n",
@ -365,7 +347,8 @@ void get_layout_from_cmos_table (void)
* Do a low-level dump of the coreboot table.
****************************************************************************/
void dump_lbtable(void)
{ const char *p, *data;
{
const char *p, *data;
uint32_t bytes_processed;
const struct lb_record *lbrec;
@ -378,26 +361,28 @@ void dump_lbtable (void)
" table_checksum: 0x%x (decimal: %d)\n"
" table_entries: 0x%x (decimal: %d)\n\n",
vtophys(lbtable), *((uint32_t *) lbtable->signature),
lbtable->signature[0], lbtable->signature[1],lbtable->signature[2],
lbtable->signature[3], lbtable->header_bytes, lbtable->header_bytes,
lbtable->signature[0], lbtable->signature[1],
lbtable->signature[2], lbtable->signature[3],
lbtable->header_bytes, lbtable->header_bytes,
lbtable->header_checksum, lbtable->header_checksum,
lbtable->table_bytes, lbtable->table_bytes, lbtable->table_checksum,
lbtable->table_checksum, lbtable->table_entries,
lbtable->table_entries);
lbtable->table_bytes, lbtable->table_bytes,
lbtable->table_checksum, lbtable->table_checksum,
lbtable->table_entries, lbtable->table_entries);
if ((lbtable->table_bytes == 0) != (lbtable->table_entries == 0))
{ printf("Inconsistent values for table_bytes and table_entries!!!\n"
if ((lbtable->table_bytes == 0) != (lbtable->table_entries == 0)) {
printf
("Inconsistent values for table_bytes and table_entries!!!\n"
"They should be either both 0 or both nonzero.\n");
return;
}
if (lbtable->table_bytes == 0)
{ printf("The coreboot table is empty!!!\n");
if (lbtable->table_bytes == 0) {
printf("The coreboot table is empty!!!\n");
return;
}
for (bytes_processed = 0; ; )
{ lbrec = (const struct lb_record *) &p[bytes_processed];
for (bytes_processed = 0;;) {
lbrec = (const struct lb_record *)&p[bytes_processed];
printf(" %s record at physical address 0x%lx:\n"
" tag: 0x%x (decimal: %d)\n"
" size: 0x%x (decimal: %d)\n"
@ -406,8 +391,8 @@ void dump_lbtable (void)
lbrec->tag, lbrec->size, lbrec->size);
data = ((const char *)lbrec) + sizeof(*lbrec);
hexdump(data, lbrec->size - sizeof(*lbrec), vtophys(data), stdout,
&format);
hexdump(data, lbrec->size - sizeof(*lbrec), vtophys(data),
stdout, &format);
bytes_processed += lbrec->size;
@ -425,10 +410,11 @@ void dump_lbtable (void)
* that may be displayed using the -l option.
****************************************************************************/
void list_lbtable_choices(void)
{ int i;
{
int i;
for (i = 0; ; )
{ printf("%s:\n%s",
for (i = 0;;) {
printf("%s:\n%s",
lbtable_choices[i].name, lbtable_choices[i].description);
if (++i >= NUM_LBTABLE_CHOICES)
@ -444,22 +430,23 @@ void list_lbtable_choices (void)
* Show the coreboot table item specified by 'item'.
****************************************************************************/
void list_lbtable_item(const char item[])
{ int i;
{
int i;
const struct lb_record *rec;
for (i = 0; i < NUM_LBTABLE_CHOICES; i++)
{ if (strcmp(item, lbtable_choices[i].name) == 0)
for (i = 0; i < NUM_LBTABLE_CHOICES; i++) {
if (strcmp(item, lbtable_choices[i].name) == 0)
break;
}
if (i == NUM_LBTABLE_CHOICES)
{ fprintf(stderr, "%s: Invalid coreboot table item %s.\n", prog_name,
item);
if (i == NUM_LBTABLE_CHOICES) {
fprintf(stderr, "%s: Invalid coreboot table item %s.\n",
prog_name, item);
exit(1);
}
if ((rec = find_lbrec(lbtable_choices[i].tag)) == NULL)
{ fprintf(stderr, lbtable_choices[i].nofound_msg, prog_name,
if ((rec = find_lbrec(lbtable_choices[i].tag)) == NULL) {
fprintf(stderr, lbtable_choices[i].nofound_msg, prog_name,
lbtable_choices[i].name);
exit(1);
}
@ -495,7 +482,8 @@ static const struct lb_header * lbtable_scan (unsigned long start,
unsigned long end,
int *bad_header_count,
int *bad_table_count)
{ static const char signature[] = { 'L', 'B', 'I', 'O' };
{
static const char signature[] = { 'L', 'B', 'I', 'O' };
const struct lb_header *table;
const struct lb_forward *forward;
const uint32_t *p;
@ -515,25 +503,24 @@ static const struct lb_header * lbtable_scan (unsigned long start,
*/
for (p = (const uint32_t *)start;
(((unsigned long)p) <= end) &&
((end - (unsigned long) p) >= (sizeof(uint32_t) - 1));
p += 4)
{ if (*p != sig)
((end - (unsigned long)p) >= (sizeof(uint32_t) - 1)); p += 4) {
if (*p != sig)
continue;
/* We found a valid signature. */
table = (const struct lb_header *)p;
/* validate header checksum */
if (compute_ip_checksum((void *) table, sizeof(*table)))
{ (*bad_header_count)++;
if (compute_ip_checksum((void *)table, sizeof(*table))) {
(*bad_header_count)++;
continue;
}
/* validate table checksum */
if (table->table_checksum !=
compute_ip_checksum(((char *)table) + sizeof(*table),
table->table_bytes))
{ (*bad_table_count)++;
table->table_bytes)) {
(*bad_table_count)++;
continue;
}
@ -549,13 +536,19 @@ static const struct lb_header * lbtable_scan (unsigned long start,
new_phys &= ~(getpagesize() - 1);
munmap((void *)low_phys_mem, BYTES_TO_MAP);
if ((low_phys_mem = mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd, (off_t)new_phys)) == MAP_FAILED)
{ fprintf(stderr, "%s: Failed to mmap /dev/mem: %s\n", prog_name,
strerror(errno));
if ((low_phys_mem =
mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd,
(off_t) new_phys)) == MAP_FAILED) {
fprintf(stderr,
"%s: Failed to mmap /dev/mem: %s\n",
prog_name, strerror(errno));
exit(1);
}
low_phys_base = new_phys;
table = lbtable_scan(phystov(low_phys_base), phystov(low_phys_base + BYTES_TO_MAP), bad_header_count, bad_table_count);
table =
lbtable_scan(phystov(low_phys_base),
phystov(low_phys_base + BYTES_TO_MAP),
bad_header_count, bad_table_count);
}
return table;
}
@ -570,14 +563,16 @@ static const struct lb_header * lbtable_scan (unsigned long start,
* internal repository.
****************************************************************************/
static void process_cmos_table(void)
{ const struct cmos_enums *p;
{
const struct cmos_enums *p;
const struct cmos_entries *q;
cmos_enum_t cmos_enum;
cmos_entry_t cmos_entry;
/* First add the enums. */
for (p = first_cmos_table_enum(); p != NULL; p = next_cmos_table_enum(p))
{ cmos_enum.config_id = p->config_id;
for (p = first_cmos_table_enum(); p != NULL;
p = next_cmos_table_enum(p)) {
cmos_enum.config_id = p->config_id;
cmos_enum.value = p->value;
strncpy(cmos_enum.text, (char *)p->text, CMOS_MAX_TEXT_LENGTH);
cmos_enum.text[CMOS_MAX_TEXT_LENGTH] = '\0';
@ -587,12 +582,13 @@ static void process_cmos_table (void)
/* Now add the entries. We must add the entries after the enums because
* the entries are sanity checked against the enums as they are added.
*/
for (q = first_cmos_table_entry(); q != NULL; q = next_cmos_table_entry(q))
{ cmos_entry.bit = q->bit;
for (q = first_cmos_table_entry(); q != NULL;
q = next_cmos_table_entry(q)) {
cmos_entry.bit = q->bit;
cmos_entry.length = q->length;
switch (q->config)
{ case 'e':
switch (q->config) {
case 'e':
cmos_entry.config = CMOS_ENTRY_ENUM;
break;
@ -628,15 +624,15 @@ static void process_cmos_table (void)
* Get layout information for CMOS checksum.
****************************************************************************/
static void get_cmos_checksum_info(void)
{ const cmos_entry_t *e;
{
const cmos_entry_t *e;
struct cmos_checksum *checksum;
cmos_checksum_layout_t layout;
unsigned index, index2;
checksum = (struct cmos_checksum *)find_lbrec(LB_TAG_OPTION_CHECKSUM);
if (checksum != NULL)
{ /* We are lucky. The coreboot table hints us to the checksum.
if (checksum != NULL) { /* We are lucky. The coreboot table hints us to the checksum.
* We might have to check the type field here though.
*/
layout.summed_area_start = checksum->range_start;
@ -658,8 +654,9 @@ static void get_cmos_checksum_info (void)
* Thus we have to hope our presets will be fine.
*/
if (e->bit % 8)
{ fprintf(stderr, "%s: Error: CMOS checksum is not byte-aligned.\n",
if (e->bit % 8) {
fprintf(stderr,
"%s: Error: CMOS checksum is not byte-aligned.\n",
prog_name);
exit(1);
}
@ -667,15 +664,18 @@ static void get_cmos_checksum_info (void)
index = e->bit / 8;
index2 = index + 1; /* The CMOS checksum occupies 16 bits. */
if (verify_cmos_byte_index(index) || verify_cmos_byte_index(index2))
{ fprintf(stderr, "%s: Error: CMOS checksum location out of range.\n",
if (verify_cmos_byte_index(index) || verify_cmos_byte_index(index2)) {
fprintf(stderr,
"%s: Error: CMOS checksum location out of range.\n",
prog_name);
exit(1);
}
if (((index >= cmos_checksum_start) && (index <= cmos_checksum_end)) ||
(((index2) >= cmos_checksum_start) && ((index2) <= cmos_checksum_end)))
{ fprintf(stderr, "%s: Error: CMOS checksum overlaps checksummed area.\n",
(((index2) >= cmos_checksum_start)
&& ((index2) <= cmos_checksum_end))) {
fprintf(stderr,
"%s: Error: CMOS checksum overlaps checksummed area.\n",
prog_name);
exit(1);
}
@ -691,8 +691,9 @@ static void get_cmos_checksum_info (void)
* success or an error code on failure.
****************************************************************************/
static void try_convert_checksum_layout(cmos_checksum_layout_t * layout)
{ switch (checksum_layout_to_bytes(layout))
{ case OK:
{
switch (checksum_layout_to_bytes(layout)) {
case OK:
return;
case LAYOUT_SUMMED_AREA_START_NOT_ALIGNED:
@ -716,8 +717,7 @@ static void try_convert_checksum_layout (cmos_checksum_layout_t *layout)
case LAYOUT_INVALID_SUMMED_AREA:
fprintf(stderr,
"%s: CMOS checksummed area end must be greater than "
"CMOS checksummed area start.\n",
prog_name);
"CMOS checksummed area start.\n", prog_name);
break;
case LAYOUT_CHECKSUM_OVERLAPS_SUMMED_AREA:
@ -728,8 +728,7 @@ static void try_convert_checksum_layout (cmos_checksum_layout_t *layout)
case LAYOUT_SUMMED_AREA_OUT_OF_RANGE:
fprintf(stderr,
"%s: CMOS checksummed area out of range.\n",
prog_name);
"%s: CMOS checksummed area out of range.\n", prog_name);
break;
case LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE:
@ -752,8 +751,9 @@ static void try_convert_checksum_layout (cmos_checksum_layout_t *layout)
* message on failure.
****************************************************************************/
static void try_add_cmos_table_enum(cmos_enum_t * cmos_enum)
{ switch (add_cmos_enum(cmos_enum))
{ case OK:
{
switch (add_cmos_enum(cmos_enum)) {
case OK:
return;
case LAYOUT_DUPLICATE_ENUM:
@ -775,10 +775,11 @@ static void try_add_cmos_table_enum (cmos_enum_t *cmos_enum)
* error message on failure.
****************************************************************************/
static void try_add_cmos_table_entry(cmos_entry_t * cmos_entry)
{ const cmos_entry_t *conflict;
{
const cmos_entry_t *conflict;
switch (add_cmos_entry(cmos_entry, &conflict))
{ case OK:
switch (add_cmos_entry(cmos_entry, &conflict)) {
case OK:
return;
case CMOS_AREA_OUT_OF_RANGE:
@ -796,7 +797,8 @@ static void try_add_cmos_table_entry (cmos_entry_t *cmos_entry)
case LAYOUT_ENTRY_OVERLAP:
fprintf(stderr,
"%s: CMOS option table entries %s and %s have overlapping "
"layouts.\n", prog_name, cmos_entry->name, conflict->name);
"layouts.\n", prog_name, cmos_entry->name,
conflict->name);
break;
case LAYOUT_ENTRY_BAD_LENGTH:
@ -820,7 +822,8 @@ static void try_add_cmos_table_entry (cmos_entry_t *cmos_entry)
* to record on success or NULL if record not found.
****************************************************************************/
static const struct lb_record *find_lbrec(uint32_t tag)
{ const char *p;
{
const char *p;
uint32_t bytes_processed;
const struct lb_record *lbrec;
@ -828,8 +831,8 @@ static const struct lb_record * find_lbrec (uint32_t tag)
for (bytes_processed = 0;
bytes_processed < lbtable->table_bytes;
bytes_processed += lbrec->size)
{ lbrec = (const struct lb_record *) &p[bytes_processed];
bytes_processed += lbrec->size) {
lbrec = (const struct lb_record *)&p[bytes_processed];
if (lbrec->tag == tag)
return lbrec;
@ -845,8 +848,9 @@ static const struct lb_record * find_lbrec (uint32_t tag)
* tag.
****************************************************************************/
static const char *lbrec_tag_to_str(uint32_t tag)
{ switch (tag)
{ case LB_TAG_UNUSED:
{
switch (tag) {
case LB_TAG_UNUSED:
return "UNUSED";
case LB_TAG_MEMORY:
@ -917,7 +921,9 @@ static const char * lbrec_tag_to_str (uint32_t tag)
* CMOS parameter. Return NULL if CMOS table is empty.
****************************************************************************/
static const struct cmos_entries *first_cmos_table_entry(void)
{ return (const struct cmos_entries *) first_cmos_rec(LB_TAG_OPTION); }
{
return (const struct cmos_entries *)first_cmos_rec(LB_TAG_OPTION);
}
/****************************************************************************
* next_cmos_table_entry
@ -925,9 +931,10 @@ static const struct cmos_entries * first_cmos_table_entry (void)
* Return a pointer to the next entry after 'last' in the CMOS table that
* represents a CMOS parameter. Return NULL if there are no more parameters.
****************************************************************************/
static const struct cmos_entries *
next_cmos_table_entry (const struct cmos_entries *last)
{ return (const struct cmos_entries *)
static const struct cmos_entries *next_cmos_table_entry(const struct
cmos_entries *last)
{
return (const struct cmos_entries *)
next_cmos_rec((const struct lb_record *)last, LB_TAG_OPTION);
}
@ -939,7 +946,9 @@ static const struct cmos_entries *
* any such entries.
****************************************************************************/
static const struct cmos_enums *first_cmos_table_enum(void)
{ return (const struct cmos_enums *) first_cmos_rec(LB_TAG_OPTION_ENUM); }
{
return (const struct cmos_enums *)first_cmos_rec(LB_TAG_OPTION_ENUM);
}
/****************************************************************************
* next_cmos_table_enum
@ -949,8 +958,8 @@ static const struct cmos_enums * first_cmos_table_enum (void)
* more parameter values.
****************************************************************************/
static const struct cmos_enums *next_cmos_table_enum
(const struct cmos_enums *last)
{ return (const struct cmos_enums *)
(const struct cmos_enums *last) {
return (const struct cmos_enums *)
next_cmos_rec((const struct lb_record *)last, LB_TAG_OPTION_ENUM);
}
@ -971,7 +980,8 @@ static const struct cmos_enums * next_cmos_table_enum
* 'reserved'.
****************************************************************************/
static const struct lb_record *first_cmos_rec(uint32_t tag)
{ const char *p;
{
const char *p;
uint32_t bytes_processed, bytes_for_entries;
const struct lb_record *lbrec;
@ -980,8 +990,8 @@ static const struct lb_record * first_cmos_rec (uint32_t tag)
for (bytes_processed = 0;
bytes_processed < bytes_for_entries;
bytes_processed += lbrec->size)
{ lbrec = (const struct lb_record *) &p[bytes_processed];
bytes_processed += lbrec->size) {
lbrec = (const struct lb_record *)&p[bytes_processed];
if (lbrec->tag == tag)
return lbrec;
@ -999,7 +1009,8 @@ static const struct lb_record * first_cmos_rec (uint32_t tag)
****************************************************************************/
static const struct lb_record *next_cmos_rec(const struct lb_record *last,
uint32_t tag)
{ const char *p;
{
const char *p;
uint32_t bytes_processed, bytes_for_entries, last_offset;
const struct lb_record *lbrec;
@ -1009,8 +1020,8 @@ static const struct lb_record * next_cmos_rec (const struct lb_record *last,
for (bytes_processed = last_offset + last->size;
bytes_processed < bytes_for_entries;
bytes_processed += lbrec->size)
{ lbrec = (const struct lb_record *) &p[bytes_processed];
bytes_processed += lbrec->size) {
lbrec = (const struct lb_record *)&p[bytes_processed];
if (lbrec->tag == tag)
return lbrec;
@ -1025,7 +1036,8 @@ static const struct lb_record * next_cmos_rec (const struct lb_record *last,
* Display function for 'memory' item of coreboot table.
****************************************************************************/
static void memory_print_fn(const struct lb_record *rec)
{ char start_str[19], end_str[19], size_str[19];
{
char start_str[19], end_str[19], size_str[19];
const struct lb_memory *p;
const char *mem_type;
const struct lb_memory_range *ranges;
@ -1036,14 +1048,14 @@ static void memory_print_fn (const struct lb_record *rec)
entries = (p->size - sizeof(*p)) / sizeof(p->map[0]);
ranges = p->map;
if (entries == 0)
{ printf("No memory ranges were found.\n");
if (entries == 0) {
printf("No memory ranges were found.\n");
return;
}
for (i = 0; ; )
{ switch (ranges[i].type)
{ case LB_MEM_RAM:
for (i = 0;;) {
switch (ranges[i].type) {
case LB_MEM_RAM:
mem_type = "AVAILABLE";
break;
@ -1085,13 +1097,13 @@ static void memory_print_fn (const struct lb_record *rec)
* Display function for 'mainboard' item of coreboot table.
****************************************************************************/
static void mainboard_print_fn(const struct lb_record *rec)
{ const struct lb_mainboard *p;
{
const struct lb_mainboard *p;
p = (const struct lb_mainboard *)rec;
printf("Vendor: %s\n"
"Part number: %s\n",
&p->strings[p->vendor_idx],
&p->strings[p->part_number_idx]);
&p->strings[p->vendor_idx], &p->strings[p->part_number_idx]);
}
/****************************************************************************
@ -1117,23 +1129,25 @@ static void cmos_opt_table_print_fn (const struct lb_record *rec)
vtophys(p), p->tag, p->tag, p->size, p->size, p->header_length,
p->header_length);
if (p->header_length > p->size)
{ printf("Header length for CMOS option table is greater than the size "
if (p->header_length > p->size) {
printf
("Header length for CMOS option table is greater than the size "
"of the entire table including header!!!\n");
return;
}
if (bytes_for_entries == 0)
{ printf("The CMOS option table is empty!!!\n");
if (bytes_for_entries == 0) {
printf("The CMOS option table is empty!!!\n");
return;
}
for (bytes_processed = 0; ; )
{ cmos_item = (const struct lb_record *) &q[bytes_processed];
for (bytes_processed = 0;;) {
cmos_item = (const struct lb_record *)&q[bytes_processed];
switch (cmos_item->tag)
{ case LB_TAG_OPTION:
print_option_record((const struct cmos_entries *) cmos_item);
switch (cmos_item->tag) {
case LB_TAG_OPTION:
print_option_record((const struct cmos_entries *)
cmos_item);
break;
case LB_TAG_OPTION_ENUM:
@ -1141,7 +1155,8 @@ static void cmos_opt_table_print_fn (const struct lb_record *rec)
break;
case LB_TAG_OPTION_DEFAULTS:
print_defaults_record((const struct cmos_defaults *) cmos_item);
print_defaults_record((const struct cmos_defaults *)
cmos_item);
break;
default:
@ -1164,11 +1179,12 @@ static void cmos_opt_table_print_fn (const struct lb_record *rec)
* Display "option" record from CMOS option table.
****************************************************************************/
static void print_option_record(const struct cmos_entries *cmos_entry)
{ static const size_t S_BUFSIZE = 80;
{
static const size_t S_BUFSIZE = 80;
char s[S_BUFSIZE];
switch (cmos_entry->config)
{ case 'e':
switch (cmos_entry->config) {
case 'e':
strcpy(s, "ENUM");
break;
@ -1206,15 +1222,17 @@ static void print_option_record (const struct cmos_entries *cmos_entry)
* Display "enum" record from CMOS option table.
****************************************************************************/
static void print_enum_record(const struct cmos_enums *cmos_enum)
{ printf(" ENUM record at physical address 0x%lx:\n"
{
printf(" ENUM record at physical address 0x%lx:\n"
" tag: 0x%x (decimal: %d)\n"
" size: 0x%x (decimal: %d)\n"
" config_id: 0x%x (decimal: %d)\n"
" value: 0x%x (decimal: %d)\n"
" text: %s\n",
vtophys(cmos_enum), cmos_enum->tag, cmos_enum->tag, cmos_enum->size,
cmos_enum->size, cmos_enum->config_id, cmos_enum->config_id,
cmos_enum->value, cmos_enum->value, cmos_enum->text);
vtophys(cmos_enum), cmos_enum->tag, cmos_enum->tag,
cmos_enum->size, cmos_enum->size, cmos_enum->config_id,
cmos_enum->config_id, cmos_enum->value, cmos_enum->value,
cmos_enum->text);
}
/****************************************************************************
@ -1223,7 +1241,8 @@ static void print_enum_record (const struct cmos_enums *cmos_enum)
* Display "defaults" record from CMOS option table.
****************************************************************************/
static void print_defaults_record(const struct cmos_defaults *cmos_defaults)
{ printf(" DEFAULTS record at physical address 0x%lx:\n"
{
printf(" DEFAULTS record at physical address 0x%lx:\n"
" tag: 0x%x (decimal: %d)\n"
" size: 0x%x (decimal: %d)\n"
" name_length: 0x%x (decimal: %d)\n"
@ -1243,7 +1262,8 @@ static void print_defaults_record (const struct cmos_defaults *cmos_defaults)
* Display record of unknown type from CMOS option table.
****************************************************************************/
static void print_unknown_record(const struct lb_record *cmos_item)
{ const char *data;
{
const char *data;
printf(" UNKNOWN record at physical address 0x%lx:\n"
" tag: 0x%x (decimal: %d)\n"
@ -1252,8 +1272,8 @@ static void print_unknown_record (const struct lb_record *cmos_item)
vtophys(cmos_item), cmos_item->tag, cmos_item->tag,
cmos_item->size, cmos_item->size);
data = ((const char *)cmos_item) + sizeof(*cmos_item);
hexdump(data, cmos_item->size - sizeof(*cmos_item), vtophys(data), stdout,
&format);
hexdump(data, cmos_item->size - sizeof(*cmos_item), vtophys(data),
stdout, &format);
}
/****************************************************************************
@ -1262,7 +1282,8 @@ static void print_unknown_record (const struct lb_record *cmos_item)
* Display function for 'option_checksum' item of coreboot table.
****************************************************************************/
static void option_checksum_print_fn(const struct lb_record *rec)
{ struct cmos_checksum *p;
{
struct cmos_checksum *p;
p = (struct cmos_checksum *)rec;
printf("CMOS checksum from bit %d to bit %d\n"
@ -1278,7 +1299,8 @@ static void option_checksum_print_fn (const struct lb_record *rec)
* consists of a string.
****************************************************************************/
static void string_print_fn(const struct lb_record *rec)
{ const struct lb_string *p;
{
const struct lb_string *p;
p = (const struct lb_string *)rec;
printf("%s\n", p->string);
@ -1294,7 +1316,8 @@ static void string_print_fn (const struct lb_record *rec)
* will be displayed as "0x0000000000000001").
****************************************************************************/
static void uint64_to_hex_string(char str[], uint64_t n)
{ int chars_printed;
{
int chars_printed;
str[0] = '0';
str[1] = 'x';

View File

@ -62,13 +62,11 @@ static int list_all_params (void);
static void list_param_enums(const char name[]);
static void set_one_param(const char name[], const char value[]);
static void set_params(FILE * f);
static void parse_assignment (char arg[], const char **name,
const char **value);
static void parse_assignment(char arg[], const char **name, const char **value);
static int list_cmos_entry(const cmos_entry_t * e, int show_name);
static uint16_t convert_checksum_value(const char value[]);
static const op_fn_t op_fns[] =
{ op_show_version,
static const op_fn_t op_fns[] = { op_show_version,
op_show_usage,
op_lbtable_show_info,
op_lbtable_dump,
@ -93,16 +91,16 @@ static const hexdump_format_t cmos_dump_format =
* main
****************************************************************************/
int main(int argc, char *argv[])
{ cmos_layout_get_fn_t fn;
{
cmos_layout_get_fn_t fn;
parse_nvramtool_args(argc, argv);
if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found)
{ set_layout_filename(
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].param);
if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found) {
set_layout_filename(nvramtool_op_modifiers
[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].param);
fn = get_layout_from_file;
}
else
} else
fn = get_layout_from_cmos_table;
register_cmos_layout_get_fn(fn);
@ -118,7 +116,9 @@ int main (int argc, char *argv[])
* Show version information for this program.
****************************************************************************/
static void op_show_version(void)
{ printf("This is %s version %s.\n", prog_name, prog_version); }
{
printf("This is %s version %s.\n", prog_name, prog_version);
}
/****************************************************************************
* op_show_usage
@ -128,7 +128,9 @@ static void op_show_version (void)
* Show a usage message for this program.
****************************************************************************/
static void op_show_usage(void)
{ usage(stdout); }
{
usage(stdout);
}
/****************************************************************************
* op_lbtable_show_info
@ -139,10 +141,11 @@ static void op_show_usage (void)
* Else show all possible values for ARG.
****************************************************************************/
static void op_lbtable_show_info(void)
{ if (nvramtool_op.param == NULL)
{
if (nvramtool_op.param == NULL)
list_lbtable_choices();
else
{ get_lbtable();
else {
get_lbtable();
list_lbtable_item(nvramtool_op.param);
}
}
@ -155,7 +158,8 @@ static void op_lbtable_show_info (void)
* Do low-level dump of coreboot table.
****************************************************************************/
static void op_lbtable_dump(void)
{ get_lbtable();
{
get_lbtable();
dump_lbtable();
}
@ -167,7 +171,8 @@ static void op_lbtable_dump (void)
* Show all possible values for parameter NAME.
****************************************************************************/
static void op_show_param_values(void)
{ get_cmos_layout();
{
get_cmos_layout();
list_param_enums(nvramtool_op.param);
}
@ -180,11 +185,13 @@ static void op_show_param_values (void)
* and value.
****************************************************************************/
static void op_cmos_show_one_param(void)
{ int result;
{
int result;
get_cmos_layout();
result = list_one_param(nvramtool_op.param,
!nvramtool_op_modifiers[NVRAMTOOL_MOD_SHOW_VALUE_ONLY].found);
!nvramtool_op_modifiers
[NVRAMTOOL_MOD_SHOW_VALUE_ONLY].found);
cmos_checksum_verify();
if (result)
@ -199,7 +206,8 @@ static void op_cmos_show_one_param (void)
* Show names and values for all parameters.
****************************************************************************/
static void op_cmos_show_all_params(void)
{ int result;
{
int result;
get_cmos_layout();
result = list_all_params();
@ -217,7 +225,8 @@ static void op_cmos_show_all_params (void)
* Set parameter NAME to VALUE.
****************************************************************************/
static void op_cmos_set_one_param(void)
{ const char *name, *value;
{
const char *name, *value;
get_cmos_layout();
@ -237,7 +246,8 @@ static void op_cmos_set_one_param (void)
* Set parameters according to standard input.
****************************************************************************/
static void op_cmos_set_params_stdin(void)
{ get_cmos_layout();
{
get_cmos_layout();
set_params(stdin);
}
@ -249,10 +259,11 @@ static void op_cmos_set_params_stdin (void)
* Set parameters according to INPUT_FILE.
****************************************************************************/
static void op_cmos_set_params_file(void)
{ FILE *f;
{
FILE *f;
if ((f = fopen(nvramtool_op.param, "r")) == NULL)
{ fprintf(stderr, "%s: Can not open file %s for reading: %s\n",
if ((f = fopen(nvramtool_op.param, "r")) == NULL) {
fprintf(stderr, "%s: Can not open file %s for reading: %s\n",
prog_name, nvramtool_op.param, strerror(errno));
exit(1);
}
@ -271,18 +282,18 @@ static void op_cmos_set_params_file (void)
* checksum value.
****************************************************************************/
static void op_cmos_checksum(void)
{ uint16_t checksum;
{
uint16_t checksum;
get_cmos_layout();
if (nvramtool_op.param == NULL)
{ set_iopl(3);
if (nvramtool_op.param == NULL) {
set_iopl(3);
checksum = cmos_checksum_read();
set_iopl(0);
printf("0x%x\n", checksum);
}
else
{ checksum = convert_checksum_value(nvramtool_op.param);
} else {
checksum = convert_checksum_value(nvramtool_op.param);
set_iopl(3);
cmos_checksum_write(checksum);
set_iopl(0);
@ -297,7 +308,8 @@ static void op_cmos_checksum (void)
* Write CMOS layout information to standard output.
****************************************************************************/
static void op_show_layout(void)
{ get_cmos_layout();
{
get_cmos_layout();
write_cmos_layout(stdout);
}
@ -309,11 +321,12 @@ static void op_show_layout (void)
* Write the contents of CMOS memory to a binary file.
****************************************************************************/
static void op_write_cmos_dump(void)
{ unsigned char data[CMOS_SIZE];
{
unsigned char data[CMOS_SIZE];
FILE *f;
if ((f = fopen(nvramtool_op.param, "w")) == NULL)
{ fprintf(stderr, "%s: Can not open file %s for writing: %s\n",
if ((f = fopen(nvramtool_op.param, "w")) == NULL) {
fprintf(stderr, "%s: Can not open file %s for writing: %s\n",
prog_name, nvramtool_op.param, strerror(errno));
exit(1);
}
@ -322,8 +335,8 @@ static void op_write_cmos_dump (void)
cmos_read_all(data);
set_iopl(0);
if (fwrite(data, 1, CMOS_SIZE, f) != CMOS_SIZE)
{ fprintf(stderr, "%s: Error writing CMOS data to file %s: %s\n",
if (fwrite(data, 1, CMOS_SIZE, f) != CMOS_SIZE) {
fprintf(stderr, "%s: Error writing CMOS data to file %s: %s\n",
prog_name, nvramtool_op.param, strerror(errno));
exit(1);
}
@ -339,18 +352,20 @@ static void op_write_cmos_dump (void)
* Read binary data from a file and write the data to CMOS memory.
****************************************************************************/
static void op_read_cmos_dump(void)
{ unsigned char data[CMOS_SIZE];
{
unsigned char data[CMOS_SIZE];
size_t nr_bytes;
FILE *f;
if ((f = fopen(nvramtool_op.param, "r")) == NULL)
{ fprintf(stderr, "%s: Can not open file %s for reading: %s\n",
if ((f = fopen(nvramtool_op.param, "r")) == NULL) {
fprintf(stderr, "%s: Can not open file %s for reading: %s\n",
prog_name, nvramtool_op.param, strerror(errno));
exit(1);
}
if ((nr_bytes = fread(data, 1, CMOS_SIZE, f)) != CMOS_SIZE)
{ fprintf(stderr, "%s: Error: Only able to read %d bytes of CMOS data "
if ((nr_bytes = fread(data, 1, CMOS_SIZE, f)) != CMOS_SIZE) {
fprintf(stderr,
"%s: Error: Only able to read %d bytes of CMOS data "
"from file %s. CMOS data is unchanged.\n", prog_name,
(int)nr_bytes, nvramtool_op.param);
exit(1);
@ -370,7 +385,8 @@ static void op_read_cmos_dump (void)
* Write a hex dump of CMOS memory to standard output.
****************************************************************************/
static void op_show_cmos_hex_dump(void)
{ unsigned char data[CMOS_SIZE];
{
unsigned char data[CMOS_SIZE];
set_iopl(3);
cmos_read_all(data);
@ -387,12 +403,13 @@ static void op_show_cmos_hex_dump (void)
* hex dump of the CMOS data from the file.
****************************************************************************/
static void op_show_cmos_dumpfile(void)
{ unsigned char data[CMOS_SIZE];
{
unsigned char data[CMOS_SIZE];
size_t nr_bytes;
FILE *f;
if ((f = fopen(nvramtool_op.param, "r")) == NULL)
{ fprintf(stderr, "%s: Can not open file %s for reading: %s\n",
if ((f = fopen(nvramtool_op.param, "r")) == NULL) {
fprintf(stderr, "%s: Can not open file %s for reading: %s\n",
prog_name, nvramtool_op.param, strerror(errno));
exit(1);
}
@ -410,15 +427,18 @@ static void op_show_cmos_dumpfile (void)
* along with its value. Return 1 if error was encountered. Else return OK.
****************************************************************************/
static int list_one_param(const char name[], int show_name)
{ const cmos_entry_t *e;
{
const cmos_entry_t *e;
if (is_checksum_name(name) || ((e = find_cmos_entry(name)) == NULL))
{ fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name, name);
if (is_checksum_name(name) || ((e = find_cmos_entry(name)) == NULL)) {
fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name,
name);
exit(1);
}
if (e->config == CMOS_ENTRY_RESERVED)
{ fprintf(stderr, "%s: Parameter %s is reserved.\n", prog_name, name);
if (e->config == CMOS_ENTRY_RESERVED) {
fprintf(stderr, "%s: Parameter %s is reserved.\n", prog_name,
name);
exit(1);
}
@ -432,13 +452,15 @@ static int list_one_param (const char name[], int show_name)
* Else return OK.
****************************************************************************/
static int list_all_params(void)
{ const cmos_entry_t *e;
{
const cmos_entry_t *e;
int result;
result = OK;
for (e = first_cmos_entry(); e != NULL; e = next_cmos_entry(e))
{ if ((e->config == CMOS_ENTRY_RESERVED) || is_checksum_name(e->name))
for (e = first_cmos_entry(); e != NULL; e = next_cmos_entry(e)) {
if ((e->config == CMOS_ENTRY_RESERVED)
|| is_checksum_name(e->name))
continue;
if (list_cmos_entry(e, TRUE))
@ -454,26 +476,27 @@ static int list_all_params (void)
* List all possible values for CMOS parameter given by 'name'.
****************************************************************************/
static void list_param_enums(const char name[])
{ const cmos_entry_t *e;
{
const cmos_entry_t *e;
const cmos_enum_t *p;
if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL)
{ fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name, name);
if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL) {
fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name,
name);
exit(1);
}
switch (e->config)
{ case CMOS_ENTRY_ENUM:
switch (e->config) {
case CMOS_ENTRY_ENUM:
for (p = first_cmos_enum_id(e->config_id);
p != NULL;
p = next_cmos_enum_id(p))
p != NULL; p = next_cmos_enum_id(p))
printf("%s\n", p->text);
break;
case CMOS_ENTRY_HEX:
printf("Parameter %s requires a %u-bit unsigned integer.\n", name,
e->length);
printf("Parameter %s requires a %u-bit unsigned integer.\n",
name, e->length);
break;
case CMOS_ENTRY_STRING:
@ -501,20 +524,23 @@ static void list_param_enums (const char name[])
* decimal, hex, or octal.
****************************************************************************/
static void set_one_param(const char name[], const char value[])
{ const cmos_entry_t *e;
{
const cmos_entry_t *e;
unsigned long long n;
if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL)
{ fprintf(stderr, "%s: CMOS parameter %s not found.", prog_name, name);
if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL) {
fprintf(stderr, "%s: CMOS parameter %s not found.", prog_name,
name);
exit(1);
}
switch (prepare_cmos_write(e, value, &n))
{ case OK:
switch (prepare_cmos_write(e, value, &n)) {
case OK:
break;
case CMOS_OP_BAD_ENUM_VALUE:
fprintf(stderr, "%s: Bad value for parameter %s.", prog_name, name);
fprintf(stderr, "%s: Bad value for parameter %s.", prog_name,
name);
goto fail;
case CMOS_OP_NEGATIVE_INT:
@ -524,7 +550,8 @@ static void set_one_param (const char name[], const char value[])
goto fail;
case CMOS_OP_INVALID_INT:
fprintf(stderr, "%s: %s is not a valid integer.", prog_name, value);
fprintf(stderr, "%s: %s is not a valid integer.", prog_name,
value);
goto fail;
case CMOS_OP_RESERVED:
@ -536,7 +563,8 @@ static void set_one_param (const char name[], const char value[])
case CMOS_OP_VALUE_TOO_WIDE:
fprintf(stderr,
"%s: Can not write value %s to CMOS parameter %s that is "
"only %d bits wide.", prog_name, value, name, e->length);
"only %d bits wide.", prog_name, value, name,
e->length);
goto fail;
case CMOS_OP_NO_MATCHING_ENUM:
@ -548,7 +576,8 @@ static void set_one_param (const char name[], const char value[])
case CMOS_AREA_OUT_OF_RANGE:
fprintf(stderr,
"%s: The CMOS area specified by the layout info for "
"coreboot parameter %s is out of range.", prog_name, name);
"coreboot parameter %s is out of range.", prog_name,
name);
goto fail;
case CMOS_AREA_OVERLAPS_RTC:
@ -561,8 +590,7 @@ static void set_one_param (const char name[], const char value[])
case CMOS_AREA_TOO_WIDE:
fprintf(stderr,
"%s: The CMOS area specified by the layout info for "
"coreboot parameter %s is too wide.",
prog_name, name);
"coreboot parameter %s is too wide.", prog_name, name);
goto fail;
default:
@ -606,9 +634,9 @@ static void set_params (FILE *f)
* into substrings representing NAME and VALUE, and *name and *value are set
* to point to these two substrings.
****************************************************************************/
static void parse_assignment (char arg[], const char **name,
const char **value)
{ static const size_t N_MATCHES = 4;
static void parse_assignment(char arg[], const char **name, const char **value)
{
static const size_t N_MATCHES = 4;
regmatch_t match[N_MATCHES];
regex_t assignment;
@ -641,37 +669,42 @@ static void parse_assignment (char arg[], const char **name,
* message and return 1.
****************************************************************************/
static int list_cmos_entry(const cmos_entry_t * e, int show_name)
{ const cmos_enum_t *p;
{
const cmos_enum_t *p;
unsigned long long value;
/* sanity check CMOS entry */
switch (prepare_cmos_read(e))
{ case OK:
switch (prepare_cmos_read(e)) {
case OK:
break;
case CMOS_OP_RESERVED:
BUG();
case CMOS_AREA_OUT_OF_RANGE:
fprintf(stderr, "%s: Can not read coreboot parameter %s because "
"layout info specifies out of range CMOS area.\n", prog_name,
e->name);
fprintf(stderr,
"%s: Can not read coreboot parameter %s because "
"layout info specifies out of range CMOS area.\n",
prog_name, e->name);
return 1;
case CMOS_AREA_OVERLAPS_RTC:
fprintf(stderr, "%s: Can not read coreboot parameter %s because "
fprintf(stderr,
"%s: Can not read coreboot parameter %s because "
"layout info specifies CMOS area that overlaps realtime "
"clock area.\n", prog_name, e->name);
return 1;
case CMOS_AREA_TOO_WIDE:
fprintf(stderr, "%s: Can not read coreboot parameter %s because "
fprintf(stderr,
"%s: Can not read coreboot parameter %s because "
"layout info specifies CMOS area that is too wide.\n",
prog_name, e->name);
return 1;
default:
fprintf(stderr, "%s: Unknown error encountered while attempting to "
fprintf(stderr,
"%s: Unknown error encountered while attempting to "
"read coreboot parameter %s\n", prog_name, e->name);
return 1;
}
@ -682,16 +715,16 @@ static int list_cmos_entry (const cmos_entry_t *e, int show_name)
set_iopl(0);
/* display the value */
switch (e->config)
{ case CMOS_ENTRY_ENUM:
if ((p = find_cmos_enum(e->config_id, value)) == NULL)
{ if (show_name)
printf("# Bad value -> %s = 0x%llx\n", e->name, value);
switch (e->config) {
case CMOS_ENTRY_ENUM:
if ((p = find_cmos_enum(e->config_id, value)) == NULL) {
if (show_name)
printf("# Bad value -> %s = 0x%llx\n", e->name,
value);
else
printf("Bad value -> 0x%llx\n", value);
}
else
{ if (show_name)
} else {
if (show_name)
printf("%s = %s\n", e->name, p->text);
else
printf("%s\n", p->text);
@ -709,7 +742,8 @@ static int list_cmos_entry (const cmos_entry_t *e, int show_name)
case CMOS_ENTRY_STRING:
if (show_name)
printf("%s = %s\n", e->name, (char *)(unsigned long)value);
printf("%s = %s\n", e->name,
(char *)(unsigned long)value);
else
printf("%s\n", (char *)(unsigned long)value);
@ -734,7 +768,8 @@ static int list_cmos_entry (const cmos_entry_t *e, int show_name)
* 'value' is invalid.
****************************************************************************/
static uint16_t convert_checksum_value(const char value[])
{ unsigned long n;
{
unsigned long n;
const char *p;
uint16_t result;
int negative;
@ -744,23 +779,26 @@ static uint16_t convert_checksum_value (const char value[])
negative = (*p == '-');
n = strtoul(value, (char **)&p, 0);
if (*p)
{ fprintf(stderr, "%s: Checksum value %s is not a valid integer.\n",
if (*p) {
fprintf(stderr,
"%s: Checksum value %s is not a valid integer.\n",
prog_name, value);
exit(1);
}
if (negative)
{ fprintf(stderr,
"%s: Checksum must be an unsigned integer.\n", prog_name);
if (negative) {
fprintf(stderr,
"%s: Checksum must be an unsigned integer.\n",
prog_name);
exit(1);
}
result = (uint16_t) n;
if (result != n)
{ fprintf(stderr,
"%s: Checksum value must fit within 16 bits.\n", prog_name);
if (result != n) {
fprintf(stderr,
"%s: Checksum value must fit within 16 bits.\n",
prog_name);
exit(1);
}

View File

@ -49,14 +49,14 @@ static const char getopt_string[] = "-ab:B:c::de:hil::np:r:tvw:xX:y:Y";
* Parse command line arguments.
****************************************************************************/
void parse_nvramtool_args(int argc, char *argv[])
{ nvramtool_op_modifier_info_t *mod_info;
{
nvramtool_op_modifier_info_t *mod_info;
int i, op_found;
char c;
for (i = 0, mod_info = nvramtool_op_modifiers;
i < NVRAMTOOL_NUM_OP_MODIFIERS;
i++, mod_info++)
{ mod_info->found = FALSE;
i < NVRAMTOOL_NUM_OP_MODIFIERS; i++, mod_info++) {
mod_info->found = FALSE;
mod_info->found_seq = 0;
mod_info->param = NULL;
}
@ -64,16 +64,19 @@ void parse_nvramtool_args (int argc, char *argv[])
op_found = FALSE;
opterr = 0;
do
{ switch (c = getopt(argc, argv, getopt_string))
{ case 'a':
register_op(&op_found, NVRAMTOOL_OP_CMOS_SHOW_ALL_PARAMS, NULL);
do {
switch (c = getopt(argc, argv, getopt_string)) {
case 'a':
register_op(&op_found,
NVRAMTOOL_OP_CMOS_SHOW_ALL_PARAMS, NULL);
break;
case 'b':
register_op(&op_found, NVRAMTOOL_OP_WRITE_CMOS_DUMP, optarg);
register_op(&op_found, NVRAMTOOL_OP_WRITE_CMOS_DUMP,
optarg);
break;
case 'B':
register_op(&op_found, NVRAMTOOL_OP_READ_CMOS_DUMP, optarg);
register_op(&op_found, NVRAMTOOL_OP_READ_CMOS_DUMP,
optarg);
break;
case 'c':
register_op(&op_found, NVRAMTOOL_OP_CMOS_CHECKSUM,
@ -83,44 +86,54 @@ void parse_nvramtool_args (int argc, char *argv[])
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_DUMP, NULL);
break;
case 'e':
register_op(&op_found, NVRAMTOOL_OP_SHOW_PARAM_VALUES, optarg);
register_op(&op_found, NVRAMTOOL_OP_SHOW_PARAM_VALUES,
optarg);
break;
case 'h':
register_op(&op_found, NVRAMTOOL_OP_SHOW_USAGE, NULL);
break;
case 'i':
register_op(&op_found, NVRAMTOOL_OP_CMOS_SET_PARAMS_STDIN, NULL);
register_op(&op_found,
NVRAMTOOL_OP_CMOS_SET_PARAMS_STDIN, NULL);
break;
case 'l':
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_SHOW_INFO,
handle_optional_arg(argc, argv));
break;
case 'n':
register_op_modifier(NVRAMTOOL_MOD_SHOW_VALUE_ONLY, NULL);
register_op_modifier(NVRAMTOOL_MOD_SHOW_VALUE_ONLY,
NULL);
break;
case 'p':
register_op(&op_found, NVRAMTOOL_OP_CMOS_SET_PARAMS_FILE, optarg);
register_op(&op_found,
NVRAMTOOL_OP_CMOS_SET_PARAMS_FILE, optarg);
break;
case 'r':
register_op(&op_found, NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM, optarg);
register_op(&op_found, NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM,
optarg);
break;
case 't':
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE, NULL);
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE,
NULL);
break;
case 'v':
register_op(&op_found, NVRAMTOOL_OP_SHOW_VERSION, NULL);
break;
case 'w':
register_op(&op_found, NVRAMTOOL_OP_CMOS_SET_ONE_PARAM, optarg);
register_op(&op_found, NVRAMTOOL_OP_CMOS_SET_ONE_PARAM,
optarg);
break;
case 'x':
register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_HEX_DUMP, NULL);
register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_HEX_DUMP,
NULL);
break;
case 'X':
register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE, optarg);
register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE,
optarg);
break;
case 'y':
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE, optarg);
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE,
optarg);
break;
case 'Y':
register_op(&op_found, NVRAMTOOL_OP_SHOW_LAYOUT, NULL);
@ -133,8 +146,7 @@ void parse_nvramtool_args (int argc, char *argv[])
usage(stderr);
break;
}
}
while (c != -1);
} while (c != -1);
if (!op_found)
usage(stderr);
@ -149,12 +161,14 @@ void parse_nvramtool_args (int argc, char *argv[])
* Handle a command line option with an optional argument.
****************************************************************************/
static char *handle_optional_arg(int argc, char *argv[])
{ char *arg;
{
char *arg;
if (optarg != NULL)
{ /* optional arg is present and arg was specified as "-zarg" (with no
* whitespace between "z" and "arg"), where -z is the option and "arg"
* is the value of the optional arg
if (optarg != NULL) {
/* optional arg is present and arg was specified as
* "-zarg" (with no whitespace between "z" and "arg"),
* where -z is the option and "arg" is the value of the
* optional arg
*/
return optarg;
}
@ -164,8 +178,8 @@ static char * handle_optional_arg (int argc, char *argv[])
arg = argv[optind]; /* optional arg is present */
/* This call to getopt yields the optional arg we just found, which we want
* to skip.
/* This call to getopt yields the optional arg we just found,
* which we want to skip.
*/
getopt(argc, argv, getopt_string);
@ -178,7 +192,8 @@ static char * handle_optional_arg (int argc, char *argv[])
* Store the user's selection of which operation this program should perform.
****************************************************************************/
static void register_op(int *op_found, nvramtool_op_t op, char op_param[])
{ if (*op_found && (op != nvramtool_op.op))
{
if (*op_found && (op != nvramtool_op.op))
usage(stderr);
*op_found = TRUE;
@ -193,7 +208,8 @@ static void register_op (int *op_found, nvramtool_op_t op, char op_param[])
* the user's selection of which operation this program should perform.
****************************************************************************/
static void register_op_modifier(nvramtool_op_modifier_t mod, char mod_param[])
{ static int found_seq = 0;
{
static int found_seq = 0;
nvramtool_op_modifier_info_t *mod_info;
mod_info = &nvramtool_op_modifiers[mod];
@ -209,13 +225,16 @@ static void register_op_modifier (nvramtool_op_modifier_t mod, char mod_param[])
* the last specified argument overrides previous conflicting arguments.
****************************************************************************/
static void resolve_op_modifiers(void)
{ if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found &&
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found)
{ if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found_seq >
{
if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found &&
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found) {
if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found_seq >
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found_seq)
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found = FALSE;
nvramtool_op_modifiers
[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found = FALSE;
else
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found = FALSE;
nvramtool_op_modifiers
[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found = FALSE;
}
}
@ -225,7 +244,8 @@ static void resolve_op_modifiers (void)
* Perform sanity checking on command line arguments.
****************************************************************************/
static void sanity_check_args(void)
{ if ((nvramtool_op_modifiers[NVRAMTOOL_MOD_SHOW_VALUE_ONLY].found) &&
{
if ((nvramtool_op_modifiers[NVRAMTOOL_MOD_SHOW_VALUE_ONLY].found) &&
(nvramtool_op.op != NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM))
usage(stderr);
}

View File

@ -33,8 +33,7 @@
#include "common.h"
typedef enum
{ NVRAMTOOL_OP_SHOW_VERSION = 0,
typedef enum { NVRAMTOOL_OP_SHOW_VERSION = 0,
NVRAMTOOL_OP_SHOW_USAGE,
NVRAMTOOL_OP_LBTABLE_SHOW_INFO,
NVRAMTOOL_OP_LBTABLE_DUMP,
@ -50,29 +49,24 @@ typedef enum
NVRAMTOOL_OP_READ_CMOS_DUMP,
NVRAMTOOL_OP_SHOW_CMOS_HEX_DUMP,
NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE
}
nvramtool_op_t;
} nvramtool_op_t;
typedef struct
{ nvramtool_op_t op;
typedef struct {
nvramtool_op_t op;
char *param;
}
nvramtool_op_info_t;
} nvramtool_op_info_t;
typedef enum
{ NVRAMTOOL_MOD_SHOW_VALUE_ONLY = 0,
typedef enum { NVRAMTOOL_MOD_SHOW_VALUE_ONLY = 0,
NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE,
NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE,
NVRAMTOOL_NUM_OP_MODIFIERS /* must always be last */
}
nvramtool_op_modifier_t;
} nvramtool_op_modifier_t;
typedef struct
{ int found;
typedef struct {
int found;
int found_seq;
char *param;
}
nvramtool_op_modifier_info_t;
} nvramtool_op_modifier_info_t;
extern nvramtool_op_info_t nvramtool_op;

View File

@ -39,7 +39,8 @@
****************************************************************************/
void compile_reg_exprs(int cflags, int num_exprs,
/* const char *expr1, regex_t *reg1, */ ...)
{ static const size_t ERROR_BUF_SIZE = 256;
{
static const size_t ERROR_BUF_SIZE = 256;
char error_msg[ERROR_BUF_SIZE];
va_list ap;
regex_t *reg;
@ -48,12 +49,12 @@ void compile_reg_exprs (int cflags, int num_exprs,
va_start(ap, num_exprs);
for (i = 0; i < num_exprs; i++)
{ expr = va_arg(ap, const char *);
for (i = 0; i < num_exprs; i++) {
expr = va_arg(ap, const char *);
reg = va_arg(ap, regex_t *);
if ((result = regcomp(reg, expr, cflags)) != 0)
{ regerror(result, reg, error_msg, ERROR_BUF_SIZE);
if ((result = regcomp(reg, expr, cflags)) != 0) {
regerror(result, reg, error_msg, ERROR_BUF_SIZE);
fprintf(stderr, "%s: %s\n", prog_name, error_msg);
exit(1);
}
@ -68,7 +69,8 @@ void compile_reg_exprs (int cflags, int num_exprs,
* Destroy a bunch of previously compiled regular expressions.
****************************************************************************/
void free_reg_exprs(int num_exprs, /* regex_t *reg1, */ ...)
{ va_list ap;
{
va_list ap;
int i;
va_start(ap, num_exprs);