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:
committed by
Stefan Reinauer
parent
766db7ea09
commit
90b96b68e0
@ -36,21 +36,20 @@
|
|||||||
#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);
|
||||||
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);
|
||||||
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);
|
||||||
static unsigned char get_bits (unsigned long long value, unsigned bit,
|
static unsigned char get_bits(unsigned long long value, unsigned bit,
|
||||||
unsigned nr_bits);
|
unsigned nr_bits);
|
||||||
static void put_bits (unsigned char value, unsigned bit, unsigned nr_bits,
|
static void put_bits(unsigned char value, unsigned bit, unsigned nr_bits,
|
||||||
unsigned long long *result);
|
unsigned long long *result);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -59,9 +58,11 @@ static void put_bits (unsigned char value, unsigned bit, unsigned nr_bits,
|
|||||||
* Extract a value 'nr_bits' bits wide starting at bit position 'bit' from
|
* Extract a value 'nr_bits' bits wide starting at bit position 'bit' from
|
||||||
* 'value' and return the result. It is assumed that 'nr_bits' is at most 8.
|
* 'value' and return the result. It is assumed that 'nr_bits' is at most 8.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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
|
||||||
@ -71,9 +72,12 @@ static inline unsigned char get_bits (unsigned long long value, unsigned bit,
|
|||||||
* positions in 'result' where the result is stored are assumed to be
|
* positions in 'result' where the result is stored are assumed to be
|
||||||
* initially zero.
|
* initially zero.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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
|
||||||
@ -82,9 +86,10 @@ static inline void put_bits (unsigned char value, unsigned bit,
|
|||||||
* and return this value. The I/O privilege level of the currently executing
|
* and return this value. The I/O privilege level of the currently executing
|
||||||
* 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;
|
{
|
||||||
unsigned bit = e->bit, length=e->length;
|
cmos_bit_op_location_t where;
|
||||||
|
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;
|
||||||
unsigned char value;
|
unsigned char value;
|
||||||
@ -92,33 +97,37 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_write
|
* cmos_write
|
||||||
@ -127,34 +136,38 @@ unsigned long long cmos_read (const cmos_entry_t *e)
|
|||||||
* The I/O privilege level of the currently executing process must be set
|
* The I/O privilege level of the currently executing process must be set
|
||||||
* 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;
|
{
|
||||||
unsigned bit = e->bit, length=e->length;
|
cmos_bit_op_location_t where;
|
||||||
|
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,
|
||||||
value = data[next_bit/usize];
|
&where);
|
||||||
cmos_write_bits(&where, nr_bits, get_bits(value, next_bit % usize, nr_bits));
|
value = data[next_bit / usize];
|
||||||
}
|
cmos_write_bits(&where, nr_bits,
|
||||||
}
|
get_bits(value, next_bit % usize, nr_bits));
|
||||||
else
|
}
|
||||||
{ for (next_bit = 0, bits_left = length;
|
} else {
|
||||||
bits_left;
|
for (next_bit = 0, bits_left = length;
|
||||||
next_bit += nr_bits, bits_left -= nr_bits)
|
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
|
||||||
{ nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left, &where);
|
nr_bits = cmos_bit_op_strategy(bit + next_bit,
|
||||||
cmos_write_bits(&where, nr_bits, get_bits(value, next_bit, nr_bits));
|
bits_left, &where);
|
||||||
}
|
cmos_write_bits(&where, nr_bits,
|
||||||
|
get_bits(value, next_bit, nr_bits));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_read_byte
|
* cmos_read_byte
|
||||||
@ -166,23 +179,23 @@ void cmos_write (const cmos_entry_t *e, unsigned long long value)
|
|||||||
* Note: the first 14 bytes of nonvolatile RAM provide an interface to the
|
* Note: the first 14 bytes of nonvolatile RAM provide an interface to the
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTB(index, port_0);
|
OUTB(index, port_0);
|
||||||
return INB(port_1);
|
return INB(port_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_write_byte
|
* cmos_write_byte
|
||||||
@ -194,23 +207,23 @@ unsigned char cmos_read_byte (unsigned index)
|
|||||||
* real time clock. Writing to any of these bytes will therefore
|
* real time clock. Writing to any of these bytes will therefore
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTB(index, port_0);
|
OUTB(index, port_0);
|
||||||
OUTB(value, port_1);
|
OUTB(value, port_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_read_all
|
* cmos_read_all
|
||||||
@ -218,15 +231,16 @@ void cmos_write_byte (unsigned index, unsigned char value)
|
|||||||
* Read all contents of CMOS memory into array 'data'. The first 14 bytes of
|
* Read all contents of CMOS memory into array 'data'. The first 14 bytes of
|
||||||
* '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;
|
||||||
|
|
||||||
for (; i < CMOS_SIZE; i++)
|
for (; i < CMOS_SIZE; i++)
|
||||||
data[i] = cmos_read_byte(i);
|
data[i] = cmos_read_byte(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_write_all
|
* cmos_write_all
|
||||||
@ -235,12 +249,13 @@ void cmos_read_all (unsigned char data[])
|
|||||||
* bytes of 'data' are ignored since this corresponds to the real time clock
|
* bytes of 'data' are ignored since this corresponds to the real time clock
|
||||||
* 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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* set_iopl
|
* set_iopl
|
||||||
@ -251,8 +266,8 @@ void cmos_write_all (unsigned char data[])
|
|||||||
* interrupts while executing in user space. Messing with the I/O privilege
|
* interrupts while executing in user space. Messing with the I/O privilege
|
||||||
* level is therefore somewhat dangerous.
|
* level is therefore somewhat dangerous.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
void set_iopl (int level)
|
void set_iopl(int level)
|
||||||
{
|
{
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
static int io_fd = -1;
|
static int io_fd = -1;
|
||||||
#endif
|
#endif
|
||||||
@ -260,36 +275,28 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* verify_cmos_op
|
* verify_cmos_op
|
||||||
@ -300,8 +307,9 @@ void set_iopl (int level)
|
|||||||
* wish to read or write. Perform sanity checking on 'bit' and 'length'. If
|
* wish to read or write. Perform sanity checking on 'bit' and 'length'. If
|
||||||
* 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))
|
||||||
@ -314,7 +322,7 @@ int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config)
|
|||||||
return CMOS_AREA_TOO_WIDE;
|
return CMOS_AREA_TOO_WIDE;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_bit_op_strategy
|
* cmos_bit_op_strategy
|
||||||
@ -322,15 +330,16 @@ int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config)
|
|||||||
* Helper function used by cmos_read() and cmos_write() to determine which
|
* Helper function used by cmos_read() and cmos_write() to determine which
|
||||||
* bits to read or write next.
|
* bits to read or write next.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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;
|
||||||
max_bits = 8 - where->bit_offset;
|
max_bits = 8 - where->bit_offset;
|
||||||
return (bits_left > max_bits) ? max_bits : bits_left;
|
return (bits_left > max_bits) ? max_bits : bits_left;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_read_bits
|
* cmos_read_bits
|
||||||
@ -338,11 +347,12 @@ static unsigned cmos_bit_op_strategy (unsigned bit, unsigned bits_left,
|
|||||||
* Read a chunk of bits from a byte location within CMOS memory. Return the
|
* Read a chunk of bits from a byte location within CMOS memory. Return the
|
||||||
* value represented by the chunk of bits.
|
* value represented by the chunk of bits.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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) &
|
{
|
||||||
((unsigned char) ((1 << nr_bits) - 1));
|
return (cmos_read_byte(where->byte_index) >> where->bit_offset) &
|
||||||
}
|
((unsigned char)((1 << nr_bits) - 1));
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_write_bits
|
* cmos_write_bits
|
||||||
@ -350,17 +360,18 @@ static unsigned char cmos_read_bits (const cmos_bit_op_location_t *where,
|
|||||||
* Write a chunk of bits (the low order 'nr_bits' bits of 'value') to an area
|
* Write a chunk of bits (the low order 'nr_bits' bits of 'value') to an area
|
||||||
* within a particular byte of CMOS memory.
|
* within a particular byte of CMOS memory.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = cmos_read_byte(where->byte_index);
|
n = cmos_read_byte(where->byte_index);
|
||||||
mask = ((unsigned char) ((1 << nr_bits) - 1)) << where->bit_offset;
|
mask = ((unsigned char)((1 << nr_bits) - 1)) << where->bit_offset;
|
||||||
n = (n & ~mask) + ((value << where->bit_offset) & mask);
|
n = (n & ~mask) + ((value << where->bit_offset) & mask);
|
||||||
cmos_write_byte(where->byte_index, n);
|
cmos_write_byte(where->byte_index, n);
|
||||||
}
|
}
|
||||||
|
@ -38,14 +38,14 @@
|
|||||||
#define CMOS_AREA_OVERLAPS_RTC (CMOS_RESULT_START + 1)
|
#define CMOS_AREA_OVERLAPS_RTC (CMOS_RESULT_START + 1)
|
||||||
#define CMOS_AREA_TOO_WIDE (CMOS_RESULT_START + 2)
|
#define CMOS_AREA_TOO_WIDE (CMOS_RESULT_START + 2)
|
||||||
|
|
||||||
unsigned long long cmos_read (const cmos_entry_t *e);
|
unsigned long long cmos_read(const cmos_entry_t * e);
|
||||||
void cmos_write (const cmos_entry_t *e, unsigned long long value);
|
void cmos_write(const cmos_entry_t * e, unsigned long long value);
|
||||||
unsigned char cmos_read_byte (unsigned index);
|
unsigned char cmos_read_byte(unsigned index);
|
||||||
void cmos_write_byte (unsigned index, unsigned char value);
|
void cmos_write_byte(unsigned index, unsigned char value);
|
||||||
void cmos_read_all (unsigned char data[]);
|
void cmos_read_all(unsigned char data[]);
|
||||||
void cmos_write_all (unsigned char data[]);
|
void cmos_write_all(unsigned char data[]);
|
||||||
void set_iopl (int level);
|
void set_iopl(int level);
|
||||||
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);
|
||||||
|
|
||||||
#define CMOS_SIZE 256 /* size of CMOS memory in bytes */
|
#define CMOS_SIZE 256 /* size of CMOS memory in bytes */
|
||||||
#define CMOS_RTC_AREA_SIZE 14 /* first 14 bytes control real time clock */
|
#define CMOS_RTC_AREA_SIZE 14 /* first 14 bytes control real time clock */
|
||||||
@ -56,7 +56,9 @@ int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config);
|
|||||||
* Return 1 if 'index' does NOT specify a valid CMOS memory location. Else
|
* Return 1 if 'index' does NOT specify a valid CMOS memory location. Else
|
||||||
* 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 */
|
||||||
|
@ -32,15 +32,16 @@
|
|||||||
#include "cmos_ops.h"
|
#include "cmos_ops.h"
|
||||||
#include "cmos_lowlevel.h"
|
#include "cmos_lowlevel.h"
|
||||||
|
|
||||||
static int prepare_cmos_op_common (const cmos_entry_t *e);
|
static int prepare_cmos_op_common(const cmos_entry_t * e);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* prepare_cmos_op_common
|
* prepare_cmos_op_common
|
||||||
*
|
*
|
||||||
* 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. */
|
||||||
@ -51,7 +52,7 @@ static int prepare_cmos_op_common (const cmos_entry_t *e)
|
|||||||
|
|
||||||
assert(e->length > 0);
|
assert(e->length > 0);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* prepare_cmos_read
|
* prepare_cmos_read
|
||||||
@ -60,14 +61,15 @@ static int prepare_cmos_op_common (const cmos_entry_t *e)
|
|||||||
* sanity checking on 'e'. If a problem was found with e, return an error
|
* sanity checking on 'e'. If a problem was found with e, return an error
|
||||||
* 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;
|
||||||
@ -77,7 +79,7 @@ int prepare_cmos_read (const cmos_entry_t *e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* prepare_cmos_write
|
* prepare_cmos_write
|
||||||
@ -87,9 +89,10 @@ int prepare_cmos_read (const cmos_entry_t *e)
|
|||||||
* checking on 'value_str'. On error, return an error code. Else store the
|
* checking on 'value_str'. On error, return an error code. Else store the
|
||||||
* numeric equivalent of 'value_str' in '*value' and return OK.
|
* numeric equivalent of 'value_str' in '*value' and return OK.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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,20 +122,20 @@ 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 == '-');
|
||||||
|
|
||||||
out = strtoull(value_str, (char **) &p, 0);
|
out = strtoull(value_str, (char **)&p, 0);
|
||||||
|
|
||||||
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,13 +155,12 @@ 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;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_checksum_read
|
* cmos_checksum_read
|
||||||
@ -167,14 +168,15 @@ int prepare_cmos_write (const cmos_entry_t *e, const char value_str[],
|
|||||||
* Read the checksum for the coreboot parameters stored in CMOS and return
|
* Read the checksum for the coreboot parameters stored in CMOS and return
|
||||||
* 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);
|
||||||
lo = cmos_read_byte(cmos_checksum_index + 1);
|
lo = cmos_read_byte(cmos_checksum_index + 1);
|
||||||
return (hi << 8) + lo;
|
return (hi << 8) + lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_checksum_write
|
* cmos_checksum_write
|
||||||
@ -182,15 +184,16 @@ uint16_t cmos_checksum_read (void)
|
|||||||
* Set the checksum for the coreboot parameters stored in CMOS to
|
* Set the checksum for the coreboot parameters stored in CMOS to
|
||||||
* '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);
|
||||||
lo = (unsigned char) (checksum & 0x00ff);
|
lo = (unsigned char)(checksum & 0x00ff);
|
||||||
cmos_write_byte(cmos_checksum_index, hi);
|
cmos_write_byte(cmos_checksum_index, hi);
|
||||||
cmos_write_byte(cmos_checksum_index + 1, lo);
|
cmos_write_byte(cmos_checksum_index + 1, lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_checksum_compute
|
* cmos_checksum_compute
|
||||||
@ -198,8 +201,9 @@ void cmos_checksum_write (uint16_t checksum)
|
|||||||
* Compute a checksum for the coreboot parameter values currently stored in
|
* Compute a checksum for the coreboot parameter values currently stored in
|
||||||
* 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;
|
||||||
|
|
||||||
@ -207,7 +211,7 @@ uint16_t cmos_checksum_compute (void)
|
|||||||
sum += cmos_read_byte(i);
|
sum += cmos_read_byte(i);
|
||||||
|
|
||||||
return ~((uint16_t) (sum & 0xffff));
|
return ~((uint16_t) (sum & 0xffff));
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_checksum_verify
|
* cmos_checksum_verify
|
||||||
@ -215,17 +219,18 @@ uint16_t cmos_checksum_compute (void)
|
|||||||
* Verify that the coreboot CMOS checksum is valid. If checksum is not
|
* Verify that the coreboot CMOS checksum is valid. If checksum is not
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@
|
|||||||
#define CMOS_OP_VALUE_TOO_WIDE (CMOS_OP_RESULT_START + 4)
|
#define CMOS_OP_VALUE_TOO_WIDE (CMOS_OP_RESULT_START + 4)
|
||||||
#define CMOS_OP_NO_MATCHING_ENUM (CMOS_OP_RESULT_START + 5)
|
#define CMOS_OP_NO_MATCHING_ENUM (CMOS_OP_RESULT_START + 5)
|
||||||
|
|
||||||
int prepare_cmos_read (const cmos_entry_t *e);
|
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);
|
||||||
uint16_t cmos_checksum_read (void);
|
uint16_t cmos_checksum_read(void);
|
||||||
void cmos_checksum_write (uint16_t checksum);
|
void cmos_checksum_write(uint16_t checksum);
|
||||||
uint16_t cmos_checksum_compute (void);
|
uint16_t cmos_checksum_compute(void);
|
||||||
void cmos_checksum_verify (void);
|
void cmos_checksum_verify(void);
|
||||||
|
|
||||||
#endif /* CMOS_OPS_H */
|
#endif /* CMOS_OPS_H */
|
||||||
|
@ -42,27 +42,29 @@ const char prog_version[] = "2.1";
|
|||||||
* Get a line of input from file 'f'. Store result in 'line' which is an
|
* Get a line of input from file 'f'. Store result in 'line' which is an
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* out_of_memory
|
* out_of_memory
|
||||||
*
|
*
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* usage
|
* usage
|
||||||
@ -70,8 +72,9 @@ void out_of_memory (void)
|
|||||||
* Write a usage message to 'outfile'. If 'outfile' is 'stderr' then exit
|
* Write a usage message to 'outfile'. If 'outfile' is 'stderr' then exit
|
||||||
* 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"
|
||||||
@ -102,4 +105,4 @@ void usage (FILE *outfile)
|
|||||||
" -v: Show version info for this program.\n"
|
" -v: Show version info for this program.\n"
|
||||||
" -h: Show this message.\n", prog_name);
|
" -h: Show this message.\n", prog_name);
|
||||||
exit(outfile == stderr);
|
exit(outfile == stderr);
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ extern const char prog_name[];
|
|||||||
/* version of this program */
|
/* version of this program */
|
||||||
extern const char prog_version[];
|
extern const char prog_version[];
|
||||||
|
|
||||||
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);
|
||||||
void out_of_memory (void);
|
void out_of_memory(void);
|
||||||
void usage (FILE *outfile);
|
void usage(FILE * outfile);
|
||||||
|
|
||||||
#endif /* COMMON_H */
|
#endif /* COMMON_H */
|
||||||
|
@ -25,7 +25,7 @@ unsigned long compute_ip_checksum(void *addr, unsigned long length)
|
|||||||
*/
|
*/
|
||||||
sum = 0;
|
sum = 0;
|
||||||
ptr = addr;
|
ptr = addr;
|
||||||
for(i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
value = ptr[i];
|
value = ptr[i];
|
||||||
if (i & 1) {
|
if (i & 1) {
|
||||||
|
@ -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 */
|
||||||
|
@ -43,9 +43,9 @@
|
|||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void addrprint (FILE *outfile, uint64_t address, int width);
|
static void addrprint(FILE * outfile, uint64_t address, int width);
|
||||||
static void hexprint (FILE *outfile, unsigned char byte);
|
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);
|
||||||
|
|
||||||
@ -65,9 +65,10 @@ static void charprint (FILE *outfile, unsigned char byte,
|
|||||||
* format: A structure specifying how the hex dump should be
|
* format: A structure specifying how the hex dump should be
|
||||||
* formatted.
|
* formatted.
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
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;
|
||||||
|
|
||||||
@ -80,24 +81,25 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
|
|||||||
if (is_printable_fn == NULL)
|
if (is_printable_fn == NULL)
|
||||||
is_printable_fn = default_is_printable_fn;
|
is_printable_fn = default_is_printable_fn;
|
||||||
|
|
||||||
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,14 +148,15 @@ 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++)
|
||||||
fprintf(outfile, " ");
|
fprintf(outfile, " ");
|
||||||
|
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* default_is_printable_fn
|
* default_is_printable_fn
|
||||||
@ -169,8 +172,10 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
|
|||||||
* return value:
|
* return value:
|
||||||
* 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
|
||||||
@ -183,8 +188,9 @@ int default_is_printable_fn (unsigned char c)
|
|||||||
* width: The number of bytes wide the address should be displayed as.
|
* width: The number of bytes wide the address should be displayed as.
|
||||||
* 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 */
|
||||||
@ -194,13 +200,13 @@ static void addrprint (FILE *outfile, uint64_t address, int width)
|
|||||||
width = 8;
|
width = 8;
|
||||||
|
|
||||||
/* 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;
|
||||||
@ -208,7 +214,7 @@ static void addrprint (FILE *outfile, uint64_t address, int width)
|
|||||||
if ((i % 4) == 0)
|
if ((i % 4) == 0)
|
||||||
fprintf(outfile, ":");
|
fprintf(outfile, ":");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* hexprint
|
* hexprint
|
||||||
@ -219,14 +225,15 @@ static void addrprint (FILE *outfile, uint64_t address, int width)
|
|||||||
* outfile: the place where the output should be written
|
* outfile: the place where the output should be written
|
||||||
* 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'
|
||||||
};
|
};
|
||||||
|
|
||||||
fprintf(outfile, "%c%c", tbl[byte >> 4], tbl[byte & 0x0f]);
|
fprintf(outfile, "%c%c", tbl[byte >> 4], tbl[byte & 0x0f]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* charprint
|
* charprint
|
||||||
@ -241,7 +248,9 @@ static void hexprint (FILE *outfile, unsigned char byte)
|
|||||||
* is_printable_fn: a function that returns a boolean value indicating
|
* is_printable_fn: a function that returns a boolean value indicating
|
||||||
* whether a given character is printable
|
* whether a given character is printable
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
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);
|
||||||
|
}
|
||||||
|
@ -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
|
||||||
@ -109,8 +108,8 @@ hexdump_format_t;
|
|||||||
* format: A structure specifying how the hex dump should be
|
* format: A structure specifying how the hex dump should be
|
||||||
* formatted.
|
* formatted.
|
||||||
*--------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------*/
|
||||||
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);
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* default_is_printable_fn
|
* default_is_printable_fn
|
||||||
@ -126,6 +125,6 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
|
|||||||
* return value:
|
* return value:
|
||||||
* 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);
|
||||||
|
|
||||||
#endif /* _HEXDUMP_H */
|
#endif /* _HEXDUMP_H */
|
||||||
|
@ -35,17 +35,14 @@
|
|||||||
#include "cmos_lowlevel.h"
|
#include "cmos_lowlevel.h"
|
||||||
#include "reg_expr.h"
|
#include "reg_expr.h"
|
||||||
|
|
||||||
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);
|
||||||
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[]);
|
||||||
|
|
||||||
/* 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 */
|
||||||
@ -77,8 +74,8 @@ static int line_num;
|
|||||||
* write operations. Perform sanity checking on all write operations and
|
* write operations. Perform sanity checking on all write operations and
|
||||||
* exit with an error message if there is a problem.
|
* exit with an error message if there is a problem.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
cmos_write_t * process_input_file (FILE *f)
|
cmos_write_t *process_input_file(FILE * f)
|
||||||
{
|
{
|
||||||
static const int LINE_BUF_SIZE = 256;
|
static const int LINE_BUF_SIZE = 256;
|
||||||
static const size_t N_MATCHES = 4;
|
static const size_t N_MATCHES = 4;
|
||||||
char line[LINE_BUF_SIZE];
|
char line[LINE_BUF_SIZE];
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
@ -147,7 +144,7 @@ cmos_write_t * process_input_file (FILE *f)
|
|||||||
|
|
||||||
free_reg_exprs(2, &blank_or_comment, &assignment);
|
free_reg_exprs(2, &blank_or_comment, &assignment);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* do_cmos_writes
|
* do_cmos_writes
|
||||||
@ -156,13 +153,14 @@ cmos_write_t * process_input_file (FILE *f)
|
|||||||
* all sanity checks. Perform all write operations, destroying the list as
|
* all sanity checks. Perform all write operations, destroying the list as
|
||||||
* 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;
|
||||||
@ -174,7 +172,7 @@ void do_cmos_writes (cmos_write_t *list)
|
|||||||
|
|
||||||
cmos_checksum_write(cmos_checksum_compute());
|
cmos_checksum_write(cmos_checksum_compute());
|
||||||
set_iopl(0);
|
set_iopl(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* get_input_file_line
|
* get_input_file_line
|
||||||
@ -183,16 +181,18 @@ void do_cmos_writes (cmos_write_t *list)
|
|||||||
* array of 'line_buf_size' bytes. Return OK on success or an error code on
|
* array of 'line_buf_size' bytes. Return OK on success or an error code on
|
||||||
* 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;
|
||||||
@ -203,7 +203,7 @@ static int get_input_file_line (FILE *f, char line[], int line_buf_size)
|
|||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
return 1; /* keep compiler happy */
|
return 1; /* keep compiler happy */
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* try_prepare_cmos_write
|
* try_prepare_cmos_write
|
||||||
@ -212,63 +212,73 @@ static int get_input_file_line (FILE *f, char line[], int line_buf_size)
|
|||||||
* CMOS memory. On success, return the converted value. On error, exit with
|
* CMOS memory. On success, return the converted value. On error, exit with
|
||||||
* an error message.
|
* an error message.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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:
|
||||||
@ -281,4 +291,4 @@ static unsigned long long try_prepare_cmos_write (const cmos_entry_t *e,
|
|||||||
fprintf(stderr, " No CMOS writes performed.\n");
|
fprintf(stderr, " No CMOS writes performed.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
return 0; /* keep compiler happy */
|
return 0; /* keep compiler happy */
|
||||||
}
|
}
|
||||||
|
@ -36,21 +36,21 @@
|
|||||||
|
|
||||||
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;
|
||||||
cmos_write_t *next;
|
cmos_write_t *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
cmos_write_t * process_input_file (FILE *f);
|
cmos_write_t *process_input_file(FILE * f);
|
||||||
void do_cmos_writes (cmos_write_t *list);
|
void do_cmos_writes(cmos_write_t * list);
|
||||||
|
|
||||||
extern const char assignment_regex[];
|
extern const char assignment_regex[];
|
||||||
|
|
||||||
|
@ -34,23 +34,23 @@
|
|||||||
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void default_cmos_layout_get_fn (void);
|
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);
|
||||||
static int entries_overlap (const cmos_entry_t *p, const cmos_entry_t *q);
|
static int entries_overlap(const cmos_entry_t * p, const cmos_entry_t * q);
|
||||||
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);
|
||||||
|
|
||||||
const char checksum_param_name[] = "check_sum";
|
const char checksum_param_name[] = "check_sum";
|
||||||
|
|
||||||
@ -99,39 +99,41 @@ static cmos_layout_get_fn_t cmos_layout_get_fn = default_cmos_layout_get_fn;
|
|||||||
*
|
*
|
||||||
* Return 1 if cmos entries 'p' and 'q' overlap. Else return 0.
|
* Return 1 if cmos entries 'p' and 'q' overlap. Else return 0.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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
|
||||||
*
|
*
|
||||||
* 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;
|
||||||
address = ((unsigned long) p) - offset;
|
address = ((unsigned long)p) - offset;
|
||||||
return (const cmos_entry_item_t *) address;
|
return (const cmos_entry_item_t *)address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_enum_to_const_item
|
* cmos_enum_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;
|
||||||
address = ((unsigned long) p) - offset;
|
address = ((unsigned long)p) - offset;
|
||||||
return (const cmos_enum_item_t *) address;
|
return (const cmos_enum_item_t *)address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* register_cmos_layout_get_fn
|
* register_cmos_layout_get_fn
|
||||||
@ -139,16 +141,20 @@ static inline const cmos_enum_item_t * cmos_enum_to_const_item
|
|||||||
* Set 'fn' as the function that will be called to retrieve CMOS layout
|
* Set 'fn' as the function that will be called to retrieve CMOS layout
|
||||||
* 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
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@ -158,21 +164,23 @@ void get_cmos_layout (void)
|
|||||||
* operation fails because 'e' overlaps an existing CMOS entry, '*conflict'
|
* operation fails because 'e' overlaps an existing CMOS entry, '*conflict'
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
@ -182,11 +190,11 @@ int add_cmos_entry (const cmos_entry_t *e, const cmos_entry_t **conflict)
|
|||||||
*/
|
*/
|
||||||
for (item = cmos_entry_list, prev = NULL;
|
for (item = cmos_entry_list, prev = NULL;
|
||||||
(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,10 +217,10 @@ int add_cmos_entry (const cmos_entry_t *e, const cmos_entry_t **conflict)
|
|||||||
prev->next = new_entry;
|
prev->next = new_entry;
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
free(new_entry);
|
free(new_entry);
|
||||||
return LAYOUT_ENTRY_OVERLAP;
|
return LAYOUT_ENTRY_OVERLAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* find_cmos_entry
|
* find_cmos_entry
|
||||||
@ -220,16 +228,17 @@ fail:
|
|||||||
* Search for a CMOS entry whose name is 'name'. Return pointer to matching
|
* Search for a CMOS entry whose name is 'name'. Return pointer to matching
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* first_cmos_entry
|
* first_cmos_entry
|
||||||
@ -237,8 +246,10 @@ const cmos_entry_t * find_cmos_entry (const char name[])
|
|||||||
* Return a pointer to the first CMOS entry in our list or NULL if list is
|
* Return a pointer to the first CMOS entry in our list or NULL if list is
|
||||||
* 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
|
||||||
@ -246,13 +257,14 @@ const cmos_entry_t * first_cmos_entry (void)
|
|||||||
* Return a pointer to next entry in list after 'last' or NULL if no more
|
* Return a pointer to next entry in list after 'last' or NULL if no more
|
||||||
* 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;
|
||||||
return (next_item == NULL) ? NULL : &next_item->item;
|
return (next_item == NULL) ? NULL : &next_item->item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* add_cmos_enum
|
* add_cmos_enum
|
||||||
@ -260,36 +272,37 @@ const cmos_entry_t * next_cmos_entry (const cmos_entry_t *last)
|
|||||||
* Attempt to add CMOS enum 'e' to our internal repository of layout
|
* Attempt to add CMOS enum 'e' to our internal repository of layout
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +340,7 @@ int add_cmos_enum (const cmos_enum_t *e)
|
|||||||
prev->next = new_enum;
|
prev->next = new_enum;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* find_cmos_enum
|
* find_cmos_enum
|
||||||
@ -334,22 +348,22 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (item->item.value == value) ? &item->item : NULL;
|
return (item->item.value == value) ? &item->item : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* first_cmos_enum
|
* first_cmos_enum
|
||||||
@ -357,8 +371,10 @@ const cmos_enum_t * find_cmos_enum (unsigned config_id,
|
|||||||
* Return a pointer to the first CMOS enum in our list or NULL if list is
|
* Return a pointer to the first CMOS enum in our list or NULL if list is
|
||||||
* 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
|
||||||
@ -366,13 +382,14 @@ const cmos_enum_t * first_cmos_enum (void)
|
|||||||
* Return a pointer to next enum in list after 'last' or NULL if no more
|
* Return a pointer to next enum in list after 'last' or NULL if no more
|
||||||
* 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;
|
||||||
return (next_item == NULL) ? NULL : &next_item->item;
|
return (next_item == NULL) ? NULL : &next_item->item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* first_cmos_enum_id
|
* first_cmos_enum_id
|
||||||
@ -380,12 +397,13 @@ const cmos_enum_t * next_cmos_enum (const cmos_enum_t *last)
|
|||||||
* Return a pointer to the first CMOS enum in our list that matches
|
* Return a pointer to the first CMOS enum in our list that matches
|
||||||
* '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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* next_cmos_enum_id
|
* next_cmos_enum_id
|
||||||
@ -393,13 +411,14 @@ const cmos_enum_t * first_cmos_enum_id (unsigned config_id)
|
|||||||
* Return a pointer to next enum in list after 'last' that matches the
|
* Return a pointer to next enum in list after 'last' that matches the
|
||||||
* '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)) ?
|
||||||
NULL : &item->item;
|
NULL : &item->item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* is_checksum_name
|
* is_checksum_name
|
||||||
@ -407,8 +426,10 @@ const cmos_enum_t * next_cmos_enum_id (const cmos_enum_t *last)
|
|||||||
* Return 1 if 'name' matches the name of the parameter representing the CMOS
|
* Return 1 if 'name' matches the name of the parameter representing the CMOS
|
||||||
* 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
|
||||||
@ -418,8 +439,9 @@ int is_checksum_name (const char name[])
|
|||||||
* bit positions to byte positions. Return OK on success or an error code if
|
* bit positions to byte positions. Return OK on success or an error code if
|
||||||
* 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;
|
||||||
@ -456,7 +478,7 @@ int checksum_layout_to_bytes (cmos_checksum_layout_t *layout)
|
|||||||
layout->summed_area_end = end;
|
layout->summed_area_end = end;
|
||||||
layout->checksum_at = index;
|
layout->checksum_at = index;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* checksum_layout_to_bits
|
* checksum_layout_to_bits
|
||||||
@ -464,11 +486,12 @@ int checksum_layout_to_bytes (cmos_checksum_layout_t *layout)
|
|||||||
* On entry, '*layout' contains checksum-related layout information expressed
|
* On entry, '*layout' contains checksum-related layout information expressed
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* default_cmos_layout_get_fn
|
* default_cmos_layout_get_fn
|
||||||
@ -477,22 +500,25 @@ void checksum_layout_to_bits (cmos_checksum_layout_t *layout)
|
|||||||
* obtaining CMOS layout information was not set before attempting to
|
* obtaining CMOS layout information was not set before attempting to
|
||||||
* 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
|
||||||
*
|
*
|
||||||
* Return 1 if the two given areas overlap. Else return 0.
|
* Return 1 if the two given areas overlap. Else return 0.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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;
|
||||||
return ((area_1_start <= area_0_end) && (area_0_start <= area_1_end));
|
return ((area_1_start <= area_0_end) && (area_0_start <= area_1_end));
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* find_first_cmos_enum_id
|
* find_first_cmos_enum_id
|
||||||
@ -500,13 +526,14 @@ static int areas_overlap (unsigned area_0_start, unsigned area_0_length,
|
|||||||
* Return a pointer to the first item in our list of enums that matches
|
* Return a pointer to the first item in our list of enums that matches
|
||||||
* '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);
|
||||||
item = item->next);
|
item = item->next) ;
|
||||||
|
|
||||||
return ((item == NULL) || (item->item.config_id > config_id)) ?
|
return ((item == NULL) || (item->item.config_id > config_id)) ?
|
||||||
NULL : item;
|
NULL : item;
|
||||||
}
|
}
|
||||||
|
@ -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[];
|
||||||
|
|
||||||
@ -94,21 +90,20 @@ extern unsigned cmos_checksum_index;
|
|||||||
|
|
||||||
typedef void (*cmos_layout_get_fn_t) (void);
|
typedef void (*cmos_layout_get_fn_t) (void);
|
||||||
|
|
||||||
void register_cmos_layout_get_fn (cmos_layout_get_fn_t fn);
|
void register_cmos_layout_get_fn(cmos_layout_get_fn_t fn);
|
||||||
void get_cmos_layout (void);
|
void get_cmos_layout(void);
|
||||||
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);
|
||||||
const cmos_entry_t * find_cmos_entry (const char name[]);
|
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);
|
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);
|
int is_checksum_name(const char name[]);
|
||||||
int is_checksum_name (const char name[]);
|
int checksum_layout_to_bytes(cmos_checksum_layout_t * layout);
|
||||||
int checksum_layout_to_bytes (cmos_checksum_layout_t *layout);
|
void checksum_layout_to_bits(cmos_checksum_layout_t * layout);
|
||||||
void checksum_layout_to_bits (cmos_checksum_layout_t *layout);
|
|
||||||
|
|
||||||
#endif /* LAYOUT_H */
|
#endif /* LAYOUT_H */
|
||||||
|
@ -34,38 +34,35 @@
|
|||||||
#include "cmos_lowlevel.h"
|
#include "cmos_lowlevel.h"
|
||||||
#include "reg_expr.h"
|
#include "reg_expr.h"
|
||||||
|
|
||||||
static void process_layout_file (FILE *f);
|
static void process_layout_file(FILE * f);
|
||||||
static void skip_past_start (FILE *f);
|
static void skip_past_start(FILE * f);
|
||||||
static int process_entry (FILE *f, int skip_add);
|
static int process_entry(FILE * f, int skip_add);
|
||||||
static int process_enum (FILE *f, int skip_add);
|
static int process_enum(FILE * f, int skip_add);
|
||||||
static void process_checksum_info (FILE *f);
|
static void process_checksum_info(FILE * f);
|
||||||
static void skip_remaining_lines (FILE *f);
|
static void skip_remaining_lines(FILE * f);
|
||||||
static void create_entry (cmos_entry_t *cmos_entry,
|
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[]);
|
||||||
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);
|
||||||
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[]);
|
||||||
static void try_add_cmos_enum (const cmos_enum_t *cmos_enum);
|
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[]);
|
||||||
static char cmos_entry_char_value (cmos_entry_config_t config);
|
static char cmos_entry_char_value(cmos_entry_config_t config);
|
||||||
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);
|
||||||
static unsigned string_to_unsigned (const char str[], const char str_name[]);
|
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[]);
|
||||||
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[]);
|
||||||
|
|
||||||
/* 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 */
|
||||||
@ -194,28 +191,32 @@ 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
|
||||||
*
|
*
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
process_layout_file(f);
|
process_layout_file(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* write_cmos_layout
|
* write_cmos_layout
|
||||||
@ -223,27 +224,27 @@ void get_layout_from_file (void)
|
|||||||
* Write CMOS layout information to file 'f'. The output is written in the
|
* Write CMOS layout information to file 'f'. The output is written in the
|
||||||
* 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;
|
||||||
@ -251,7 +252,7 @@ void write_cmos_layout (FILE *f)
|
|||||||
checksum_layout_to_bits(&layout);
|
checksum_layout_to_bits(&layout);
|
||||||
fprintf(f, "\nchecksums\nchecksum %u %u %u\n", layout.summed_area_start,
|
fprintf(f, "\nchecksums\nchecksum %u %u %u\n", layout.summed_area_start,
|
||||||
layout.summed_area_end, layout.checksum_at);
|
layout.summed_area_end, layout.checksum_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* process_layout_file
|
* process_layout_file
|
||||||
@ -259,8 +260,9 @@ void write_cmos_layout (FILE *f)
|
|||||||
* Read CMOS layout information from file 'f' and add it to our internal
|
* Read CMOS layout information from file 'f' and add it to our internal
|
||||||
* 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,20 +273,21 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!process_enum(f, 0));
|
while (!process_enum(f, 0)) ;
|
||||||
|
|
||||||
/* Go back to start of file. */
|
/* Go back to start of file. */
|
||||||
line_num = 1;
|
line_num = 1;
|
||||||
@ -292,28 +295,30 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!process_entry(f, 0));
|
while (!process_entry(f, 0)) ;
|
||||||
|
|
||||||
/* Skip past all enums. They have already been processed. */
|
/* Skip past all enums. They have already been processed. */
|
||||||
while (!process_enum(f, 1));
|
while (!process_enum(f, 1)) ;
|
||||||
|
|
||||||
/* 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);
|
||||||
|
|
||||||
@ -321,19 +326,20 @@ static void process_layout_file (FILE *f)
|
|||||||
&entries_line_expr, &start_enums_expr,
|
&entries_line_expr, &start_enums_expr,
|
||||||
&enums_line_expr, &start_checksums_expr,
|
&enums_line_expr, &start_checksums_expr,
|
||||||
&checksum_line_expr);
|
&checksum_line_expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* skip_past_start
|
* skip_past_start
|
||||||
*
|
*
|
||||||
* 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,13 +351,14 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
line_num++;
|
line_num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* process_entry
|
* process_entry
|
||||||
@ -360,8 +367,9 @@ static void skip_past_start (FILE *f)
|
|||||||
* of layout information. Return 0 if an entry was found and processed.
|
* of layout information. Return 0 if an entry was found and processed.
|
||||||
* 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,16 +409,16 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
line_num++;
|
line_num++;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* process_enum
|
* process_enum
|
||||||
@ -418,8 +427,9 @@ static int process_entry (FILE *f, int skip_add)
|
|||||||
* repository of layout information. Return 0 if an enumeration was found
|
* repository of layout information. Return 0 if an enumeration was found
|
||||||
* 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,29 +468,30 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
line_num++;
|
line_num++;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* process_checksum_info
|
* process_checksum_info
|
||||||
*
|
*
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,7 +516,7 @@ static void process_checksum_info (FILE *f)
|
|||||||
&line[match[3].rm_so]);
|
&line[match[3].rm_so]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* skip_remaining_lines
|
* skip_remaining_lines
|
||||||
@ -510,20 +524,21 @@ static void process_checksum_info (FILE *f)
|
|||||||
* Get any remaining lines of unprocessed input. Complain if we find a line
|
* Get any remaining lines of unprocessed input. Complain if we find a line
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* create_entry
|
* create_entry
|
||||||
@ -531,18 +546,19 @@ static void skip_remaining_lines (FILE *f)
|
|||||||
* Create a CMOS entry structure representing the given information. Perform
|
* Create a CMOS entry structure representing the given information. Perform
|
||||||
* sanity checking on input parameters.
|
* sanity checking on input parameters.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void create_entry (cmos_entry_t *cmos_entry,
|
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);
|
||||||
@ -574,11 +591,12 @@ static void create_entry (cmos_entry_t *cmos_entry,
|
|||||||
strcpy(cmos_entry->name, name_str);
|
strcpy(cmos_entry->name, name_str);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* try_add_layout_file_entry
|
* try_add_layout_file_entry
|
||||||
@ -586,27 +604,31 @@ bad_config_str:
|
|||||||
* Attempt to add the given CMOS entry to our internal repository. Exit with
|
* Attempt to add the given CMOS entry to our internal repository. Exit with
|
||||||
* 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;
|
||||||
@ -623,7 +645,7 @@ static void try_add_layout_file_entry (const cmos_entry_t *cmos_entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* create_enum
|
* create_enum
|
||||||
@ -631,20 +653,22 @@ static void try_add_layout_file_entry (const cmos_entry_t *cmos_entry)
|
|||||||
* Create a CMOS enumeration structure representing the given information.
|
* Create a CMOS enumeration structure representing the given information.
|
||||||
* Perform sanity checking on input parameters.
|
* Perform sanity checking on input parameters.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(cmos_enum->text, text_str);
|
strcpy(cmos_enum->text, text_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* try_add_cmos_enum
|
* try_add_cmos_enum
|
||||||
@ -652,9 +676,10 @@ static void create_enum (cmos_enum_t *cmos_enum, const char id_str[],
|
|||||||
* Attempt to add the given CMOS enum to our internal repository. Exit with
|
* Attempt to add the given CMOS enum to our internal repository. Exit with
|
||||||
* 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:
|
||||||
@ -668,7 +693,7 @@ static void try_add_cmos_enum (const cmos_enum_t *cmos_enum)
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* set_checksum_info
|
* set_checksum_info
|
||||||
@ -676,9 +701,10 @@ static void try_add_cmos_enum (const cmos_enum_t *cmos_enum)
|
|||||||
* Set CMOS checksum information according to input parameters and perform
|
* Set CMOS checksum information according to input parameters and perform
|
||||||
* sanity checking on input parameters.
|
* sanity checking on input parameters.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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:
|
||||||
@ -741,18 +776,19 @@ static void set_checksum_info (const char start_str[], const char end_str[],
|
|||||||
cmos_checksum_index = layout.checksum_at;
|
cmos_checksum_index = layout.checksum_at;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* cmos_entry_char_value
|
* cmos_entry_char_value
|
||||||
*
|
*
|
||||||
* 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:
|
||||||
@ -769,7 +805,7 @@ static char cmos_entry_char_value (cmos_entry_config_t config)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0; /* not reached */
|
return 0; /* not reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* get_layout_file_line
|
* get_layout_file_line
|
||||||
@ -778,56 +814,62 @@ static char cmos_entry_char_value (cmos_entry_config_t config)
|
|||||||
* array of 'line_buf_size' bytes. Return OK on success or an error code on
|
* array of 'line_buf_size' bytes. Return OK on success or an error code on
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
return 1; /* keep compiler happy */
|
return 1; /* keep compiler happy */
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* string_to_unsigned
|
* string_to_unsigned
|
||||||
*
|
*
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* string_to_unsigned_long
|
* string_to_unsigned_long
|
||||||
*
|
*
|
||||||
* Convert the string 'str' to an unsigned long and return the result.
|
* Convert the string 'str' to an unsigned long and return the result.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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
|
||||||
@ -835,20 +877,22 @@ static unsigned long string_to_unsigned_long (const char str[],
|
|||||||
* Convert the string 'str' to an unsigned long and return the result. Exit
|
* Convert the string 'str' to an unsigned long and return the result. Exit
|
||||||
* with an appropriate error message on failure.
|
* with an appropriate error message on failure.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "coreboot_tables.h"
|
#include "coreboot_tables.h"
|
||||||
|
|
||||||
void set_layout_filename (const char filename[]);
|
void set_layout_filename(const char filename[]);
|
||||||
void get_layout_from_file (void);
|
void get_layout_from_file(void);
|
||||||
void write_cmos_layout (FILE *f);
|
void write_cmos_layout(FILE * f);
|
||||||
|
|
||||||
#endif /* LAYOUT_FILE_H */
|
#endif /* LAYOUT_FILE_H */
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -33,10 +33,10 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
void get_lbtable (void);
|
void get_lbtable(void);
|
||||||
void get_layout_from_cmos_table (void);
|
void get_layout_from_cmos_table(void);
|
||||||
void dump_lbtable (void);
|
void dump_lbtable(void);
|
||||||
void list_lbtable_choices (void);
|
void list_lbtable_choices(void);
|
||||||
void list_lbtable_item (const char item[]);
|
void list_lbtable_item(const char item[]);
|
||||||
|
|
||||||
#endif /* LBTABLE_H */
|
#endif /* LBTABLE_H */
|
||||||
|
@ -41,34 +41,32 @@
|
|||||||
|
|
||||||
typedef void (*op_fn_t) (void);
|
typedef void (*op_fn_t) (void);
|
||||||
|
|
||||||
static void op_show_version (void);
|
static void op_show_version(void);
|
||||||
static void op_show_usage (void);
|
static void op_show_usage(void);
|
||||||
static void op_lbtable_show_info (void);
|
static void op_lbtable_show_info(void);
|
||||||
static void op_lbtable_dump (void);
|
static void op_lbtable_dump(void);
|
||||||
static void op_show_param_values (void);
|
static void op_show_param_values(void);
|
||||||
static void op_cmos_show_one_param (void);
|
static void op_cmos_show_one_param(void);
|
||||||
static void op_cmos_show_all_params (void);
|
static void op_cmos_show_all_params(void);
|
||||||
static void op_cmos_set_one_param (void);
|
static void op_cmos_set_one_param(void);
|
||||||
static void op_cmos_set_params_stdin (void);
|
static void op_cmos_set_params_stdin(void);
|
||||||
static void op_cmos_set_params_file (void);
|
static void op_cmos_set_params_file(void);
|
||||||
static void op_cmos_checksum (void);
|
static void op_cmos_checksum(void);
|
||||||
static void op_show_layout (void);
|
static void op_show_layout(void);
|
||||||
static void op_write_cmos_dump (void);
|
static void op_write_cmos_dump(void);
|
||||||
static void op_read_cmos_dump (void);
|
static void op_read_cmos_dump(void);
|
||||||
static void op_show_cmos_hex_dump (void);
|
static void op_show_cmos_hex_dump(void);
|
||||||
static void op_show_cmos_dumpfile (void);
|
static void op_show_cmos_dumpfile(void);
|
||||||
static int list_one_param (const char name[], int show_name);
|
static int list_one_param(const char name[], int show_name);
|
||||||
static int list_all_params (void);
|
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,
|
||||||
@ -84,7 +82,7 @@ static const op_fn_t op_fns[] =
|
|||||||
op_read_cmos_dump,
|
op_read_cmos_dump,
|
||||||
op_show_cmos_hex_dump,
|
op_show_cmos_hex_dump,
|
||||||
op_show_cmos_dumpfile
|
op_show_cmos_dumpfile
|
||||||
};
|
};
|
||||||
|
|
||||||
static const hexdump_format_t cmos_dump_format =
|
static const hexdump_format_t cmos_dump_format =
|
||||||
{ 16, 2, "", " | ", " ", " | ", '.', NULL };
|
{ 16, 2, "", " | ", " ", " | ", '.', NULL };
|
||||||
@ -92,23 +90,23 @@ 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);
|
||||||
op_fns[nvramtool_op.op]();
|
op_fns[nvramtool_op.op] ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_show_version
|
* op_show_version
|
||||||
@ -117,8 +115,10 @@ 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
|
||||||
@ -127,8 +127,10 @@ 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
|
||||||
@ -138,14 +140,15 @@ static void op_show_usage (void)
|
|||||||
* If ARG is present, show coreboot table information specified by ARG.
|
* If ARG is present, show coreboot table information specified by ARG.
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_lbtable_dump
|
* op_lbtable_dump
|
||||||
@ -154,10 +157,11 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_show_param_values
|
* op_show_param_values
|
||||||
@ -166,10 +170,11 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_cmos_show_one_param
|
* op_cmos_show_one_param
|
||||||
@ -179,17 +184,19 @@ static void op_show_param_values (void)
|
|||||||
* Show parameter NAME. If -n is specified, show value only. Else show name
|
* Show parameter NAME. If -n is specified, show value only. Else show name
|
||||||
* 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)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_cmos_show_all_params
|
* op_cmos_show_all_params
|
||||||
@ -198,8 +205,9 @@ 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();
|
||||||
@ -207,7 +215,7 @@ static void op_cmos_show_all_params (void)
|
|||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_cmos_set_one_param
|
* op_cmos_set_one_param
|
||||||
@ -216,8 +224,9 @@ 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();
|
||||||
|
|
||||||
@ -227,7 +236,7 @@ static void op_cmos_set_one_param (void)
|
|||||||
parse_assignment(nvramtool_op.param, &name, &value);
|
parse_assignment(nvramtool_op.param, &name, &value);
|
||||||
|
|
||||||
set_one_param(name, value);
|
set_one_param(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_cmos_set_params_stdin
|
* op_cmos_set_params_stdin
|
||||||
@ -236,10 +245,11 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_cmos_set_params_file
|
* op_cmos_set_params_file
|
||||||
@ -248,11 +258,12 @@ 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);
|
||||||
}
|
}
|
||||||
@ -260,7 +271,7 @@ static void op_cmos_set_params_file (void)
|
|||||||
get_cmos_layout();
|
get_cmos_layout();
|
||||||
set_params(f);
|
set_params(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_cmos_checksum
|
* op_cmos_checksum
|
||||||
@ -270,24 +281,24 @@ static void op_cmos_set_params_file (void)
|
|||||||
* If VALUE is present, set coreboot CMOS checksum to VALUE. Else show
|
* If VALUE is present, set coreboot CMOS checksum to VALUE. Else show
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_show_layout
|
* op_show_layout
|
||||||
@ -296,10 +307,11 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_write_cmos_dump
|
* op_write_cmos_dump
|
||||||
@ -308,12 +320,13 @@ 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,14 +335,14 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_read_cmos_dump
|
* op_read_cmos_dump
|
||||||
@ -338,21 +351,23 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +375,7 @@ static void op_read_cmos_dump (void)
|
|||||||
set_iopl(3);
|
set_iopl(3);
|
||||||
cmos_write_all(data);
|
cmos_write_all(data);
|
||||||
set_iopl(0);
|
set_iopl(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_show_cmos_hex_dump
|
* op_show_cmos_hex_dump
|
||||||
@ -369,14 +384,15 @@ 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);
|
||||||
set_iopl(0);
|
set_iopl(0);
|
||||||
hexdump(data, CMOS_SIZE, 0, stdout, &cmos_dump_format);
|
hexdump(data, CMOS_SIZE, 0, stdout, &cmos_dump_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* op_show_cmos_dumpfile
|
* op_show_cmos_dumpfile
|
||||||
@ -386,13 +402,14 @@ static void op_show_cmos_hex_dump (void)
|
|||||||
* Read binary data from a file (presumably a CMOS dump file) and display a
|
* Read binary data from a file (presumably a CMOS dump file) and display a
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
@ -400,7 +417,7 @@ static void op_show_cmos_dumpfile (void)
|
|||||||
nr_bytes = fread(data, 1, CMOS_SIZE, f);
|
nr_bytes = fread(data, 1, CMOS_SIZE, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
hexdump(data, nr_bytes, 0, stdout, &cmos_dump_format);
|
hexdump(data, nr_bytes, 0, stdout, &cmos_dump_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* list_one_param
|
* list_one_param
|
||||||
@ -409,21 +426,24 @@ static void op_show_cmos_dumpfile (void)
|
|||||||
* boolean value indicating whether the parameter name should be displayed
|
* boolean value indicating whether the parameter name should be displayed
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (list_cmos_entry(e, show_name) != 0);
|
return (list_cmos_entry(e, show_name) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* list_all_params
|
* list_all_params
|
||||||
@ -431,14 +451,16 @@ static int list_one_param (const char name[], int show_name)
|
|||||||
* Attempt to list all CMOS parameters. Return 1 if error was encountered.
|
* Attempt to list all CMOS parameters. Return 1 if error was encountered.
|
||||||
* 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))
|
||||||
@ -446,34 +468,35 @@ static int list_all_params (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* list_param_enums
|
* list_param_enums
|
||||||
*
|
*
|
||||||
* 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:
|
||||||
@ -488,7 +511,7 @@ static void list_param_enums (const char name[])
|
|||||||
default:
|
default:
|
||||||
BUG();
|
BUG();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* set_one_param
|
* set_one_param
|
||||||
@ -500,21 +523,24 @@ static void list_param_enums (const char name[])
|
|||||||
* a string representation of an unsigned integer that may be specified in
|
* a string representation of an unsigned integer that may be specified in
|
||||||
* 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:
|
||||||
@ -579,23 +607,23 @@ static void set_one_param (const char name[], const char value[])
|
|||||||
set_iopl(0);
|
set_iopl(0);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
fprintf(stderr, " CMOS write not performed.\n");
|
fprintf(stderr, " CMOS write not performed.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* set_params
|
* set_params
|
||||||
*
|
*
|
||||||
* Set coreboot parameters according to the contents of file 'f'.
|
* Set coreboot parameters according to the contents of file 'f'.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
static void set_params (FILE *f)
|
static void set_params(FILE * f)
|
||||||
{ /* First process the input file. Then perform writes only if there were
|
{ /* First process the input file. Then perform writes only if there were
|
||||||
* no problems processing the input. Either all values will be written
|
* no problems processing the input. Either all values will be written
|
||||||
* successfully or no values will be written.
|
* successfully or no values will be written.
|
||||||
*/
|
*/
|
||||||
do_cmos_writes(process_input_file(f));
|
do_cmos_writes(process_input_file(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* parse_assignment
|
* parse_assignment
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -630,7 +658,7 @@ static void parse_assignment (char arg[], const char **name,
|
|||||||
*value = &arg[match[2].rm_so];
|
*value = &arg[match[2].rm_so];
|
||||||
|
|
||||||
free_reg_exprs(1, &assignment);
|
free_reg_exprs(1, &assignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* list_cmos_entry
|
* list_cmos_entry
|
||||||
@ -640,38 +668,43 @@ static void parse_assignment (char arg[], const char **name,
|
|||||||
* along with its value. On success, return OK. On error, print an error
|
* along with its value. On success, return OK. On error, print an error
|
||||||
* 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);
|
||||||
|
|
||||||
@ -723,7 +757,7 @@ static int list_cmos_entry (const cmos_entry_t *e, int show_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* convert_checksum_value
|
* convert_checksum_value
|
||||||
@ -733,36 +767,40 @@ static int list_cmos_entry (const cmos_entry_t *e, int show_name)
|
|||||||
* unsigned integer and return the result. Exit with an error message if
|
* unsigned integer and return the result. Exit with an error message if
|
||||||
* '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;
|
||||||
|
|
||||||
for (p = value; isspace(*p); p++);
|
for (p = value; isspace(*p); p++) ;
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -35,11 +35,11 @@ nvramtool_op_info_t nvramtool_op;
|
|||||||
|
|
||||||
nvramtool_op_modifier_info_t nvramtool_op_modifiers[NVRAMTOOL_NUM_OP_MODIFIERS];
|
nvramtool_op_modifier_info_t nvramtool_op_modifiers[NVRAMTOOL_NUM_OP_MODIFIERS];
|
||||||
|
|
||||||
static char * handle_optional_arg (int argc, char *argv[]);
|
static char *handle_optional_arg(int argc, char *argv[]);
|
||||||
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[]);
|
||||||
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 void resolve_op_modifiers (void);
|
static void resolve_op_modifiers(void);
|
||||||
static void sanity_check_args (void);
|
static void sanity_check_args(void);
|
||||||
|
|
||||||
static const char getopt_string[] = "-ab:B:c::de:hil::np:r:tvw:xX:y:Y";
|
static const char getopt_string[] = "-ab:B:c::de:hil::np:r:tvw:xX:y:Y";
|
||||||
|
|
||||||
@ -48,15 +48,15 @@ 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,28 +146,29 @@ 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);
|
||||||
|
|
||||||
resolve_op_modifiers();
|
resolve_op_modifiers();
|
||||||
sanity_check_args();
|
sanity_check_args();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* handle_optional_arg
|
* handle_optional_arg
|
||||||
*
|
*
|
||||||
* 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,27 +178,28 @@ 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);
|
||||||
|
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* register_op
|
* register_op
|
||||||
*
|
*
|
||||||
* 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;
|
||||||
nvramtool_op.op = op;
|
nvramtool_op.op = op;
|
||||||
nvramtool_op.param = op_param;
|
nvramtool_op.param = op_param;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* register_op_modifier
|
* register_op_modifier
|
||||||
@ -192,15 +207,16 @@ static void register_op (int *op_found, nvramtool_op_t op, char op_param[])
|
|||||||
* Store information regarding an optional argument specified in addition to
|
* Store information regarding an optional argument specified in addition to
|
||||||
* 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];
|
||||||
mod_info->found = TRUE;
|
mod_info->found = TRUE;
|
||||||
mod_info->found_seq = ++found_seq;
|
mod_info->found_seq = ++found_seq;
|
||||||
mod_info->param = mod_param;
|
mod_info->param = mod_param;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* resolve_op_modifiers
|
* resolve_op_modifiers
|
||||||
@ -208,24 +224,28 @@ static void register_op_modifier (nvramtool_op_modifier_t mod, char mod_param[])
|
|||||||
* If the user specifies multiple arguments that conflict with each other,
|
* If the user specifies multiple arguments that conflict with each other,
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sanity_check_args
|
* sanity_check_args
|
||||||
*
|
*
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
|
@ -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,34 +49,29 @@ 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;
|
||||||
|
|
||||||
extern nvramtool_op_modifier_info_t nvramtool_op_modifiers[];
|
extern nvramtool_op_modifier_info_t nvramtool_op_modifiers[];
|
||||||
|
|
||||||
void parse_nvramtool_args (int argc, char *argv[]);
|
void parse_nvramtool_args(int argc, char *argv[]);
|
||||||
|
|
||||||
#endif /* OPTS_H */
|
#endif /* OPTS_H */
|
||||||
|
@ -37,9 +37,10 @@
|
|||||||
*
|
*
|
||||||
* Compile a bunch of regular expressions.
|
* Compile a bunch of regular expressions.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
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,27 +49,28 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* free_reg_exprs
|
* free_reg_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);
|
||||||
@ -77,4 +79,4 @@ void free_reg_exprs (int num_exprs, /* regex_t *reg1, */ ...)
|
|||||||
regfree(va_arg(ap, regex_t *));
|
regfree(va_arg(ap, regex_t *));
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
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, */ ...);
|
||||||
void free_reg_exprs (int num_exprs, /* regex_t *reg1, */ ...);
|
void free_reg_exprs(int num_exprs, /* regex_t *reg1, */ ...);
|
||||||
|
|
||||||
#endif /* REG_EXPR_H */
|
#endif /* REG_EXPR_H */
|
||||||
|
Reference in New Issue
Block a user