Changeset 3613 for trunk/util

Show
Ignore:
Timestamp:
09/27/08 12:08:28 (3 months ago)
Author:
stepan
Message:

Add string support to nvramtool.

To add a string to your cmos.layout, you need to specify type 's':

#start len type unused name
416 512 s 0 boot_devices

With this patch you can do

$ nvramtool -w boot_devices="(hd0,0);(hd2,1);(hd3)"

And FILO will attempt to load a menu.lst from any of these devices in that
order.

The patch is not exactly pretty, but a cleaner solution might have resulted in
a complete rewrite of the tool, which I did not want.

Signed-off-by: Stefan Reinauer <stepan@…>
Acked-by: Joseph Smith <joe@…>

Location:
trunk/util/nvramtool
Files:
29 modified

Legend:

Unmodified
Added
Removed
  • trunk/util/nvramtool/ChangeLog

    r3075 r3613  
     1Tue 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 
    19Mon Jan 23 16:00:00 PST 2006  David S. Peterson (dsp@llnl.gov) 
    210 
  • trunk/util/nvramtool/DISCLAIMER

    r3122 r3613  
    1 #################################################################### 
    2 # $Id$ 
    31#################################################################### 
    42 
    53Copyright (C) 2002 The Regents of the University of California. 
     4Copyright (C) 2008 coresystems GmbH 
     5 
    66Produced at the Lawrence Livermore National Laboratory. 
    77Written 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# 
    27 
    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 
     8PROGRAM = nvramtool 
    139 
    14 all: nvramtool man 
     10CC      = gcc 
     11STRIP   = strip 
     12INSTALL = /usr/bin/install 
     13PREFIX  = /usr/local 
     14CFLAGS  = -O2 -g -Wall -W 
     15#CFLAGS  = -Os -Wall 
    1516 
    16 nvramtool: $(OBJS) 
    17         $(CC) $(LDFLAGS) -o $@ $(OBJS) 
     17OBJS =  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 
    1820 
    19 man: nvramtool.1.gz 
     21all: dep $(PROGRAM) 
    2022 
    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) 
    2526 
    2627clean: 
    27         rm -f *.o nvramtool nvramtool.1.gz 
     28        rm -f $(PROGRAM) *.o 
    2829 
     30distclean: clean 
     31        rm -f .dependencies 
     32 
     33dep: 
     34        @$(CC) -MM *.c > .dependencies 
     35 
     36install: $(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  
    31Summary of Operation 
    42-------------------- 
  • trunk/util/nvramtool/cmos_lowlevel.c

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * cmos_lowlevel.c 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    7170static inline void put_bits (unsigned char value, unsigned bit, 
    7271                             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; } 
    7473 
    7574/**************************************************************************** 
     
    8079 * process must be set appropriately. 
    8180 ****************************************************************************/ 
    82 unsigned long long cmos_read (unsigned bit, unsigned length) 
     81unsigned long long cmos_read (const cmos_entry_t *e) 
    8382 { cmos_bit_op_location_t where; 
     83   unsigned bit = e->bit, length=e->length; 
    8484   unsigned next_bit, bits_left, nr_bits; 
    85    unsigned long long result; 
     85   unsigned long long result = 0; 
    8686   unsigned char value; 
    8787 
    88    assert(!verify_cmos_op(bit, length)); 
     88   assert(!verify_cmos_op(bit, length, e->config)); 
    8989   result = 0; 
    9090 
    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       } 
    97114    } 
    98115 
     
    107124 * appropriately. 
    108125 ****************************************************************************/ 
    109 void cmos_write (unsigned bit, unsigned length, unsigned long long value) 
     126void cmos_write (const cmos_entry_t *e, unsigned long long value) 
    110127 { cmos_bit_op_location_t where; 
     128   unsigned bit = e->bit, length=e->length; 
    111129   unsigned next_bit, bits_left, nr_bits; 
    112130 
    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       } 
    120152    } 
    121153 } 
     
    237269 * no problems were encountered, return OK.  Else return an error code. 
    238270 ****************************************************************************/ 
    239 int verify_cmos_op (unsigned bit, unsigned length) 
     271int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config) 
    240272 { if ((bit >= (8 * CMOS_SIZE)) || ((bit + length) > (8 * CMOS_SIZE))) 
    241273      return CMOS_AREA_OUT_OF_RANGE; 
     
    243275   if (bit < (8 * CMOS_RTC_AREA_SIZE)) 
    244276      return CMOS_AREA_OVERLAPS_RTC; 
     277 
     278   if (config == CMOS_ENTRY_STRING) 
     279      return OK; 
    245280 
    246281   if (length > (8 * sizeof(unsigned long long))) 
  • trunk/util/nvramtool/cmos_lowlevel.h

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * cmos_lowlevel.h 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    3433 
    3534#include "common.h" 
     35#include "layout.h" 
    3636 
    3737#define CMOS_AREA_OUT_OF_RANGE (CMOS_RESULT_START + 0) 
     
    3939#define CMOS_AREA_TOO_WIDE (CMOS_RESULT_START + 2) 
    4040 
    41 unsigned long long cmos_read (unsigned bit, unsigned length); 
    42 void cmos_write (unsigned bit, unsigned length, unsigned long long value); 
     41unsigned long long cmos_read (const cmos_entry_t *e); 
     42void cmos_write (const cmos_entry_t *e, unsigned long long value); 
    4343unsigned char cmos_read_byte (unsigned index); 
    4444void cmos_write_byte (unsigned index, unsigned char value); 
     
    4646void cmos_write_all (unsigned char data[]); 
    4747void set_iopl (int level); 
    48 int verify_cmos_op (unsigned bit, unsigned length); 
     48int verify_cmos_op (unsigned bit, unsigned length, cmos_entry_config_t config); 
    4949 
    5050#define CMOS_SIZE 256  /* size of CMOS memory in bytes */ 
  • trunk/util/nvramtool/cmos_ops.c

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * cmos_ops.c 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    4847      return CMOS_OP_RESERVED; 
    4948 
    50    if ((result = verify_cmos_op(e->bit, e->length)) != OK) 
     49   if ((result = verify_cmos_op(e->bit, e->length, e->config)) != OK) 
    5150      return result; 
    5251 
     
    7170    { case CMOS_ENTRY_ENUM: 
    7271      case CMOS_ENTRY_HEX: 
     72      case CMOS_ENTRY_STRING: 
    7373         break; 
    7474 
     
    9393   unsigned long long out; 
    9494   const char *p; 
     95   char *memory; 
    9596   int negative, result, found_one; 
    9697 
     
    140141         break; 
    141142 
     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 
    142152      default: 
    143153         BUG(); 
  • trunk/util/nvramtool/cmos_ops.h

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * cmos_ops.h 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
  • trunk/util/nvramtool/common.c

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * common.c 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    3635 
    3736/* version of this program */ 
    38 const char prog_version[] = "2.0.1"; 
     37const char prog_version[] = "2.1"; 
    3938 
    4039/**************************************************************************** 
  • trunk/util/nvramtool/common.h

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * common.h 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
  • trunk/util/nvramtool/compute_ip_checksum.c

    r3075 r3613  
    11/*****************************************************************************\ 
    22 * compute_ip_checksum.c 
    3  * $Id$ 
    43\*****************************************************************************/ 
    54 
  • trunk/util/nvramtool/hexdump.c

    r3075 r3613  
    11/*****************************************************************************\ 
    22 * hexdump.c 
    3  * $Id$ 
    43\*****************************************************************************/ 
    54 
  • trunk/util/nvramtool/hexdump.h

    r3075 r3613  
    11/*****************************************************************************\ 
    22 * hexdump.h 
    3  * $Id$ 
    43\*****************************************************************************/ 
    54 
  • trunk/util/nvramtool/input_file.c

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * input_file.c 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    138137      item->bit = e->bit; 
    139138      item->length = e->length; 
     139      item->config = e->config; 
    140140      item->value = try_prepare_cmos_write(e, value); 
    141141 
     
    163163 
    164164   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; 
    166170      list = item->next; 
    167       cmos_write(item->bit, item->length, item->value); 
     171      cmos_write(&e, item->value); 
    168172      free(item); 
    169173    } 
  • trunk/util/nvramtool/input_file.h

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * input_file.h 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    3433 
    3534#include "common.h" 
     35#include "layout.h" 
    3636 
    3737typedef struct cmos_write_t cmos_write_t; 
     
    4545 { unsigned bit; 
    4646   unsigned length; 
     47   cmos_entry_config_t config; 
    4748   unsigned long long value; 
    4849   cmos_write_t *next; 
  • trunk/util/nvramtool/ip_checksum.h

    r3075 r3613  
    11/*****************************************************************************\ 
    22 * ip_checksum.h 
    3  * $Id$ 
    43\*****************************************************************************/ 
    54 
  • trunk/util/nvramtool/layout.c

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * layout.c 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
  • trunk/util/nvramtool/layout.h

    r3582 r3613  
    11/*****************************************************************************\ 
    22 * layout.h 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    5049 { CMOS_ENTRY_ENUM, 
    5150   CMOS_ENTRY_HEX, 
     51   CMOS_ENTRY_STRING, 
    5252   CMOS_ENTRY_RESERVED 
    5353 } 
  • trunk/util/nvramtool/layout_file.c

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * layout_file.c 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    552551         break; 
    553552 
     553      case 's': 
     554         cmos_entry->config = CMOS_ENTRY_STRING; 
     555         break; 
     556 
    554557      case 'r': 
    555558         cmos_entry->config = CMOS_ENTRY_RESERVED; 
     
    759762         return 'r'; 
    760763 
     764      case CMOS_ENTRY_STRING: 
     765         return 's'; 
     766 
    761767      default: 
    762768         BUG(); 
  • trunk/util/nvramtool/layout_file.h

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * layout_file.h 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
  • trunk/util/nvramtool/lbtable.c

    r3582 r3613  
    11/*****************************************************************************\ 
    22 * lbtable.c 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    583582            break; 
    584583 
     584         case 's': 
     585            cmos_entry.config = CMOS_ENTRY_STRING; 
     586            break; 
     587 
    585588         default: 
    586589            fprintf(stderr, 
  • trunk/util/nvramtool/lbtable.h

    r3122 r3613  
    11/*****************************************************************************\ 
    22 * lbtable.h 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
  • trunk/util/nvramtool/nvramtool.1

    r3123 r3613  
    11.\"***************************************************************************\ 
    22.\" nvramtool.1 
    3 .\" $Id$ 
    43.\"*************************************************************************** 
    54.\"  Copyright (C) 2002, 2003 The Regents of the University of California. 
     
    2928.\"  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 
    3029.\"***************************************************************************/ 
    31 .TH NVRAMTOOL 1 "January 2008" Linux 
     30.TH NVRAMTOOL 1 "September 2008" Linux 
    3231.SH NAME 
    3332nvramtool \- read/write coreboot-related information 
     
    253252David S. Peterson <dsp@llnl.gov> <dave_peterson@pobox.com> 
    254253.br 
    255 Stefan Reinauer <stepan@openbios.org> 
     254Stefan Reinauer <stepan@coresystems.de> 
  • trunk/util/nvramtool/nvramtool.c

    r3123 r3613  
    11/*****************************************************************************\ 
    22 * nvramtool.c 
    3  * $Id$ 
    43 ***************************************************************************** 
    54 *  Copyright (C) 2002-2005 The Regents of the University of California. 
     
    478477         break; 
    479478 
     479      case CMOS_ENTRY_STRING: 
     480         printf("Parameter %s requires a %u-byte string.\n", name, 
     481                e->length / 8); 
     482         break; 
     483 
    480484      case CMOS_ENTRY_RESERVED: 
    481485         printf("Parameter %s is reserved.\n", name); 
     
    571575   /* write the value to nonvolatile RAM */ 
    572576   set_iopl(3); 
    573    cmos_write(e->bit, e->length, n); 
     577   cmos_write(e, n);