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:
parent
766db7ea09
commit
90b96b68e0
|
@ -36,22 +36,21 @@
|
|||
#include "common.h"
|
||||
#include "cmos_lowlevel.h"
|
||||
|
||||
typedef struct
|
||||
{ unsigned byte_index;
|
||||
unsigned bit_offset;
|
||||
}
|
||||
cmos_bit_op_location_t;
|
||||
typedef struct {
|
||||
unsigned byte_index;
|
||||
unsigned bit_offset;
|
||||
} cmos_bit_op_location_t;
|
||||
|
||||
static unsigned cmos_bit_op_strategy (unsigned bit, unsigned bits_left,
|
||||
cmos_bit_op_location_t *where);
|
||||
static unsigned char cmos_read_bits (const cmos_bit_op_location_t *where,
|
||||
unsigned nr_bits);
|
||||
static void cmos_write_bits (const cmos_bit_op_location_t *where,
|
||||
unsigned nr_bits, unsigned char value);
|
||||
static unsigned char get_bits (unsigned long long value, unsigned bit,
|
||||
unsigned nr_bits);
|
||||
static void put_bits (unsigned char value, unsigned bit, unsigned nr_bits,
|
||||
unsigned long long *result);
|
||||
static unsigned cmos_bit_op_strategy(unsigned bit, unsigned bits_left,
|
||||
cmos_bit_op_location_t * where);
|
||||
static unsigned char cmos_read_bits(const cmos_bit_op_location_t * where,
|
||||
unsigned nr_bits);
|
||||
static void cmos_write_bits(const cmos_bit_op_location_t * where,
|
||||
unsigned nr_bits, unsigned char value);
|
||||
static unsigned char get_bits(unsigned long long value, unsigned bit,
|
||||
unsigned nr_bits);
|
||||
static void put_bits(unsigned char value, unsigned bit, unsigned nr_bits,
|
||||
unsigned long long *result);
|
||||
|
||||
/****************************************************************************
|
||||
* get_bits
|
||||
|
@ -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
|
||||
* '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,
|
||||
unsigned nr_bits)
|
||||
{ return (value >> bit) & ((unsigned char) ((1 << nr_bits) - 1)); }
|
||||
static inline unsigned char get_bits(unsigned long long value, unsigned bit,
|
||||
unsigned nr_bits)
|
||||
{
|
||||
return (value >> bit) & ((unsigned char)((1 << nr_bits) - 1));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* initially zero.
|
||||
****************************************************************************/
|
||||
static inline void put_bits (unsigned char value, unsigned bit,
|
||||
unsigned nr_bits, unsigned long long *result)
|
||||
{ *result += ((unsigned long long)(value & ((unsigned char) ((1 << nr_bits) - 1)))) << bit; }
|
||||
static inline void put_bits(unsigned char value, unsigned bit,
|
||||
unsigned nr_bits, unsigned long long *result)
|
||||
{
|
||||
*result += ((unsigned long long)(value &
|
||||
((unsigned char)((1 << nr_bits) - 1)))) << bit;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* cmos_read
|
||||
|
@ -82,43 +86,48 @@ static inline void put_bits (unsigned char value, unsigned bit,
|
|||
* and return this value. The I/O privilege level of the currently executing
|
||||
* process must be set appropriately.
|
||||
****************************************************************************/
|
||||
unsigned long long cmos_read (const cmos_entry_t *e)
|
||||
{ cmos_bit_op_location_t where;
|
||||
unsigned bit = e->bit, length=e->length;
|
||||
unsigned next_bit, bits_left, nr_bits;
|
||||
unsigned long long result = 0;
|
||||
unsigned char value;
|
||||
unsigned long long cmos_read(const cmos_entry_t * e)
|
||||
{
|
||||
cmos_bit_op_location_t where;
|
||||
unsigned bit = e->bit, length = e->length;
|
||||
unsigned next_bit, bits_left, nr_bits;
|
||||
unsigned long long result = 0;
|
||||
unsigned char value;
|
||||
|
||||
assert(!verify_cmos_op(bit, length, e->config));
|
||||
result = 0;
|
||||
assert(!verify_cmos_op(bit, length, e->config));
|
||||
result = 0;
|
||||
|
||||
if (e->config == CMOS_ENTRY_STRING)
|
||||
{ char *newstring = calloc(1, (length+7)/8);
|
||||
unsigned usize = (8 * sizeof(unsigned long long));
|
||||
if (e->config == CMOS_ENTRY_STRING) {
|
||||
char *newstring = calloc(1, (length + 7) / 8);
|
||||
unsigned usize = (8 * sizeof(unsigned long long));
|
||||
|
||||
if(!newstring) { out_of_memory(); }
|
||||
if (!newstring) {
|
||||
out_of_memory();
|
||||
}
|
||||
|
||||
for (next_bit = 0, bits_left = length;
|
||||
bits_left;
|
||||
next_bit += nr_bits, bits_left -= nr_bits)
|
||||
{ nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left>usize?usize:bits_left, &where);
|
||||
value = cmos_read_bits(&where, nr_bits);
|
||||
put_bits(value, next_bit % usize, nr_bits, &((unsigned long long *)newstring)[next_bit/usize]);
|
||||
result = (unsigned long)newstring;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ for (next_bit = 0, bits_left = length;
|
||||
bits_left;
|
||||
next_bit += nr_bits, bits_left -= nr_bits)
|
||||
{ nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left, &where);
|
||||
value = cmos_read_bits(&where, nr_bits);
|
||||
put_bits(value, next_bit, nr_bits, &result);
|
||||
}
|
||||
}
|
||||
for (next_bit = 0, bits_left = length;
|
||||
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
|
||||
nr_bits = cmos_bit_op_strategy(bit + next_bit,
|
||||
bits_left > usize ? usize : bits_left, &where);
|
||||
value = cmos_read_bits(&where, nr_bits);
|
||||
put_bits(value, next_bit % usize, nr_bits,
|
||||
&((unsigned long long *)newstring)[next_bit /
|
||||
usize]);
|
||||
result = (unsigned long)newstring;
|
||||
}
|
||||
} else {
|
||||
for (next_bit = 0, bits_left = length;
|
||||
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
|
||||
nr_bits =
|
||||
cmos_bit_op_strategy(bit + next_bit, bits_left,
|
||||
&where);
|
||||
value = cmos_read_bits(&where, nr_bits);
|
||||
put_bits(value, next_bit, nr_bits, &result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* appropriately.
|
||||
****************************************************************************/
|
||||
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;
|
||||
unsigned next_bit, bits_left, nr_bits;
|
||||
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;
|
||||
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)
|
||||
{ unsigned long long *data = (unsigned long long *)(unsigned long)value;
|
||||
unsigned usize = (8 * sizeof(unsigned long long));
|
||||
if (e->config == CMOS_ENTRY_STRING) {
|
||||
unsigned long long *data =
|
||||
(unsigned long long *)(unsigned long)value;
|
||||
unsigned usize = (8 * sizeof(unsigned long long));
|
||||
|
||||
for (next_bit = 0, bits_left = length;
|
||||
bits_left;
|
||||
next_bit += nr_bits, bits_left -= nr_bits)
|
||||
{ nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left>usize?usize:bits_left, &where);
|
||||
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;
|
||||
bits_left;
|
||||
next_bit += nr_bits, bits_left -= nr_bits)
|
||||
{ nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left, &where);
|
||||
cmos_write_bits(&where, nr_bits, get_bits(value, next_bit, nr_bits));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (next_bit = 0, bits_left = length;
|
||||
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
|
||||
nr_bits = cmos_bit_op_strategy(bit + next_bit,
|
||||
bits_left > usize ? usize : bits_left,
|
||||
&where);
|
||||
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;
|
||||
bits_left; next_bit += nr_bits, bits_left -= nr_bits) {
|
||||
nr_bits = cmos_bit_op_strategy(bit + next_bit,
|
||||
bits_left, &where);
|
||||
cmos_write_bits(&where, nr_bits,
|
||||
get_bits(value, next_bit, nr_bits));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* real time clock.
|
||||
****************************************************************************/
|
||||
unsigned char cmos_read_byte (unsigned index)
|
||||
{ unsigned short port_0, port_1;
|
||||
unsigned char cmos_read_byte(unsigned index)
|
||||
{
|
||||
unsigned short port_0, port_1;
|
||||
|
||||
assert(!verify_cmos_byte_index(index));
|
||||
assert(!verify_cmos_byte_index(index));
|
||||
|
||||
if (index < 128)
|
||||
{ port_0 = 0x70;
|
||||
port_1 = 0x71;
|
||||
}
|
||||
else
|
||||
{ port_0 = 0x72;
|
||||
port_1 = 0x73;
|
||||
}
|
||||
if (index < 128) {
|
||||
port_0 = 0x70;
|
||||
port_1 = 0x71;
|
||||
} else {
|
||||
port_0 = 0x72;
|
||||
port_1 = 0x73;
|
||||
}
|
||||
|
||||
OUTB(index, port_0);
|
||||
return INB(port_1);
|
||||
}
|
||||
OUTB(index, port_0);
|
||||
return INB(port_1);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* affect its functioning.
|
||||
****************************************************************************/
|
||||
void cmos_write_byte (unsigned index, unsigned char value)
|
||||
{ unsigned short port_0, port_1;
|
||||
void cmos_write_byte(unsigned index, unsigned char value)
|
||||
{
|
||||
unsigned short port_0, port_1;
|
||||
|
||||
assert(!verify_cmos_byte_index(index));
|
||||
assert(!verify_cmos_byte_index(index));
|
||||
|
||||
if (index < 128)
|
||||
{ port_0 = 0x70;
|
||||
port_1 = 0x71;
|
||||
}
|
||||
else
|
||||
{ port_0 = 0x72;
|
||||
port_1 = 0x73;
|
||||
}
|
||||
if (index < 128) {
|
||||
port_0 = 0x70;
|
||||
port_1 = 0x71;
|
||||
} else {
|
||||
port_0 = 0x72;
|
||||
port_1 = 0x73;
|
||||
}
|
||||
|
||||
OUTB(index, port_0);
|
||||
OUTB(value, port_1);
|
||||
}
|
||||
OUTB(index, port_0);
|
||||
OUTB(value, port_1);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* 'data' are set to zero since this corresponds to the real time clock area.
|
||||
****************************************************************************/
|
||||
void cmos_read_all (unsigned char data[])
|
||||
{ unsigned i;
|
||||
void cmos_read_all(unsigned char data[])
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < CMOS_RTC_AREA_SIZE; i++)
|
||||
data[i] = 0;
|
||||
for (i = 0; i < CMOS_RTC_AREA_SIZE; i++)
|
||||
data[i] = 0;
|
||||
|
||||
for (; i < CMOS_SIZE; i++)
|
||||
data[i] = cmos_read_byte(i);
|
||||
}
|
||||
for (; i < CMOS_SIZE; i++)
|
||||
data[i] = cmos_read_byte(i);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* area.
|
||||
****************************************************************************/
|
||||
void cmos_write_all (unsigned char data[])
|
||||
{ unsigned i;
|
||||
void cmos_write_all(unsigned char data[])
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = CMOS_RTC_AREA_SIZE; i < CMOS_SIZE; i++)
|
||||
cmos_write_byte(i, data[i]);
|
||||
}
|
||||
for (i = CMOS_RTC_AREA_SIZE; i < CMOS_SIZE; i++)
|
||||
cmos_write_byte(i, data[i]);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* set_iopl
|
||||
|
@ -251,45 +266,37 @@ void cmos_write_all (unsigned char data[])
|
|||
* interrupts while executing in user space. Messing with the I/O privilege
|
||||
* level is therefore somewhat dangerous.
|
||||
****************************************************************************/
|
||||
void set_iopl (int level)
|
||||
{
|
||||
void set_iopl(int level)
|
||||
{
|
||||
#if defined(__FreeBSD__)
|
||||
static int io_fd = -1;
|
||||
static int io_fd = -1;
|
||||
#endif
|
||||
|
||||
assert((level >= 0) && (level <= 3));
|
||||
assert((level >= 0) && (level <= 3));
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
if (level == 0)
|
||||
{
|
||||
if (io_fd != -1)
|
||||
{
|
||||
close(io_fd);
|
||||
io_fd = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (io_fd == -1)
|
||||
{
|
||||
io_fd = open("/dev/io", O_RDWR);
|
||||
if (io_fd < 0)
|
||||
{
|
||||
perror("/dev/io");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (level == 0) {
|
||||
if (io_fd != -1) {
|
||||
close(io_fd);
|
||||
io_fd = -1;
|
||||
}
|
||||
} else {
|
||||
if (io_fd == -1) {
|
||||
io_fd = open("/dev/io", O_RDWR);
|
||||
if (io_fd < 0) {
|
||||
perror("/dev/io");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (iopl(level))
|
||||
{ fprintf(stderr,
|
||||
"%s: iopl() system call failed. You must be root to do "
|
||||
"this.\n",
|
||||
prog_name);
|
||||
exit(1);
|
||||
}
|
||||
if (iopl(level)) {
|
||||
fprintf(stderr, "%s: iopl() system call failed. "
|
||||
"You must be root to do this.\n", prog_name);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* verify_cmos_op
|
||||
|
@ -300,21 +307,22 @@ void set_iopl (int level)
|
|||
* wish to read or write. Perform sanity checking on 'bit' and 'length'. If
|
||||
* no problems were encountered, return OK. Else return an error code.
|
||||
****************************************************************************/
|
||||
int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config)
|
||||
{ if ((bit >= (8 * CMOS_SIZE)) || ((bit + length) > (8 * CMOS_SIZE)))
|
||||
return CMOS_AREA_OUT_OF_RANGE;
|
||||
int verify_cmos_op(unsigned bit, unsigned length, cmos_entry_config_t config)
|
||||
{
|
||||
if ((bit >= (8 * CMOS_SIZE)) || ((bit + length) > (8 * CMOS_SIZE)))
|
||||
return CMOS_AREA_OUT_OF_RANGE;
|
||||
|
||||
if (bit < (8 * CMOS_RTC_AREA_SIZE))
|
||||
return CMOS_AREA_OVERLAPS_RTC;
|
||||
if (bit < (8 * CMOS_RTC_AREA_SIZE))
|
||||
return CMOS_AREA_OVERLAPS_RTC;
|
||||
|
||||
if (config == CMOS_ENTRY_STRING)
|
||||
return OK;
|
||||
if (config == CMOS_ENTRY_STRING)
|
||||
return OK;
|
||||
|
||||
if (length > (8 * sizeof(unsigned long long)))
|
||||
return CMOS_AREA_TOO_WIDE;
|
||||
if (length > (8 * sizeof(unsigned long long)))
|
||||
return CMOS_AREA_TOO_WIDE;
|
||||
|
||||
return OK;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* bits to read or write next.
|
||||
****************************************************************************/
|
||||
static unsigned cmos_bit_op_strategy (unsigned bit, unsigned bits_left,
|
||||
cmos_bit_op_location_t *where)
|
||||
{ unsigned max_bits;
|
||||
static unsigned cmos_bit_op_strategy(unsigned bit, unsigned bits_left,
|
||||
cmos_bit_op_location_t * where)
|
||||
{
|
||||
unsigned max_bits;
|
||||
|
||||
where->byte_index = bit >> 3;
|
||||
where->bit_offset = bit & 0x07;
|
||||
max_bits = 8 - where->bit_offset;
|
||||
return (bits_left > max_bits) ? max_bits : bits_left;
|
||||
}
|
||||
where->byte_index = bit >> 3;
|
||||
where->bit_offset = bit & 0x07;
|
||||
max_bits = 8 - where->bit_offset;
|
||||
return (bits_left > max_bits) ? max_bits : bits_left;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* value represented by the chunk of bits.
|
||||
****************************************************************************/
|
||||
static unsigned char cmos_read_bits (const cmos_bit_op_location_t *where,
|
||||
unsigned nr_bits)
|
||||
{ return (cmos_read_byte(where->byte_index) >> where->bit_offset) &
|
||||
((unsigned char) ((1 << nr_bits) - 1));
|
||||
}
|
||||
static unsigned char cmos_read_bits(const cmos_bit_op_location_t * where,
|
||||
unsigned nr_bits)
|
||||
{
|
||||
return (cmos_read_byte(where->byte_index) >> where->bit_offset) &
|
||||
((unsigned char)((1 << nr_bits) - 1));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* within a particular byte of CMOS memory.
|
||||
****************************************************************************/
|
||||
static void cmos_write_bits (const cmos_bit_op_location_t *where,
|
||||
unsigned nr_bits, unsigned char value)
|
||||
{ unsigned char n, mask;
|
||||
static void cmos_write_bits(const cmos_bit_op_location_t * where,
|
||||
unsigned nr_bits, unsigned char value)
|
||||
{
|
||||
unsigned char n, mask;
|
||||
|
||||
if (nr_bits == 8)
|
||||
{ cmos_write_byte(where->byte_index, value);
|
||||
return;
|
||||
}
|
||||
if (nr_bits == 8) {
|
||||
cmos_write_byte(where->byte_index, value);
|
||||
return;
|
||||
}
|
||||
|
||||
n = cmos_read_byte(where->byte_index);
|
||||
mask = ((unsigned char) ((1 << nr_bits) - 1)) << where->bit_offset;
|
||||
n = (n & ~mask) + ((value << where->bit_offset) & mask);
|
||||
cmos_write_byte(where->byte_index, n);
|
||||
}
|
||||
n = cmos_read_byte(where->byte_index);
|
||||
mask = ((unsigned char)((1 << nr_bits) - 1)) << where->bit_offset;
|
||||
n = (n & ~mask) + ((value << where->bit_offset) & mask);
|
||||
cmos_write_byte(where->byte_index, n);
|
||||
}
|
||||
|
|
|
@ -38,17 +38,17 @@
|
|||
#define CMOS_AREA_OVERLAPS_RTC (CMOS_RESULT_START + 1)
|
||||
#define CMOS_AREA_TOO_WIDE (CMOS_RESULT_START + 2)
|
||||
|
||||
unsigned long long cmos_read (const cmos_entry_t *e);
|
||||
void cmos_write (const cmos_entry_t *e, unsigned long long value);
|
||||
unsigned char cmos_read_byte (unsigned index);
|
||||
void cmos_write_byte (unsigned index, unsigned char value);
|
||||
void cmos_read_all (unsigned char data[]);
|
||||
void cmos_write_all (unsigned char data[]);
|
||||
void set_iopl (int level);
|
||||
int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config);
|
||||
unsigned long long cmos_read(const cmos_entry_t * e);
|
||||
void cmos_write(const cmos_entry_t * e, unsigned long long value);
|
||||
unsigned char cmos_read_byte(unsigned index);
|
||||
void cmos_write_byte(unsigned index, unsigned char value);
|
||||
void cmos_read_all(unsigned char data[]);
|
||||
void cmos_write_all(unsigned char data[]);
|
||||
void set_iopl(int level);
|
||||
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_RTC_AREA_SIZE 14 /* first 14 bytes control real time clock */
|
||||
#define CMOS_SIZE 256 /* size of CMOS memory in bytes */
|
||||
#define CMOS_RTC_AREA_SIZE 14 /* first 14 bytes control real time clock */
|
||||
|
||||
/****************************************************************************
|
||||
* verify_cmos_byte_index
|
||||
|
@ -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 0.
|
||||
****************************************************************************/
|
||||
static inline int verify_cmos_byte_index (unsigned index)
|
||||
{ return (index < CMOS_RTC_AREA_SIZE) || (index >= CMOS_SIZE); }
|
||||
static inline int verify_cmos_byte_index(unsigned index)
|
||||
{
|
||||
return (index < CMOS_RTC_AREA_SIZE) || (index >= CMOS_SIZE);
|
||||
}
|
||||
|
||||
#endif /* NVRAMTOOL_CMOS_LOWLEVEL_H */
|
||||
#endif /* NVRAMTOOL_CMOS_LOWLEVEL_H */
|
||||
|
|
|
@ -32,26 +32,27 @@
|
|||
#include "cmos_ops.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
|
||||
*
|
||||
* Perform a few checks common to both reads and writes.
|
||||
****************************************************************************/
|
||||
static int prepare_cmos_op_common (const cmos_entry_t *e)
|
||||
{ int result;
|
||||
static int prepare_cmos_op_common(const cmos_entry_t * e)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (e->config == CMOS_ENTRY_RESERVED)
|
||||
/* Access to reserved parameters is not permitted. */
|
||||
return CMOS_OP_RESERVED;
|
||||
if (e->config == CMOS_ENTRY_RESERVED)
|
||||
/* Access to reserved parameters is not permitted. */
|
||||
return CMOS_OP_RESERVED;
|
||||
|
||||
if ((result = verify_cmos_op(e->bit, e->length, e->config)) != OK)
|
||||
return result;
|
||||
if ((result = verify_cmos_op(e->bit, e->length, e->config)) != OK)
|
||||
return result;
|
||||
|
||||
assert(e->length > 0);
|
||||
return OK;
|
||||
}
|
||||
assert(e->length > 0);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* prepare_cmos_read
|
||||
|
@ -60,24 +61,25 @@ 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
|
||||
* code. Else return OK.
|
||||
****************************************************************************/
|
||||
int prepare_cmos_read (const cmos_entry_t *e)
|
||||
{ int result;
|
||||
int prepare_cmos_read(const cmos_entry_t * e)
|
||||
{
|
||||
int result;
|
||||
|
||||
if ((result = prepare_cmos_op_common(e)) != OK)
|
||||
return result;
|
||||
if ((result = prepare_cmos_op_common(e)) != OK)
|
||||
return result;
|
||||
|
||||
switch (e->config)
|
||||
{ case CMOS_ENTRY_ENUM:
|
||||
case CMOS_ENTRY_HEX:
|
||||
case CMOS_ENTRY_STRING:
|
||||
break;
|
||||
switch (e->config) {
|
||||
case CMOS_ENTRY_ENUM:
|
||||
case CMOS_ENTRY_HEX:
|
||||
case CMOS_ENTRY_STRING:
|
||||
break;
|
||||
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* prepare_cmos_write
|
||||
|
@ -87,79 +89,78 @@ int prepare_cmos_read (const cmos_entry_t *e)
|
|||
* checking on 'value_str'. On error, return an error code. Else store the
|
||||
* numeric equivalent of 'value_str' in '*value' and return OK.
|
||||
****************************************************************************/
|
||||
int prepare_cmos_write (const cmos_entry_t *e, const char value_str[],
|
||||
unsigned long long *value)
|
||||
{ const cmos_enum_t *q;
|
||||
unsigned long long out;
|
||||
const char *p;
|
||||
char *memory;
|
||||
int negative, result, found_one;
|
||||
int prepare_cmos_write(const cmos_entry_t * e, const char value_str[],
|
||||
unsigned long long *value)
|
||||
{
|
||||
const cmos_enum_t *q;
|
||||
unsigned long long out;
|
||||
const char *p;
|
||||
char *memory;
|
||||
int negative, result, found_one;
|
||||
|
||||
if ((result = prepare_cmos_op_common(e)) != OK)
|
||||
return result;
|
||||
if ((result = prepare_cmos_op_common(e)) != OK)
|
||||
return result;
|
||||
|
||||
switch (e->config)
|
||||
{ case CMOS_ENTRY_ENUM:
|
||||
/* Make sure the user's input corresponds to a valid option. */
|
||||
for (q = first_cmos_enum_id(e->config_id), found_one = 0;
|
||||
q != NULL;
|
||||
q = next_cmos_enum_id(q))
|
||||
{ found_one = 1;
|
||||
switch (e->config) {
|
||||
case CMOS_ENTRY_ENUM:
|
||||
/* Make sure the user's input corresponds to a valid option. */
|
||||
for (q = first_cmos_enum_id(e->config_id), found_one = 0;
|
||||
q != NULL; q = next_cmos_enum_id(q)) {
|
||||
found_one = 1;
|
||||
|
||||
if (!strncmp(q->text, value_str, CMOS_MAX_TEXT_LENGTH))
|
||||
break;
|
||||
}
|
||||
if (!strncmp(q->text, value_str, CMOS_MAX_TEXT_LENGTH))
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found_one)
|
||||
return CMOS_OP_NO_MATCHING_ENUM;
|
||||
if (!found_one)
|
||||
return CMOS_OP_NO_MATCHING_ENUM;
|
||||
|
||||
if (q == NULL)
|
||||
return CMOS_OP_BAD_ENUM_VALUE;
|
||||
if (q == NULL)
|
||||
return CMOS_OP_BAD_ENUM_VALUE;
|
||||
|
||||
out = q->value;
|
||||
break;
|
||||
out = q->value;
|
||||
break;
|
||||
|
||||
case CMOS_ENTRY_HEX:
|
||||
/* See if the first character of 'value_str' (excluding any initial
|
||||
* whitespace) is a minus sign.
|
||||
*/
|
||||
for (p = value_str; isspace(*p); p++);
|
||||
negative = (*p == '-');
|
||||
case CMOS_ENTRY_HEX:
|
||||
/* See if the first character of 'value_str' (excluding
|
||||
* any initial whitespace) is a minus sign.
|
||||
*/
|
||||
for (p = value_str; isspace(*p); p++) ;
|
||||
negative = (*p == '-');
|
||||
|
||||
out = strtoull(value_str, (char **) &p, 0);
|
||||
out = strtoull(value_str, (char **)&p, 0);
|
||||
|
||||
if (*p)
|
||||
return CMOS_OP_INVALID_INT;
|
||||
if (*p)
|
||||
return CMOS_OP_INVALID_INT;
|
||||
|
||||
/* If we get this far, the user specified a valid integer. However
|
||||
* we do not currently support the use of negative numbers as CMOS
|
||||
* parameter values.
|
||||
*/
|
||||
if (negative)
|
||||
return CMOS_OP_NEGATIVE_INT;
|
||||
/* If we get this far, the user specified a valid integer.
|
||||
* However we do not currently support the use of negative
|
||||
* numbers as CMOS parameter values.
|
||||
*/
|
||||
if (negative)
|
||||
return CMOS_OP_NEGATIVE_INT;
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case CMOS_ENTRY_STRING:
|
||||
if (e->length < (8 * strlen(value_str)))
|
||||
return CMOS_OP_VALUE_TOO_WIDE;
|
||||
memory = malloc(e->length / 8);
|
||||
memset(memory, 0, e->length / 8);
|
||||
strcpy(memory, value_str);
|
||||
out = (unsigned long)memory;
|
||||
break;
|
||||
case CMOS_ENTRY_STRING:
|
||||
if (e->length < (8 * strlen(value_str)))
|
||||
return CMOS_OP_VALUE_TOO_WIDE;
|
||||
memory = malloc(e->length / 8);
|
||||
memset(memory, 0, e->length / 8);
|
||||
strcpy(memory, value_str);
|
||||
out = (unsigned long)memory;
|
||||
break;
|
||||
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
|
||||
if ((e->length < (8 * sizeof(*value))) &&
|
||||
(out >= (1ull << e->length)))
|
||||
return CMOS_OP_VALUE_TOO_WIDE;
|
||||
if ((e->length < (8 * sizeof(*value))) && (out >= (1ull << e->length)))
|
||||
return CMOS_OP_VALUE_TOO_WIDE;
|
||||
|
||||
*value = out;
|
||||
return OK;
|
||||
}
|
||||
*value = out;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* this value.
|
||||
****************************************************************************/
|
||||
uint16_t cmos_checksum_read (void)
|
||||
{ uint16_t lo, hi;
|
||||
uint16_t cmos_checksum_read(void)
|
||||
{
|
||||
uint16_t lo, hi;
|
||||
|
||||
/* The checksum is stored in a big-endian format. */
|
||||
hi = cmos_read_byte(cmos_checksum_index);
|
||||
lo = cmos_read_byte(cmos_checksum_index + 1);
|
||||
return (hi << 8) + lo;
|
||||
}
|
||||
/* The checksum is stored in a big-endian format. */
|
||||
hi = cmos_read_byte(cmos_checksum_index);
|
||||
lo = cmos_read_byte(cmos_checksum_index + 1);
|
||||
return (hi << 8) + lo;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* cmos_checksum_write
|
||||
|
@ -182,15 +184,16 @@ uint16_t cmos_checksum_read (void)
|
|||
* Set the checksum for the coreboot parameters stored in CMOS to
|
||||
* 'checksum'.
|
||||
****************************************************************************/
|
||||
void cmos_checksum_write (uint16_t checksum)
|
||||
{ unsigned char lo, hi;
|
||||
void cmos_checksum_write(uint16_t checksum)
|
||||
{
|
||||
unsigned char lo, hi;
|
||||
|
||||
/* The checksum is stored in a big-endian format. */
|
||||
hi = (unsigned char) (checksum >> 8);
|
||||
lo = (unsigned char) (checksum & 0x00ff);
|
||||
cmos_write_byte(cmos_checksum_index, hi);
|
||||
cmos_write_byte(cmos_checksum_index + 1, lo);
|
||||
}
|
||||
/* The checksum is stored in a big-endian format. */
|
||||
hi = (unsigned char)(checksum >> 8);
|
||||
lo = (unsigned char)(checksum & 0x00ff);
|
||||
cmos_write_byte(cmos_checksum_index, hi);
|
||||
cmos_write_byte(cmos_checksum_index + 1, lo);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* cmos_checksum_compute
|
||||
|
@ -198,16 +201,17 @@ void cmos_checksum_write (uint16_t checksum)
|
|||
* Compute a checksum for the coreboot parameter values currently stored in
|
||||
* CMOS and return this checksum.
|
||||
****************************************************************************/
|
||||
uint16_t cmos_checksum_compute (void)
|
||||
{ unsigned i, sum;
|
||||
uint16_t cmos_checksum_compute(void)
|
||||
{
|
||||
unsigned i, sum;
|
||||
|
||||
sum = 0;
|
||||
sum = 0;
|
||||
|
||||
for (i = cmos_checksum_start; i <= cmos_checksum_end; i++)
|
||||
sum += cmos_read_byte(i);
|
||||
for (i = cmos_checksum_start; i <= cmos_checksum_end; i++)
|
||||
sum += cmos_read_byte(i);
|
||||
|
||||
return ~((uint16_t) (sum & 0xffff));
|
||||
}
|
||||
return ~((uint16_t) (sum & 0xffff));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* valid then print warning message and exit.
|
||||
****************************************************************************/
|
||||
void cmos_checksum_verify (void)
|
||||
{ uint16_t computed, actual;
|
||||
void cmos_checksum_verify(void)
|
||||
{
|
||||
uint16_t computed, actual;
|
||||
|
||||
set_iopl(3);
|
||||
computed = cmos_checksum_compute();
|
||||
actual = cmos_checksum_read();
|
||||
set_iopl(0);
|
||||
set_iopl(3);
|
||||
computed = cmos_checksum_compute();
|
||||
actual = cmos_checksum_read();
|
||||
set_iopl(0);
|
||||
|
||||
if (computed != actual)
|
||||
{ fprintf(stderr, "%s: Warning: Coreboot CMOS checksum is bad.\n",
|
||||
prog_name);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (computed != actual) {
|
||||
fprintf(stderr, "%s: Warning: Coreboot CMOS checksum is bad.\n",
|
||||
prog_name);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,12 +41,12 @@
|
|||
#define CMOS_OP_VALUE_TOO_WIDE (CMOS_OP_RESULT_START + 4)
|
||||
#define CMOS_OP_NO_MATCHING_ENUM (CMOS_OP_RESULT_START + 5)
|
||||
|
||||
int prepare_cmos_read (const cmos_entry_t *e);
|
||||
int prepare_cmos_write (const cmos_entry_t *e, const char value_str[],
|
||||
unsigned long long *value);
|
||||
uint16_t cmos_checksum_read (void);
|
||||
void cmos_checksum_write (uint16_t checksum);
|
||||
uint16_t cmos_checksum_compute (void);
|
||||
void cmos_checksum_verify (void);
|
||||
int prepare_cmos_read(const cmos_entry_t * e);
|
||||
int prepare_cmos_write(const cmos_entry_t * e, const char value_str[],
|
||||
unsigned long long *value);
|
||||
uint16_t cmos_checksum_read(void);
|
||||
void cmos_checksum_write(uint16_t checksum);
|
||||
uint16_t cmos_checksum_compute(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
|
||||
* array of 'line_buf_size' bytes.
|
||||
****************************************************************************/
|
||||
int get_line_from_file (FILE *f, char line[], int line_buf_size)
|
||||
{ if (fgets(line, line_buf_size, f) == NULL)
|
||||
return LINE_EOF;
|
||||
int get_line_from_file(FILE * f, char line[], int line_buf_size)
|
||||
{
|
||||
if (fgets(line, line_buf_size, f) == NULL)
|
||||
return LINE_EOF;
|
||||
|
||||
/* If the file contains a line that is too long, then it's best to let the
|
||||
* user know right away rather than passing back a truncated result that
|
||||
* will lead to problems later on.
|
||||
*/
|
||||
return (strlen(line) == ((size_t) (line_buf_size - 1))) ?
|
||||
LINE_TOO_LONG : OK;
|
||||
}
|
||||
/* If the file contains a line that is too long, then it's best
|
||||
* to let the user know right away rather than passing back a
|
||||
* truncated result that will lead to problems later on.
|
||||
*/
|
||||
return (strlen(line) == ((size_t) (line_buf_size - 1))) ?
|
||||
LINE_TOO_LONG : OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* out_of_memory
|
||||
*
|
||||
* We ran out of memory. Print an error message and die.
|
||||
****************************************************************************/
|
||||
void out_of_memory (void)
|
||||
{ fprintf(stderr, "%s: Out of memory.\n", prog_name);
|
||||
exit(1);
|
||||
}
|
||||
void out_of_memory(void)
|
||||
{
|
||||
fprintf(stderr, "%s: Out of memory.\n", prog_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* usage
|
||||
|
@ -70,36 +72,37 @@ void out_of_memory (void)
|
|||
* Write a usage message to 'outfile'. If 'outfile' is 'stderr' then exit
|
||||
* with a value of 1. Otherwise exit with a value of 0.
|
||||
****************************************************************************/
|
||||
void usage (FILE *outfile)
|
||||
{ fprintf(outfile,
|
||||
"Usage: %s [-y LAYOUT_FILE | -t] PARAMETER ...\n\n"
|
||||
" Read/write coreboot parameters or show info from "
|
||||
"coreboot table.\n\n"
|
||||
" -y LAYOUT_FILE: Use CMOS layout specified by "
|
||||
"LAYOUT_FILE.\n"
|
||||
" -t: Use CMOS layout specified by CMOS option "
|
||||
"table.\n"
|
||||
" [-n] -r NAME: Show parameter NAME. If -n is given, "
|
||||
"show value only.\n"
|
||||
" -e NAME: Show all possible values for parameter "
|
||||
"NAME.\n"
|
||||
" -a: Show names and values for all "
|
||||
"parameters.\n"
|
||||
" -w NAME=VALUE: Set parameter NAME to VALUE.\n"
|
||||
" -p INPUT_FILE: Set parameters according to INPUT_FILE.\n"
|
||||
" -i: Same as -p but file contents taken from "
|
||||
"standard input.\n"
|
||||
" -c [VALUE]: Show CMOS checksum or set checksum to "
|
||||
"VALUE.\n"
|
||||
" -l [ARG]: Show coreboot table info for ARG, or "
|
||||
"all ARG choices.\n"
|
||||
" -d: Show low-level dump of coreboot table.\n"
|
||||
" -Y: Show CMOS layout info.\n"
|
||||
" -b OUTPUT_FILE: Dump CMOS memory contents to file.\n"
|
||||
" -B INPUT_FILE: Write file contents to CMOS memory.\n"
|
||||
" -x: Show hex dump of CMOS memory.\n"
|
||||
" -X DUMPFILE: Show hex dump of CMOS dumpfile.\n"
|
||||
" -v: Show version info for this program.\n"
|
||||
" -h: Show this message.\n", prog_name);
|
||||
exit(outfile == stderr);
|
||||
}
|
||||
void usage(FILE * outfile)
|
||||
{
|
||||
fprintf(outfile,
|
||||
"Usage: %s [-y LAYOUT_FILE | -t] PARAMETER ...\n\n"
|
||||
" Read/write coreboot parameters or show info from "
|
||||
"coreboot table.\n\n"
|
||||
" -y LAYOUT_FILE: Use CMOS layout specified by "
|
||||
"LAYOUT_FILE.\n"
|
||||
" -t: Use CMOS layout specified by CMOS option "
|
||||
"table.\n"
|
||||
" [-n] -r NAME: Show parameter NAME. If -n is given, "
|
||||
"show value only.\n"
|
||||
" -e NAME: Show all possible values for parameter "
|
||||
"NAME.\n"
|
||||
" -a: Show names and values for all "
|
||||
"parameters.\n"
|
||||
" -w NAME=VALUE: Set parameter NAME to VALUE.\n"
|
||||
" -p INPUT_FILE: Set parameters according to INPUT_FILE.\n"
|
||||
" -i: Same as -p but file contents taken from "
|
||||
"standard input.\n"
|
||||
" -c [VALUE]: Show CMOS checksum or set checksum to "
|
||||
"VALUE.\n"
|
||||
" -l [ARG]: Show coreboot table info for ARG, or "
|
||||
"all ARG choices.\n"
|
||||
" -d: Show low-level dump of coreboot table.\n"
|
||||
" -Y: Show CMOS layout info.\n"
|
||||
" -b OUTPUT_FILE: Dump CMOS memory contents to file.\n"
|
||||
" -B INPUT_FILE: Write file contents to CMOS memory.\n"
|
||||
" -x: Show hex dump of CMOS memory.\n"
|
||||
" -X DUMPFILE: Show hex dump of CMOS dumpfile.\n"
|
||||
" -v: Show version info for this program.\n"
|
||||
" -h: Show this message.\n", prog_name);
|
||||
exit(outfile == stderr);
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
#define CMOS_RESULT_START 0x30000
|
||||
#define CMOS_OP_RESULT_START 0x40000
|
||||
|
||||
#define OK 0 /* 0 is used universally to indicate success. */
|
||||
#define OK 0 /* 0 is used universally to indicate success. */
|
||||
|
||||
#define LINE_EOF (COMMON_RESULT_START + 0)
|
||||
#define LINE_TOO_LONG (COMMON_RESULT_START + 1)
|
||||
|
@ -88,8 +88,8 @@ extern const char prog_name[];
|
|||
/* version of this program */
|
||||
extern const char prog_version[];
|
||||
|
||||
int get_line_from_file (FILE *f, char line[], int line_buf_size);
|
||||
void out_of_memory (void);
|
||||
void usage (FILE *outfile);
|
||||
int get_line_from_file(FILE * f, char line[], int line_buf_size);
|
||||
void out_of_memory(void);
|
||||
void usage(FILE * outfile);
|
||||
|
||||
#endif /* COMMON_H */
|
||||
#endif /* COMMON_H */
|
||||
|
|
|
@ -13,32 +13,32 @@
|
|||
|
||||
unsigned long compute_ip_checksum(void *addr, unsigned long length)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
volatile union {
|
||||
uint8_t byte[2];
|
||||
uint16_t word;
|
||||
} value;
|
||||
unsigned long sum;
|
||||
unsigned long i;
|
||||
/* In the most straight forward way possible,
|
||||
* compute an ip style checksum.
|
||||
*/
|
||||
sum = 0;
|
||||
ptr = addr;
|
||||
for(i = 0; i < length; i++) {
|
||||
unsigned long value;
|
||||
value = ptr[i];
|
||||
if (i & 1) {
|
||||
value <<= 8;
|
||||
}
|
||||
/* Add the new value */
|
||||
sum += value;
|
||||
/* Wrap around the carry */
|
||||
if (sum > 0xFFFF) {
|
||||
sum = (sum + (sum >> 16)) & 0xFFFF;
|
||||
}
|
||||
}
|
||||
value.byte[0] = sum & 0xff;
|
||||
value.byte[1] = (sum >> 8) & 0xff;
|
||||
return (~value.word) & 0xFFFF;
|
||||
uint8_t *ptr;
|
||||
volatile union {
|
||||
uint8_t byte[2];
|
||||
uint16_t word;
|
||||
} value;
|
||||
unsigned long sum;
|
||||
unsigned long i;
|
||||
/* In the most straight forward way possible,
|
||||
* compute an ip style checksum.
|
||||
*/
|
||||
sum = 0;
|
||||
ptr = addr;
|
||||
for (i = 0; i < length; i++) {
|
||||
unsigned long value;
|
||||
value = ptr[i];
|
||||
if (i & 1) {
|
||||
value <<= 8;
|
||||
}
|
||||
/* Add the new value */
|
||||
sum += value;
|
||||
/* Wrap around the carry */
|
||||
if (sum > 0xFFFF) {
|
||||
sum = (sum + (sum >> 16)) & 0xFFFF;
|
||||
}
|
||||
}
|
||||
value.byte[0] = sum & 0xff;
|
||||
value.byte[1] = (sum >> 8) & 0xff;
|
||||
return (~value.word) & 0xFFFF;
|
||||
}
|
||||
|
|
|
@ -59,30 +59,27 @@ struct lb_uint64 {
|
|||
|
||||
static inline uint64_t unpack_lb64(struct lb_uint64 value)
|
||||
{
|
||||
uint64_t result;
|
||||
result = value.hi;
|
||||
result = (result << 32) + value.lo;
|
||||
return result;
|
||||
uint64_t result;
|
||||
result = value.hi;
|
||||
result = (result << 32) + value.lo;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline struct lb_uint64 pack_lb64(uint64_t value)
|
||||
{
|
||||
struct lb_uint64 result;
|
||||
result.lo = (value >> 0) & 0xffffffff;
|
||||
result.hi = (value >> 32) & 0xffffffff;
|
||||
return result;
|
||||
struct lb_uint64 result;
|
||||
result.lo = (value >> 0) & 0xffffffff;
|
||||
result.hi = (value >> 32) & 0xffffffff;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct lb_header
|
||||
{
|
||||
uint8_t signature[4]; /* LBIO */
|
||||
uint32_t header_bytes;
|
||||
uint32_t header_checksum;
|
||||
uint32_t table_bytes;
|
||||
uint32_t table_checksum;
|
||||
uint32_t table_entries;
|
||||
struct lb_header {
|
||||
uint8_t signature[4]; /* LBIO */
|
||||
uint32_t header_bytes;
|
||||
uint32_t header_checksum;
|
||||
uint32_t table_bytes;
|
||||
uint32_t table_checksum;
|
||||
uint32_t table_entries;
|
||||
};
|
||||
|
||||
/* Every entry in the boot enviroment list will correspond to a boot
|
||||
|
@ -92,8 +89,8 @@ struct lb_header
|
|||
* forward compatibility with records not yet defined.
|
||||
*/
|
||||
struct lb_record {
|
||||
uint32_t tag; /* tag ID */
|
||||
uint32_t size; /* size of record (in bytes) */
|
||||
uint32_t tag; /* tag ID */
|
||||
uint32_t size; /* size of record (in bytes) */
|
||||
};
|
||||
|
||||
#define LB_TAG_UNUSED 0x0000
|
||||
|
@ -103,48 +100,48 @@ struct lb_record {
|
|||
struct lb_memory_range {
|
||||
struct lb_uint64 start;
|
||||
struct lb_uint64 size;
|
||||
uint32_t type;
|
||||
#define LB_MEM_RAM 1 /* Memory anyone can use */
|
||||
#define LB_MEM_RESERVED 2 /* Don't use this memory region */
|
||||
#define LB_MEM_TABLE 16 /* Ram configuration tables are kept in */
|
||||
uint32_t type;
|
||||
#define LB_MEM_RAM 1 /* Memory anyone can use */
|
||||
#define LB_MEM_RESERVED 2 /* Don't use this memory region */
|
||||
#define LB_MEM_TABLE 16 /* Ram configuration tables are kept in */
|
||||
};
|
||||
|
||||
struct lb_memory {
|
||||
uint32_t tag;
|
||||
uint32_t size;
|
||||
struct lb_memory_range map[0];
|
||||
uint32_t tag;
|
||||
uint32_t size;
|
||||
struct lb_memory_range map[0];
|
||||
};
|
||||
|
||||
#define LB_TAG_HWRPB 0x0002
|
||||
#define LB_TAG_HWRPB 0x0002
|
||||
struct lb_hwrpb {
|
||||
uint32_t tag;
|
||||
uint32_t size;
|
||||
uint64_t hwrpb;
|
||||
uint32_t tag;
|
||||
uint32_t size;
|
||||
uint64_t hwrpb;
|
||||
};
|
||||
|
||||
#define LB_TAG_MAINBOARD 0x0003
|
||||
struct lb_mainboard {
|
||||
uint32_t tag;
|
||||
uint32_t size;
|
||||
uint8_t vendor_idx;
|
||||
uint8_t part_number_idx;
|
||||
uint8_t strings[0];
|
||||
uint32_t tag;
|
||||
uint32_t size;
|
||||
uint8_t vendor_idx;
|
||||
uint8_t part_number_idx;
|
||||
uint8_t strings[0];
|
||||
};
|
||||
|
||||
#define LB_TAG_VERSION 0x0004
|
||||
#define LB_TAG_EXTRA_VERSION 0x0005
|
||||
#define LB_TAG_BUILD 0x0006
|
||||
#define LB_TAG_COMPILE_TIME 0x0007
|
||||
#define LB_TAG_COMPILE_BY 0x0008
|
||||
#define LB_TAG_COMPILE_HOST 0x0009
|
||||
#define LB_TAG_COMPILE_DOMAIN 0x000a
|
||||
#define LB_TAG_COMPILER 0x000b
|
||||
#define LB_TAG_LINKER 0x000c
|
||||
#define LB_TAG_VERSION 0x0004
|
||||
#define LB_TAG_EXTRA_VERSION 0x0005
|
||||
#define LB_TAG_BUILD 0x0006
|
||||
#define LB_TAG_COMPILE_TIME 0x0007
|
||||
#define LB_TAG_COMPILE_BY 0x0008
|
||||
#define LB_TAG_COMPILE_HOST 0x0009
|
||||
#define LB_TAG_COMPILE_DOMAIN 0x000a
|
||||
#define LB_TAG_COMPILER 0x000b
|
||||
#define LB_TAG_LINKER 0x000c
|
||||
#define LB_TAG_ASSEMBLER 0x000d
|
||||
struct lb_string {
|
||||
uint32_t tag;
|
||||
uint32_t size;
|
||||
uint8_t string[0];
|
||||
uint32_t tag;
|
||||
uint32_t size;
|
||||
uint8_t string[0];
|
||||
};
|
||||
#define LB_TAG_SERIAL 0x000f
|
||||
#define LB_TAG_CONSOLE 0x0010
|
||||
|
@ -159,9 +156,9 @@ struct lb_forward {
|
|||
#define LB_TAG_CMOS_OPTION_TABLE 200
|
||||
/* cmos header record */
|
||||
struct cmos_option_table {
|
||||
uint32_t tag; /* CMOS definitions table type */
|
||||
uint32_t size; /* size of the entire table */
|
||||
uint32_t header_length; /* length of header */
|
||||
uint32_t tag; /* CMOS definitions table type */
|
||||
uint32_t size; /* size of the entire table */
|
||||
uint32_t header_length; /* length of header */
|
||||
};
|
||||
|
||||
/* cmos entry record
|
||||
|
@ -173,31 +170,30 @@ struct cmos_option_table {
|
|||
*/
|
||||
#define LB_TAG_OPTION 201
|
||||
struct cmos_entries {
|
||||
uint32_t tag; /* entry type */
|
||||
uint32_t size; /* length of this record */
|
||||
uint32_t bit; /* starting bit from start of image */
|
||||
uint32_t length; /* length of field in bits */
|
||||
uint32_t config; /* e=enumeration, h=hex, r=reserved */
|
||||
uint32_t config_id; /* a number linking to an enumeration record */
|
||||
uint32_t tag; /* entry type */
|
||||
uint32_t size; /* length of this record */
|
||||
uint32_t bit; /* starting bit from start of image */
|
||||
uint32_t length; /* length of field in bits */
|
||||
uint32_t config; /* e=enumeration, h=hex, r=reserved */
|
||||
uint32_t config_id; /* a number linking to an enumeration record */
|
||||
#define CMOS_MAX_NAME_LENGTH 32
|
||||
uint8_t name[CMOS_MAX_NAME_LENGTH]; /* name of entry in ascii,
|
||||
variable length int aligned */
|
||||
uint8_t name[CMOS_MAX_NAME_LENGTH]; /* name of entry in ascii,
|
||||
variable length int aligned */
|
||||
};
|
||||
|
||||
|
||||
/* cmos enumerations record
|
||||
This record is variable length. The text field may be
|
||||
shorter than CMOS_MAX_TEXT_LENGTH.
|
||||
*/
|
||||
#define LB_TAG_OPTION_ENUM 202
|
||||
struct cmos_enums {
|
||||
uint32_t tag; /* enumeration type */
|
||||
uint32_t size; /* length of this record */
|
||||
uint32_t config_id; /* a number identifying the config id */
|
||||
uint32_t value; /* the value associated with the text */
|
||||
uint32_t tag; /* enumeration type */
|
||||
uint32_t size; /* length of this record */
|
||||
uint32_t config_id; /* a number identifying the config id */
|
||||
uint32_t value; /* the value associated with the text */
|
||||
#define CMOS_MAX_TEXT_LENGTH 32
|
||||
uint8_t text[CMOS_MAX_TEXT_LENGTH]; /* enum description in ascii,
|
||||
variable length int aligned */
|
||||
uint8_t text[CMOS_MAX_TEXT_LENGTH]; /* enum description in ascii,
|
||||
variable length int aligned */
|
||||
};
|
||||
|
||||
/* cmos defaults record
|
||||
|
@ -205,16 +201,16 @@ struct cmos_enums {
|
|||
*/
|
||||
#define LB_TAG_OPTION_DEFAULTS 203
|
||||
struct cmos_defaults {
|
||||
uint32_t tag; /* default type */
|
||||
uint32_t size; /* length of this record */
|
||||
uint32_t name_length; /* length of the following name field */
|
||||
uint8_t name[CMOS_MAX_NAME_LENGTH]; /* name identifying the default */
|
||||
uint32_t tag; /* default type */
|
||||
uint32_t size; /* length of this record */
|
||||
uint32_t name_length; /* length of the following name field */
|
||||
uint8_t name[CMOS_MAX_NAME_LENGTH]; /* name identifying the default */
|
||||
#define CMOS_IMAGE_BUFFER_SIZE 128
|
||||
uint8_t default_set[CMOS_IMAGE_BUFFER_SIZE]; /* default settings */
|
||||
uint8_t default_set[CMOS_IMAGE_BUFFER_SIZE]; /* default settings */
|
||||
};
|
||||
|
||||
#define LB_TAG_OPTION_CHECKSUM 204
|
||||
struct cmos_checksum {
|
||||
struct cmos_checksum {
|
||||
uint32_t tag;
|
||||
uint32_t size;
|
||||
/* In practice everything is byte aligned, but things are measured
|
||||
|
@ -228,6 +224,4 @@ struct cmos_checksum {
|
|||
#define CHECKSUM_PCBIOS 1
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* COREBOOT_TABLES_H */
|
||||
#endif /* COREBOOT_TABLES_H */
|
||||
|
|
|
@ -43,11 +43,11 @@
|
|||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
static void addrprint (FILE *outfile, uint64_t address, int width);
|
||||
static void hexprint (FILE *outfile, unsigned char byte);
|
||||
static void charprint (FILE *outfile, unsigned char byte,
|
||||
unsigned char nonprintable,
|
||||
is_printable_fn_t is_printable_fn);
|
||||
static void addrprint(FILE * outfile, uint64_t address, int width);
|
||||
static void hexprint(FILE * outfile, unsigned char byte);
|
||||
static void charprint(FILE * outfile, unsigned char byte,
|
||||
unsigned char nonprintable,
|
||||
is_printable_fn_t is_printable_fn);
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* hexdump
|
||||
|
@ -65,95 +65,98 @@ static void charprint (FILE *outfile, unsigned char byte,
|
|||
* format: A structure specifying how the hex dump should be
|
||||
* formatted.
|
||||
*--------------------------------------------------------------------------*/
|
||||
void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
|
||||
FILE *outfile, const hexdump_format_t *format)
|
||||
{ int bytes_left, index, i;
|
||||
const unsigned char *p;
|
||||
is_printable_fn_t is_printable_fn;
|
||||
void hexdump(const void *mem, int bytes, uint64_t addrprint_start,
|
||||
FILE * outfile, const hexdump_format_t * format)
|
||||
{
|
||||
int bytes_left, index, i;
|
||||
const unsigned char *p;
|
||||
is_printable_fn_t is_printable_fn;
|
||||
|
||||
/* Quietly return if the caller asks us to do something unreasonable. */
|
||||
if ((format->bytes_per_line <= 0) || (bytes < 0))
|
||||
return;
|
||||
/* Quietly return if the caller asks us to do something unreasonable. */
|
||||
if ((format->bytes_per_line <= 0) || (bytes < 0))
|
||||
return;
|
||||
|
||||
is_printable_fn = format->is_printable_fn;
|
||||
is_printable_fn = format->is_printable_fn;
|
||||
|
||||
if (is_printable_fn == NULL)
|
||||
is_printable_fn = default_is_printable_fn;
|
||||
if (is_printable_fn == NULL)
|
||||
is_printable_fn = default_is_printable_fn;
|
||||
|
||||
p = (const unsigned char *) mem;
|
||||
index = 0;
|
||||
p = (const unsigned char *)mem;
|
||||
index = 0;
|
||||
|
||||
/* Each iteration handles one full line of output. When loop terminates,
|
||||
* the number of remaining bytes to display (if any) will not be enough to
|
||||
* fill an entire line.
|
||||
*/
|
||||
for (bytes_left = bytes;
|
||||
bytes_left >= format->bytes_per_line;
|
||||
bytes_left -= format->bytes_per_line)
|
||||
{ /* print start address for current line */
|
||||
fprintf(outfile, format->indent);
|
||||
addrprint(outfile, addrprint_start + index, format->addrprint_width);
|
||||
fprintf(outfile, format->sep1);
|
||||
/* Each iteration handles one full line of output. When loop
|
||||
* terminates, the number of remaining bytes to display (if any)
|
||||
* will not be enough to fill an entire line.
|
||||
*/
|
||||
for (bytes_left = bytes;
|
||||
bytes_left >= format->bytes_per_line;
|
||||
bytes_left -= format->bytes_per_line) {
|
||||
/* print start address for current line */
|
||||
fprintf(outfile, format->indent);
|
||||
addrprint(outfile, addrprint_start + index,
|
||||
format->addrprint_width);
|
||||
fprintf(outfile, format->sep1);
|
||||
|
||||
/* display the bytes in hex */
|
||||
for (i = 0; ; )
|
||||
{ hexprint(outfile, p[index++]);
|
||||
/* display the bytes in hex */
|
||||
for (i = 0;;) {
|
||||
hexprint(outfile, p[index++]);
|
||||
|
||||
if (++i >= format->bytes_per_line)
|
||||
break;
|
||||
if (++i >= format->bytes_per_line)
|
||||
break;
|
||||
|
||||
fprintf(outfile, format->sep2);
|
||||
}
|
||||
fprintf(outfile, format->sep2);
|
||||
}
|
||||
|
||||
index -= format->bytes_per_line;
|
||||
fprintf(outfile, format->sep3);
|
||||
index -= format->bytes_per_line;
|
||||
fprintf(outfile, format->sep3);
|
||||
|
||||
/* display the bytes as characters */
|
||||
for (i = 0; i < format->bytes_per_line; i++)
|
||||
charprint(outfile, p[index++], format->nonprintable,
|
||||
is_printable_fn);
|
||||
/* display the bytes as characters */
|
||||
for (i = 0; i < format->bytes_per_line; i++)
|
||||
charprint(outfile, p[index++], format->nonprintable,
|
||||
is_printable_fn);
|
||||
|
||||
fprintf(outfile, "\n");
|
||||
}
|
||||
fprintf(outfile, "\n");
|
||||
}
|
||||
|
||||
if (bytes_left == 0)
|
||||
return;
|
||||
if (bytes_left == 0)
|
||||
return;
|
||||
|
||||
/* print start address for last line */
|
||||
fprintf(outfile, format->indent);
|
||||
addrprint(outfile, addrprint_start + index, format->addrprint_width);
|
||||
fprintf(outfile, format->sep1);
|
||||
/* print start address for last line */
|
||||
fprintf(outfile, format->indent);
|
||||
addrprint(outfile, addrprint_start + index, format->addrprint_width);
|
||||
fprintf(outfile, format->sep1);
|
||||
|
||||
/* display bytes for last line in hex */
|
||||
for (i = 0; i < bytes_left; i++)
|
||||
{ hexprint(outfile, p[index++]);
|
||||
fprintf(outfile, format->sep2);
|
||||
}
|
||||
/* display bytes for last line in hex */
|
||||
for (i = 0; i < bytes_left; i++) {
|
||||
hexprint(outfile, p[index++]);
|
||||
fprintf(outfile, format->sep2);
|
||||
}
|
||||
|
||||
index -= bytes_left;
|
||||
index -= bytes_left;
|
||||
|
||||
/* pad the rest of the hex byte area with spaces */
|
||||
for (; ; )
|
||||
{ fprintf(outfile, " ");
|
||||
/* pad the rest of the hex byte area with spaces */
|
||||
for (;;) {
|
||||
fprintf(outfile, " ");
|
||||
|
||||
if (++i >= format->bytes_per_line)
|
||||
break;
|
||||
if (++i >= format->bytes_per_line)
|
||||
break;
|
||||
|
||||
fprintf(outfile, format->sep2);
|
||||
}
|
||||
fprintf(outfile, format->sep2);
|
||||
}
|
||||
|
||||
fprintf(outfile, format->sep3);
|
||||
fprintf(outfile, format->sep3);
|
||||
|
||||
/* display bytes for last line as characters */
|
||||
for (i = 0; i < bytes_left; i++)
|
||||
charprint(outfile, p[index++], format->nonprintable, is_printable_fn);
|
||||
/* display bytes for last line as characters */
|
||||
for (i = 0; i < bytes_left; i++)
|
||||
charprint(outfile, p[index++], format->nonprintable,
|
||||
is_printable_fn);
|
||||
|
||||
/* pad the rest of the character area with spaces */
|
||||
for (; i < format->bytes_per_line; i++)
|
||||
fprintf(outfile, " ");
|
||||
/* pad the rest of the character area with spaces */
|
||||
for (; i < format->bytes_per_line; i++)
|
||||
fprintf(outfile, " ");
|
||||
|
||||
fprintf(outfile, "\n");
|
||||
}
|
||||
fprintf(outfile, "\n");
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* default_is_printable_fn
|
||||
|
@ -169,8 +172,10 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
|
|||
* return value:
|
||||
* Return 1 if the input character is printable. Otherwise return 0.
|
||||
*--------------------------------------------------------------------------*/
|
||||
int default_is_printable_fn (unsigned char c)
|
||||
{ return (c >= 0x20) && (c <= 0x7e); }
|
||||
int default_is_printable_fn(unsigned char c)
|
||||
{
|
||||
return (c >= 0x20) && (c <= 0x7e);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* addrprint
|
||||
|
@ -183,32 +188,33 @@ int default_is_printable_fn (unsigned char c)
|
|||
* width: The number of bytes wide the address should be displayed as.
|
||||
* Must be a value from 1 to 8.
|
||||
*--------------------------------------------------------------------------*/
|
||||
static void addrprint (FILE *outfile, uint64_t address, int width)
|
||||
{ char s[17];
|
||||
int i;
|
||||
static void addrprint(FILE * outfile, uint64_t address, int width)
|
||||
{
|
||||
char s[17];
|
||||
int i;
|
||||
|
||||
/* force the user's input to be valid */
|
||||
if (width < 1)
|
||||
width = 1;
|
||||
else if (width > 8)
|
||||
width = 8;
|
||||
/* force the user's input to be valid */
|
||||
if (width < 1)
|
||||
width = 1;
|
||||
else if (width > 8)
|
||||
width = 8;
|
||||
|
||||
/* convert address to string */
|
||||
sprintf(s, "%016llx", (unsigned long long) address);
|
||||
/* convert address to string */
|
||||
sprintf(s, "%016llx", (unsigned long long)address);
|
||||
|
||||
/* write it out, with colons separating consecutive 16-bit chunks of the
|
||||
* address
|
||||
*/
|
||||
for (i = 16 - (2 * width); ; )
|
||||
{ fprintf(outfile, "%c", s[i]);
|
||||
/* write it out, with colons separating consecutive 16-bit
|
||||
* chunks of the address
|
||||
*/
|
||||
for (i = 16 - (2 * width);;) {
|
||||
fprintf(outfile, "%c", s[i]);
|
||||
|
||||
if (++i >= 16)
|
||||
break;
|
||||
if (++i >= 16)
|
||||
break;
|
||||
|
||||
if ((i % 4) == 0)
|
||||
fprintf(outfile, ":");
|
||||
}
|
||||
}
|
||||
if ((i % 4) == 0)
|
||||
fprintf(outfile, ":");
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* hexprint
|
||||
|
@ -219,14 +225,15 @@ static void addrprint (FILE *outfile, uint64_t address, int width)
|
|||
* outfile: the place where the output should be written
|
||||
* byte: the byte to display
|
||||
*--------------------------------------------------------------------------*/
|
||||
static void hexprint (FILE *outfile, unsigned char byte)
|
||||
{ static const char tbl[] =
|
||||
{ '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
||||
};
|
||||
static void hexprint(FILE * outfile, unsigned char byte)
|
||||
{
|
||||
static const char tbl[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'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
|
||||
|
@ -241,7 +248,9 @@ static void hexprint (FILE *outfile, unsigned char byte)
|
|||
* is_printable_fn: a function that returns a boolean value indicating
|
||||
* whether a given character is printable
|
||||
*--------------------------------------------------------------------------*/
|
||||
static void charprint (FILE *outfile, unsigned char byte,
|
||||
unsigned char nonprintable,
|
||||
is_printable_fn_t is_printable_fn)
|
||||
{ fprintf(outfile, "%c", is_printable_fn(byte) ? byte : nonprintable); }
|
||||
static void charprint(FILE * outfile, unsigned char byte,
|
||||
unsigned char nonprintable,
|
||||
is_printable_fn_t is_printable_fn)
|
||||
{
|
||||
fprintf(outfile, "%c", is_printable_fn(byte) ? byte : nonprintable);
|
||||
}
|
||||
|
|
|
@ -81,17 +81,16 @@ typedef int (*is_printable_fn_t) (unsigned char c);
|
|||
* printable. A value of NULL will cause
|
||||
* default_is_printable_fn to be used.
|
||||
*--------------------------------------------------------------------------*/
|
||||
typedef struct
|
||||
{ int bytes_per_line;
|
||||
int addrprint_width;
|
||||
const char *indent;
|
||||
const char *sep1;
|
||||
const char *sep2;
|
||||
const char *sep3;
|
||||
unsigned char nonprintable;
|
||||
is_printable_fn_t is_printable_fn;
|
||||
}
|
||||
hexdump_format_t;
|
||||
typedef struct {
|
||||
int bytes_per_line;
|
||||
int addrprint_width;
|
||||
const char *indent;
|
||||
const char *sep1;
|
||||
const char *sep2;
|
||||
const char *sep3;
|
||||
unsigned char nonprintable;
|
||||
is_printable_fn_t is_printable_fn;
|
||||
} hexdump_format_t;
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* hexdump
|
||||
|
@ -109,8 +108,8 @@ hexdump_format_t;
|
|||
* format: A structure specifying how the hex dump should be
|
||||
* formatted.
|
||||
*--------------------------------------------------------------------------*/
|
||||
void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
|
||||
FILE *outfile, const hexdump_format_t *format);
|
||||
void hexdump(const void *mem, int bytes, uint64_t addrprint_start,
|
||||
FILE * outfile, const hexdump_format_t * format);
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* default_is_printable_fn
|
||||
|
@ -126,6 +125,6 @@ void hexdump (const void *mem, int bytes, uint64_t addrprint_start,
|
|||
* return value:
|
||||
* 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,38 +35,35 @@
|
|||
#include "cmos_lowlevel.h"
|
||||
#include "reg_expr.h"
|
||||
|
||||
static int get_input_file_line (FILE *f, char line[], int line_buf_size);
|
||||
static unsigned long long try_prepare_cmos_write (const cmos_entry_t *e,
|
||||
const char value_str[]);
|
||||
static int get_input_file_line(FILE * f, char line[], int line_buf_size);
|
||||
static unsigned long long try_prepare_cmos_write(const cmos_entry_t * e,
|
||||
const char value_str[]);
|
||||
|
||||
/* matches either a blank line or a comment line */
|
||||
static const char blank_or_comment_regex[] =
|
||||
/* a blank line */
|
||||
"(^[[:space:]]+$)"
|
||||
|
||||
"|" /* or ... */
|
||||
|
||||
/* a line consisting of: optional whitespace followed by */
|
||||
"(^[[:space:]]*"
|
||||
/* a '#' character and optionally, additional characters */
|
||||
"#.*$)";
|
||||
/* a blank line */
|
||||
"(^[[:space:]]+$)" "|" /* or ... */
|
||||
/* a line consisting of: optional whitespace followed by */
|
||||
"(^[[:space:]]*"
|
||||
/* a '#' character and optionally, additional characters */
|
||||
"#.*$)";
|
||||
|
||||
/* matches an assignment line */
|
||||
const char assignment_regex[] =
|
||||
/* optional whitespace */
|
||||
"^[[:space:]]*"
|
||||
/* followed by a coreboot parameter name */
|
||||
"([^[:space:]]+)"
|
||||
/* followed by optional whitespace */
|
||||
"[[:space:]]*"
|
||||
/* followed by an '=' character */
|
||||
"="
|
||||
/* followed by optional whitespace */
|
||||
"[[:space:]]*"
|
||||
/* followed by a value that may contain embedded whitespace */
|
||||
"([^[:space:]]+([[:space:]]+[^[:space:]]+)*)+"
|
||||
/* followed by optional whitespace */
|
||||
"[[:space:]]*$";
|
||||
/* optional whitespace */
|
||||
"^[[:space:]]*"
|
||||
/* followed by a coreboot parameter name */
|
||||
"([^[:space:]]+)"
|
||||
/* followed by optional whitespace */
|
||||
"[[:space:]]*"
|
||||
/* followed by an '=' character */
|
||||
"="
|
||||
/* followed by optional whitespace */
|
||||
"[[:space:]]*"
|
||||
/* followed by a value that may contain embedded whitespace */
|
||||
"([^[:space:]]+([[:space:]]+[^[:space:]]+)*)+"
|
||||
/* followed by optional whitespace */
|
||||
"[[:space:]]*$";
|
||||
|
||||
static int line_num;
|
||||
|
||||
|
@ -77,77 +74,77 @@ static int line_num;
|
|||
* write operations. Perform sanity checking on all write operations and
|
||||
* exit with an error message if there is a problem.
|
||||
****************************************************************************/
|
||||
cmos_write_t * process_input_file (FILE *f)
|
||||
{
|
||||
static const int LINE_BUF_SIZE = 256;
|
||||
static const size_t N_MATCHES = 4;
|
||||
char line[LINE_BUF_SIZE];
|
||||
const char *name, *value;
|
||||
cmos_write_t *list, *item, **p;
|
||||
regex_t blank_or_comment, assignment;
|
||||
regmatch_t match[N_MATCHES];
|
||||
const cmos_entry_t *e;
|
||||
cmos_write_t *process_input_file(FILE * f)
|
||||
{
|
||||
static const int LINE_BUF_SIZE = 256;
|
||||
static const size_t N_MATCHES = 4;
|
||||
char line[LINE_BUF_SIZE];
|
||||
const char *name, *value;
|
||||
cmos_write_t *list, *item, **p;
|
||||
regex_t blank_or_comment, assignment;
|
||||
regmatch_t match[N_MATCHES];
|
||||
const cmos_entry_t *e;
|
||||
|
||||
list = NULL;
|
||||
p = &list;
|
||||
list = NULL;
|
||||
p = &list;
|
||||
|
||||
compile_reg_exprs(REG_EXTENDED | REG_NEWLINE, 2, blank_or_comment_regex,
|
||||
&blank_or_comment, assignment_regex, &assignment);
|
||||
compile_reg_exprs(REG_EXTENDED | REG_NEWLINE, 2, blank_or_comment_regex,
|
||||
&blank_or_comment, assignment_regex, &assignment);
|
||||
|
||||
/* each iteration processes one line from input file */
|
||||
for (line_num = 1;
|
||||
get_input_file_line(f, line, LINE_BUF_SIZE) == OK;
|
||||
line_num++)
|
||||
{ /* skip comments and blank lines */
|
||||
if (!regexec(&blank_or_comment, line, 0, NULL, 0))
|
||||
continue;
|
||||
/* each iteration processes one line from input file */
|
||||
for (line_num = 1; get_input_file_line(f, line, LINE_BUF_SIZE) == OK; line_num++) { /* skip comments and blank lines */
|
||||
if (!regexec(&blank_or_comment, line, 0, NULL, 0))
|
||||
continue;
|
||||
|
||||
/* Is this a valid assignment line? If not, then it's a syntax
|
||||
* error.
|
||||
*/
|
||||
if (regexec(&assignment, line, N_MATCHES, match, 0))
|
||||
{ fprintf(stderr, "%s: Syntax error on line %d of input file.\n",
|
||||
prog_name, line_num);
|
||||
exit(1);
|
||||
}
|
||||
/* Is this a valid assignment line? If not, then it's a syntax
|
||||
* error.
|
||||
*/
|
||||
if (regexec(&assignment, line, N_MATCHES, match, 0)) {
|
||||
fprintf(stderr,
|
||||
"%s: Syntax error on line %d of input file.\n",
|
||||
prog_name, line_num);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* OK, we found an assignment. Break the line into substrings
|
||||
* representing the lefthand and righthand sides of the assignment.
|
||||
*/
|
||||
line[match[1].rm_eo] = '\0';
|
||||
line[match[2].rm_eo] = '\0';
|
||||
name = &line[match[1].rm_so];
|
||||
value = &line[match[2].rm_so];
|
||||
/* OK, we found an assignment. Break the line into substrings
|
||||
* representing the lefthand and righthand sides of the assignment.
|
||||
*/
|
||||
line[match[1].rm_eo] = '\0';
|
||||
line[match[2].rm_eo] = '\0';
|
||||
name = &line[match[1].rm_so];
|
||||
value = &line[match[2].rm_so];
|
||||
|
||||
/* now look up the coreboot parameter name */
|
||||
if (is_checksum_name(name) || (e = find_cmos_entry(name)) == NULL)
|
||||
{ fprintf(stderr, "%s: Error on line %d of input file: CMOS parameter "
|
||||
"%s not found.\n", prog_name, line_num, name);
|
||||
exit(1);
|
||||
}
|
||||
/* now look up the coreboot parameter name */
|
||||
if (is_checksum_name(name)
|
||||
|| (e = find_cmos_entry(name)) == NULL) {
|
||||
fprintf(stderr,
|
||||
"%s: Error on line %d of input file: CMOS parameter "
|
||||
"%s not found.\n", prog_name, line_num, name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* At this point, we figure out what numeric value needs to be written
|
||||
* to which location. At the same time, we perform sanity checking on
|
||||
* the write operation.
|
||||
*/
|
||||
/* At this point, we figure out what numeric value needs to be written
|
||||
* to which location. At the same time, we perform sanity checking on
|
||||
* the write operation.
|
||||
*/
|
||||
|
||||
if ((item = (cmos_write_t *) malloc(sizeof(*item))) == NULL)
|
||||
out_of_memory();
|
||||
if ((item = (cmos_write_t *) malloc(sizeof(*item))) == NULL)
|
||||
out_of_memory();
|
||||
|
||||
item->bit = e->bit;
|
||||
item->length = e->length;
|
||||
item->config = e->config;
|
||||
item->value = try_prepare_cmos_write(e, value);
|
||||
item->bit = e->bit;
|
||||
item->length = e->length;
|
||||
item->config = e->config;
|
||||
item->value = try_prepare_cmos_write(e, value);
|
||||
|
||||
/* Append write operation to pending write list. */
|
||||
item->next = NULL;
|
||||
*p = item;
|
||||
p = &item->next;
|
||||
}
|
||||
/* Append write operation to pending write list. */
|
||||
item->next = NULL;
|
||||
*p = item;
|
||||
p = &item->next;
|
||||
}
|
||||
|
||||
free_reg_exprs(2, &blank_or_comment, &assignment);
|
||||
return list;
|
||||
}
|
||||
free_reg_exprs(2, &blank_or_comment, &assignment);
|
||||
return list;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* do_cmos_writes
|
||||
|
@ -156,25 +153,26 @@ cmos_write_t * process_input_file (FILE *f)
|
|||
* all sanity checks. Perform all write operations, destroying the list as
|
||||
* we go.
|
||||
****************************************************************************/
|
||||
void do_cmos_writes (cmos_write_t *list)
|
||||
{ cmos_write_t *item;
|
||||
void do_cmos_writes(cmos_write_t * list)
|
||||
{
|
||||
cmos_write_t *item;
|
||||
|
||||
set_iopl(3);
|
||||
set_iopl(3);
|
||||
|
||||
while (list != NULL)
|
||||
{ cmos_entry_t e;
|
||||
item = list;
|
||||
e.bit = item->bit;
|
||||
e.length = item->length;
|
||||
e.config = item->config;
|
||||
list = item->next;
|
||||
cmos_write(&e, item->value);
|
||||
free(item);
|
||||
}
|
||||
while (list != NULL) {
|
||||
cmos_entry_t e;
|
||||
item = list;
|
||||
e.bit = item->bit;
|
||||
e.length = item->length;
|
||||
e.config = item->config;
|
||||
list = item->next;
|
||||
cmos_write(&e, item->value);
|
||||
free(item);
|
||||
}
|
||||
|
||||
cmos_checksum_write(cmos_checksum_compute());
|
||||
set_iopl(0);
|
||||
}
|
||||
cmos_checksum_write(cmos_checksum_compute());
|
||||
set_iopl(0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* get_input_file_line
|
||||
|
@ -183,27 +181,29 @@ void do_cmos_writes (cmos_write_t *list)
|
|||
* array of 'line_buf_size' bytes. Return OK on success or an error code on
|
||||
* error.
|
||||
****************************************************************************/
|
||||
static int get_input_file_line (FILE *f, char line[], int line_buf_size)
|
||||
{ switch (get_line_from_file(f, line, line_buf_size))
|
||||
{ case OK:
|
||||
return OK;
|
||||
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:
|
||||
return OK;
|
||||
|
||||
case LINE_EOF:
|
||||
return LINE_EOF;
|
||||
case LINE_EOF:
|
||||
return LINE_EOF;
|
||||
|
||||
case LINE_TOO_LONG:
|
||||
fprintf(stderr, "%s: Error on line %d of input file: Maximum line "
|
||||
"length exceeded. Max is %d characters.\n", prog_name,
|
||||
line_num, line_buf_size - 2);
|
||||
break;
|
||||
case LINE_TOO_LONG:
|
||||
fprintf(stderr,
|
||||
"%s: Error on line %d of input file: Maximum line "
|
||||
"length exceeded. Max is %d characters.\n", prog_name,
|
||||
line_num, line_buf_size - 2);
|
||||
break;
|
||||
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
|
||||
exit(1);
|
||||
return 1; /* keep compiler happy */
|
||||
}
|
||||
exit(1);
|
||||
return 1; /* keep compiler happy */
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* try_prepare_cmos_write
|
||||
|
@ -212,73 +212,83 @@ 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
|
||||
* an error message.
|
||||
****************************************************************************/
|
||||
static unsigned long long try_prepare_cmos_write (const cmos_entry_t *e,
|
||||
const char value_str[])
|
||||
{ unsigned long long value;
|
||||
static unsigned long long try_prepare_cmos_write(const cmos_entry_t * e,
|
||||
const char value_str[])
|
||||
{
|
||||
unsigned long long value;
|
||||
|
||||
switch (prepare_cmos_write(e, value_str, &value))
|
||||
{ case OK:
|
||||
return value;
|
||||
switch (prepare_cmos_write(e, value_str, &value)) {
|
||||
case OK:
|
||||
return value;
|
||||
|
||||
case CMOS_OP_BAD_ENUM_VALUE:
|
||||
fprintf(stderr, "%s: Error on line %d of input file: Bad value for "
|
||||
"parameter %s.", prog_name, line_num, e->name);
|
||||
break;
|
||||
case CMOS_OP_BAD_ENUM_VALUE:
|
||||
fprintf(stderr,
|
||||
"%s: Error on line %d of input file: Bad value for "
|
||||
"parameter %s.", prog_name, line_num, e->name);
|
||||
break;
|
||||
|
||||
case CMOS_OP_NEGATIVE_INT:
|
||||
fprintf(stderr, "%s: Error on line %d of input file: This program "
|
||||
"does not support assignment of negative numbers to "
|
||||
"coreboot parameters.", prog_name, line_num);
|
||||
break;
|
||||
case CMOS_OP_NEGATIVE_INT:
|
||||
fprintf(stderr,
|
||||
"%s: Error on line %d of input file: This program "
|
||||
"does not support assignment of negative numbers to "
|
||||
"coreboot parameters.", prog_name, line_num);
|
||||
break;
|
||||
|
||||
case CMOS_OP_INVALID_INT:
|
||||
fprintf(stderr, "%s: Error on line %d of input file: %s is not a "
|
||||
"valid integer.", prog_name, line_num, value_str);
|
||||
break;
|
||||
case CMOS_OP_INVALID_INT:
|
||||
fprintf(stderr,
|
||||
"%s: Error on line %d of input file: %s is not a "
|
||||
"valid integer.", prog_name, line_num, value_str);
|
||||
break;
|
||||
|
||||
case CMOS_OP_RESERVED:
|
||||
fprintf(stderr, "%s: Error on line %d of input file: Can not modify "
|
||||
"reserved coreboot parameter %s.", prog_name, line_num,
|
||||
e->name);
|
||||
break;
|
||||
case CMOS_OP_RESERVED:
|
||||
fprintf(stderr,
|
||||
"%s: Error on line %d of input file: Can not modify "
|
||||
"reserved coreboot parameter %s.", prog_name, line_num,
|
||||
e->name);
|
||||
break;
|
||||
|
||||
case CMOS_OP_VALUE_TOO_WIDE:
|
||||
fprintf(stderr, "%s: Error on line %d of input file: Can not write "
|
||||
"value %s to CMOS parameter %s that is only %d bits wide.",
|
||||
prog_name, line_num, value_str, e->name, e->length);
|
||||
break;
|
||||
case CMOS_OP_VALUE_TOO_WIDE:
|
||||
fprintf(stderr,
|
||||
"%s: Error on line %d of input file: Can not write "
|
||||
"value %s to CMOS parameter %s that is only %d bits wide.",
|
||||
prog_name, line_num, value_str, e->name, e->length);
|
||||
break;
|
||||
|
||||
case CMOS_OP_NO_MATCHING_ENUM:
|
||||
fprintf(stderr, "%s: coreboot parameter %s has no matching enums.",
|
||||
prog_name, e->name);
|
||||
break;
|
||||
case CMOS_OP_NO_MATCHING_ENUM:
|
||||
fprintf(stderr,
|
||||
"%s: coreboot parameter %s has no matching enums.",
|
||||
prog_name, e->name);
|
||||
break;
|
||||
|
||||
case CMOS_AREA_OUT_OF_RANGE:
|
||||
fprintf(stderr, "%s: The CMOS area specified by the layout info for "
|
||||
"coreboot parameter %s is out of range.", prog_name,
|
||||
e->name);
|
||||
break;
|
||||
case CMOS_AREA_OUT_OF_RANGE:
|
||||
fprintf(stderr,
|
||||
"%s: The CMOS area specified by the layout info for "
|
||||
"coreboot parameter %s is out of range.", prog_name,
|
||||
e->name);
|
||||
break;
|
||||
|
||||
case CMOS_AREA_OVERLAPS_RTC:
|
||||
fprintf(stderr, "%s: The CMOS area specified by the layout info for "
|
||||
"coreboot parameter %s overlaps the realtime clock area.",
|
||||
prog_name, e->name);
|
||||
break;
|
||||
case CMOS_AREA_OVERLAPS_RTC:
|
||||
fprintf(stderr,
|
||||
"%s: The CMOS area specified by the layout info for "
|
||||
"coreboot parameter %s overlaps the realtime clock area.",
|
||||
prog_name, e->name);
|
||||
break;
|
||||
|
||||
case CMOS_AREA_TOO_WIDE:
|
||||
fprintf(stderr, "%s: The CMOS area specified by the layout info for "
|
||||
"coreboot parameter %s is too wide.",
|
||||
prog_name, e->name);
|
||||
break;
|
||||
case CMOS_AREA_TOO_WIDE:
|
||||
fprintf(stderr,
|
||||
"%s: The CMOS area specified by the layout info for "
|
||||
"coreboot parameter %s is too wide.", prog_name,
|
||||
e->name);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"%s: Unknown error encountered while attempting to modify "
|
||||
"coreboot parameter %s.", prog_name, e->name);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"%s: Unknown error encountered while attempting to modify "
|
||||
"coreboot parameter %s.", prog_name, e->name);
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, " No CMOS writes performed.\n");
|
||||
exit(1);
|
||||
return 0; /* keep compiler happy */
|
||||
}
|
||||
fprintf(stderr, " No CMOS writes performed.\n");
|
||||
exit(1);
|
||||
return 0; /* keep compiler happy */
|
||||
}
|
||||
|
|
|
@ -36,22 +36,22 @@
|
|||
|
||||
typedef struct cmos_write_t cmos_write_t;
|
||||
|
||||
/* This represents a pending CMOS write operation. When changing multiple
|
||||
* CMOS parameter values, we first represent the changes as a list of pending
|
||||
* write operations. This allows us to sanity check all write operations
|
||||
* before any of them are performed.
|
||||
/* This represents a pending CMOS write operation. When changing
|
||||
* multiple CMOS parameter values, we first represent the changes as a
|
||||
* list of pending write operations. This allows us to sanity check all
|
||||
* write operations before any of them are performed.
|
||||
*/
|
||||
struct cmos_write_t
|
||||
{ unsigned bit;
|
||||
unsigned length;
|
||||
cmos_entry_config_t config;
|
||||
unsigned long long value;
|
||||
cmos_write_t *next;
|
||||
};
|
||||
struct cmos_write_t {
|
||||
unsigned bit;
|
||||
unsigned length;
|
||||
cmos_entry_config_t config;
|
||||
unsigned long long value;
|
||||
cmos_write_t *next;
|
||||
};
|
||||
|
||||
cmos_write_t * process_input_file (FILE *f);
|
||||
void do_cmos_writes (cmos_write_t *list);
|
||||
cmos_write_t *process_input_file(FILE * f);
|
||||
void do_cmos_writes(cmos_write_t * list);
|
||||
|
||||
extern const char assignment_regex[];
|
||||
|
||||
#endif /* INPUT_FILE_H */
|
||||
#endif /* INPUT_FILE_H */
|
||||
|
|
|
@ -13,4 +13,4 @@
|
|||
|
||||
unsigned long compute_ip_checksum(void *addr, unsigned long length);
|
||||
|
||||
#endif /* IP_CHECKSUM_H */
|
||||
#endif /* IP_CHECKSUM_H */
|
||||
|
|
|
@ -34,23 +34,23 @@
|
|||
|
||||
typedef struct cmos_entry_item_t cmos_entry_item_t;
|
||||
|
||||
struct cmos_entry_item_t
|
||||
{ cmos_entry_t item;
|
||||
cmos_entry_item_t *next;
|
||||
};
|
||||
struct cmos_entry_item_t {
|
||||
cmos_entry_t item;
|
||||
cmos_entry_item_t *next;
|
||||
};
|
||||
|
||||
typedef struct cmos_enum_item_t cmos_enum_item_t;
|
||||
|
||||
struct cmos_enum_item_t
|
||||
{ cmos_enum_t item;
|
||||
cmos_enum_item_t *next;
|
||||
};
|
||||
struct cmos_enum_item_t {
|
||||
cmos_enum_t item;
|
||||
cmos_enum_item_t *next;
|
||||
};
|
||||
|
||||
static void default_cmos_layout_get_fn (void);
|
||||
static int areas_overlap (unsigned area_0_start, unsigned area_0_length,
|
||||
unsigned area_1_start, unsigned area_1_length);
|
||||
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 void default_cmos_layout_get_fn(void);
|
||||
static int areas_overlap(unsigned area_0_start, unsigned area_0_length,
|
||||
unsigned area_1_start, unsigned area_1_length);
|
||||
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);
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
static inline int entries_overlap (const cmos_entry_t *p,
|
||||
const cmos_entry_t *q)
|
||||
{ return areas_overlap(p->bit, p->length, q->bit, q->length); }
|
||||
static inline int entries_overlap(const cmos_entry_t * p,
|
||||
const cmos_entry_t * q)
|
||||
{
|
||||
return areas_overlap(p->bit, p->length, q->bit, q->length);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* cmos_entry_to_const_item
|
||||
*
|
||||
* Return a pointer to the cmos_entry_item_t that 'p' is embedded within.
|
||||
****************************************************************************/
|
||||
static inline const cmos_entry_item_t * cmos_entry_to_const_item
|
||||
(const cmos_entry_t *p)
|
||||
{ static const cmos_entry_t *pos = &((cmos_entry_item_t *) 0)->item;
|
||||
unsigned long offset, address;
|
||||
static inline const cmos_entry_item_t *cmos_entry_to_const_item
|
||||
(const cmos_entry_t * p) {
|
||||
static const cmos_entry_t *pos = &((cmos_entry_item_t *) 0)->item;
|
||||
unsigned long offset, address;
|
||||
|
||||
offset = (unsigned long) pos;
|
||||
address = ((unsigned long) p) - offset;
|
||||
return (const cmos_entry_item_t *) address;
|
||||
}
|
||||
offset = (unsigned long)pos;
|
||||
address = ((unsigned long)p) - offset;
|
||||
return (const cmos_entry_item_t *)address;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* cmos_enum_to_const_item
|
||||
*
|
||||
* Return a pointer to the cmos_enum_item_t that 'p' is embedded within.
|
||||
****************************************************************************/
|
||||
static inline const cmos_enum_item_t * cmos_enum_to_const_item
|
||||
(const cmos_enum_t *p)
|
||||
{ static const cmos_enum_t *pos = &((cmos_enum_item_t *) 0)->item;
|
||||
unsigned long offset, address;
|
||||
static inline const cmos_enum_item_t *cmos_enum_to_const_item
|
||||
(const cmos_enum_t * p) {
|
||||
static const cmos_enum_t *pos = &((cmos_enum_item_t *) 0)->item;
|
||||
unsigned long offset, address;
|
||||
|
||||
offset = (unsigned long) pos;
|
||||
address = ((unsigned long) p) - offset;
|
||||
return (const cmos_enum_item_t *) address;
|
||||
}
|
||||
offset = (unsigned long)pos;
|
||||
address = ((unsigned long)p) - offset;
|
||||
return (const cmos_enum_item_t *)address;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* information.
|
||||
****************************************************************************/
|
||||
void register_cmos_layout_get_fn (cmos_layout_get_fn_t fn)
|
||||
{ cmos_layout_get_fn = fn; }
|
||||
void register_cmos_layout_get_fn(cmos_layout_get_fn_t fn)
|
||||
{
|
||||
cmos_layout_get_fn = fn;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* get_cmos_layout
|
||||
*
|
||||
* Retrieve CMOS layout information and store it in our internal repository.
|
||||
****************************************************************************/
|
||||
void get_cmos_layout (void)
|
||||
{ cmos_layout_get_fn(); }
|
||||
void get_cmos_layout(void)
|
||||
{
|
||||
cmos_layout_get_fn();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* add_cmos_entry
|
||||
|
@ -158,61 +164,63 @@ void get_cmos_layout (void)
|
|||
* operation fails because 'e' overlaps an existing CMOS entry, '*conflict'
|
||||
* will be set to point to the overlapping entry.
|
||||
****************************************************************************/
|
||||
int add_cmos_entry (const cmos_entry_t *e, const cmos_entry_t **conflict)
|
||||
{ cmos_entry_item_t *item, *prev, *new_entry;
|
||||
int add_cmos_entry(const cmos_entry_t * e, const cmos_entry_t ** conflict)
|
||||
{
|
||||
cmos_entry_item_t *item, *prev, *new_entry;
|
||||
|
||||
*conflict = NULL;
|
||||
*conflict = NULL;
|
||||
|
||||
if (e->length < 1)
|
||||
return LAYOUT_ENTRY_BAD_LENGTH;
|
||||
if (e->length < 1)
|
||||
return LAYOUT_ENTRY_BAD_LENGTH;
|
||||
|
||||
if ((new_entry = (cmos_entry_item_t *) malloc(sizeof(*new_entry))) == NULL)
|
||||
out_of_memory();
|
||||
if ((new_entry =
|
||||
(cmos_entry_item_t *) malloc(sizeof(*new_entry))) == NULL)
|
||||
out_of_memory();
|
||||
|
||||
new_entry->item = *e;
|
||||
new_entry->item = *e;
|
||||
|
||||
if (cmos_entry_list == NULL)
|
||||
{ new_entry->next = NULL;
|
||||
cmos_entry_list = new_entry;
|
||||
return OK;
|
||||
}
|
||||
if (cmos_entry_list == NULL) {
|
||||
new_entry->next = NULL;
|
||||
cmos_entry_list = new_entry;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Find place in list to insert new entry. List is sorted in ascending
|
||||
* order.
|
||||
*/
|
||||
for (item = cmos_entry_list, prev = NULL;
|
||||
(item != NULL) && (item->item.bit < e->bit);
|
||||
prev = item, item = item->next);
|
||||
/* Find place in list to insert new entry. List is sorted in ascending
|
||||
* order.
|
||||
*/
|
||||
for (item = cmos_entry_list, prev = NULL;
|
||||
(item != NULL) && (item->item.bit < e->bit);
|
||||
prev = item, item = item->next) ;
|
||||
|
||||
if (prev == NULL)
|
||||
{ if (entries_overlap(e, &cmos_entry_list->item))
|
||||
{ *conflict = &cmos_entry_list->item;
|
||||
goto fail;
|
||||
}
|
||||
if (prev == NULL) {
|
||||
if (entries_overlap(e, &cmos_entry_list->item)) {
|
||||
*conflict = &cmos_entry_list->item;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
new_entry->next = cmos_entry_list;
|
||||
cmos_entry_list = new_entry;
|
||||
return OK;
|
||||
}
|
||||
new_entry->next = cmos_entry_list;
|
||||
cmos_entry_list = new_entry;
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (entries_overlap(&prev->item, e))
|
||||
{ *conflict = &prev->item;
|
||||
goto fail;
|
||||
}
|
||||
if (entries_overlap(&prev->item, e)) {
|
||||
*conflict = &prev->item;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ((item != NULL) && entries_overlap(e, &item->item))
|
||||
{ *conflict = &item->item;
|
||||
goto fail;
|
||||
}
|
||||
if ((item != NULL) && entries_overlap(e, &item->item)) {
|
||||
*conflict = &item->item;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
new_entry->next = item;
|
||||
prev->next = new_entry;
|
||||
return OK;
|
||||
new_entry->next = item;
|
||||
prev->next = new_entry;
|
||||
return OK;
|
||||
|
||||
fail:
|
||||
free(new_entry);
|
||||
return LAYOUT_ENTRY_OVERLAP;
|
||||
}
|
||||
fail:
|
||||
free(new_entry);
|
||||
return LAYOUT_ENTRY_OVERLAP;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* find_cmos_entry
|
||||
|
@ -220,16 +228,17 @@ fail:
|
|||
* Search for a CMOS entry whose name is 'name'. Return pointer to matching
|
||||
* entry or NULL if entry not found.
|
||||
****************************************************************************/
|
||||
const cmos_entry_t * find_cmos_entry (const char name[])
|
||||
{ cmos_entry_item_t *item;
|
||||
const cmos_entry_t *find_cmos_entry(const char name[])
|
||||
{
|
||||
cmos_entry_item_t *item;
|
||||
|
||||
for (item = cmos_entry_list; item != NULL; item = item->next)
|
||||
{ if (!strcmp(item->item.name, name))
|
||||
return &item->item;
|
||||
}
|
||||
for (item = cmos_entry_list; item != NULL; item = item->next) {
|
||||
if (!strcmp(item->item.name, name))
|
||||
return &item->item;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* empty.
|
||||
****************************************************************************/
|
||||
const cmos_entry_t * first_cmos_entry (void)
|
||||
{ return (cmos_entry_list == NULL) ? NULL : &cmos_entry_list->item; }
|
||||
const cmos_entry_t *first_cmos_entry(void)
|
||||
{
|
||||
return (cmos_entry_list == NULL) ? NULL : &cmos_entry_list->item;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* entries.
|
||||
****************************************************************************/
|
||||
const cmos_entry_t * next_cmos_entry (const cmos_entry_t *last)
|
||||
{ const cmos_entry_item_t *last_item, *next_item;
|
||||
const cmos_entry_t *next_cmos_entry(const cmos_entry_t * last)
|
||||
{
|
||||
const cmos_entry_item_t *last_item, *next_item;
|
||||
|
||||
last_item = cmos_entry_to_const_item(last);
|
||||
next_item = last_item->next;
|
||||
return (next_item == NULL) ? NULL : &next_item->item;
|
||||
}
|
||||
last_item = cmos_entry_to_const_item(last);
|
||||
next_item = last_item->next;
|
||||
return (next_item == NULL) ? NULL : &next_item->item;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* add_cmos_enum
|
||||
|
@ -260,73 +272,75 @@ const cmos_entry_t * next_cmos_entry (const cmos_entry_t *last)
|
|||
* Attempt to add CMOS enum 'e' to our internal repository of layout
|
||||
* information. Return OK on success or an error code on failure.
|
||||
****************************************************************************/
|
||||
int add_cmos_enum (const cmos_enum_t *e)
|
||||
{ cmos_enum_item_t *item, *prev, *new_enum;
|
||||
int add_cmos_enum(const cmos_enum_t * e)
|
||||
{
|
||||
cmos_enum_item_t *item, *prev, *new_enum;
|
||||
|
||||
if ((new_enum = (cmos_enum_item_t *) malloc(sizeof(*new_enum))) == NULL)
|
||||
out_of_memory();
|
||||
if ((new_enum = (cmos_enum_item_t *) malloc(sizeof(*new_enum))) == NULL)
|
||||
out_of_memory();
|
||||
|
||||
new_enum->item = *e;
|
||||
new_enum->item = *e;
|
||||
|
||||
if (cmos_enum_list == NULL)
|
||||
{ new_enum->next = NULL;
|
||||
cmos_enum_list = new_enum;
|
||||
return OK;
|
||||
}
|
||||
if (cmos_enum_list == NULL) {
|
||||
new_enum->next = NULL;
|
||||
cmos_enum_list = new_enum;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* The list of enums is sorted in ascending order, first by 'config_id' and
|
||||
* then by 'value'. Look for the first enum whose 'config_id' field
|
||||
* matches 'e'.
|
||||
*/
|
||||
for (item = cmos_enum_list, prev = NULL;
|
||||
(item != NULL) && (item->item.config_id < e->config_id);
|
||||
prev = item, item = item->next);
|
||||
/* The list of enums is sorted in ascending order, first by
|
||||
* 'config_id' and then by 'value'. Look for the first enum
|
||||
* whose 'config_id' field matches 'e'.
|
||||
*/
|
||||
for (item = cmos_enum_list, prev = NULL;
|
||||
(item != NULL) && (item->item.config_id < e->config_id);
|
||||
prev = item, item = item->next) ;
|
||||
|
||||
if (item == NULL)
|
||||
{ new_enum->next = NULL;
|
||||
prev->next = new_enum;
|
||||
return OK;
|
||||
}
|
||||
if (item == NULL) {
|
||||
new_enum->next = NULL;
|
||||
prev->next = new_enum;
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (item->item.config_id > e->config_id)
|
||||
{ new_enum->next = item;
|
||||
if (item->item.config_id > e->config_id) {
|
||||
new_enum->next = item;
|
||||
|
||||
if (prev == NULL)
|
||||
cmos_enum_list = new_enum;
|
||||
else
|
||||
prev->next = new_enum;
|
||||
if (prev == NULL)
|
||||
cmos_enum_list = new_enum;
|
||||
else
|
||||
prev->next = new_enum;
|
||||
|
||||
return OK;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* List already contains at least one enum whose 'config_id' matches 'e'.
|
||||
* Now find proper place to insert 'e' based on 'value'.
|
||||
*/
|
||||
while (item->item.value < e->value)
|
||||
{ prev = item;
|
||||
item = item->next;
|
||||
/* List already contains at least one enum whose 'config_id'
|
||||
* matches 'e'. Now find proper place to insert 'e' based on
|
||||
* 'value'.
|
||||
*/
|
||||
while (item->item.value < e->value) {
|
||||
prev = item;
|
||||
item = item->next;
|
||||
|
||||
if ((item == NULL) || (item->item.config_id != e->config_id))
|
||||
{ new_enum->next = item;
|
||||
prev->next = new_enum;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
if ((item == NULL) || (item->item.config_id != e->config_id)) {
|
||||
new_enum->next = item;
|
||||
prev->next = new_enum;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (item->item.value == e->value)
|
||||
{ free(new_enum);
|
||||
return LAYOUT_DUPLICATE_ENUM;
|
||||
}
|
||||
if (item->item.value == e->value) {
|
||||
free(new_enum);
|
||||
return LAYOUT_DUPLICATE_ENUM;
|
||||
}
|
||||
|
||||
new_enum->next = item;
|
||||
new_enum->next = item;
|
||||
|
||||
if (prev == NULL)
|
||||
cmos_enum_list = new_enum;
|
||||
else
|
||||
prev->next = new_enum;
|
||||
if (prev == NULL)
|
||||
cmos_enum_list = new_enum;
|
||||
else
|
||||
prev->next = new_enum;
|
||||
|
||||
return OK;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* a pointer to the mathcing enum. Else return NULL.
|
||||
****************************************************************************/
|
||||
const cmos_enum_t * find_cmos_enum (unsigned config_id,
|
||||
unsigned long long value)
|
||||
{ const cmos_enum_item_t *item;
|
||||
const cmos_enum_t *find_cmos_enum(unsigned config_id, unsigned long long value)
|
||||
{
|
||||
const cmos_enum_item_t *item;
|
||||
|
||||
if ((item = find_first_cmos_enum_id(config_id)) == NULL)
|
||||
return NULL;
|
||||
if ((item = find_first_cmos_enum_id(config_id)) == NULL)
|
||||
return NULL;
|
||||
|
||||
while (item->item.value < value)
|
||||
{ item = item->next;
|
||||
while (item->item.value < value) {
|
||||
item = item->next;
|
||||
|
||||
if ((item == NULL) || (item->item.config_id != config_id))
|
||||
return NULL;
|
||||
}
|
||||
if ((item == NULL) || (item->item.config_id != config_id))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (item->item.value == value) ? &item->item : NULL;
|
||||
}
|
||||
return (item->item.value == value) ? &item->item : NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* empty.
|
||||
****************************************************************************/
|
||||
const cmos_enum_t * first_cmos_enum (void)
|
||||
{ return (cmos_enum_list == NULL) ? NULL : &cmos_enum_list->item; }
|
||||
const cmos_enum_t *first_cmos_enum(void)
|
||||
{
|
||||
return (cmos_enum_list == NULL) ? NULL : &cmos_enum_list->item;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* enums.
|
||||
****************************************************************************/
|
||||
const cmos_enum_t * next_cmos_enum (const cmos_enum_t *last)
|
||||
{ const cmos_enum_item_t *last_item, *next_item;
|
||||
const cmos_enum_t *next_cmos_enum(const cmos_enum_t * last)
|
||||
{
|
||||
const cmos_enum_item_t *last_item, *next_item;
|
||||
|
||||
last_item = cmos_enum_to_const_item(last);
|
||||
next_item = last_item->next;
|
||||
return (next_item == NULL) ? NULL : &next_item->item;
|
||||
}
|
||||
last_item = cmos_enum_to_const_item(last);
|
||||
next_item = last_item->next;
|
||||
return (next_item == NULL) ? NULL : &next_item->item;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* 'config_id' or NULL if there are no matching enums.
|
||||
****************************************************************************/
|
||||
const cmos_enum_t * first_cmos_enum_id (unsigned config_id)
|
||||
{ const cmos_enum_item_t *item;
|
||||
const cmos_enum_t *first_cmos_enum_id(unsigned config_id)
|
||||
{
|
||||
const cmos_enum_item_t *item;
|
||||
|
||||
item = find_first_cmos_enum_id(config_id);
|
||||
return (item == NULL) ? NULL : &item->item;
|
||||
}
|
||||
item = find_first_cmos_enum_id(config_id);
|
||||
return (item == NULL) ? NULL : &item->item;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* 'config_id' field of 'last' or NULL if there are no more matching enums.
|
||||
****************************************************************************/
|
||||
const cmos_enum_t * next_cmos_enum_id (const cmos_enum_t *last)
|
||||
{ const cmos_enum_item_t *item;
|
||||
const cmos_enum_t *next_cmos_enum_id(const cmos_enum_t * last)
|
||||
{
|
||||
const cmos_enum_item_t *item;
|
||||
|
||||
item = cmos_enum_to_const_item(last)->next;
|
||||
return ((item == NULL) || (item->item.config_id != last->config_id)) ?
|
||||
NULL : &item->item;
|
||||
}
|
||||
item = cmos_enum_to_const_item(last)->next;
|
||||
return ((item == NULL) || (item->item.config_id != last->config_id)) ?
|
||||
NULL : &item->item;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* checksum. Else return 0.
|
||||
****************************************************************************/
|
||||
int is_checksum_name (const char name[])
|
||||
{ return !strcmp(name, checksum_param_name); }
|
||||
int is_checksum_name(const char name[])
|
||||
{
|
||||
return !strcmp(name, checksum_param_name);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* checksum_layout_to_bytes
|
||||
|
@ -418,45 +439,46 @@ int is_checksum_name (const char name[])
|
|||
* bit positions to byte positions. Return OK on success or an error code if
|
||||
* a sanity check fails.
|
||||
****************************************************************************/
|
||||
int checksum_layout_to_bytes (cmos_checksum_layout_t *layout)
|
||||
{ unsigned start, end, index;
|
||||
int checksum_layout_to_bytes(cmos_checksum_layout_t * layout)
|
||||
{
|
||||
unsigned start, end, index;
|
||||
|
||||
start = layout->summed_area_start;
|
||||
end = layout->summed_area_end;
|
||||
index = layout->checksum_at;
|
||||
start = layout->summed_area_start;
|
||||
end = layout->summed_area_end;
|
||||
index = layout->checksum_at;
|
||||
|
||||
if (start % 8)
|
||||
return LAYOUT_SUMMED_AREA_START_NOT_ALIGNED;
|
||||
if (start % 8)
|
||||
return LAYOUT_SUMMED_AREA_START_NOT_ALIGNED;
|
||||
|
||||
if ((end % 8) != 7)
|
||||
return LAYOUT_SUMMED_AREA_END_NOT_ALIGNED;
|
||||
if ((end % 8) != 7)
|
||||
return LAYOUT_SUMMED_AREA_END_NOT_ALIGNED;
|
||||
|
||||
if (index % 8)
|
||||
return LAYOUT_CHECKSUM_LOCATION_NOT_ALIGNED;
|
||||
if (index % 8)
|
||||
return LAYOUT_CHECKSUM_LOCATION_NOT_ALIGNED;
|
||||
|
||||
if (end <= start)
|
||||
return LAYOUT_INVALID_SUMMED_AREA;
|
||||
if (end <= start)
|
||||
return LAYOUT_INVALID_SUMMED_AREA;
|
||||
|
||||
/* Convert bit positions to byte positions. */
|
||||
start /= 8;
|
||||
end /= 8; /* equivalent to "end = ((end - 7) / 8)" */
|
||||
index /= 8;
|
||||
/* Convert bit positions to byte positions. */
|
||||
start /= 8;
|
||||
end /= 8; /* equivalent to "end = ((end - 7) / 8)" */
|
||||
index /= 8;
|
||||
|
||||
if (verify_cmos_byte_index(start) || verify_cmos_byte_index(end))
|
||||
return LAYOUT_SUMMED_AREA_OUT_OF_RANGE;
|
||||
if (verify_cmos_byte_index(start) || verify_cmos_byte_index(end))
|
||||
return LAYOUT_SUMMED_AREA_OUT_OF_RANGE;
|
||||
|
||||
if (verify_cmos_byte_index(index))
|
||||
return LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE;
|
||||
if (verify_cmos_byte_index(index))
|
||||
return LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE;
|
||||
|
||||
/* checksum occupies 16 bits */
|
||||
if (areas_overlap(start, end - start + 1, index, index + 1))
|
||||
return LAYOUT_CHECKSUM_OVERLAPS_SUMMED_AREA;
|
||||
/* checksum occupies 16 bits */
|
||||
if (areas_overlap(start, end - start + 1, index, index + 1))
|
||||
return LAYOUT_CHECKSUM_OVERLAPS_SUMMED_AREA;
|
||||
|
||||
layout->summed_area_start = start;
|
||||
layout->summed_area_end = end;
|
||||
layout->checksum_at = index;
|
||||
return OK;
|
||||
}
|
||||
layout->summed_area_start = start;
|
||||
layout->summed_area_end = end;
|
||||
layout->checksum_at = index;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* in bytes. Convert this information to bit positions.
|
||||
****************************************************************************/
|
||||
void checksum_layout_to_bits (cmos_checksum_layout_t *layout)
|
||||
{ layout->summed_area_start *= 8;
|
||||
layout->summed_area_end = (layout->summed_area_end * 8) + 7;
|
||||
layout->checksum_at *= 8;
|
||||
}
|
||||
void checksum_layout_to_bits(cmos_checksum_layout_t * layout)
|
||||
{
|
||||
layout->summed_area_start *= 8;
|
||||
layout->summed_area_end = (layout->summed_area_end * 8) + 7;
|
||||
layout->checksum_at *= 8;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* retrieve layout information.
|
||||
****************************************************************************/
|
||||
static void default_cmos_layout_get_fn (void)
|
||||
{ BUG(); }
|
||||
static void default_cmos_layout_get_fn(void)
|
||||
{
|
||||
BUG();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* areas_overlap
|
||||
*
|
||||
* Return 1 if the two given areas overlap. Else return 0.
|
||||
****************************************************************************/
|
||||
static int areas_overlap (unsigned area_0_start, unsigned area_0_length,
|
||||
unsigned area_1_start, unsigned area_1_length)
|
||||
{ unsigned area_0_end, area_1_end;
|
||||
static int areas_overlap(unsigned area_0_start, unsigned area_0_length,
|
||||
unsigned area_1_start, unsigned area_1_length)
|
||||
{
|
||||
unsigned area_0_end, area_1_end;
|
||||
|
||||
area_0_end = area_0_start + area_0_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));
|
||||
}
|
||||
area_0_end = area_0_start + area_0_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));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* 'config_id'. Return NULL if there is no matching enum.
|
||||
****************************************************************************/
|
||||
static const cmos_enum_item_t * find_first_cmos_enum_id (unsigned config_id)
|
||||
{ cmos_enum_item_t *item;
|
||||
static const cmos_enum_item_t *find_first_cmos_enum_id(unsigned config_id)
|
||||
{
|
||||
cmos_enum_item_t *item;
|
||||
|
||||
for (item = cmos_enum_list;
|
||||
(item != NULL) && (item->item.config_id < config_id);
|
||||
item = item->next);
|
||||
for (item = cmos_enum_list;
|
||||
(item != NULL) && (item->item.config_id < config_id);
|
||||
item = item->next) ;
|
||||
|
||||
return ((item == NULL) || (item->item.config_id > config_id)) ?
|
||||
NULL : item;
|
||||
}
|
||||
return ((item == NULL) || (item->item.config_id > config_id)) ?
|
||||
NULL : item;
|
||||
}
|
||||
|
|
|
@ -45,44 +45,40 @@
|
|||
#define LAYOUT_SUMMED_AREA_OUT_OF_RANGE (LAYOUT_RESULT_START + 8)
|
||||
#define LAYOUT_CHECKSUM_LOCATION_OUT_OF_RANGE (LAYOUT_RESULT_START + 9)
|
||||
|
||||
typedef enum
|
||||
{ CMOS_ENTRY_ENUM,
|
||||
CMOS_ENTRY_HEX,
|
||||
CMOS_ENTRY_STRING,
|
||||
CMOS_ENTRY_RESERVED
|
||||
}
|
||||
cmos_entry_config_t;
|
||||
typedef enum {
|
||||
CMOS_ENTRY_ENUM,
|
||||
CMOS_ENTRY_HEX,
|
||||
CMOS_ENTRY_STRING,
|
||||
CMOS_ENTRY_RESERVED
|
||||
} cmos_entry_config_t;
|
||||
|
||||
/* This represents a CMOS parameter. */
|
||||
typedef struct
|
||||
{ unsigned bit;
|
||||
unsigned length;
|
||||
cmos_entry_config_t config;
|
||||
unsigned config_id;
|
||||
char name[CMOS_MAX_NAME_LENGTH + 1];
|
||||
}
|
||||
cmos_entry_t;
|
||||
typedef struct {
|
||||
unsigned bit;
|
||||
unsigned length;
|
||||
cmos_entry_config_t config;
|
||||
unsigned config_id;
|
||||
char name[CMOS_MAX_NAME_LENGTH + 1];
|
||||
} cmos_entry_t;
|
||||
|
||||
/* This represents a possible value for a CMOS parameter of type
|
||||
* CMOS_ENTRY_ENUM.
|
||||
*/
|
||||
typedef struct
|
||||
{ unsigned config_id;
|
||||
unsigned long long value;
|
||||
char text[CMOS_MAX_TEXT_LENGTH + 1];
|
||||
}
|
||||
cmos_enum_t;
|
||||
typedef struct {
|
||||
unsigned config_id;
|
||||
unsigned long long value;
|
||||
char text[CMOS_MAX_TEXT_LENGTH + 1];
|
||||
} cmos_enum_t;
|
||||
|
||||
/* This represents the location of the CMOS checksum and the area over which
|
||||
* it is computed. Depending on the context, the values may be represented as
|
||||
* either bit positions or byte positions.
|
||||
/* This represents the location of the CMOS checksum and the area over
|
||||
* which it is computed. Depending on the context, the values may be
|
||||
* represented as either bit positions or byte positions.
|
||||
*/
|
||||
typedef struct
|
||||
{ unsigned summed_area_start; /* first checksummed location */
|
||||
unsigned summed_area_end; /* last checksummed location */
|
||||
unsigned checksum_at; /* location of checksum */
|
||||
}
|
||||
cmos_checksum_layout_t;
|
||||
typedef struct {
|
||||
unsigned summed_area_start; /* first checksummed location */
|
||||
unsigned summed_area_end; /* last checksummed location */
|
||||
unsigned checksum_at; /* location of checksum */
|
||||
} cmos_checksum_layout_t;
|
||||
|
||||
extern const char checksum_param_name[];
|
||||
|
||||
|
@ -94,21 +90,20 @@ extern unsigned cmos_checksum_index;
|
|||
|
||||
typedef void (*cmos_layout_get_fn_t) (void);
|
||||
|
||||
void register_cmos_layout_get_fn (cmos_layout_get_fn_t fn);
|
||||
void get_cmos_layout (void);
|
||||
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 * first_cmos_entry (void);
|
||||
const cmos_entry_t * next_cmos_entry (const cmos_entry_t *last);
|
||||
int add_cmos_enum (const cmos_enum_t *e);
|
||||
const cmos_enum_t * find_cmos_enum (unsigned config_id,
|
||||
unsigned long long value);
|
||||
const cmos_enum_t * first_cmos_enum (void);
|
||||
const cmos_enum_t * next_cmos_enum (const cmos_enum_t *last);
|
||||
const cmos_enum_t * first_cmos_enum_id (unsigned config_id);
|
||||
const cmos_enum_t * next_cmos_enum_id (const cmos_enum_t *last);
|
||||
int is_checksum_name (const char name[]);
|
||||
int checksum_layout_to_bytes (cmos_checksum_layout_t *layout);
|
||||
void checksum_layout_to_bits (cmos_checksum_layout_t *layout);
|
||||
void register_cmos_layout_get_fn(cmos_layout_get_fn_t fn);
|
||||
void get_cmos_layout(void);
|
||||
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 *first_cmos_entry(void);
|
||||
const cmos_entry_t *next_cmos_entry(const cmos_entry_t * last);
|
||||
int add_cmos_enum(const cmos_enum_t * e);
|
||||
const cmos_enum_t *find_cmos_enum(unsigned config_id, unsigned long long value);
|
||||
const cmos_enum_t *first_cmos_enum(void);
|
||||
const cmos_enum_t *next_cmos_enum(const cmos_enum_t * last);
|
||||
const cmos_enum_t *first_cmos_enum_id(unsigned config_id);
|
||||
const cmos_enum_t *next_cmos_enum_id(const cmos_enum_t * last);
|
||||
int is_checksum_name(const char name[]);
|
||||
int checksum_layout_to_bytes(cmos_checksum_layout_t * layout);
|
||||
void checksum_layout_to_bits(cmos_checksum_layout_t * layout);
|
||||
|
||||
#endif /* LAYOUT_H */
|
||||
#endif /* LAYOUT_H */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -34,8 +34,8 @@
|
|||
#include "common.h"
|
||||
#include "coreboot_tables.h"
|
||||
|
||||
void set_layout_filename (const char filename[]);
|
||||
void get_layout_from_file (void);
|
||||
void write_cmos_layout (FILE *f);
|
||||
void set_layout_filename(const char filename[]);
|
||||
void get_layout_from_file(void);
|
||||
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"
|
||||
|
||||
void get_lbtable (void);
|
||||
void get_layout_from_cmos_table (void);
|
||||
void dump_lbtable (void);
|
||||
void list_lbtable_choices (void);
|
||||
void list_lbtable_item (const char item[]);
|
||||
void get_lbtable(void);
|
||||
void get_layout_from_cmos_table(void);
|
||||
void dump_lbtable(void);
|
||||
void list_lbtable_choices(void);
|
||||
void list_lbtable_item(const char item[]);
|
||||
|
||||
#endif /* LBTABLE_H */
|
||||
#endif /* LBTABLE_H */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -35,11 +35,11 @@ nvramtool_op_info_t nvramtool_op;
|
|||
|
||||
nvramtool_op_modifier_info_t nvramtool_op_modifiers[NVRAMTOOL_NUM_OP_MODIFIERS];
|
||||
|
||||
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_modifier (nvramtool_op_modifier_t mod, char mod_param[]);
|
||||
static void resolve_op_modifiers (void);
|
||||
static void sanity_check_args (void);
|
||||
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_modifier(nvramtool_op_modifier_t mod, char mod_param[]);
|
||||
static void resolve_op_modifiers(void);
|
||||
static void sanity_check_args(void);
|
||||
|
||||
static const char getopt_string[] = "-ab:B:c::de:hil::np:r:tvw:xX:y:Y";
|
||||
|
||||
|
@ -48,143 +48,158 @@ static const char getopt_string[] = "-ab:B:c::de:hil::np:r:tvw:xX:y:Y";
|
|||
*
|
||||
* Parse command line arguments.
|
||||
****************************************************************************/
|
||||
void parse_nvramtool_args (int argc, char *argv[])
|
||||
{ nvramtool_op_modifier_info_t *mod_info;
|
||||
int i, op_found;
|
||||
char c;
|
||||
void parse_nvramtool_args(int argc, char *argv[])
|
||||
{
|
||||
nvramtool_op_modifier_info_t *mod_info;
|
||||
int i, op_found;
|
||||
char c;
|
||||
|
||||
for (i = 0, mod_info = nvramtool_op_modifiers;
|
||||
i < NVRAMTOOL_NUM_OP_MODIFIERS;
|
||||
i++, mod_info++)
|
||||
{ mod_info->found = FALSE;
|
||||
mod_info->found_seq = 0;
|
||||
mod_info->param = NULL;
|
||||
}
|
||||
for (i = 0, mod_info = nvramtool_op_modifiers;
|
||||
i < NVRAMTOOL_NUM_OP_MODIFIERS; i++, mod_info++) {
|
||||
mod_info->found = FALSE;
|
||||
mod_info->found_seq = 0;
|
||||
mod_info->param = NULL;
|
||||
}
|
||||
|
||||
op_found = FALSE;
|
||||
opterr = 0;
|
||||
op_found = FALSE;
|
||||
opterr = 0;
|
||||
|
||||
do
|
||||
{ switch (c = getopt(argc, argv, getopt_string))
|
||||
{ case 'a':
|
||||
register_op(&op_found, NVRAMTOOL_OP_CMOS_SHOW_ALL_PARAMS, NULL);
|
||||
break;
|
||||
case 'b':
|
||||
register_op(&op_found, NVRAMTOOL_OP_WRITE_CMOS_DUMP, optarg);
|
||||
break;
|
||||
case 'B':
|
||||
register_op(&op_found, NVRAMTOOL_OP_READ_CMOS_DUMP, optarg);
|
||||
break;
|
||||
case 'c':
|
||||
register_op(&op_found, NVRAMTOOL_OP_CMOS_CHECKSUM,
|
||||
handle_optional_arg(argc, argv));
|
||||
break;
|
||||
case 'd':
|
||||
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_DUMP, NULL);
|
||||
break;
|
||||
case 'e':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_PARAM_VALUES, optarg);
|
||||
break;
|
||||
case 'h':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_USAGE, NULL);
|
||||
break;
|
||||
case 'i':
|
||||
register_op(&op_found, NVRAMTOOL_OP_CMOS_SET_PARAMS_STDIN, NULL);
|
||||
break;
|
||||
case 'l':
|
||||
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_SHOW_INFO,
|
||||
handle_optional_arg(argc, argv));
|
||||
break;
|
||||
case 'n':
|
||||
register_op_modifier(NVRAMTOOL_MOD_SHOW_VALUE_ONLY, NULL);
|
||||
break;
|
||||
case 'p':
|
||||
register_op(&op_found, NVRAMTOOL_OP_CMOS_SET_PARAMS_FILE, optarg);
|
||||
break;
|
||||
case 'r':
|
||||
register_op(&op_found, NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM, optarg);
|
||||
break;
|
||||
case 't':
|
||||
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE, NULL);
|
||||
break;
|
||||
case 'v':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_VERSION, NULL);
|
||||
break;
|
||||
case 'w':
|
||||
register_op(&op_found, NVRAMTOOL_OP_CMOS_SET_ONE_PARAM, optarg);
|
||||
break;
|
||||
case 'x':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_HEX_DUMP, NULL);
|
||||
break;
|
||||
case 'X':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE, optarg);
|
||||
break;
|
||||
case 'y':
|
||||
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE, optarg);
|
||||
break;
|
||||
case 'Y':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_LAYOUT, NULL);
|
||||
break;
|
||||
case -1: /* no more command line args */
|
||||
break;
|
||||
case '?': /* unknown option found */
|
||||
case 1: /* nonoption command line arg found */
|
||||
default:
|
||||
usage(stderr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (c != -1);
|
||||
do {
|
||||
switch (c = getopt(argc, argv, getopt_string)) {
|
||||
case 'a':
|
||||
register_op(&op_found,
|
||||
NVRAMTOOL_OP_CMOS_SHOW_ALL_PARAMS, NULL);
|
||||
break;
|
||||
case 'b':
|
||||
register_op(&op_found, NVRAMTOOL_OP_WRITE_CMOS_DUMP,
|
||||
optarg);
|
||||
break;
|
||||
case 'B':
|
||||
register_op(&op_found, NVRAMTOOL_OP_READ_CMOS_DUMP,
|
||||
optarg);
|
||||
break;
|
||||
case 'c':
|
||||
register_op(&op_found, NVRAMTOOL_OP_CMOS_CHECKSUM,
|
||||
handle_optional_arg(argc, argv));
|
||||
break;
|
||||
case 'd':
|
||||
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_DUMP, NULL);
|
||||
break;
|
||||
case 'e':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_PARAM_VALUES,
|
||||
optarg);
|
||||
break;
|
||||
case 'h':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_USAGE, NULL);
|
||||
break;
|
||||
case 'i':
|
||||
register_op(&op_found,
|
||||
NVRAMTOOL_OP_CMOS_SET_PARAMS_STDIN, NULL);
|
||||
break;
|
||||
case 'l':
|
||||
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_SHOW_INFO,
|
||||
handle_optional_arg(argc, argv));
|
||||
break;
|
||||
case 'n':
|
||||
register_op_modifier(NVRAMTOOL_MOD_SHOW_VALUE_ONLY,
|
||||
NULL);
|
||||
break;
|
||||
case 'p':
|
||||
register_op(&op_found,
|
||||
NVRAMTOOL_OP_CMOS_SET_PARAMS_FILE, optarg);
|
||||
break;
|
||||
case 'r':
|
||||
register_op(&op_found, NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM,
|
||||
optarg);
|
||||
break;
|
||||
case 't':
|
||||
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE,
|
||||
NULL);
|
||||
break;
|
||||
case 'v':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_VERSION, NULL);
|
||||
break;
|
||||
case 'w':
|
||||
register_op(&op_found, NVRAMTOOL_OP_CMOS_SET_ONE_PARAM,
|
||||
optarg);
|
||||
break;
|
||||
case 'x':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_HEX_DUMP,
|
||||
NULL);
|
||||
break;
|
||||
case 'X':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE,
|
||||
optarg);
|
||||
break;
|
||||
case 'y':
|
||||
register_op_modifier(NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE,
|
||||
optarg);
|
||||
break;
|
||||
case 'Y':
|
||||
register_op(&op_found, NVRAMTOOL_OP_SHOW_LAYOUT, NULL);
|
||||
break;
|
||||
case -1: /* no more command line args */
|
||||
break;
|
||||
case '?': /* unknown option found */
|
||||
case 1: /* nonoption command line arg found */
|
||||
default:
|
||||
usage(stderr);
|
||||
break;
|
||||
}
|
||||
} while (c != -1);
|
||||
|
||||
if (!op_found)
|
||||
usage(stderr);
|
||||
if (!op_found)
|
||||
usage(stderr);
|
||||
|
||||
resolve_op_modifiers();
|
||||
sanity_check_args();
|
||||
}
|
||||
resolve_op_modifiers();
|
||||
sanity_check_args();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* handle_optional_arg
|
||||
*
|
||||
* Handle a command line option with an optional argument.
|
||||
****************************************************************************/
|
||||
static char * handle_optional_arg (int argc, char *argv[])
|
||||
{ char *arg;
|
||||
static char *handle_optional_arg(int argc, char *argv[])
|
||||
{
|
||||
char *arg;
|
||||
|
||||
if (optarg != NULL)
|
||||
{ /* optional arg is present and arg was specified as "-zarg" (with no
|
||||
* whitespace between "z" and "arg"), where -z is the option and "arg"
|
||||
* is the value of the optional arg
|
||||
*/
|
||||
return optarg;
|
||||
}
|
||||
if (optarg != NULL) {
|
||||
/* optional arg is present and arg was specified as
|
||||
* "-zarg" (with no whitespace between "z" and "arg"),
|
||||
* where -z is the option and "arg" is the value of the
|
||||
* optional arg
|
||||
*/
|
||||
return optarg;
|
||||
}
|
||||
|
||||
if ((argv[optind] == NULL) || (argv[optind][0] == '-'))
|
||||
return NULL;
|
||||
if ((argv[optind] == NULL) || (argv[optind][0] == '-'))
|
||||
return NULL;
|
||||
|
||||
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
|
||||
* to skip.
|
||||
*/
|
||||
getopt(argc, argv, getopt_string);
|
||||
/* This call to getopt yields the optional arg we just found,
|
||||
* which we want to skip.
|
||||
*/
|
||||
getopt(argc, argv, getopt_string);
|
||||
|
||||
return arg;
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* register_op
|
||||
*
|
||||
* Store the user's selection of which operation this program should perform.
|
||||
****************************************************************************/
|
||||
static void register_op (int *op_found, nvramtool_op_t op, char op_param[])
|
||||
{ if (*op_found && (op != nvramtool_op.op))
|
||||
usage(stderr);
|
||||
static void register_op(int *op_found, nvramtool_op_t op, char op_param[])
|
||||
{
|
||||
if (*op_found && (op != nvramtool_op.op))
|
||||
usage(stderr);
|
||||
|
||||
*op_found = TRUE;
|
||||
nvramtool_op.op = op;
|
||||
nvramtool_op.param = op_param;
|
||||
}
|
||||
*op_found = TRUE;
|
||||
nvramtool_op.op = op;
|
||||
nvramtool_op.param = op_param;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* the user's selection of which operation this program should perform.
|
||||
****************************************************************************/
|
||||
static void register_op_modifier (nvramtool_op_modifier_t mod, char mod_param[])
|
||||
{ static int found_seq = 0;
|
||||
nvramtool_op_modifier_info_t *mod_info;
|
||||
static void register_op_modifier(nvramtool_op_modifier_t mod, char mod_param[])
|
||||
{
|
||||
static int found_seq = 0;
|
||||
nvramtool_op_modifier_info_t *mod_info;
|
||||
|
||||
mod_info = &nvramtool_op_modifiers[mod];
|
||||
mod_info->found = TRUE;
|
||||
mod_info->found_seq = ++found_seq;
|
||||
mod_info->param = mod_param;
|
||||
}
|
||||
mod_info = &nvramtool_op_modifiers[mod];
|
||||
mod_info->found = TRUE;
|
||||
mod_info->found_seq = ++found_seq;
|
||||
mod_info->param = mod_param;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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,
|
||||
* the last specified argument overrides previous conflicting arguments.
|
||||
****************************************************************************/
|
||||
static void resolve_op_modifiers (void)
|
||||
{ if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found &&
|
||||
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found)
|
||||
{ if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found_seq >
|
||||
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found_seq)
|
||||
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found = FALSE;
|
||||
else
|
||||
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found = FALSE;
|
||||
}
|
||||
}
|
||||
static void resolve_op_modifiers(void)
|
||||
{
|
||||
if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found &&
|
||||
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found) {
|
||||
if (nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found_seq >
|
||||
nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found_seq)
|
||||
nvramtool_op_modifiers
|
||||
[NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE].found = FALSE;
|
||||
else
|
||||
nvramtool_op_modifiers
|
||||
[NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE].found = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* sanity_check_args
|
||||
*
|
||||
* Perform sanity checking on command line arguments.
|
||||
****************************************************************************/
|
||||
static void sanity_check_args (void)
|
||||
{ if ((nvramtool_op_modifiers[NVRAMTOOL_MOD_SHOW_VALUE_ONLY].found) &&
|
||||
(nvramtool_op.op != NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM))
|
||||
usage(stderr);
|
||||
}
|
||||
static void sanity_check_args(void)
|
||||
{
|
||||
if ((nvramtool_op_modifiers[NVRAMTOOL_MOD_SHOW_VALUE_ONLY].found) &&
|
||||
(nvramtool_op.op != NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM))
|
||||
usage(stderr);
|
||||
}
|
||||
|
|
|
@ -33,51 +33,45 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
typedef enum
|
||||
{ NVRAMTOOL_OP_SHOW_VERSION = 0,
|
||||
NVRAMTOOL_OP_SHOW_USAGE,
|
||||
NVRAMTOOL_OP_LBTABLE_SHOW_INFO,
|
||||
NVRAMTOOL_OP_LBTABLE_DUMP,
|
||||
NVRAMTOOL_OP_SHOW_PARAM_VALUES,
|
||||
NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM,
|
||||
NVRAMTOOL_OP_CMOS_SHOW_ALL_PARAMS,
|
||||
NVRAMTOOL_OP_CMOS_SET_ONE_PARAM,
|
||||
NVRAMTOOL_OP_CMOS_SET_PARAMS_STDIN,
|
||||
NVRAMTOOL_OP_CMOS_SET_PARAMS_FILE,
|
||||
NVRAMTOOL_OP_CMOS_CHECKSUM,
|
||||
NVRAMTOOL_OP_SHOW_LAYOUT,
|
||||
NVRAMTOOL_OP_WRITE_CMOS_DUMP,
|
||||
NVRAMTOOL_OP_READ_CMOS_DUMP,
|
||||
NVRAMTOOL_OP_SHOW_CMOS_HEX_DUMP,
|
||||
NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE
|
||||
}
|
||||
nvramtool_op_t;
|
||||
typedef enum { NVRAMTOOL_OP_SHOW_VERSION = 0,
|
||||
NVRAMTOOL_OP_SHOW_USAGE,
|
||||
NVRAMTOOL_OP_LBTABLE_SHOW_INFO,
|
||||
NVRAMTOOL_OP_LBTABLE_DUMP,
|
||||
NVRAMTOOL_OP_SHOW_PARAM_VALUES,
|
||||
NVRAMTOOL_OP_CMOS_SHOW_ONE_PARAM,
|
||||
NVRAMTOOL_OP_CMOS_SHOW_ALL_PARAMS,
|
||||
NVRAMTOOL_OP_CMOS_SET_ONE_PARAM,
|
||||
NVRAMTOOL_OP_CMOS_SET_PARAMS_STDIN,
|
||||
NVRAMTOOL_OP_CMOS_SET_PARAMS_FILE,
|
||||
NVRAMTOOL_OP_CMOS_CHECKSUM,
|
||||
NVRAMTOOL_OP_SHOW_LAYOUT,
|
||||
NVRAMTOOL_OP_WRITE_CMOS_DUMP,
|
||||
NVRAMTOOL_OP_READ_CMOS_DUMP,
|
||||
NVRAMTOOL_OP_SHOW_CMOS_HEX_DUMP,
|
||||
NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE
|
||||
} nvramtool_op_t;
|
||||
|
||||
typedef struct
|
||||
{ nvramtool_op_t op;
|
||||
char *param;
|
||||
}
|
||||
nvramtool_op_info_t;
|
||||
typedef struct {
|
||||
nvramtool_op_t op;
|
||||
char *param;
|
||||
} nvramtool_op_info_t;
|
||||
|
||||
typedef enum
|
||||
{ NVRAMTOOL_MOD_SHOW_VALUE_ONLY = 0,
|
||||
NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE,
|
||||
NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE,
|
||||
NVRAMTOOL_NUM_OP_MODIFIERS /* must always be last */
|
||||
}
|
||||
nvramtool_op_modifier_t;
|
||||
typedef enum { NVRAMTOOL_MOD_SHOW_VALUE_ONLY = 0,
|
||||
NVRAMTOOL_MOD_USE_CMOS_LAYOUT_FILE,
|
||||
NVRAMTOOL_MOD_USE_CMOS_OPT_TABLE,
|
||||
NVRAMTOOL_NUM_OP_MODIFIERS /* must always be last */
|
||||
} nvramtool_op_modifier_t;
|
||||
|
||||
typedef struct
|
||||
{ int found;
|
||||
int found_seq;
|
||||
char *param;
|
||||
}
|
||||
nvramtool_op_modifier_info_t;
|
||||
typedef struct {
|
||||
int found;
|
||||
int found_seq;
|
||||
char *param;
|
||||
} nvramtool_op_modifier_info_t;
|
||||
|
||||
extern nvramtool_op_info_t nvramtool_op;
|
||||
|
||||
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,44 +37,46 @@
|
|||
*
|
||||
* Compile a bunch of regular expressions.
|
||||
****************************************************************************/
|
||||
void compile_reg_exprs (int cflags, int num_exprs,
|
||||
/* const char *expr1, regex_t *reg1, */ ...)
|
||||
{ static const size_t ERROR_BUF_SIZE = 256;
|
||||
char error_msg[ERROR_BUF_SIZE];
|
||||
va_list ap;
|
||||
regex_t *reg;
|
||||
const char *expr;
|
||||
int i, result;
|
||||
void compile_reg_exprs(int cflags, int num_exprs,
|
||||
/* const char *expr1, regex_t *reg1, */ ...)
|
||||
{
|
||||
static const size_t ERROR_BUF_SIZE = 256;
|
||||
char error_msg[ERROR_BUF_SIZE];
|
||||
va_list ap;
|
||||
regex_t *reg;
|
||||
const char *expr;
|
||||
int i, result;
|
||||
|
||||
va_start(ap, num_exprs);
|
||||
va_start(ap, num_exprs);
|
||||
|
||||
for (i = 0; i < num_exprs; i++)
|
||||
{ expr = va_arg(ap, const char *);
|
||||
reg = va_arg(ap, regex_t *);
|
||||
for (i = 0; i < num_exprs; i++) {
|
||||
expr = va_arg(ap, const char *);
|
||||
reg = va_arg(ap, regex_t *);
|
||||
|
||||
if ((result = regcomp(reg, expr, cflags)) != 0)
|
||||
{ regerror(result, reg, error_msg, ERROR_BUF_SIZE);
|
||||
fprintf(stderr, "%s: %s\n", prog_name, error_msg);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if ((result = regcomp(reg, expr, cflags)) != 0) {
|
||||
regerror(result, reg, error_msg, ERROR_BUF_SIZE);
|
||||
fprintf(stderr, "%s: %s\n", prog_name, error_msg);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* free_reg_exprs
|
||||
*
|
||||
* Destroy a bunch of previously compiled regular expressions.
|
||||
****************************************************************************/
|
||||
void free_reg_exprs (int num_exprs, /* regex_t *reg1, */ ...)
|
||||
{ va_list ap;
|
||||
int i;
|
||||
void free_reg_exprs(int num_exprs, /* regex_t *reg1, */ ...)
|
||||
{
|
||||
va_list ap;
|
||||
int i;
|
||||
|
||||
va_start(ap, num_exprs);
|
||||
va_start(ap, num_exprs);
|
||||
|
||||
for (i = 0; i < num_exprs; i++)
|
||||
regfree(va_arg(ap, regex_t *));
|
||||
for (i = 0; i < num_exprs; i++)
|
||||
regfree(va_arg(ap, regex_t *));
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
#include <regex.h>
|
||||
#include "common.h"
|
||||
|
||||
void compile_reg_exprs (int cflags, int num_exprs,
|
||||
/* const char *expr1, regex_t *reg1, */ ...);
|
||||
void free_reg_exprs (int num_exprs, /* regex_t *reg1, */ ...);
|
||||
void compile_reg_exprs(int cflags, int num_exprs,
|
||||
/* const char *expr1, regex_t *reg1, */ ...);
|
||||
void free_reg_exprs(int num_exprs, /* regex_t *reg1, */ ...);
|
||||
|
||||
#endif /* REG_EXPR_H */
|
||||
#endif /* REG_EXPR_H */
|
||||
|
|
Loading…
Reference in New Issue