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

View File

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

View File

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

View File

@ -73,10 +73,7 @@ static inline struct lb_uint64 pack_lb64(uint64_t value)
return result; return result;
} }
struct lb_header {
struct lb_header
{
uint8_t signature[4]; /* LBIO */ uint8_t signature[4]; /* LBIO */
uint32_t header_bytes; uint32_t header_bytes;
uint32_t header_checksum; uint32_t header_checksum;
@ -184,7 +181,6 @@ struct cmos_entries {
variable length int aligned */ variable length int aligned */
}; };
/* cmos enumerations record /* cmos enumerations record
This record is variable length. The text field may be This record is variable length. The text field may be
shorter than CMOS_MAX_TEXT_LENGTH. shorter than CMOS_MAX_TEXT_LENGTH.
@ -228,6 +224,4 @@ struct cmos_checksum {
#define CHECKSUM_PCBIOS 1 #define CHECKSUM_PCBIOS 1
}; };
#endif /* COREBOOT_TABLES_H */ #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, void hexdump(const void *mem, int bytes, uint64_t addrprint_start,
FILE * outfile, const hexdump_format_t * format) FILE * outfile, const hexdump_format_t * format)
{ int bytes_left, index, i; {
int bytes_left, index, i;
const unsigned char *p; const unsigned char *p;
is_printable_fn_t is_printable_fn; 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; p = (const unsigned char *)mem;
index = 0; index = 0;
/* Each iteration handles one full line of output. When loop terminates, /* Each iteration handles one full line of output. When loop
* the number of remaining bytes to display (if any) will not be enough to * terminates, the number of remaining bytes to display (if any)
* fill an entire line. * will not be enough to fill an entire line.
*/ */
for (bytes_left = bytes; for (bytes_left = bytes;
bytes_left >= format->bytes_per_line; bytes_left >= format->bytes_per_line;
bytes_left -= format->bytes_per_line) bytes_left -= format->bytes_per_line) {
{ /* print start address for current line */ /* print start address for current line */
fprintf(outfile, format->indent); fprintf(outfile, format->indent);
addrprint(outfile, addrprint_start + index, format->addrprint_width); addrprint(outfile, addrprint_start + index,
format->addrprint_width);
fprintf(outfile, format->sep1); fprintf(outfile, format->sep1);
/* display the bytes in hex */ /* display the bytes in hex */
for (i = 0; ; ) for (i = 0;;) {
{ hexprint(outfile, p[index++]); hexprint(outfile, p[index++]);
if (++i >= format->bytes_per_line) if (++i >= format->bytes_per_line)
break; break;
@ -125,16 +127,16 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
fprintf(outfile, format->sep1); fprintf(outfile, format->sep1);
/* display bytes for last line in hex */ /* display bytes for last line in hex */
for (i = 0; i < bytes_left; i++) for (i = 0; i < bytes_left; i++) {
{ hexprint(outfile, p[index++]); hexprint(outfile, p[index++]);
fprintf(outfile, format->sep2); fprintf(outfile, format->sep2);
} }
index -= bytes_left; index -= bytes_left;
/* pad the rest of the hex byte area with spaces */ /* pad the rest of the hex byte area with spaces */
for (; ; ) for (;;) {
{ fprintf(outfile, " "); fprintf(outfile, " ");
if (++i >= format->bytes_per_line) if (++i >= format->bytes_per_line)
break; break;
@ -146,7 +148,8 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
/* display bytes for last line as characters */ /* display bytes for last line as characters */
for (i = 0; i < bytes_left; i++) 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 */ /* pad the rest of the character area with spaces */
for (; i < format->bytes_per_line; i++) 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. * Return 1 if the input character is printable. Otherwise return 0.
*--------------------------------------------------------------------------*/ *--------------------------------------------------------------------------*/
int default_is_printable_fn(unsigned char c) int default_is_printable_fn(unsigned char c)
{ return (c >= 0x20) && (c <= 0x7e); } {
return (c >= 0x20) && (c <= 0x7e);
}
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
* addrprint * addrprint
@ -184,7 +189,8 @@ int default_is_printable_fn (unsigned char c)
* Must be a value from 1 to 8. * Must be a value from 1 to 8.
*--------------------------------------------------------------------------*/ *--------------------------------------------------------------------------*/
static void addrprint(FILE * outfile, uint64_t address, int width) static void addrprint(FILE * outfile, uint64_t address, int width)
{ char s[17]; {
char s[17];
int i; int i;
/* force the user's input to be valid */ /* 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 */ /* convert address to string */
sprintf(s, "%016llx", (unsigned long long)address); sprintf(s, "%016llx", (unsigned long long)address);
/* write it out, with colons separating consecutive 16-bit chunks of the /* write it out, with colons separating consecutive 16-bit
* address * chunks of the address
*/ */
for (i = 16 - (2 * width); ; ) for (i = 16 - (2 * width);;) {
{ fprintf(outfile, "%c", s[i]); fprintf(outfile, "%c", s[i]);
if (++i >= 16) if (++i >= 16)
break; break;
@ -220,8 +226,9 @@ static void addrprint (FILE *outfile, uint64_t address, int width)
* byte: the byte to display * byte: the byte to display
*--------------------------------------------------------------------------*/ *--------------------------------------------------------------------------*/
static void hexprint(FILE * outfile, unsigned char byte) 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' '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, static void charprint(FILE * outfile, unsigned char byte,
unsigned char nonprintable, unsigned char nonprintable,
is_printable_fn_t is_printable_fn) 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 * printable. A value of NULL will cause
* default_is_printable_fn to be used. * default_is_printable_fn to be used.
*--------------------------------------------------------------------------*/ *--------------------------------------------------------------------------*/
typedef struct typedef struct {
{ int bytes_per_line; int bytes_per_line;
int addrprint_width; int addrprint_width;
const char *indent; const char *indent;
const char *sep1; const char *sep1;
@ -90,8 +90,7 @@ typedef struct
const char *sep3; const char *sep3;
unsigned char nonprintable; unsigned char nonprintable;
is_printable_fn_t is_printable_fn; is_printable_fn_t is_printable_fn;
} } hexdump_format_t;
hexdump_format_t;
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
* hexdump * 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 */ /* matches either a blank line or a comment line */
static const char blank_or_comment_regex[] = static const char blank_or_comment_regex[] =
/* a blank line */ /* a blank line */
"(^[[:space:]]+$)" "(^[[:space:]]+$)" "|" /* or ... */
"|" /* or ... */
/* a line consisting of: optional whitespace followed by */ /* a line consisting of: optional whitespace followed by */
"(^[[:space:]]*" "(^[[:space:]]*"
/* a '#' character and optionally, additional characters */ /* a '#' character and optionally, additional characters */
@ -95,18 +92,16 @@ cmos_write_t * process_input_file (FILE *f)
&blank_or_comment, assignment_regex, &assignment); &blank_or_comment, assignment_regex, &assignment);
/* each iteration processes one line from input file */ /* each iteration processes one line from input file */
for (line_num = 1; for (line_num = 1; get_input_file_line(f, line, LINE_BUF_SIZE) == OK; line_num++) { /* skip comments and blank lines */
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)) if (!regexec(&blank_or_comment, line, 0, NULL, 0))
continue; continue;
/* Is this a valid assignment line? If not, then it's a syntax /* Is this a valid assignment line? If not, then it's a syntax
* error. * error.
*/ */
if (regexec(&assignment, line, N_MATCHES, match, 0)) if (regexec(&assignment, line, N_MATCHES, match, 0)) {
{ fprintf(stderr, "%s: Syntax error on line %d of input file.\n", fprintf(stderr,
"%s: Syntax error on line %d of input file.\n",
prog_name, line_num); prog_name, line_num);
exit(1); exit(1);
} }
@ -120,8 +115,10 @@ cmos_write_t * process_input_file (FILE *f)
value = &line[match[2].rm_so]; value = &line[match[2].rm_so];
/* now look up the coreboot parameter name */ /* now look up the coreboot parameter name */
if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL) if (is_checksum_name(name)
{ fprintf(stderr, "%s: Error on line %d of input file: CMOS parameter " || (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); "%s not found.\n", prog_name, line_num, name);
exit(1); exit(1);
} }
@ -157,12 +154,13 @@ cmos_write_t * process_input_file (FILE *f)
* we go. * we go.
****************************************************************************/ ****************************************************************************/
void do_cmos_writes(cmos_write_t * list) void do_cmos_writes(cmos_write_t * list)
{ cmos_write_t *item; {
cmos_write_t *item;
set_iopl(3); set_iopl(3);
while (list != NULL) while (list != NULL) {
{ cmos_entry_t e; cmos_entry_t e;
item = list; item = list;
e.bit = item->bit; e.bit = item->bit;
e.length = item->length; e.length = item->length;
@ -184,15 +182,17 @@ void do_cmos_writes (cmos_write_t *list)
* error. * error.
****************************************************************************/ ****************************************************************************/
static int get_input_file_line(FILE * f, char line[], int line_buf_size) 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; return OK;
case LINE_EOF: case LINE_EOF:
return LINE_EOF; return LINE_EOF;
case LINE_TOO_LONG: 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, "length exceeded. Max is %d characters.\n", prog_name,
line_num, line_buf_size - 2); line_num, line_buf_size - 2);
break; 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, static unsigned long long try_prepare_cmos_write(const cmos_entry_t * e,
const char value_str[]) const char value_str[])
{ unsigned long long value; {
unsigned long long value;
switch (prepare_cmos_write(e, value_str, &value)) switch (prepare_cmos_write(e, value_str, &value)) {
{ case OK: case OK:
return value; return value;
case CMOS_OP_BAD_ENUM_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); "parameter %s.", prog_name, line_num, e->name);
break; break;
case CMOS_OP_NEGATIVE_INT: 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 " "does not support assignment of negative numbers to "
"coreboot parameters.", prog_name, line_num); "coreboot parameters.", prog_name, line_num);
break; break;
case CMOS_OP_INVALID_INT: 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); "valid integer.", prog_name, line_num, value_str);
break; break;
case CMOS_OP_RESERVED: 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, "reserved coreboot parameter %s.", prog_name, line_num,
e->name); e->name);
break; break;
case CMOS_OP_VALUE_TOO_WIDE: 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.", "value %s to CMOS parameter %s that is only %d bits wide.",
prog_name, line_num, value_str, e->name, e->length); prog_name, line_num, value_str, e->name, e->length);
break; break;
case CMOS_OP_NO_MATCHING_ENUM: 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); prog_name, e->name);
break; break;
case CMOS_AREA_OUT_OF_RANGE: 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, "coreboot parameter %s is out of range.", prog_name,
e->name); e->name);
break; break;
case CMOS_AREA_OVERLAPS_RTC: 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.", "coreboot parameter %s overlaps the realtime clock area.",
prog_name, e->name); prog_name, e->name);
break; break;
case CMOS_AREA_TOO_WIDE: case CMOS_AREA_TOO_WIDE:
fprintf(stderr, "%s: The CMOS area specified by the layout info for " fprintf(stderr,
"coreboot parameter %s is too wide.", "%s: The CMOS area specified by the layout info for "
prog_name, e->name); "coreboot parameter %s is too wide.", prog_name,
e->name);
break; break;
default: default:

View File

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

View File

