Changeset 3613
- Timestamp:
- 09/27/08 12:08:28 (8 weeks ago)
- Location:
- trunk/util/nvramtool
- Files:
-
- 29 modified
-
ChangeLog (modified) (1 diff)
-
DISCLAIMER (modified) (1 diff)
-
Makefile (modified) (1 diff)
-
README (modified) (1 diff)
-
cmos_lowlevel.c (modified) (6 diffs)
-
cmos_lowlevel.h (modified) (4 diffs)
-
cmos_ops.c (modified) (5 diffs)
-
cmos_ops.h (modified) (1 diff)
-
common.c (modified) (2 diffs)
-
common.h (modified) (1 diff)
-
compute_ip_checksum.c (modified) (1 diff)
-
hexdump.c (modified) (1 diff)
-
hexdump.h (modified) (1 diff)
-
input_file.c (modified) (3 diffs)
-
input_file.h (modified) (3 diffs)
-
ip_checksum.h (modified) (1 diff)
-
layout.c (modified) (1 diff)
-
layout.h (modified) (2 diffs)
-
layout_file.c (modified) (3 diffs)
-
layout_file.h (modified) (1 diff)
-
lbtable.c (modified) (2 diffs)
-
lbtable.h (modified) (1 diff)
-
nvramtool.1 (modified) (3 diffs)
-
nvramtool.c (modified) (5 diffs)
-
nvramtool.spec (modified) (1 diff)
-
opts.c (modified) (1 diff)
-
opts.h (modified) (1 diff)
-
reg_expr.c (modified) (1 diff)
-
reg_expr.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/util/nvramtool/ChangeLog
r3075 r3613 1 Tue Sep 23 19:14:27 CEST 2008 Stefan Reinauer (stepan@coresystems.de) 2 3 Version 2.1 4 5 * Fix a number of off by one errors when accessing arrays 6 7 * Add support for reading/writing strings from/to CMOS. 8 1 9 Mon Jan 23 16:00:00 PST 2006 David S. Peterson (dsp@llnl.gov) 2 10 -
trunk/util/nvramtool/DISCLAIMER
r3122 r3613 1 ####################################################################2 # $Id$3 1 #################################################################### 4 2 5 3 Copyright (C) 2002 The Regents of the University of California. 4 Copyright (C) 2008 coresystems GmbH 5 6 6 Produced at the Lawrence Livermore National Laboratory. 7 7 Written by David S. Peterson <dsp@llnl.gov>. -
trunk/util/nvramtool/Makefile
r3122 r3613 1 # $Id$ 1 # 2 # Makefile for nvram utility 3 # 4 # (C) 2005-2008 coresystems GmbH 5 # written by Stefan Reinauer <stepan@coresystems.de> 6 # 2 7 3 PROJECT = nvramtool 4 CC = gcc 5 CFLAGS = -O2 -W -Wall 6 LDFLAGS = 7 OBJS = common.o compute_ip_checksum.o hexdump.o cmos_lowlevel.o \ 8 reg_expr.o layout.o layout_file.o lbtable.o cmos_ops.o input_file.o \ 9 opts.o nvramtool.o 10 HEADERS = common.h ip_checksum.h coreboot_tables.h hexdump.h \ 11 cmos_lowlevel.h reg_expr.h layout.h layout_file.h lbtable.h \ 12 cmos_ops.h input_file.h opts.h 8 PROGRAM = nvramtool 13 9 14 all: nvramtool man 10 CC = gcc 11 STRIP = strip 12 INSTALL = /usr/bin/install 13 PREFIX = /usr/local 14 CFLAGS = -O2 -g -Wall -W 15 #CFLAGS = -Os -Wall 15 16 16 nvramtool: $(OBJS) 17 $(CC) $(LDFLAGS) -o $@ $(OBJS) 17 OBJS = cmos_lowlevel.o cmos_ops.o common.o compute_ip_checksum.o \ 18 hexdump.o input_file.o layout.o layout_file.o lbtable.o \ 19 nvramtool.o opts.o reg_expr.o 18 20 19 man: nvramtool.1.gz 21 all: dep $(PROGRAM) 20 22 21 $(OBJS): $(HEADERS) 22 23 nvramtool.1.gz: nvramtool.1 24 gzip -c --best nvramtool.1 > nvramtool.1.gz 23 $(PROGRAM): $(OBJS) 24 $(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS) 25 $(STRIP) $(STRIP_ARGS) $(PROGRAM) 25 26 26 27 clean: 27 rm -f *.o nvramtool nvramtool.1.gz28 rm -f $(PROGRAM) *.o 28 29 30 distclean: clean 31 rm -f .dependencies 32 33 dep: 34 @$(CC) -MM *.c > .dependencies 35 36 install: $(PROGRAM) 37 $(INSTALL) $(PROGRAM) $(PREFIX)/sbin 38 mkdir -p $(PREFIX)/share/man/man1 39 $(INSTALL) $(PROGRAM).1 $(PREFIX)/share/man/man1 40 41 .PHONY: all clean distclean dep 42 43 -include .dependencies -
trunk/util/nvramtool/README
r3122 r3613 1 $Id$2 3 1 Summary of Operation 4 2 -------------------- -
trunk/util/nvramtool/cmos_lowlevel.c
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * cmos_lowlevel.c 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 71 70 static inline void put_bits (unsigned char value, unsigned bit, 72 71 unsigned nr_bits, unsigned long long *result) 73 { *result += ( value & ((unsigned char) ((1 << nr_bits) - 1))) << bit; }72 { *result += ((unsigned long long)(value & ((unsigned char) ((1 << nr_bits) - 1)))) << bit; } 74 73 75 74 /**************************************************************************** … … 80 79 * process must be set appropriately. 81 80 ****************************************************************************/ 82 unsigned long long cmos_read ( unsigned bit, unsigned length)81 unsigned long long cmos_read (const cmos_entry_t *e) 83 82 { cmos_bit_op_location_t where; 83 unsigned bit = e->bit, length=e->length; 84 84 unsigned next_bit, bits_left, nr_bits; 85 unsigned long long result ;85 unsigned long long result = 0; 86 86 unsigned char value; 87 87 88 assert(!verify_cmos_op(bit, length ));88 assert(!verify_cmos_op(bit, length, e->config)); 89 89 result = 0; 90 90 91 for (next_bit = 0, bits_left = length; 92 bits_left; 93 next_bit += nr_bits, bits_left -= nr_bits) 94 { nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left, &where); 95 value = cmos_read_bits(&where, nr_bits); 96 put_bits(value, next_bit, nr_bits, &result); 91 if (e->config == CMOS_ENTRY_STRING) 92 { char *newstring = malloc((length+7)/8); 93 unsigned usize = (8 * sizeof(unsigned long long)); 94 95 if(!newstring) { out_of_memory(); } 96 97 for (next_bit = 0, bits_left = length; 98 bits_left; 99 next_bit += nr_bits, bits_left -= nr_bits) 100 { nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left>usize?usize:bits_left, &where); 101 value = cmos_read_bits(&where, nr_bits); 102 put_bits(value, next_bit % usize, nr_bits, &((unsigned long long *)newstring)[next_bit/usize]); 103 result = (unsigned long)newstring; 104 } 105 } 106 else 107 { for (next_bit = 0, bits_left = length; 108 bits_left; 109 next_bit += nr_bits, bits_left -= nr_bits) 110 { nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left, &where); 111 value = cmos_read_bits(&where, nr_bits); 112 put_bits(value, next_bit, nr_bits, &result); 113 } 97 114 } 98 115 … … 107 124 * appropriately. 108 125 ****************************************************************************/ 109 void cmos_write ( unsigned bit, unsigned length, unsigned long long value)126 void cmos_write (const cmos_entry_t *e, unsigned long long value) 110 127 { cmos_bit_op_location_t where; 128 unsigned bit = e->bit, length=e->length; 111 129 unsigned next_bit, bits_left, nr_bits; 112 130 113 assert(!verify_cmos_op(bit, length)); 114 115 for (next_bit = 0, bits_left = length; 116 bits_left; 117 next_bit += nr_bits, bits_left -= nr_bits) 118 { nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left, &where); 119 cmos_write_bits(&where, nr_bits, get_bits(value, next_bit, nr_bits)); 131 assert(!verify_cmos_op(bit, length, e->config)); 132 133 if (e->config == CMOS_ENTRY_STRING) 134 { unsigned long long *data = (unsigned long long *)(unsigned long)value; 135 unsigned usize = (8 * sizeof(unsigned long long)); 136 137 for (next_bit = 0, bits_left = length; 138 bits_left; 139 next_bit += nr_bits, bits_left -= nr_bits) 140 { nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left>usize?usize:bits_left, &where); 141 value = data[next_bit/usize]; 142 cmos_write_bits(&where, nr_bits, get_bits(value, next_bit % usize, nr_bits)); 143 } 144 } 145 else 146 { for (next_bit = 0, bits_left = length; 147 bits_left; 148 next_bit += nr_bits, bits_left -= nr_bits) 149 { nr_bits = cmos_bit_op_strategy(bit + next_bit, bits_left, &where); 150 cmos_write_bits(&where, nr_bits, get_bits(value, next_bit, nr_bits)); 151 } 120 152 } 121 153 } … … 237 269 * no problems were encountered, return OK. Else return an error code. 238 270 ****************************************************************************/ 239 int verify_cmos_op (unsigned bit, unsigned length )271 int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config) 240 272 { if ((bit >= (8 * CMOS_SIZE)) || ((bit + length) > (8 * CMOS_SIZE))) 241 273 return CMOS_AREA_OUT_OF_RANGE; … … 243 275 if (bit < (8 * CMOS_RTC_AREA_SIZE)) 244 276 return CMOS_AREA_OVERLAPS_RTC; 277 278 if (config == CMOS_ENTRY_STRING) 279 return OK; 245 280 246 281 if (length > (8 * sizeof(unsigned long long))) -
trunk/util/nvramtool/cmos_lowlevel.h
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * cmos_lowlevel.h 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 34 33 35 34 #include "common.h" 35 #include "layout.h" 36 36 37 37 #define CMOS_AREA_OUT_OF_RANGE (CMOS_RESULT_START + 0) … … 39 39 #define CMOS_AREA_TOO_WIDE (CMOS_RESULT_START + 2) 40 40 41 unsigned long long cmos_read ( unsigned bit, unsigned length);42 void cmos_write ( unsigned bit, unsigned length, unsigned long long value);41 unsigned long long cmos_read (const cmos_entry_t *e); 42 void cmos_write (const cmos_entry_t *e, unsigned long long value); 43 43 unsigned char cmos_read_byte (unsigned index); 44 44 void cmos_write_byte (unsigned index, unsigned char value); … … 46 46 void cmos_write_all (unsigned char data[]); 47 47 void set_iopl (int level); 48 int verify_cmos_op (unsigned bit, unsigned length );48 int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config); 49 49 50 50 #define CMOS_SIZE 256 /* size of CMOS memory in bytes */ -
trunk/util/nvramtool/cmos_ops.c
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * cmos_ops.c 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 48 47 return CMOS_OP_RESERVED; 49 48 50 if ((result = verify_cmos_op(e->bit, e->length )) != OK)49 if ((result = verify_cmos_op(e->bit, e->length, e->config)) != OK) 51 50 return result; 52 51 … … 71 70 { case CMOS_ENTRY_ENUM: 72 71 case CMOS_ENTRY_HEX: 72 case CMOS_ENTRY_STRING: 73 73 break; 74 74 … … 93 93 unsigned long long out; 94 94 const char *p; 95 char *memory; 95 96 int negative, result, found_one; 96 97 … … 140 141 break; 141 142 143 case CMOS_ENTRY_STRING: 144 if (e->length < (8 * strlen(value_str))) 145 return CMOS_OP_VALUE_TOO_WIDE; 146 memory = malloc(e->length / 8); 147 memset(memory, 0, e->length / 8); 148 strcpy(memory, value_str); 149 out = (unsigned long)memory; 150 break; 151 142 152 default: 143 153 BUG(); -
trunk/util/nvramtool/cmos_ops.h
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * cmos_ops.h 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. -
trunk/util/nvramtool/common.c
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * common.c 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 36 35 37 36 /* version of this program */ 38 const char prog_version[] = "2. 0.1";37 const char prog_version[] = "2.1"; 39 38 40 39 /**************************************************************************** -
trunk/util/nvramtool/common.h
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * common.h 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. -
trunk/util/nvramtool/compute_ip_checksum.c
r3075 r3613 1 1 /*****************************************************************************\ 2 2 * compute_ip_checksum.c 3 * $Id$4 3 \*****************************************************************************/ 5 4 -
trunk/util/nvramtool/hexdump.c
r3075 r3613 1 1 /*****************************************************************************\ 2 2 * hexdump.c 3 * $Id$4 3 \*****************************************************************************/ 5 4 -
trunk/util/nvramtool/hexdump.h
r3075 r3613 1 1 /*****************************************************************************\ 2 2 * hexdump.h 3 * $Id$4 3 \*****************************************************************************/ 5 4 -
trunk/util/nvramtool/input_file.c
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * input_file.c 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 138 137 item->bit = e->bit; 139 138 item->length = e->length; 139 item->config = e->config; 140 140 item->value = try_prepare_cmos_write(e, value); 141 141 … … 163 163 164 164 while (list != NULL) 165 { item = list; 165 { cmos_entry_t e; 166 item = list; 167 e.bit = item->bit; 168 e.length = item->length; 169 e.config = item->config; 166 170 list = item->next; 167 cmos_write( item->bit, item->length, item->value);171 cmos_write(&e, item->value); 168 172 free(item); 169 173 } -
trunk/util/nvramtool/input_file.h
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * input_file.h 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 34 33 35 34 #include "common.h" 35 #include "layout.h" 36 36 37 37 typedef struct cmos_write_t cmos_write_t; … … 45 45 { unsigned bit; 46 46 unsigned length; 47 cmos_entry_config_t config; 47 48 unsigned long long value; 48 49 cmos_write_t *next; -
trunk/util/nvramtool/ip_checksum.h
r3075 r3613 1 1 /*****************************************************************************\ 2 2 * ip_checksum.h 3 * $Id$4 3 \*****************************************************************************/ 5 4 -
trunk/util/nvramtool/layout.c
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * layout.c 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. -
trunk/util/nvramtool/layout.h
r3582 r3613 1 1 /*****************************************************************************\ 2 2 * layout.h 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 50 49 { CMOS_ENTRY_ENUM, 51 50 CMOS_ENTRY_HEX, 51 CMOS_ENTRY_STRING, 52 52 CMOS_ENTRY_RESERVED 53 53 } -
trunk/util/nvramtool/layout_file.c
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * layout_file.c 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 552 551 break; 553 552 553 case 's': 554 cmos_entry->config = CMOS_ENTRY_STRING; 555 break; 556 554 557 case 'r': 555 558 cmos_entry->config = CMOS_ENTRY_RESERVED; … … 759 762 return 'r'; 760 763 764 case CMOS_ENTRY_STRING: 765 return 's'; 766 761 767 default: 762 768 BUG(); -
trunk/util/nvramtool/layout_file.h
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * layout_file.h 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. -
trunk/util/nvramtool/lbtable.c
r3582 r3613 1 1 /*****************************************************************************\ 2 2 * lbtable.c 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 583 582 break; 584 583 584 case 's': 585 cmos_entry.config = CMOS_ENTRY_STRING; 586 break; 587 585 588 default: 586 589 fprintf(stderr, -
trunk/util/nvramtool/lbtable.h
r3122 r3613 1 1 /*****************************************************************************\ 2 2 * lbtable.h 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. -
trunk/util/nvramtool/nvramtool.1
r3123 r3613 1 1 .\"***************************************************************************\ 2 2 .\" nvramtool.1 3 .\" $Id$4 3 .\"*************************************************************************** 5 4 .\" Copyright (C) 2002, 2003 The Regents of the University of California. … … 29 28 .\" 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 30 29 .\"***************************************************************************/ 31 .TH NVRAMTOOL 1 " January2008" Linux30 .TH NVRAMTOOL 1 "September 2008" Linux 32 31 .SH NAME 33 32 nvramtool \- read/write coreboot-related information … … 253 252 David S. Peterson <dsp@llnl.gov> <dave_peterson@pobox.com> 254 253 .br 255 Stefan Reinauer <stepan@ openbios.org>254 Stefan Reinauer <stepan@coresystems.de> -
trunk/util/nvramtool/nvramtool.c
r3123 r3613 1 1 /*****************************************************************************\ 2 2 * nvramtool.c 3 * $Id$4 3 ***************************************************************************** 5 4 * Copyright (C) 2002-2005 The Regents of the University of California. … … 478 477 break; 479 478 479 case CMOS_ENTRY_STRING: 480 printf("Parameter %s requires a %u-byte string.\n", name, 481 e->length / 8); 482 break; 483 480 484 case CMOS_ENTRY_RESERVED: 481 485 printf("Parameter %s is reserved.\n", name); … … 571 575 /* write the value to nonvolatile RAM */ 572 576 set_iopl(3); 573 cmos_write(e ->bit, e->length, n);577 cmos_write(e, n); 574 578 cmos_checksum_write(cmos_checks