@ -34,15 +34,15 @@
typedef struct cmos_entry_item_t cmos_entry_item_t; typedef struct cmos_entry_item_t cmos_entry_item_t;
struct cmos_entry_item_t struct cmos_entry_item_t {
{ cmos_entry_t item; cmos_entry_t item;
cmos_entry_item_t *next; cmos_entry_item_t *next;
}; };
typedef struct cmos_enum_item_t cmos_enum_item_t; typedef struct cmos_enum_item_t cmos_enum_item_t;
struct cmos_enum_item_t struct cmos_enum_item_t {
{ cmos_enum_t item; cmos_enum_t item;
cmos_enum_item_t *next; 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, static inline int entries_overlap(const cmos_entry_t * p,
const cmos_entry_t * q) 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 * 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. * 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 static inline const cmos_entry_item_t *cmos_entry_to_const_item
(const cmos_entry_t *p) (const cmos_entry_t * p) {
{ static const cmos_entry_t *pos = &((cmos_entry_item_t *) 0)->item; static const cmos_entry_t *pos = &((cmos_entry_item_t *) 0)->item;
unsigned long offset, address; unsigned long offset, address;
offset = (unsigned long)pos; 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. * 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 static inline const cmos_enum_item_t *cmos_enum_to_const_item
(const cmos_enum_t *p) (const cmos_enum_t * p) {
{ static const cmos_enum_t *pos = &((cmos_enum_item_t *) 0)->item; static const cmos_enum_t *pos = &((cmos_enum_item_t *) 0)->item;
unsigned long offset, address; unsigned long offset, address;
offset = (unsigned long)pos; offset = (unsigned long)pos;
@ -140,7 +142,9 @@ static inline const cmos_enum_item_t * cmos_enum_to_const_item
* information. * information.
****************************************************************************/ ****************************************************************************/
void register_cmos_layout_get_fn(cmos_layout_get_fn_t fn) 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 * 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. * Retrieve CMOS layout information and store it in our internal repository.
****************************************************************************/ ****************************************************************************/
void get_cmos_layout(void) void get_cmos_layout(void)
{ cmos_layout_get_fn(); } {
cmos_layout_get_fn();
}
/**************************************************************************** /****************************************************************************
* add_cmos_entry * add_cmos_entry
@ -159,20 +165,22 @@ void get_cmos_layout (void)
* will be set to point to the overlapping entry. * will be set to point to the overlapping entry.
****************************************************************************/ ****************************************************************************/
int add_cmos_entry(const cmos_entry_t * e, const cmos_entry_t ** conflict) 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; *conflict = NULL;
if (e->length < 1) if (e->length < 1)
return LAYOUT_ENTRY_BAD_LENGTH; 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(); out_of_memory();
new_entry->item = *e; new_entry->item = *e;
if (cmos_entry_list == NULL) if (cmos_entry_list == NULL) {
{ new_entry->next = NULL; new_entry->next = NULL;
cmos_entry_list = new_entry; cmos_entry_list = new_entry;
return OK; 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); (item != NULL) && (item->item.bit < e->bit);
prev = item, item = item->next) ; prev = item, item = item->next) ;
if (prev == NULL) if (prev == NULL) {
{ if (entries_overlap(e, &cmos_entry_list->item)) if (entries_overlap(e, &cmos_entry_list->item)) {
{ *conflict = &cmos_entry_list->item; *conflict = &cmos_entry_list->item;
goto fail; goto fail;
} }
@ -195,13 +203,13 @@ int add_cmos_entry (const cmos_entry_t *e, const cmos_entry_t **conflict)
return OK; return OK;
} }
if (entries_overlap(&prev->item, e)) if (entries_overlap(&prev->item, e)) {
{ *conflict = &prev->item; *conflict = &prev->item;
goto fail; goto fail;
} }
if ((item != NULL) && entries_overlap(e, &item->item)) if ((item != NULL) && entries_overlap(e, &item->item)) {
{ *conflict = &item->item; *conflict = &item->item;
goto fail; goto fail;
} }
@ -221,10 +229,11 @@ fail:
* entry or NULL if entry not found. * entry or NULL if entry not found.
****************************************************************************/ ****************************************************************************/
const cmos_entry_t *find_cmos_entry(const char name[]) 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) for (item = cmos_entry_list; item != NULL; item = item->next) {
{ if (!strcmp(item->item.name, name)) if (!strcmp(item->item.name, name))
return &item->item; return &item->item;
} }
@ -238,7 +247,9 @@ const cmos_entry_t * find_cmos_entry (const char name[])
* empty. * empty.
****************************************************************************/ ****************************************************************************/
const cmos_entry_t *first_cmos_entry(void) 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 * next_cmos_entry
@ -247,7 +258,8 @@ const cmos_entry_t * first_cmos_entry (void)
* entries. * entries.
****************************************************************************/ ****************************************************************************/
const cmos_entry_t *next_cmos_entry(const cmos_entry_t * last) 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); last_item = cmos_entry_to_const_item(last);
next_item = last_item->next; 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. * information. Return OK on success or an error code on failure.
****************************************************************************/ ****************************************************************************/
int add_cmos_enum(const cmos_enum_t * e) 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) if ((new_enum = (cmos_enum_item_t *) malloc(sizeof(*new_enum))) == NULL)
out_of_memory(); out_of_memory();
new_enum->item = *e; new_enum->item = *e;
if (cmos_enum_list == NULL) if (cmos_enum_list == NULL) {
{ new_enum->next = NULL; new_enum->next = NULL;
cmos_enum_list = new_enum; cmos_enum_list = new_enum;
return OK; return OK;
} }
/* The list of enums is sorted in ascending order, first by 'config_id' and /* The list of enums is sorted in ascending order, first by
* then by 'value'. Look for the first enum whose 'config_id' field * 'config_id' and then by 'value'. Look for the first enum
* matches 'e'. * whose 'config_id' field matches 'e'.
*/ */
for (item = cmos_enum_list, prev = NULL; for (item = cmos_enum_list, prev = NULL;
(item != NULL) && (item->item.config_id < e->config_id); (item != NULL) && (item->item.config_id < e->config_id);
prev = item, item = item->next) ; prev = item, item = item->next) ;
if (item == NULL) if (item == NULL) {
{ new_enum->next = NULL; new_enum->next = NULL;
prev->next = new_enum; prev->next = new_enum;
return OK; return OK;
} }
if (item->item.config_id > e->config_id) if (item->item.config_id > e->config_id) {
{ new_enum->next = item; new_enum->next = item;
if (prev == NULL) if (prev == NULL)
cmos_enum_list = new_enum; cmos_enum_list = new_enum;
@ -299,22 +312,23 @@ int add_cmos_enum (const cmos_enum_t *e)
return OK; return OK;
} }
/* List already contains at least one enum whose 'config_id' matches 'e'. /* List already contains at least one enum whose 'config_id'
* Now find proper place to insert 'e' based on 'value'. * matches 'e'. Now find proper place to insert 'e' based on
* 'value'.
*/ */
while (item->item.value < e->value) while (item->item.value < e->value) {
{ prev = item; prev = item;
item = item->next; item = item->next;
if ((item == NULL) || (item->item.config_id != e->config_id)) if ((item == NULL) || (item->item.config_id != e->config_id)) {
{ new_enum->next = item; new_enum->next = item;
prev->next = new_enum; prev->next = new_enum;
return OK; return OK;
} }
} }
if (item->item.value == e->value) if (item->item.value == e->value) {
{ free(new_enum); free(new_enum);
return LAYOUT_DUPLICATE_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 * Search for an enum that matches 'config_id' and 'value'. If found, return
* a pointer to the mathcing enum. Else return NULL. * a pointer to the mathcing enum. Else return NULL.
****************************************************************************/ ****************************************************************************/
const cmos_enum_t * find_cmos_enum (unsigned config_id, const cmos_enum_t *find_cmos_enum(unsigned config_id, unsigned long long value)
unsigned long long value) {
{ const cmos_enum_item_t *item; const cmos_enum_item_t *item;
if ((item = find_first_cmos_enum_id(config_id)) == NULL) if ((item = find_first_cmos_enum_id(config_id)) == NULL)
return NULL; return NULL;
while (item->item.value < value) while (item->item.value < value) {
{ item = item->next; item = item->next;
if ((item == NULL) || (item->item.config_id != config_id)) if ((item == NULL) || (item->item.config_id != config_id))
return NULL; return NULL;
@ -358,7 +372,9 @@ const cmos_enum_t * find_cmos_enum (unsigned config_id,
* empty. * empty.
****************************************************************************/ ****************************************************************************/
const cmos_enum_t *first_cmos_enum(void) 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 * next_cmos_enum
@ -367,7 +383,8 @@ const cmos_enum_t * first_cmos_enum (void)
* enums. * enums.
****************************************************************************/ ****************************************************************************/
const cmos_enum_t *next_cmos_enum(const cmos_enum_t * last) 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); last_item = cmos_enum_to_const_item(last);
next_item = last_item->next; 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. * 'config_id' or NULL if there are no matching enums.
****************************************************************************/ ****************************************************************************/
const cmos_enum_t *first_cmos_enum_id(unsigned config_id) 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); item = find_first_cmos_enum_id(config_id);
return (item == NULL) ? NULL : &item->item; 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. * '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_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; item = cmos_enum_to_const_item(last)->next;
return ((item == NULL) || (item->item.config_id != last->config_id)) ? 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. * checksum. Else return 0.
****************************************************************************/ ****************************************************************************/
int is_checksum_name(const char name[]) int is_checksum_name(const char name[])
{ return !strcmp(name, checksum_param_name); } {
return !strcmp(name, checksum_param_name);
}
/**************************************************************************** /****************************************************************************
* checksum_layout_to_bytes * checksum_layout_to_bytes
@ -419,7 +440,8 @@ int is_checksum_name (const char name[])
* a sanity check fails. * a sanity check fails.
****************************************************************************/ ****************************************************************************/
int checksum_layout_to_bytes(cmos_checksum_layout_t * layout) int checksum_layout_to_bytes(cmos_checksum_layout_t * layout)
{ unsigned start, end, index; {
unsigned start, end, index;
start = layout->summed_area_start; start = layout->summed_area_start;
end = layout->summed_area_end; 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. * in bytes. Convert this information to bit positions.
****************************************************************************/ ****************************************************************************/
void checksum_layout_to_bits(cmos_checksum_layout_t * layout) 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->summed_area_end = (layout->summed_area_end * 8) + 7;
layout->checksum_at *= 8; layout->checksum_at *= 8;
} }
@ -478,7 +501,9 @@ void checksum_layout_to_bits (cmos_checksum_layout_t *layout)
* retrieve layout information. * retrieve layout information.
****************************************************************************/ ****************************************************************************/
static void default_cmos_layout_get_fn(void) static void default_cmos_layout_get_fn(void)
{ BUG(); } {
BUG();
}
/**************************************************************************** /****************************************************************************
* areas_overlap * 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, static int areas_overlap(unsigned area_0_start, unsigned area_0_length,
unsigned area_1_start, unsigned area_1_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_0_end = area_0_start + area_0_length - 1;
area_1_end = area_1_start + area_1_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. * 'config_id'. Return NULL if there is no matching enum.
****************************************************************************/ ****************************************************************************/
static const cmos_enum_item_t *find_first_cmos_enum_id(unsigned config_id) 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; for (item = cmos_enum_list;
(item != NULL) && (item->item.config_id < config_id); (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_SUMMED_AREA_OUT_OF_RANGE (LAYOUT_RESULT_START + 8)
#define LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE (LAYOUT_RESULT_START + 9) #define LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE (LAYOUT_RESULT_START + 9)
typedef enum typedef enum {
{ CMOS_ENTRY_ENUM, CMOS_ENTRY_ENUM,
CMOS_ENTRY_HEX, CMOS_ENTRY_HEX,
CMOS_ENTRY_STRING, CMOS_ENTRY_STRING,
CMOS_ENTRY_RESERVED CMOS_ENTRY_RESERVED
} } cmos_entry_config_t;
cmos_entry_config_t;
/* This represents a CMOS parameter. */ /* This represents a CMOS parameter. */
typedef struct typedef struct {
{ unsigned bit; unsigned bit;
unsigned length; unsigned length;
cmos_entry_config_t config; cmos_entry_config_t config;
unsigned config_id; unsigned config_id;
char name[CMOS_MAX_NAME_LENGTH + 1]; char name[CMOS_MAX_NAME_LENGTH + 1];
} } cmos_entry_t;
cmos_entry_t;
/* This represents a possible value for a CMOS parameter of type /* This represents a possible value for a CMOS parameter of type
* CMOS_ENTRY_ENUM. * CMOS_ENTRY_ENUM.
*/ */
typedef struct typedef struct {
{ unsigned config_id; unsigned config_id;
unsigned long long value; unsigned long long value;
char text[CMOS_MAX_TEXT_LENGTH + 1]; 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 /* This represents the location of the CMOS checksum and the area over
* it is computed. Depending on the context, the values may be represented as * which it is computed. Depending on the context, the values may be
* either bit positions or byte positions. * represented as either bit positions or byte positions.
*/ */
typedef struct typedef struct {
{ unsigned summed_area_start; /* first checksummed location */ unsigned summed_area_start; /* first checksummed location */
unsigned summed_area_end; /* last checksummed location */ unsigned summed_area_end; /* last checksummed location */
unsigned checksum_at; /* location of checksum */ unsigned checksum_at; /* location of checksum */
} } cmos_checksum_layout_t;
cmos_checksum_layout_t;
extern const char checksum_param_name[]; 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 *first_cmos_entry(void);
const cmos_entry_t *next_cmos_entry(const cmos_entry_t * last); const cmos_entry_t *next_cmos_entry(const cmos_entry_t * last);
int add_cmos_enum(const cmos_enum_t * e); int add_cmos_enum(const cmos_enum_t * e);
const cmos_enum_t * find_cmos_enum (unsigned config_id, const cmos_enum_t *find_cmos_enum(unsigned config_id, unsigned long long value);
unsigned long long value);
const cmos_enum_t *first_cmos_enum(void); const cmos_enum_t *first_cmos_enum(void);
const cmos_enum_t *next_cmos_enum(const cmos_enum_t * last); const cmos_enum_t *next_cmos_enum(const cmos_enum_t * last);
const cmos_enum_t *first_cmos_enum_id(unsigned config_id); 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 */ /* matches either a blank line or a comment line */
static const char blank_or_comment_regex[] = static const char blank_or_comment_regex[] =
/* a blank line */ /* a blank line */
"(^[[:space:]]+$)" "(^[[:space:]]+$)" "|" /* or ... */
"|" /* or ... */
/* a line consisting of: optional whitespace followed by */ /* a line consisting of: optional whitespace followed by */
"(^[[:space:]]*" "(^[[:space:]]*"
/* a '#' character and optionally, additional characters */ /* 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. * Set the name of the file we will obtain CMOS layout information from.
****************************************************************************/ ****************************************************************************/
void set_layout_filename(const char filename[]) void set_layout_filename(const char filename[])
{ layout_filename = filename; } {
layout_filename = filename;
}
/**************************************************************************** /****************************************************************************
* get_layout_from_file * 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. * Read CMOS layout information from the user-specified CMOS layout file.
****************************************************************************/ ****************************************************************************/
void get_layout_from_file(void) void get_layout_from_file(void)
{ FILE *f; {
FILE *f;
assert(layout_filename != NULL); assert(layout_filename != NULL);
if ((f = fopen(layout_filename, "r")) == NULL) if ((f = fopen(layout_filename, "r")) == NULL) {
{ fprintf(stderr, "%s: Can not open CMOS layout file %s for reading: " fprintf(stderr,
"%s: Can not open CMOS layout file %s for reading: "
"%s\n", prog_name, layout_filename, strerror(errno)); "%s\n", prog_name, layout_filename, strerror(errno));
exit(1); exit(1);
} }
@ -224,26 +225,26 @@ void get_layout_from_file (void)
* format that CMOS layout files adhere to. * format that CMOS layout files adhere to.
****************************************************************************/ ****************************************************************************/
void write_cmos_layout(FILE * f) void write_cmos_layout(FILE * f)
{ const cmos_entry_t *cmos_entry; {
const cmos_entry_t *cmos_entry;
const cmos_enum_t *cmos_enum; const cmos_enum_t *cmos_enum;
cmos_checksum_layout_t layout; cmos_checksum_layout_t layout;
fprintf(f, "entries\n"); fprintf(f, "entries\n");
for (cmos_entry = first_cmos_entry(); for (cmos_entry = first_cmos_entry();
cmos_entry != NULL; cmos_entry != NULL; cmos_entry = next_cmos_entry(cmos_entry))
cmos_entry = next_cmos_entry(cmos_entry)) fprintf(f, "%u %u %c %u %s\n", cmos_entry->bit,
fprintf(f, "%u %u %c %u %s\n", cmos_entry->bit, cmos_entry->length, cmos_entry->length,
cmos_entry_char_value(cmos_entry->config), cmos_entry_char_value(cmos_entry->config),
cmos_entry->config_id, cmos_entry->name); cmos_entry->config_id, cmos_entry->name);
fprintf(f, "\nenumerations\n"); fprintf(f, "\nenumerations\n");
for (cmos_enum = first_cmos_enum(); for (cmos_enum = first_cmos_enum();
cmos_enum != NULL; cmos_enum != NULL; cmos_enum = next_cmos_enum(cmos_enum))
cmos_enum = next_cmos_enum(cmos_enum)) fprintf(f, "%u %llu %s\n", cmos_enum->config_id,
fprintf(f, "%u %llu %s\n", cmos_enum->config_id, cmos_enum->value, cmos_enum->value, cmos_enum->text);
cmos_enum->text);
layout.summed_area_start = cmos_checksum_start; layout.summed_area_start = cmos_checksum_start;
layout.summed_area_end = cmos_checksum_end; layout.summed_area_end = cmos_checksum_end;
@ -260,7 +261,8 @@ void write_cmos_layout (FILE *f)
* repository. * repository.
****************************************************************************/ ****************************************************************************/
static void process_layout_file(FILE * f) 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, blank_or_comment_regex, &blank_or_comment_expr,
start_entries_regex, &start_entries_expr, start_entries_regex, &start_entries_expr,
entries_line_regex, &entries_line_expr, entries_line_regex, &entries_line_expr,
@ -271,15 +273,16 @@ static void process_layout_file (FILE *f)
line_num = 1; line_num = 1;
skip_past_start(f); skip_past_start(f);
/* Skip past all entries. We will process these later when we make a /* Skip past all entries. We will process these later when we
* second pass through the file. * make a second pass through the file.
*/ */
while (!process_entry(f, 1)) ; 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)) if (process_enum(f, 0)) {
{ fprintf(stderr, "%s: Error: CMOS layout file contains no " fprintf(stderr, "%s: Error: CMOS layout file contains no "
"enumerations.\n", prog_name); "enumerations.\n", prog_name);
exit(1); exit(1);
} }
@ -292,14 +295,16 @@ static void process_layout_file (FILE *f)
skip_past_start(f); skip_past_start(f);
/* Process all entries, adding them to the repository as we go. We must /* Process all entries, adding them to the repository as we go.
* add the entries after the enums, even though they appear in the layout * We must add the entries after the enums, even though they
* file before the enums. This is because the entries are sanity checked * appear in the layout file before the enums. This is because
* against the enums as they are added. * the entries are sanity checked against the enums as they are
* added.
*/ */
if (process_entry(f, 0)) if (process_entry(f, 0)) {
{ fprintf(stderr, "%s: Error: CMOS layout file contains no entries.\n", fprintf(stderr,
"%s: Error: CMOS layout file contains no entries.\n",
prog_name); prog_name);
exit(1); exit(1);
} }
@ -312,8 +317,8 @@ static void process_layout_file (FILE *f)
/* Process CMOS checksum info. */ /* Process CMOS checksum info. */
process_checksum_info(f); process_checksum_info(f);
/* See if there are any lines left to process. If so, verify that they are /* See if there are any lines left to process. If so, verify
* all either blank lines or comments. * that they are all either blank lines or comments.
*/ */
skip_remaining_lines(f); 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. * Skip past the line that marks the start of the "entries" section.
****************************************************************************/ ****************************************************************************/
static void skip_past_start(FILE * f) static void skip_past_start(FILE * f)
{ char line[LINE_BUF_SIZE]; {
char line[LINE_BUF_SIZE];
for (; ; line_num++) for (;; line_num++) {
{ if (get_layout_file_line(f, line, LINE_BUF_SIZE)) if (get_layout_file_line(f, line, LINE_BUF_SIZE)) {
{ fprintf(stderr, fprintf(stderr,
"%s: \"entries\" line not found in CMOS layout file.\n", "%s: \"entries\" line not found in CMOS layout file.\n",
prog_name); prog_name);
exit(1); exit(1);
@ -345,7 +351,8 @@ static void skip_past_start (FILE *f)
if (!regexec(&start_entries_expr, line, 0, NULL, 0)) if (!regexec(&start_entries_expr, line, 0, NULL, 0))
break; 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); "\"entries\" line expected.\n", prog_name, line_num);
exit(1); exit(1);
} }
@ -361,7 +368,8 @@ static void skip_past_start (FILE *f)
* Return 1 if there are no more entries. * Return 1 if there are no more entries.
****************************************************************************/ ****************************************************************************/
static int process_entry(FILE * f, int skip_add) 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]; char line[LINE_BUF_SIZE];
regmatch_t match[N_MATCHES]; regmatch_t match[N_MATCHES];
cmos_entry_t cmos_entry; cmos_entry_t cmos_entry;
@ -369,9 +377,9 @@ static int process_entry (FILE *f, int skip_add)
result = 1; result = 1;
for (; ; line_num++) for (;; line_num++) {
{ if (get_layout_file_line(f, line, LINE_BUF_SIZE)) if (get_layout_file_line(f, line, LINE_BUF_SIZE)) {
{ fprintf(stderr, fprintf(stderr,
"%s: Unexpected end of CMOS layout file reached while " "%s: Unexpected end of CMOS layout file reached while "
"reading \"entries\" section.\n", prog_name); "reading \"entries\" section.\n", prog_name);
exit(1); 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)) if (!regexec(&blank_or_comment_expr, line, 0, NULL, 0))
continue; continue;
if (regexec(&entries_line_expr, line, N_MATCHES, match, 0)) if (regexec(&entries_line_expr, line, N_MATCHES, match, 0)) {
{ if (regexec(&start_enums_expr, line, 0, NULL, 0)) if (regexec(&start_enums_expr, line, 0, NULL, 0)) {
{ fprintf(stderr, "%s: Syntax error on line %d of CMOS layout " fprintf(stderr,
"%s: Syntax error on line %d of CMOS layout "
"file.\n", prog_name, line_num); "file.\n", prog_name, line_num);
exit(1); exit(1);
} }
@ -400,9 +409,9 @@ static int process_entry (FILE *f, int skip_add)
line[match[3].rm_eo] = '\0'; line[match[3].rm_eo] = '\0';
line[match[4].rm_eo] = '\0'; line[match[4].rm_eo] = '\0';
line[match[5].rm_eo] = '\0'; line[match[5].rm_eo] = '\0';
create_entry(&cmos_entry, &line[match[1].rm_so], &line[match[2].rm_so], create_entry(&cmos_entry, &line[match[1].rm_so],
&line[match[3].rm_so], &line[match[4].rm_so], &line[match[2].rm_so], &line[match[3].rm_so],
&line[match[5].rm_so]); &line[match[4].rm_so], &line[match[5].rm_so]);
try_add_layout_file_entry(&cmos_entry); try_add_layout_file_entry(&cmos_entry);
break; break;
} }
@ -419,7 +428,8 @@ static int process_entry (FILE *f, int skip_add)
* and processed. Return 1 if there are no more enumerations. * and processed. Return 1 if there are no more enumerations.
****************************************************************************/ ****************************************************************************/
static int process_enum(FILE * f, int skip_add) 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]; char line[LINE_BUF_SIZE];
regmatch_t match[N_MATCHES]; regmatch_t match[N_MATCHES];
cmos_enum_t cmos_enum; cmos_enum_t cmos_enum;
@ -427,20 +437,22 @@ static int process_enum (FILE *f, int skip_add)
result = 1; result = 1;
for (; ; line_num++) for (;; line_num++) {
{ if (get_layout_file_line(f, line, LINE_BUF_SIZE)) if (get_layout_file_line(f, line, LINE_BUF_SIZE)) {
{ fprintf(stderr, fprintf(stderr,
"%s: Unexpected end of CMOS layout file reached while " "%s: Unexpected end of CMOS layout file reached while "
"reading \"enumerations\" section.\n", prog_name); "reading \"enumerations\" section.\n",
prog_name);
exit(1); exit(1);
} }
if (!regexec(&blank_or_comment_expr, line, 0, NULL, 0)) if (!regexec(&blank_or_comment_expr, line, 0, NULL, 0))
continue; continue;
if (regexec(&enums_line_expr, line, N_MATCHES, match, 0)) if (regexec(&enums_line_expr, line, N_MATCHES, match, 0)) {
{ if (regexec(&start_checksums_expr, line, 0, NULL, 0)) if (regexec(&start_checksums_expr, line, 0, NULL, 0)) {
{ fprintf(stderr, "%s: Syntax error on line %d of CMOS layout " fprintf(stderr,
"%s: Syntax error on line %d of CMOS layout "
"file.\n", prog_name, line_num); "file.\n", prog_name, line_num);
exit(1); exit(1);
} }
@ -456,8 +468,8 @@ static int process_enum (FILE *f, int skip_add)
line[match[1].rm_eo] = '\0'; line[match[1].rm_eo] = '\0';
line[match[2].rm_eo] = '\0'; line[match[2].rm_eo] = '\0';
line[match[3].rm_eo] = '\0'; line[match[3].rm_eo] = '\0';
create_enum(&cmos_enum, &line[match[1].rm_so], &line[match[2].rm_so], create_enum(&cmos_enum, &line[match[1].rm_so],
&line[match[3].rm_so]); &line[match[2].rm_so], &line[match[3].rm_so]);
try_add_cmos_enum(&cmos_enum); try_add_cmos_enum(&cmos_enum);
break; break;
} }
@ -472,13 +484,14 @@ static int process_enum (FILE *f, int skip_add)
* Get line conatining CMOS checksum information. * Get line conatining CMOS checksum information.
****************************************************************************/ ****************************************************************************/
static void process_checksum_info(FILE * f) 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]; char line[LINE_BUF_SIZE];
regmatch_t match[N_MATCHES]; regmatch_t match[N_MATCHES];
for (; ; line_num++) for (;; line_num++) {
{ if (get_layout_file_line(f, line, LINE_BUF_SIZE)) if (get_layout_file_line(f, line, LINE_BUF_SIZE)) {
{ fprintf(stderr, fprintf(stderr,
"%s: Unexpected end of CMOS layout file reached while " "%s: Unexpected end of CMOS layout file reached while "
"reading \"checksums\" section.\n", prog_name); "reading \"checksums\" section.\n", prog_name);
exit(1); exit(1);
@ -487,10 +500,11 @@ static void process_checksum_info (FILE *f)
if (!regexec(&blank_or_comment_expr, line, 0, NULL, 0)) if (!regexec(&blank_or_comment_expr, line, 0, NULL, 0))
continue; continue;
if (regexec(&checksum_line_expr, line, N_MATCHES, match, 0)) if (regexec(&checksum_line_expr, line, N_MATCHES, match, 0)) {
{ fprintf(stderr, "%s: Syntax error on line %d of CMOS layout " fprintf(stderr,
"file. \"checksum\" line expected.\n", prog_name, "%s: Syntax error on line %d of CMOS layout "
line_num); "file. \"checksum\" line expected.\n",
prog_name, line_num);
exit(1); exit(1);
} }
@ -511,13 +525,14 @@ static void process_checksum_info (FILE *f)
* that contains anything other than comments and whitespace. * that contains anything other than comments and whitespace.
****************************************************************************/ ****************************************************************************/
static void skip_remaining_lines(FILE * f) static void skip_remaining_lines(FILE * f)
{ char line[LINE_BUF_SIZE]; {
char line[LINE_BUF_SIZE];
for (line_num++; for (line_num++;
get_layout_file_line(f, line, LINE_BUF_SIZE) == OK; get_layout_file_line(f, line, LINE_BUF_SIZE) == OK; line_num++) {
line_num++) if (regexec(&blank_or_comment_expr, line, 0, NULL, 0)) {
{ if (regexec(&blank_or_comment_expr, line, 0, NULL, 0)) fprintf(stderr,
{ fprintf(stderr, "%s: Syntax error on line %d of CMOS layout file: " "%s: Syntax error on line %d of CMOS layout file: "
"Only comments and/or whitespace allowed after " "Only comments and/or whitespace allowed after "
"\"checksum\" line.\n", prog_name, line_num); "\"checksum\" line.\n", prog_name, line_num);
exit(1); 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 start_bit_str[], const char length_str[],
const char config_str[], const char config_id_str[], const char config_str[], const char config_id_str[],
const char name_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"); cmos_entry->length = string_to_unsigned(length_str, "length");
if (config_str[1] != '\0') if (config_str[1] != '\0')
goto bad_config_str; goto bad_config_str;
switch (config_str[0]) switch (config_str[0]) {
{ case 'e': case 'e':
cmos_entry->config = CMOS_ENTRY_ENUM; cmos_entry->config = CMOS_ENTRY_ENUM;
break; 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"); cmos_entry->config_id = string_to_unsigned(config_id_str, "config-ID");
if (strlen(name_str) >= CMOS_MAX_NAME_LENGTH) if (strlen(name_str) >= CMOS_MAX_NAME_LENGTH) {
{ fprintf(stderr, "%s: Error on line %d of CMOS layout file: name too " fprintf(stderr,
"%s: Error on line %d of CMOS layout file: name too "
"long (max length is %d).\n", prog_name, line_num, "long (max length is %d).\n", prog_name, line_num,
CMOS_MAX_NAME_LENGTH - 1); CMOS_MAX_NAME_LENGTH - 1);
exit(1); exit(1);
@ -575,7 +592,8 @@ static void create_entry (cmos_entry_t *cmos_entry,
return; return;
bad_config_str: 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); "'r' expected for config value.\n", prog_name, line_num);
exit(1); exit(1);
} }
@ -587,26 +605,30 @@ bad_config_str:
* an error message on failure. * an error message on failure.
****************************************************************************/ ****************************************************************************/
static void try_add_layout_file_entry(const cmos_entry_t * cmos_entry) 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)) switch (add_cmos_entry(cmos_entry, &conflict)) {
{ case OK: case OK:
return; return;
case CMOS_AREA_OUT_OF_RANGE: 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, "covered by entry %s is out of range.\n", prog_name,
line_num, cmos_entry->name); line_num, cmos_entry->name);
break; break;
case CMOS_AREA_TOO_WIDE: case CMOS_AREA_TOO_WIDE:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. Area " fprintf(stderr,
"covered by entry %s is too wide.\n", prog_name, line_num, "%s: Error on line %d of CMOS layout file. Area "
cmos_entry->name); "covered by entry %s is too wide.\n", prog_name,
line_num, cmos_entry->name);
break; break;
case LAYOUT_ENTRY_OVERLAP: 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, "overlap for entries %s and %s.\n", prog_name, line_num,
cmos_entry->name, conflict->name); cmos_entry->name, conflict->name);
break; 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[], static void create_enum(cmos_enum_t * cmos_enum, const char id_str[],
const char value_str[], const char text_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"); cmos_enum->value = string_to_unsigned_long(value_str, "value");
if (strlen(text_str) >= CMOS_MAX_TEXT_LENGTH) if (strlen(text_str) >= CMOS_MAX_TEXT_LENGTH) {
{ fprintf(stderr, "%s: Error on line %d of CMOS layout file: text too " fprintf(stderr,
"%s: Error on line %d of CMOS layout file: text too "
"long (max length is %d).\n", prog_name, line_num, "long (max length is %d).\n", prog_name, line_num,
CMOS_MAX_TEXT_LENGTH - 1); CMOS_MAX_TEXT_LENGTH - 1);
exit(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. * an error message on failure.
****************************************************************************/ ****************************************************************************/
static void try_add_cmos_enum(const cmos_enum_t * cmos_enum) 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; return;
case LAYOUT_DUPLICATE_ENUM: 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[], static void set_checksum_info(const char start_str[], const char end_str[],
const char index_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. */ /* These are bit positions that we want to convert to byte positions. */
layout.summed_area_start = layout.summed_area_start =
@ -688,48 +714,57 @@ static void set_checksum_info (const char start_str[], const char end_str[],
layout.checksum_at = layout.checksum_at =
string_to_unsigned(index_str, "CMOS checksum location"); string_to_unsigned(index_str, "CMOS checksum location");
switch (checksum_layout_to_bytes(&layout)) switch (checksum_layout_to_bytes(&layout)) {
{ case OK: case OK:
break; break;
case LAYOUT_SUMMED_AREA_START_NOT_ALIGNED: case LAYOUT_SUMMED_AREA_START_NOT_ALIGNED:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS " fprintf(stderr,
"checksummed area start is not byte-aligned.\n", prog_name, "%s: Error on line %d of CMOS layout file. CMOS "
line_num); "checksummed area start is not byte-aligned.\n",
prog_name, line_num);
goto fail; goto fail;
case LAYOUT_SUMMED_AREA_END_NOT_ALIGNED: case LAYOUT_SUMMED_AREA_END_NOT_ALIGNED:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS " fprintf(stderr,
"checksummed area end is not byte-aligned.\n", prog_name, "%s: Error on line %d of CMOS layout file. CMOS "
line_num); "checksummed area end is not byte-aligned.\n",
prog_name, line_num);
goto fail; goto fail;
case LAYOUT_CHECKSUM_LOCATION_NOT_ALIGNED: 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, "checksum location is not byte-aligned.\n", prog_name,
line_num); line_num);
goto fail; goto fail;
case LAYOUT_INVALID_SUMMED_AREA: 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 " "checksummed area end must be greater than CMOS checksummed "
"area start.\n", prog_name, line_num); "area start.\n", prog_name, line_num);
goto fail; goto fail;
case LAYOUT_CHECKSUM_OVERLAPS_SUMMED_AREA: 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, "checksum overlaps checksummed area.\n", prog_name,
line_num); line_num);
goto fail; goto fail;
case LAYOUT_SUMMED_AREA_OUT_OF_RANGE: case LAYOUT_SUMMED_AREA_OUT_OF_RANGE:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS " fprintf(stderr,
"checksummed area out of range.\n", prog_name, line_num); "%s: Error on line %d of CMOS layout file. CMOS "
"checksummed area out of range.\n", prog_name,
line_num);
goto fail; goto fail;
case LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE: case LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE:
fprintf(stderr, "%s: Error on line %d of CMOS layout file. CMOS " fprintf(stderr,
"checksum location out of range.\n", prog_name, line_num); "%s: Error on line %d of CMOS layout file. CMOS "
"checksum location out of range.\n", prog_name,
line_num);
goto fail; goto fail;
default: default:
@ -751,8 +786,9 @@ fail:
* Return the character representation of 'config'. * Return the character representation of 'config'.
****************************************************************************/ ****************************************************************************/
static char cmos_entry_char_value(cmos_entry_config_t 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'; return 'e';
case CMOS_ENTRY_HEX: case CMOS_ENTRY_HEX:
@ -779,17 +815,19 @@ static char cmos_entry_char_value (cmos_entry_config_t config)
* failure. * failure.
****************************************************************************/ ****************************************************************************/
static int get_layout_file_line(FILE * f, char line[], int line_buf_size) 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; return OK;
case LINE_EOF: case LINE_EOF:
return LINE_EOF; return LINE_EOF;
case LINE_TOO_LONG: case LINE_TOO_LONG:
fprintf(stderr, "%s: Error on line %d of CMOS layout file: Maximum " fprintf(stderr,
"line length exceeded. Max is %d characters.\n", prog_name, "%s: Error on line %d of CMOS layout file: Maximum "
line_num, line_buf_size - 2); "line length exceeded. Max is %d characters.\n",
prog_name, line_num, line_buf_size - 2);
break; 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. * Convert the string 'str' to an unsigned and return the result.
****************************************************************************/ ****************************************************************************/
static unsigned string_to_unsigned(const char str[], const char str_name[]) static unsigned string_to_unsigned(const char str[], const char str_name[])
{ unsigned long n; {
unsigned long n;
unsigned z; unsigned z;
n = do_string_to_unsigned_long(str, str_name, ""); n = do_string_to_unsigned_long(str, str_name, "");
if ((z = (unsigned) n) != n) if ((z = (unsigned)n) != n) {
{ /* This could happen on an architecture in which sizeof(unsigned) < /* This could happen on an architecture in which
* sizeof(unsigned long). * 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); "out of range.\n", prog_name, line_num, str_name);
exit(1); 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[], static unsigned long string_to_unsigned_long(const char str[],
const char str_name[]) 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 * 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[], static unsigned long do_string_to_unsigned_long(const char str[],
const char str_name[], const char str_name[],
const char blurb[]) const char blurb[])
{ unsigned long n; {
unsigned long n;
char *p; char *p;
n = strtoul(str, &p, 0); n = strtoul(str, &p, 0);
if (*p != '\0') if (*p != '\0') {
{ fprintf(stderr, "%s: Error on line %d of CMOS layout file: %s is not a " fprintf(stderr,
"valid unsigned%s integer.\n", prog_name, "%s: Error on line %d of CMOS layout file: %s is not a "
line_num, str_name, blurb); "valid unsigned%s integer.\n", prog_name, line_num,
str_name, blurb);
exit(1); 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 /* This structure represents an item in the coreboot table that may be
* displayed using the -l option. * displayed using the -l option.
*/ */
typedef struct typedef struct {
{ uint32_t tag; uint32_t tag;
const char *name; const char *name;
const char *description; const char *description;
const char *nofound_msg; const char *nofound_msg;
lbtable_print_fn_t print_fn; lbtable_print_fn_t print_fn;
} } lbtable_choice_t;
lbtable_choice_t;
typedef struct typedef struct {
{ unsigned long start; /* address of first byte of memory range */ unsigned long start; /* address of first byte of memory range */
unsigned long end; /* address of last 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, static const struct lb_header *lbtable_scan(unsigned long start,
unsigned long end, 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 struct lb_record *find_lbrec(uint32_t tag);
static const char *lbrec_tag_to_str(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 *first_cmos_table_entry(void);
static const struct cmos_entries * static const struct cmos_entries *next_cmos_table_entry(const struct
next_cmos_table_entry (const struct cmos_entries *last); cmos_entries *last);
static const struct cmos_enums *first_cmos_table_enum(void); static const struct cmos_enums *first_cmos_table_enum(void);
static const struct cmos_enums *next_cmos_table_enum static const struct cmos_enums *next_cmos_table_enum
(const struct cmos_enums *last); (const struct cmos_enums *last);
@ -102,14 +100,12 @@ static const char version_desc[] =
static const char extra_version_desc[] = static const char extra_version_desc[] =
" This shows extra coreboot version information.\n"; " This shows extra coreboot version information.\n";
static const char build_desc[] = static const char build_desc[] = " This shows coreboot build information.\n";
" This shows coreboot build information.\n";
static const char compile_time_desc[] = static const char compile_time_desc[] =
" This shows when coreboot was compiled.\n"; " This shows when coreboot was compiled.\n";
static const char compile_by_desc[] = static const char compile_by_desc[] = " This shows who compiled coreboot.\n";
" This shows who compiled coreboot.\n";
static const char compile_host_desc[] = static const char compile_host_desc[] =
" This shows the name of the machine that compiled coreboot.\n"; " 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[] = static const char option_checksum_desc[] =
" This shows the location of the CMOS checksum and the area over which it " " This shows the location of the CMOS checksum and the area over which it "
"is\n" "is\n" " calculated.\n";
" calculated.\n";
static const char generic_nofound_msg[] = static const char generic_nofound_msg[] =
"%s: Item %s not found in coreboot table.\n"; "%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] = static const lbtable_choice_t lbtable_choices[NUM_LBTABLE_CHOICES] =
{ {LB_TAG_MEMORY, "memory", { {LB_TAG_MEMORY, "memory",
memory_desc, generic_nofound_msg, memory_desc, generic_nofound_msg,
memory_print_fn memory_print_fn},
},
{LB_TAG_MAINBOARD, "mainboard", {LB_TAG_MAINBOARD, "mainboard",
mainboard_desc, generic_nofound_msg, mainboard_desc, generic_nofound_msg,
mainboard_print_fn mainboard_print_fn},
},
{LB_TAG_VERSION, "version", {LB_TAG_VERSION, "version",
version_desc, generic_nofound_msg, version_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_EXTRA_VERSION, "extra_version", {LB_TAG_EXTRA_VERSION, "extra_version",
extra_version_desc, generic_nofound_msg, extra_version_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_BUILD, "build", {LB_TAG_BUILD, "build",
build_desc, generic_nofound_msg, build_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_COMPILE_TIME, "compile_time", {LB_TAG_COMPILE_TIME, "compile_time",
compile_time_desc, generic_nofound_msg, compile_time_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_COMPILE_BY, "compile_by", {LB_TAG_COMPILE_BY, "compile_by",
compile_by_desc, generic_nofound_msg, compile_by_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_COMPILE_HOST, "compile_host", {LB_TAG_COMPILE_HOST, "compile_host",
compile_host_desc, generic_nofound_msg, compile_host_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_COMPILE_DOMAIN, "compile_domain", {LB_TAG_COMPILE_DOMAIN, "compile_domain",
compile_domain_desc, generic_nofound_msg, compile_domain_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_COMPILER, "compiler", {LB_TAG_COMPILER, "compiler",
compiler_desc, generic_nofound_msg, compiler_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_LINKER, "linker", {LB_TAG_LINKER, "linker",
linker_desc, generic_nofound_msg, linker_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_ASSEMBLER, "assembler", {LB_TAG_ASSEMBLER, "assembler",
assembler_desc, generic_nofound_msg, assembler_desc, generic_nofound_msg,
string_print_fn string_print_fn},
},
{LB_TAG_CMOS_OPTION_TABLE, "cmos_opt_table", {LB_TAG_CMOS_OPTION_TABLE, "cmos_opt_table",
cmos_opt_table_desc, nofound_msg_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", {LB_TAG_OPTION_CHECKSUM, "option_checksum",
option_checksum_desc, nofound_msg_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 /* 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. * Find the coreboot table and set global variable lbtable to point to it.
****************************************************************************/ ****************************************************************************/
void get_lbtable(void) 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) if (lbtable != NULL)
return; return;
@ -292,15 +274,16 @@ void get_lbtable (void)
* conveniently accessed by calling mmap() on /dev/mem. * conveniently accessed by calling mmap() on /dev/mem.
*/ */
if ((fd = open("/dev/mem", O_RDONLY, 0)) < 0) if ((fd = open("/dev/mem", O_RDONLY, 0)) < 0) {
{ fprintf(stderr, "%s: Can not open /dev/mem for reading: %s\n", fprintf(stderr, "%s: Can not open /dev/mem for reading: %s\n",
prog_name, strerror(errno)); prog_name, strerror(errno));
exit(1); exit(1);
} }
if ((low_phys_mem = mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd, 0)) if ((low_phys_mem =
== MAP_FAILED) mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd, 0))
{ fprintf(stderr, "%s: Failed to mmap /dev/mem: %s\n", prog_name, == MAP_FAILED) {
fprintf(stderr, "%s: Failed to mmap /dev/mem: %s\n", prog_name,
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
@ -308,8 +291,8 @@ void get_lbtable (void)
bad_header_count = 0; bad_header_count = 0;
bad_table_count = 0; bad_table_count = 0;
for (i = 0; i < NUM_MEM_RANGES; i++) for (i = 0; i < NUM_MEM_RANGES; i++) {
{ lbtable = lbtable_scan(phystov(mem_ranges[i].start), lbtable = lbtable_scan(phystov(mem_ranges[i].start),
phystov(mem_ranges[i].end), phystov(mem_ranges[i].end),
&bad_headers, &bad_tables); &bad_headers, &bad_tables);
@ -328,8 +311,7 @@ void get_lbtable (void)
" %d valid signatures were found with bad header " " %d valid signatures were found with bad header "
"checksums.\n" "checksums.\n"
" %d valid headers were found with bad table " " %d valid headers were found with bad table "
"checksums.\n", "checksums.\n", prog_name, bad_header_count, bad_table_count);
prog_name, bad_header_count, bad_table_count);
exit(1); exit(1);
} }
@ -346,8 +328,8 @@ void get_layout_from_cmos_table (void)
cmos_table = (const struct cmos_option_table *) cmos_table = (const struct cmos_option_table *)
find_lbrec(LB_TAG_CMOS_OPTION_TABLE); find_lbrec(LB_TAG_CMOS_OPTION_TABLE);
if ((cmos_table) == NULL) if ((cmos_table) == NULL) {
{ fprintf(stderr, fprintf(stderr,
"%s: CMOS option table not found in coreboot table. " "%s: CMOS option table not found in coreboot table. "
"Apparently, the coreboot installed on this system was " "Apparently, the coreboot installed on this system was "
"built without specifying CONFIG_HAVE_OPTION_TABLE.\n", "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. * Do a low-level dump of the coreboot table.
****************************************************************************/ ****************************************************************************/
void dump_lbtable(void) void dump_lbtable(void)
{ const char *p, *data; {
const char *p, *data;
uint32_t bytes_processed; uint32_t bytes_processed;
const struct lb_record *lbrec; const struct lb_record *lbrec;
@ -378,26 +361,28 @@ void dump_lbtable (void)
" table_checksum: 0x%x (decimal: %d)\n" " table_checksum: 0x%x (decimal: %d)\n"
" table_entries: 0x%x (decimal: %d)\n\n", " table_entries: 0x%x (decimal: %d)\n\n",
vtophys(lbtable), *((uint32_t *) lbtable->signature), vtophys(lbtable), *((uint32_t *) lbtable->signature),
lbtable->signature[0], lbtable->signature[1],lbtable->signature[2], lbtable->signature[0], lbtable->signature[1],
lbtable->signature[3], lbtable->header_bytes, lbtable->header_bytes, lbtable->signature[2], lbtable->signature[3],
lbtable->header_bytes, lbtable->header_bytes,
lbtable->header_checksum, lbtable->header_checksum, lbtable->header_checksum, lbtable->header_checksum,
lbtable->table_bytes, lbtable->table_bytes, lbtable->table_checksum, lbtable->table_bytes, lbtable->table_bytes,
lbtable->table_checksum, lbtable->table_entries, lbtable->table_checksum, lbtable->table_checksum,
lbtable->table_entries); lbtable->table_entries, lbtable->table_entries);
if ((lbtable->table_bytes == 0) != (lbtable->table_entries == 0)) if ((lbtable->table_bytes == 0) != (lbtable->table_entries == 0)) {
{ printf("Inconsistent values for table_bytes and table_entries!!!\n" printf
("Inconsistent values for table_bytes and table_entries!!!\n"
"They should be either both 0 or both nonzero.\n"); "They should be either both 0 or both nonzero.\n");
return; return;
} }
if (lbtable->table_bytes == 0) if (lbtable->table_bytes == 0) {
{ printf("The coreboot table is empty!!!\n"); printf("The coreboot table is empty!!!\n");
return; return;
} }
for (bytes_processed = 0; ; ) for (bytes_processed = 0;;) {
{ lbrec = (const struct lb_record *) &p[bytes_processed]; lbrec = (const struct lb_record *)&p[bytes_processed];
printf(" %s record at physical address 0x%lx:\n" printf(" %s record at physical address 0x%lx:\n"
" tag: 0x%x (decimal: %d)\n" " tag: 0x%x (decimal: %d)\n"
" size: 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); lbrec->tag, lbrec->size, lbrec->size);
data = ((const char *)lbrec) + sizeof(*lbrec); data = ((const char *)lbrec) + sizeof(*lbrec);
hexdump(data, lbrec->size - sizeof(*lbrec), vtophys(data), stdout, hexdump(data, lbrec->size - sizeof(*lbrec), vtophys(data),
&format); stdout, &format);
bytes_processed += lbrec->size; bytes_processed += lbrec->size;
@ -425,10 +410,11 @@ void dump_lbtable (void)
* that may be displayed using the -l option. * that may be displayed using the -l option.
****************************************************************************/ ****************************************************************************/
void list_lbtable_choices(void) void list_lbtable_choices(void)
{ int i; {
int i;
for (i = 0; ; ) for (i = 0;;) {
{ printf("%s:\n%s", printf("%s:\n%s",
lbtable_choices[i].name, lbtable_choices[i].description); lbtable_choices[i].name, lbtable_choices[i].description);
if (++i >= NUM_LBTABLE_CHOICES) if (++i >= NUM_LBTABLE_CHOICES)
@ -444,22 +430,23 @@ void list_lbtable_choices (void)
* Show the coreboot table item specified by 'item'. * Show the coreboot table item specified by 'item'.
****************************************************************************/ ****************************************************************************/
void list_lbtable_item(const char item[]) void list_lbtable_item(const char item[])
{ int i; {
int i;
const struct lb_record *rec; const struct lb_record *rec;
for (i = 0; i < NUM_LBTABLE_CHOICES; i++) for (i = 0; i < NUM_LBTABLE_CHOICES; i++) {
{ if (strcmp(item, lbtable_choices[i].name) == 0) if (strcmp(item, lbtable_choices[i].name) == 0)
break; break;
} }
if (i == NUM_LBTABLE_CHOICES) if (i == NUM_LBTABLE_CHOICES) {
{ fprintf(stderr, "%s: Invalid coreboot table item %s.\n", prog_name, fprintf(stderr, "%s: Invalid coreboot table item %s.\n",
item); prog_name, item);
exit(1); exit(1);
} }
if ((rec = find_lbrec(lbtable_choices[i].tag)) == NULL) if ((rec = find_lbrec(lbtable_choices[i].tag)) == NULL) {
{ fprintf(stderr, lbtable_choices[i].nofound_msg, prog_name, fprintf(stderr, lbtable_choices[i].nofound_msg, prog_name,
lbtable_choices[i].name); lbtable_choices[i].name);
exit(1); exit(1);
} }
@ -495,7 +482,8 @@ static const struct lb_header * lbtable_scan (unsigned long start,
unsigned long end, unsigned long end,
int *bad_header_count, int *bad_header_count,
int *bad_table_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_header *table;
const struct lb_forward *forward; const struct lb_forward *forward;
const uint32_t *p; const uint32_t *p;
@ -515,25 +503,24 @@ static const struct lb_header * lbtable_scan (unsigned long start,
*/ */
for (p = (const uint32_t *)start; for (p = (const uint32_t *)start;
(((unsigned long)p) <= end) && (((unsigned long)p) <= end) &&
((end - (unsigned long) p) >= (sizeof(uint32_t) - 1)); ((end - (unsigned long)p) >= (sizeof(uint32_t) - 1)); p += 4) {
p += 4) if (*p != sig)
{ if (*p != sig)
continue; continue;
/* We found a valid signature. */ /* We found a valid signature. */
table = (const struct lb_header *)p; table = (const struct lb_header *)p;
/* validate header checksum */ /* validate header checksum */
if (compute_ip_checksum((void *) table, sizeof(*table))) if (compute_ip_checksum((void *)table, sizeof(*table))) {
{ (*bad_header_count)++; (*bad_header_count)++;
continue; continue;
} }
/* validate table checksum */ /* validate table checksum */
if (table->table_checksum != if (table->table_checksum !=
compute_ip_checksum(((char *)table) + sizeof(*table), compute_ip_checksum(((char *)table) + sizeof(*table),
table->table_bytes)) table->table_bytes)) {
{ (*bad_table_count)++; (*bad_table_count)++;
continue; continue;
} }
@ -549,13 +536,19 @@ static const struct lb_header * lbtable_scan (unsigned long start,
new_phys &= ~(getpagesize() - 1); new_phys &= ~(getpagesize() - 1);
munmap((void *)low_phys_mem, BYTES_TO_MAP); 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) if ((low_phys_mem =
{ fprintf(stderr, "%s: Failed to mmap /dev/mem: %s\n", prog_name, mmap(NULL, BYTES_TO_MAP, PROT_READ, MAP_SHARED, fd,
strerror(errno)); (off_t) new_phys)) == MAP_FAILED) {
fprintf(stderr,
"%s: Failed to mmap /dev/mem: %s\n",
prog_name, strerror(errno));
exit(1); exit(1);
} }
low_phys_base = new_phys; 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; return table;
} }
@ -570,14 +563,16 @@ static const struct lb_header * lbtable_scan (unsigned long start,
* internal repository. * internal repository.
****************************************************************************/ ****************************************************************************/
static void process_cmos_table(void) static void process_cmos_table(void)
{ const struct cmos_enums *p; {
const struct cmos_enums *p;
const struct cmos_entries *q; const struct cmos_entries *q;
cmos_enum_t cmos_enum; cmos_enum_t cmos_enum;
cmos_entry_t cmos_entry; cmos_entry_t cmos_entry;
/* First add the enums. */ /* First add the enums. */
for (p = first_cmos_table_enum(); p != NULL; p = next_cmos_table_enum(p)) for (p = first_cmos_table_enum(); p != NULL;
{ cmos_enum.config_id = p->config_id; p = next_cmos_table_enum(p)) {
cmos_enum.config_id = p->config_id;
cmos_enum.value = p->value; cmos_enum.value = p->value;
strncpy(cmos_enum.text, (char *)p->text, CMOS_MAX_TEXT_LENGTH); strncpy(cmos_enum.text, (char *)p->text, CMOS_MAX_TEXT_LENGTH);
cmos_enum.text[CMOS_MAX_TEXT_LENGTH] = '\0'; 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 /* 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. * 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)) for (q = first_cmos_table_entry(); q != NULL;
{ cmos_entry.bit = q->bit; q = next_cmos_table_entry(q)) {
cmos_entry.bit = q->bit;
cmos_entry.length = q->length; cmos_entry.length = q->length;
switch (q->config) switch (q->config) {
{ case 'e': case 'e':
cmos_entry.config = CMOS_ENTRY_ENUM; cmos_entry.config = CMOS_ENTRY_ENUM;
break; break;
@ -628,15 +624,15 @@ static void process_cmos_table (void)
* Get layout information for CMOS checksum. * Get layout information for CMOS checksum.
****************************************************************************/ ****************************************************************************/
static void get_cmos_checksum_info(void) static void get_cmos_checksum_info(void)
{ const cmos_entry_t *e; {
const cmos_entry_t *e;
struct cmos_checksum *checksum; struct cmos_checksum *checksum;
cmos_checksum_layout_t layout; cmos_checksum_layout_t layout;
unsigned index, index2; unsigned index, index2;
checksum = (struct cmos_checksum *)find_lbrec(LB_TAG_OPTION_CHECKSUM); checksum = (struct cmos_checksum *)find_lbrec(LB_TAG_OPTION_CHECKSUM);
if (checksum != NULL) if (checksum != NULL) { /* We are lucky. The coreboot table hints us to the checksum.
{ /* We are lucky. The coreboot table hints us to the checksum.
* We might have to check the type field here though. * We might have to check the type field here though.
*/ */
layout.summed_area_start = checksum->range_start; 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. * Thus we have to hope our presets will be fine.
*/ */
if (e->bit % 8) if (e->bit % 8) {
{ fprintf(stderr, "%s: Error: CMOS checksum is not byte-aligned.\n", fprintf(stderr,
"%s: Error: CMOS checksum is not byte-aligned.\n",
prog_name); prog_name);
exit(1); exit(1);
} }
@ -667,15 +664,18 @@ static void get_cmos_checksum_info (void)
index = e->bit / 8; index = e->bit / 8;
index2 = index + 1; /* The CMOS checksum occupies 16 bits. */ index2 = index + 1; /* The CMOS checksum occupies 16 bits. */
if (verify_cmos_byte_index(index) || verify_cmos_byte_index(index2)) if (verify_cmos_byte_index(index) || verify_cmos_byte_index(index2)) {
{ fprintf(stderr, "%s: Error: CMOS checksum location out of range.\n", fprintf(stderr,
"%s: Error: CMOS checksum location out of range.\n",
prog_name); prog_name);
exit(1); exit(1);
} }
if (((index >= cmos_checksum_start) && (index <= cmos_checksum_end)) || if (((index >= cmos_checksum_start) && (index <= cmos_checksum_end)) ||
(((index2) >= cmos_checksum_start) && ((index2) <= cmos_checksum_end))) (((index2) >= cmos_checksum_start)
{ fprintf(stderr, "%s: Error: CMOS checksum overlaps checksummed area.\n", && ((index2) <= cmos_checksum_end))) {
fprintf(stderr,
"%s: Error: CMOS checksum overlaps checksummed area.\n",
prog_name); prog_name);
exit(1); exit(1);
} }
@ -691,8 +691,9 @@ static void get_cmos_checksum_info (void)
* success or an error code on failure. * success or an error code on failure.
****************************************************************************/ ****************************************************************************/
static void try_convert_checksum_layout(cmos_checksum_layout_t * layout) 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; return;
case LAYOUT_SUMMED_AREA_START_NOT_ALIGNED: 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: case LAYOUT_INVALID_SUMMED_AREA:
fprintf(stderr, fprintf(stderr,
"%s: CMOS checksummed area end must be greater than " "%s: CMOS checksummed area end must be greater than "
"CMOS checksummed area start.\n", "CMOS checksummed area start.\n", prog_name);
prog_name);
break; break;
case LAYOUT_CHECKSUM_OVERLAPS_SUMMED_AREA: 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: case LAYOUT_SUMMED_AREA_OUT_OF_RANGE:
fprintf(stderr, fprintf(stderr,
"%s: CMOS checksummed area out of range.\n", "%s: CMOS checksummed area out of range.\n", prog_name);
prog_name);
break; break;
case LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE: 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. * message on failure.
****************************************************************************/ ****************************************************************************/
static void try_add_cmos_table_enum(cmos_enum_t * cmos_enum) 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; return;
case LAYOUT_DUPLICATE_ENUM: case LAYOUT_DUPLICATE_ENUM:
@ -775,10 +775,11 @@ static void try_add_cmos_table_enum (cmos_enum_t *cmos_enum)
* error message on failure. * error message on failure.
****************************************************************************/ ****************************************************************************/
static void try_add_cmos_table_entry(cmos_entry_t * cmos_entry) 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)) switch (add_cmos_entry(cmos_entry, &conflict)) {
{ case OK: case OK:
return; return;
case CMOS_AREA_OUT_OF_RANGE: 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: case LAYOUT_ENTRY_OVERLAP:
fprintf(stderr, fprintf(stderr,
"%s: CMOS option table entries %s and %s have overlapping " "%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; break;
case LAYOUT_ENTRY_BAD_LENGTH: 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. * to record on success or NULL if record not found.
****************************************************************************/ ****************************************************************************/
static const struct lb_record *find_lbrec(uint32_t tag) static const struct lb_record *find_lbrec(uint32_t tag)
{ const char *p; {
const char *p;
uint32_t bytes_processed; uint32_t bytes_processed;
const struct lb_record *lbrec; const struct lb_record *lbrec;
@ -828,8 +831,8 @@ static const struct lb_record * find_lbrec (uint32_t tag)
for (bytes_processed = 0; for (bytes_processed = 0;
bytes_processed < lbtable->table_bytes; bytes_processed < lbtable->table_bytes;
bytes_processed += lbrec->size) bytes_processed += lbrec->size) {
{ lbrec = (const struct lb_record *) &p[bytes_processed]; lbrec = (const struct lb_record *)&p[bytes_processed];
if (lbrec->tag == tag) if (lbrec->tag == tag)
return lbrec; return lbrec;
@ -845,8 +848,9 @@ static const struct lb_record * find_lbrec (uint32_t tag)
* tag. * tag.
****************************************************************************/ ****************************************************************************/
static const char *lbrec_tag_to_str(uint32_t 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"; return "UNUSED";
case LB_TAG_MEMORY: 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. * CMOS parameter. Return NULL if CMOS table is empty.
****************************************************************************/ ****************************************************************************/
static const struct cmos_entries *first_cmos_table_entry(void) 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 * 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 * 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. * represents a CMOS parameter. Return NULL if there are no more parameters.
****************************************************************************/ ****************************************************************************/
static const struct cmos_entries * static const struct cmos_entries *next_cmos_table_entry(const struct
next_cmos_table_entry (const struct cmos_entries *last) cmos_entries *last)
{ return (const struct cmos_entries *) {
return (const struct cmos_entries *)
next_cmos_rec((const struct lb_record *)last, LB_TAG_OPTION); next_cmos_rec((const struct lb_record *)last, LB_TAG_OPTION);
} }
@ -939,7 +946,9 @@ static const struct cmos_entries *
* any such entries. * any such entries.
****************************************************************************/ ****************************************************************************/
static const struct cmos_enums *first_cmos_table_enum(void) 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 * next_cmos_table_enum
@ -949,8 +958,8 @@ static const struct cmos_enums * first_cmos_table_enum (void)
* more parameter values. * more parameter values.
****************************************************************************/ ****************************************************************************/
static const struct cmos_enums *next_cmos_table_enum static const struct cmos_enums *next_cmos_table_enum
(const struct cmos_enums *last) (const struct cmos_enums *last) {
{ return (const struct cmos_enums *) return (const struct cmos_enums *)
next_cmos_rec((const struct lb_record *)last, LB_TAG_OPTION_ENUM); 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'. * 'reserved'.
****************************************************************************/ ****************************************************************************/
static const struct lb_record *first_cmos_rec(uint32_t tag) static const struct lb_record *first_cmos_rec(uint32_t tag)
{ const char *p; {
const char *p;
uint32_t bytes_processed, bytes_for_entries; uint32_t bytes_processed, bytes_for_entries;
const struct lb_record *lbrec; const struct lb_record *lbrec;
@ -980,8 +990,8 @@ static const struct lb_record * first_cmos_rec (uint32_t tag)
for (bytes_processed = 0; for (bytes_processed = 0;
bytes_processed < bytes_for_entries; bytes_processed < bytes_for_entries;
bytes_processed += lbrec->size) bytes_processed += lbrec->size) {
{ lbrec = (const struct lb_record *) &p[bytes_processed]; lbrec = (const struct lb_record *)&p[bytes_processed];
if (lbrec->tag == tag) if (lbrec->tag == tag)
return lbrec; 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, static const struct lb_record *next_cmos_rec(const struct lb_record *last,
uint32_t tag) uint32_t tag)
{ const char *p; {
const char *p;
uint32_t bytes_processed, bytes_for_entries, last_offset; uint32_t bytes_processed, bytes_for_entries, last_offset;
const struct lb_record *lbrec; 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; for (bytes_processed = last_offset + last->size;
bytes_processed < bytes_for_entries; bytes_processed < bytes_for_entries;
bytes_processed += lbrec->size) bytes_processed += lbrec->size) {
{ lbrec = (const struct lb_record *) &p[bytes_processed]; lbrec = (const struct lb_record *)&p[bytes_processed];
if (lbrec->tag == tag) if (lbrec->tag == tag)
return lbrec; 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. * Display function for 'memory' item of coreboot table.
****************************************************************************/ ****************************************************************************/
static void memory_print_fn(const struct lb_record *rec) 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 struct lb_memory *p;
const char *mem_type; const char *mem_type;
const struct lb_memory_range *ranges; 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]); entries = (p->size - sizeof(*p)) / sizeof(p->map[0]);
ranges = p->map; ranges = p->map;
if (entries == 0) if (entries == 0) {
{ printf("No memory ranges were found.\n"); printf("No memory ranges were found.\n");
return; return;
} }
for (i = 0; ; ) for (i = 0;;) {
{ switch (ranges[i].type) switch (ranges[i].type) {
{ case LB_MEM_RAM: case LB_MEM_RAM:
mem_type = "AVAILABLE"; mem_type = "AVAILABLE";
break; break;
@ -1085,13 +1097,13 @@ static void memory_print_fn (const struct lb_record *rec)
* Display function for 'mainboard' item of coreboot table. * Display function for 'mainboard' item of coreboot table.
****************************************************************************/ ****************************************************************************/
static void mainboard_print_fn(const struct lb_record *rec) 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; p = (const struct lb_mainboard *)rec;
printf("Vendor: %s\n" printf("Vendor: %s\n"
"Part number: %s\n", "Part number: %s\n",
&p->strings[p->vendor_idx], &p->strings[p->vendor_idx], &p->strings[p->part_number_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, vtophys(p), p->tag, p->tag, p->size, p->size, p->header_length,
p->header_length); p->header_length);
if (p->header_length > p->size) if (p->header_length > p->size) {
{ printf("Header length for CMOS option table is greater than the size " printf
("Header length for CMOS option table is greater than the size "
"of the entire table including header!!!\n"); "of the entire table including header!!!\n");
return; return;
} }
if (bytes_for_entries == 0) if (bytes_for_entries == 0) {
{ printf("The CMOS option table is empty!!!\n"); printf("The CMOS option table is empty!!!\n");
return; return;
} }
for (bytes_processed = 0; ; ) for (bytes_processed = 0;;) {
{ cmos_item = (const struct lb_record *) &q[bytes_processed]; cmos_item = (const struct lb_record *)&q[bytes_processed];
switch (cmos_item->tag) switch (cmos_item->tag) {
{ case LB_TAG_OPTION: case LB_TAG_OPTION:
print_option_record((const struct cmos_entries *) cmos_item); print_option_record((const struct cmos_entries *)
cmos_item);
break; break;
case LB_TAG_OPTION_ENUM: case LB_TAG_OPTION_ENUM:
@ -1141,7 +1155,8 @@ static void cmos_opt_table_print_fn (const struct lb_record *rec)
break; break;
case LB_TAG_OPTION_DEFAULTS: case LB_TAG_OPTION_DEFAULTS:
print_defaults_record((const struct cmos_defaults *) cmos_item); print_defaults_record((const struct cmos_defaults *)
cmos_item);
break; break;
default: default:
@ -1164,11 +1179,12 @@ static void cmos_opt_table_print_fn (const struct lb_record *rec)
* Display "option" record from CMOS option table. * Display "option" record from CMOS option table.
****************************************************************************/ ****************************************************************************/
static void print_option_record(const struct cmos_entries *cmos_entry) 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]; char s[S_BUFSIZE];
switch (cmos_entry->config) switch (cmos_entry->config) {
{ case 'e': case 'e':
strcpy(s, "ENUM"); strcpy(s, "ENUM");
break; break;
@ -1206,15 +1222,17 @@ static void print_option_record (const struct cmos_entries *cmos_entry)
* Display "enum" record from CMOS option table. * Display "enum" record from CMOS option table.
****************************************************************************/ ****************************************************************************/
static void print_enum_record(const struct cmos_enums *cmos_enum) 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" " tag: 0x%x (decimal: %d)\n"
" size: 0x%x (decimal: %d)\n" " size: 0x%x (decimal: %d)\n"
" config_id: 0x%x (decimal: %d)\n" " config_id: 0x%x (decimal: %d)\n"
" value: 0x%x (decimal: %d)\n" " value: 0x%x (decimal: %d)\n"
" text: %s\n", " text: %s\n",
vtophys(cmos_enum), cmos_enum->tag, cmos_enum->tag, cmos_enum->size, vtophys(cmos_enum), cmos_enum->tag, cmos_enum->tag,
cmos_enum->size, cmos_enum->config_id, cmos_enum->config_id, cmos_enum->size, cmos_enum->size, cmos_enum->config_id,
cmos_enum->value, cmos_enum->value, cmos_enum->text); 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. * Display "defaults" record from CMOS option table.
****************************************************************************/ ****************************************************************************/
static void print_defaults_record(const struct cmos_defaults *cmos_defaults) 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" " tag: 0x%x (decimal: %d)\n"
" size: 0x%x (decimal: %d)\n" " size: 0x%x (decimal: %d)\n"
" name_length: 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. * Display record of unknown type from CMOS option table.
****************************************************************************/ ****************************************************************************/
static void print_unknown_record(const struct lb_record *cmos_item) 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" printf(" UNKNOWN record at physical address 0x%lx:\n"
" tag: 0x%x (decimal: %d)\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, vtophys(cmos_item), cmos_item->tag, cmos_item->tag,
cmos_item->size, cmos_item->size); cmos_item->size, cmos_item->size);
data = ((const char *)cmos_item) + sizeof(*cmos_item); data = ((const char *)cmos_item) + sizeof(*cmos_item);
hexdump(data, cmos_item->size - sizeof(*cmos_item), vtophys(data), stdout, hexdump(data, cmos_item->size - sizeof(*cmos_item), vtophys(data),
&format); 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. * Display function for 'option_checksum' item of coreboot table.
****************************************************************************/ ****************************************************************************/
static void option_checksum_print_fn(const struct lb_record *rec) static void option_checksum_print_fn(const struct lb_record *rec)
{ struct cmos_checksum *p; {
struct cmos_checksum *p;
p = (struct cmos_checksum *)rec; p = (struct cmos_checksum *)rec;
printf("CMOS checksum from bit %d to bit %d\n" 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. * consists of a string.
****************************************************************************/ ****************************************************************************/
static void string_print_fn(const struct lb_record *rec) 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; p = (const struct lb_string *)rec;
printf("%s\n", p->string); printf("%s\n", p->string);
@ -1294,7 +1316,8 @@ static void string_print_fn (const struct lb_record *rec)
* will be displayed as "0x0000000000000001"). * will be displayed as "0x0000000000000001").
****************************************************************************/ ****************************************************************************/
static void uint64_to_hex_string(char str[], uint64_t n) static void uint64_to_hex_string(char str[], uint64_t n)
{ int chars_printed; {
int chars_printed;
str[0] = '0'; str[0] = '0';
str[1] = 'x'; 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 list_param_enums(const char name[]);
static void set_one_param(const char name[], const char value[]); static void set_one_param(const char name[], const char value[]);
static void set_params(FILE * f); static void set_params(FILE * f);
static void parse_assignment (char arg[], const char **name, static void parse_assignment(char arg[], const char **name, const char **value);
const char **value);
static int list_cmos_entry(const cmos_entry_t * e, int show_name); static int list_cmos_entry(const cmos_entry_t * e, int show_name);
static uint16_t convert_checksum_value(const char value[]); static uint16_t convert_checksum_value(const char value[]);
static const op_fn_t op_fns[] = static const op_fn_t op_fns[] = { op_show_version,
{ op_show_version,
op_show_usage, op_show_usage,
op_lbtable_show_info, op_lbtable_show_info,
op_lbtable_dump, op_lbtable_dump,
@ -93,16 +91,16 @@ static const hexdump_format_t cmos_dump_format =
* main * main
****************************************************************************/ ****************************************************************************/
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ cmos_layout_get_fn_t fn; {
cmos_layout_get_fn_t fn;
parse_nvramtool_args(argc, argv); parse_nvramtool_args(argc, argv);
if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found) if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found) {
{ set_layout_filename( set_layout_filename(nvramtool_op_modifiers
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].param); [NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].param);
fn = get_layout_from_file; fn = get_layout_from_file;
} } else
else
fn = get_layout_from_cmos_table; fn = get_layout_from_cmos_table;
register_cmos_layout_get_fn(fn); register_cmos_layout_get_fn(fn);
@ -118,7 +116,9 @@ int main (int argc, char *argv[])
* Show version information for this program. * Show version information for this program.
****************************************************************************/ ****************************************************************************/
static void op_show_version(void) 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 * op_show_usage
@ -128,7 +128,9 @@ static void op_show_version (void)
* Show a usage message for this program. * Show a usage message for this program.
****************************************************************************/ ****************************************************************************/
static void op_show_usage(void) static void op_show_usage(void)
{ usage(stdout); } {
usage(stdout);
}
/**************************************************************************** /****************************************************************************
* op_lbtable_show_info * op_lbtable_show_info
@ -139,10 +141,11 @@ static void op_show_usage (void)
* Else show all possible values for ARG. * Else show all possible values for ARG.
****************************************************************************/ ****************************************************************************/
static void op_lbtable_show_info(void) static void op_lbtable_show_info(void)
{ if (nvramtool_op.param == NULL) {
if (nvramtool_op.param == NULL)
list_lbtable_choices(); list_lbtable_choices();
else else {
{ get_lbtable(); get_lbtable();
list_lbtable_item(nvramtool_op.param); list_lbtable_item(nvramtool_op.param);
} }
} }
@ -155,7 +158,8 @@ static void op_lbtable_show_info (void)
* Do low-level dump of coreboot table. * Do low-level dump of coreboot table.
****************************************************************************/ ****************************************************************************/
static void op_lbtable_dump(void) static void op_lbtable_dump(void)
{ get_lbtable(); {
get_lbtable();
dump_lbtable(); dump_lbtable();
} }
@ -167,7 +171,8 @@ static void op_lbtable_dump (void)
* Show all possible values for parameter NAME. * Show all possible values for parameter NAME.
****************************************************************************/ ****************************************************************************/
static void op_show_param_values(void) static void op_show_param_values(void)
{ get_cmos_layout(); {
get_cmos_layout();
list_param_enums(nvramtool_op.param); list_param_enums(nvramtool_op.param);
} }
@ -180,11 +185,13 @@ static void op_show_param_values (void)
* and value. * and value.
****************************************************************************/ ****************************************************************************/
static void op_cmos_show_one_param(void) static void op_cmos_show_one_param(void)
{ int result; {
int result;
get_cmos_layout(); get_cmos_layout();
result = list_one_param(nvramtool_op.param, 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(); cmos_checksum_verify();
if (result) if (result)
@ -199,7 +206,8 @@ static void op_cmos_show_one_param (void)
* Show names and values for all parameters. * Show names and values for all parameters.
****************************************************************************/ ****************************************************************************/
static void op_cmos_show_all_params(void) static void op_cmos_show_all_params(void)
{ int result; {
int result;
get_cmos_layout(); get_cmos_layout();
result = list_all_params(); result = list_all_params();
@ -217,7 +225,8 @@ static void op_cmos_show_all_params (void)
* Set parameter NAME to VALUE. * Set parameter NAME to VALUE.
****************************************************************************/ ****************************************************************************/
static void op_cmos_set_one_param(void) static void op_cmos_set_one_param(void)
{ const char *name, *value; {
const char *name, *value;
get_cmos_layout(); get_cmos_layout();
@ -237,7 +246,8 @@ static void op_cmos_set_one_param (void)
* Set parameters according to standard input. * Set parameters according to standard input.
****************************************************************************/ ****************************************************************************/
static void op_cmos_set_params_stdin(void) static void op_cmos_set_params_stdin(void)
{ get_cmos_layout(); {
get_cmos_layout();
set_params(stdin); set_params(stdin);
} }
@ -249,10 +259,11 @@ static void op_cmos_set_params_stdin (void)
* Set parameters according to INPUT_FILE. * Set parameters according to INPUT_FILE.
****************************************************************************/ ****************************************************************************/
static void op_cmos_set_params_file(void) static void op_cmos_set_params_file(void)
{ FILE *f; {
FILE *f;
if ((f = fopen(nvramtool_op.param, "r")) == NULL) if ((f = fopen(nvramtool_op.param, "r")) == NULL) {
{ fprintf(stderr, "%s: Can not open file %s for reading: %s\n", fprintf(stderr, "%s: Can not open file %s for reading: %s\n",
prog_name, nvramtool_op.param, strerror(errno)); prog_name, nvramtool_op.param, strerror(errno));
exit(1); exit(1);
} }
@ -271,18 +282,18 @@ static void op_cmos_set_params_file (void)
* checksum value. * checksum value.
****************************************************************************/ ****************************************************************************/
static void op_cmos_checksum(void) static void op_cmos_checksum(void)
{ uint16_t checksum; {
uint16_t checksum;
get_cmos_layout(); get_cmos_layout();
if (nvramtool_op.param == NULL) if (nvramtool_op.param == NULL) {
{ set_iopl(3); set_iopl(3);
checksum = cmos_checksum_read(); checksum = cmos_checksum_read();
set_iopl(0); set_iopl(0);
printf("0x%x\n", checksum); printf("0x%x\n", checksum);
} } else {
else checksum = convert_checksum_value(nvramtool_op.param);
{ checksum = convert_checksum_value(nvramtool_op.param);
set_iopl(3); set_iopl(3);
cmos_checksum_write(checksum); cmos_checksum_write(checksum);
set_iopl(0); set_iopl(0);
@ -297,7 +308,8 @@ static void op_cmos_checksum (void)
* Write CMOS layout information to standard output. * Write CMOS layout information to standard output.
****************************************************************************/ ****************************************************************************/
static void op_show_layout(void) static void op_show_layout(void)
{ get_cmos_layout(); {
get_cmos_layout();
write_cmos_layout(stdout); write_cmos_layout(stdout);
} }
@ -309,11 +321,12 @@ static void op_show_layout (void)
* Write the contents of CMOS memory to a binary file. * Write the contents of CMOS memory to a binary file.
****************************************************************************/ ****************************************************************************/
static void op_write_cmos_dump(void) static void op_write_cmos_dump(void)
{ unsigned char data[CMOS_SIZE]; {
unsigned char data[CMOS_SIZE];
FILE *f; FILE *f;
if ((f = fopen(nvramtool_op.param, "w")) == NULL) if ((f = fopen(nvramtool_op.param, "w")) == NULL) {
{ fprintf(stderr, "%s: Can not open file %s for writing: %s\n", fprintf(stderr, "%s: Can not open file %s for writing: %s\n",
prog_name, nvramtool_op.param, strerror(errno)); prog_name, nvramtool_op.param, strerror(errno));
exit(1); exit(1);
} }
@ -322,8 +335,8 @@ static void op_write_cmos_dump (void)
cmos_read_all(data); cmos_read_all(data);
set_iopl(0); set_iopl(0);
if (fwrite(data, 1, CMOS_SIZE, f) != CMOS_SIZE) if (fwrite(data, 1, CMOS_SIZE, f) != CMOS_SIZE) {
{ fprintf(stderr, "%s: Error writing CMOS data to file %s: %s\n", fprintf(stderr, "%s: Error writing CMOS data to file %s: %s\n",
prog_name, nvramtool_op.param, strerror(errno)); prog_name, nvramtool_op.param, strerror(errno));
exit(1); 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. * Read binary data from a file and write the data to CMOS memory.
****************************************************************************/ ****************************************************************************/
static void op_read_cmos_dump(void) static void op_read_cmos_dump(void)
{ unsigned char data[CMOS_SIZE]; {
unsigned char data[CMOS_SIZE];
size_t nr_bytes; size_t nr_bytes;
FILE *f; FILE *f;
if ((f = fopen(nvramtool_op.param, "r")) == NULL) if ((f = fopen(nvramtool_op.param, "r")) == NULL) {
{ fprintf(stderr, "%s: Can not open file %s for reading: %s\n", fprintf(stderr, "%s: Can not open file %s for reading: %s\n",
prog_name, nvramtool_op.param, strerror(errno)); prog_name, nvramtool_op.param, strerror(errno));
exit(1); exit(1);
} }
if ((nr_bytes = fread(data, 1, CMOS_SIZE, f)) != CMOS_SIZE) if ((nr_bytes = fread(data, 1, CMOS_SIZE, f)) != CMOS_SIZE) {
{ fprintf(stderr, "%s: Error: Only able to read %d bytes of CMOS data " fprintf(stderr,
"%s: Error: Only able to read %d bytes of CMOS data "
"from file %s. CMOS data is unchanged.\n", prog_name, "from file %s. CMOS data is unchanged.\n", prog_name,
(int)nr_bytes, nvramtool_op.param); (int)nr_bytes, nvramtool_op.param);
exit(1); exit(1);
@ -370,7 +385,8 @@ static void op_read_cmos_dump (void)
* Write a hex dump of CMOS memory to standard output. * Write a hex dump of CMOS memory to standard output.
****************************************************************************/ ****************************************************************************/
static void op_show_cmos_hex_dump(void) static void op_show_cmos_hex_dump(void)
{ unsigned char data[CMOS_SIZE]; {
unsigned char data[CMOS_SIZE];
set_iopl(3); set_iopl(3);
cmos_read_all(data); 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. * hex dump of the CMOS data from the file.
****************************************************************************/ ****************************************************************************/
static void op_show_cmos_dumpfile(void) static void op_show_cmos_dumpfile(void)
{ unsigned char data[CMOS_SIZE]; {
unsigned char data[CMOS_SIZE];
size_t nr_bytes; size_t nr_bytes;
FILE *f; FILE *f;
if ((f = fopen(nvramtool_op.param, "r")) == NULL) if ((f = fopen(nvramtool_op.param, "r")) == NULL) {
{ fprintf(stderr, "%s: Can not open file %s for reading: %s\n", fprintf(stderr, "%s: Can not open file %s for reading: %s\n",
prog_name, nvramtool_op.param, strerror(errno)); prog_name, nvramtool_op.param, strerror(errno));
exit(1); 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. * along with its value. Return 1 if error was encountered. Else return OK.
****************************************************************************/ ****************************************************************************/
static int list_one_param(const char name[], int show_name) 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)) if (is_checksum_name(name) || ((e = find_cmos_entry(name)) == NULL)) {
{ fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name, name); fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name,
name);
exit(1); exit(1);
} }
if (e->config == CMOS_ENTRY_RESERVED) if (e->config == CMOS_ENTRY_RESERVED) {
{ fprintf(stderr, "%s: Parameter %s is reserved.\n", prog_name, name); fprintf(stderr, "%s: Parameter %s is reserved.\n", prog_name,
name);
exit(1); exit(1);
} }
@ -432,13 +452,15 @@ static int list_one_param (const char name[], int show_name)
* Else return OK. * Else return OK.
****************************************************************************/ ****************************************************************************/
static int list_all_params(void) static int list_all_params(void)
{ const cmos_entry_t *e; {
const cmos_entry_t *e;
int result; int result;
result = OK; result = OK;
for (e = first_cmos_entry(); e != NULL; e = next_cmos_entry(e)) for (e = first_cmos_entry(); e != NULL; e = next_cmos_entry(e)) {
{ if ((e->config == CMOS_ENTRY_RESERVED) || is_checksum_name(e->name)) if ((e->config == CMOS_ENTRY_RESERVED)
|| is_checksum_name(e->name))
continue; continue;
if (list_cmos_entry(e, TRUE)) 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'. * List all possible values for CMOS parameter given by 'name'.
****************************************************************************/ ****************************************************************************/
static void list_param_enums(const char name[]) static void list_param_enums(const char name[])
{ const cmos_entry_t *e; {
const cmos_entry_t *e;
const cmos_enum_t *p; const cmos_enum_t *p;
if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL) if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL) {
{ fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name, name); fprintf(stderr, "%s: CMOS parameter %s not found.\n", prog_name,
name);
exit(1); exit(1);
} }
switch (e->config) switch (e->config) {
{ case CMOS_ENTRY_ENUM: case CMOS_ENTRY_ENUM:
for (p = first_cmos_enum_id(e->config_id); for (p = first_cmos_enum_id(e->config_id);
p != NULL; p != NULL; p = next_cmos_enum_id(p))
p = next_cmos_enum_id(p))
printf("%s\n", p->text); printf("%s\n", p->text);
break; break;
case CMOS_ENTRY_HEX: case CMOS_ENTRY_HEX:
printf("Parameter %s requires a %u-bit unsigned integer.\n", name, printf("Parameter %s requires a %u-bit unsigned integer.\n",
e->length); name, e->length);
break; break;
case CMOS_ENTRY_STRING: case CMOS_ENTRY_STRING:
@ -501,20 +524,23 @@ static void list_param_enums (const char name[])
* decimal, hex, or octal. * decimal, hex, or octal.
****************************************************************************/ ****************************************************************************/
static void set_one_param(const char name[], const char value[]) 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; unsigned long long n;
if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL) if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL) {
{ fprintf(stderr, "%s: CMOS parameter %s not found.", prog_name, name); fprintf(stderr, "%s: CMOS parameter %s not found.", prog_name,
name);
exit(1); exit(1);
} }
switch (prepare_cmos_write(e, value, &n)) switch (prepare_cmos_write(e, value, &n)) {
{ case OK: case OK:
break; break;
case CMOS_OP_BAD_ENUM_VALUE: 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; goto fail;
case CMOS_OP_NEGATIVE_INT: case CMOS_OP_NEGATIVE_INT:
@ -524,7 +550,8 @@ static void set_one_param (const char name[], const char value[])
goto fail; goto fail;
case CMOS_OP_INVALID_INT: 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; goto fail;
case CMOS_OP_RESERVED: 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: case CMOS_OP_VALUE_TOO_WIDE:
fprintf(stderr, fprintf(stderr,
"%s: Can not write value %s to CMOS parameter %s that is " "%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; goto fail;
case CMOS_OP_NO_MATCHING_ENUM: 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: case CMOS_AREA_OUT_OF_RANGE:
fprintf(stderr, fprintf(stderr,
"%s: The CMOS area specified by the layout info for " "%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; goto fail;
case CMOS_AREA_OVERLAPS_RTC: 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: case CMOS_AREA_TOO_WIDE:
fprintf(stderr, fprintf(stderr,
"%s: The CMOS area specified by the layout info for " "%s: The CMOS area specified by the layout info for "
"coreboot parameter %s is too wide.", "coreboot parameter %s is too wide.", prog_name, name);
prog_name, name);
goto fail; goto fail;
default: default:
@ -606,9 +634,9 @@ static void set_params (FILE *f)
* into substrings representing NAME and VALUE, and *name and *value are set * into substrings representing NAME and VALUE, and *name and *value are set
* to point to these two substrings. * to point to these two substrings.
****************************************************************************/ ****************************************************************************/
static void parse_assignment (char arg[], const char **name, static void parse_assignment(char arg[], const char **name, const char **value)
const char **value) {
{ static const size_t N_MATCHES = 4; static const size_t N_MATCHES = 4;
regmatch_t match[N_MATCHES]; regmatch_t match[N_MATCHES];
regex_t assignment; regex_t assignment;
@ -641,37 +669,42 @@ static void parse_assignment (char arg[], const char **name,
* message and return 1. * message and return 1.
****************************************************************************/ ****************************************************************************/
static int list_cmos_entry(const cmos_entry_t * e, int show_name) 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; unsigned long long value;
/* sanity check CMOS entry */ /* sanity check CMOS entry */
switch (prepare_cmos_read(e)) switch (prepare_cmos_read(e)) {
{ case OK: case OK:
break; break;
case CMOS_OP_RESERVED: case CMOS_OP_RESERVED:
BUG(); BUG();
case CMOS_AREA_OUT_OF_RANGE: case CMOS_AREA_OUT_OF_RANGE:
fprintf(stderr, "%s: Can not read coreboot parameter %s because " fprintf(stderr,
"layout info specifies out of range CMOS area.\n", prog_name, "%s: Can not read coreboot parameter %s because "
e->name); "layout info specifies out of range CMOS area.\n",
prog_name, e->name);
return 1; return 1;
case CMOS_AREA_OVERLAPS_RTC: 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 " "layout info specifies CMOS area that overlaps realtime "
"clock area.\n", prog_name, e->name); "clock area.\n", prog_name, e->name);
return 1; return 1;
case CMOS_AREA_TOO_WIDE: 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", "layout info specifies CMOS area that is too wide.\n",
prog_name, e->name); prog_name, e->name);
return 1; return 1;
default: 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); "read coreboot parameter %s\n", prog_name, e->name);
return 1; return 1;
} }
@ -682,16 +715,16 @@ static int list_cmos_entry (const cmos_entry_t *e, int show_name)
set_iopl(0); set_iopl(0);
/* display the value */ /* display the value */
switch (e->config) switch (e->config) {
{ case CMOS_ENTRY_ENUM: case CMOS_ENTRY_ENUM:
if ((p = find_cmos_enum(e->config_id, value)) == NULL) if ((p = find_cmos_enum(e->config_id, value)) == NULL) {
{ if (show_name) if (show_name)
printf("# Bad value -> %s = 0x%llx\n", e->name, value); printf("# Bad value -> %s = 0x%llx\n", e->name,
value);
else else
printf("Bad value -> 0x%llx\n", value); printf("Bad value -> 0x%llx\n", value);
} } else {
else if (show_name)
{ if (show_name)
printf("%s = %s\n", e->name, p->text); printf("%s = %s\n", e->name, p->text);
else else
printf("%s\n", p->text); 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: case CMOS_ENTRY_STRING:
if (show_name) if (show_name)
printf("%s = %s\n", e->name, (char *)(unsigned long)value); printf("%s = %s\n", e->name,
(char *)(unsigned long)value);
else else
printf("%s\n", (char *)(unsigned long)value); 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. * 'value' is invalid.
****************************************************************************/ ****************************************************************************/
static uint16_t convert_checksum_value(const char value[]) static uint16_t convert_checksum_value(const char value[])
{ unsigned long n; {
unsigned long n;
const char *p; const char *p;
uint16_t result; uint16_t result;
int negative; int negative;
@ -744,23 +779,26 @@ static uint16_t convert_checksum_value (const char value[])
negative = (*p == '-'); negative = (*p == '-');
n = strtoul(value, (char **)&p, 0); n = strtoul(value, (char **)&p, 0);
if (*p) if (*p) {
{ fprintf(stderr, "%s: Checksum value %s is not a valid integer.\n", fprintf(stderr,
"%s: Checksum value %s is not a valid integer.\n",
prog_name, value); prog_name, value);
exit(1); exit(1);
} }
if (negative) if (negative) {
{ fprintf(stderr, fprintf(stderr,
"%s: Checksum must be an unsigned integer.\n", prog_name); "%s: Checksum must be an unsigned integer.\n",
prog_name);
exit(1); exit(1);
} }
result = (uint16_t) n; result = (uint16_t) n;
if (result != n) if (result != n) {
{ fprintf(stderr, fprintf(stderr,
"%s: Checksum value must fit within 16 bits.\n", prog_name); "%s: Checksum value must fit within 16 bits.\n",
prog_name);
exit(1); 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. * Parse command line arguments.
****************************************************************************/ ****************************************************************************/
void parse_nvramtool_args(int argc, char *argv[]) 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; int i, op_found;
char c; char c;
for (i = 0, mod_info = nvramtool_op_modifiers; for (i = 0, mod_info = nvramtool_op_modifiers;
i < NVRAMTOOL_NUM_OP_MODIFIERS; i < NVRAMTOOL_NUM_OP_MODIFIERS; i++, mod_info++) {
i++, mod_info++) mod_info->found = FALSE;
{ mod_info->found = FALSE;
mod_info->found_seq = 0; mod_info->found_seq = 0;
mod_info->param = NULL; mod_info->param = NULL;
} }
@ -64,16 +64,19 @@ void parse_nvramtool_args (int argc, char *argv[])
op_found = FALSE; op_found = FALSE;
opterr = 0; opterr = 0;
do do {
{ switch (c = getopt(argc, argv, getopt_string)) switch (c = getopt(argc, argv, getopt_string)) {
{ case 'a': case 'a':
register_op(&op_found, NVRAMTOOL_OP_CMOS_SHOW_ALL_PARAMS, NULL); register_op(&op_found,
NVRAMTOOL_OP_CMOS_SHOW_ALL_PARAMS, NULL);
break; break;
case 'b': case 'b':
register_op(&op_found, NVRAMTOOL_OP_WRITE_CMOS_DUMP, optarg); register_op(&op_found, NVRAMTOOL_OP_WRITE_CMOS_DUMP,
optarg);
break; break;
case 'B': case 'B':
register_op(&op_found, NVRAMTOOL_OP_READ_CMOS_DUMP, optarg); register_op(&op_found, NVRAMTOOL_OP_READ_CMOS_DUMP,
optarg);
break; break;
case 'c': case 'c':
register_op(&op_found, NVRAMTOOL_OP_CMOS_CHECKSUM, 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); register_op(&op_found, NVRAMTOOL_OP_LBTABLE_DUMP, NULL);
break; break;
case 'e': case 'e':
register_op(&op_found, NVRAMTOOL_OP_SHOW_PARAM_VALUES, optarg); register_op(&op_found, NVRAMTOOL_OP_SHOW_PARAM_VALUES,
optarg);
break; break;
case 'h': case 'h':
register_op(&op_found, NVRAMTOOL_OP_SHOW_USAGE, NULL); register_op(&op_found, NVRAMTOOL_OP_SHOW_USAGE, NULL);
break; break;
case 'i': 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; break;
case 'l': case 'l':
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_SHOW_INFO, register_op(&op_found, NVRAMTOOL_OP_LBTABLE_SHOW_INFO,
handle_optional_arg(argc, argv)); handle_optional_arg(argc, argv));
break; break;
case 'n': case 'n':
register_op_modifier(NVRAMTOOL_MOD_SHOW_VALUE_ONLY, NULL); register_op_modifier(NVRAMTOOL_MOD_SHOW_VALUE_ONLY,
NULL);
break; break;
case 'p': 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; break;
case 'r': 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; break;
case 't': case 't':
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE, NULL); register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE,
NULL);
break; break;
case 'v': case 'v':
register_op(&op_found, NVRAMTOOL_OP_SHOW_VERSION, NULL); register_op(&op_found, NVRAMTOOL_OP_SHOW_VERSION, NULL);
break; break;
case 'w': 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; break;
case 'x': 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; break;
case 'X': case 'X':
register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE, optarg); register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE,
optarg);
break; break;
case 'y': case 'y':
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE, optarg); register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE,
optarg);
break; break;
case 'Y': case 'Y':
register_op(&op_found, NVRAMTOOL_OP_SHOW_LAYOUT, NULL); register_op(&op_found, NVRAMTOOL_OP_SHOW_LAYOUT, NULL);
@ -133,8 +146,7 @@ void parse_nvramtool_args (int argc, char *argv[])
usage(stderr); usage(stderr);
break; break;
} }
} } while (c != -1);
while (c != -1);
if (!op_found) if (!op_found)
usage(stderr); usage(stderr);
@ -149,12 +161,14 @@ void parse_nvramtool_args (int argc, char *argv[])
* Handle a command line option with an optional argument. * Handle a command line option with an optional argument.
****************************************************************************/ ****************************************************************************/
static char *handle_optional_arg(int argc, char *argv[]) static char *handle_optional_arg(int argc, char *argv[])
{ char *arg; {
char *arg;
if (optarg != NULL) if (optarg != NULL) {
{ /* optional arg is present and arg was specified as "-zarg" (with no /* optional arg is present and arg was specified as
* whitespace between "z" and "arg"), where -z is the option and "arg" * "-zarg" (with no whitespace between "z" and "arg"),
* is the value of the optional arg * where -z is the option and "arg" is the value of the
* optional arg
*/ */
return optarg; return optarg;
} }
@ -164,8 +178,8 @@ static char * handle_optional_arg (int argc, char *argv[])
arg = argv[optind]; /* optional arg is present */ arg = argv[optind]; /* optional arg is present */
/* This call to getopt yields the optional arg we just found, which we want /* This call to getopt yields the optional arg we just found,
* to skip. * which we want to skip.
*/ */
getopt(argc, argv, getopt_string); 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. * 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[]) 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); usage(stderr);
*op_found = TRUE; *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. * 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 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; nvramtool_op_modifier_info_t *mod_info;
mod_info = &nvramtool_op_modifiers[mod]; 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. * the last specified argument overrides previous conflicting arguments.
****************************************************************************/ ****************************************************************************/
static void resolve_op_modifiers(void) 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 &&
{ if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found_seq > 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_seq)
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found = FALSE; nvramtool_op_modifiers
[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found = FALSE;
else 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. * Perform sanity checking on command line arguments.
****************************************************************************/ ****************************************************************************/
static void sanity_check_args(void) 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)) (nvramtool_op.op != NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM))
usage(stderr); usage(stderr);
} }

View File

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

View File

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