[coreboot] Patch set updated for coreboot: a442eaf nvramtool: Unify nvramtool and build_opt_tbl
Vikram Narayanan (vikram186@gmail.com)
gerrit at coreboot.org
Mon Apr 16 22:24:29 CEST 2012
Vikram Narayanan (vikram186 at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/898
-gerrit
commit a442eafcfe6bd399a6eac61952170f763d45ac22
Author: Vikram Narayanan <vikram186 at gmail.com>
Date: Sat Apr 14 15:25:13 2012 +0530
nvramtool: Unify nvramtool and build_opt_tbl
As cmos.layout parsing capabilities are already there in nvramtool,
use those than using build_opt_tbl.c. Add binary and header file
generation in nvramtool. Make appropriate changes to Makefile.inc.
Change-Id: Iaf3f5d4f51451aeb33c92800a0c895045f2388cf
Signed-off-by: Vikram Narayanan <vikram186 at gmail.com>
---
src/arch/x86/Makefile.inc | 13 +-
util/nvramtool/accessors/layout-text.c | 226 ++++++++++++++++++++++++++++++++
util/nvramtool/accessors/layout-text.h | 2 +
util/nvramtool/cli/nvramtool.c | 18 +++-
util/nvramtool/cli/opts.c | 9 +-
util/nvramtool/cli/opts.h | 4 +-
util/nvramtool/common.c | 2 +
util/nvramtool/layout.h | 8 +-
8 files changed, 267 insertions(+), 15 deletions(-)
diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc
index 8783d4b..d3b5e07 100755
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -128,18 +128,15 @@ bootsplash.jpg-type := bootsplash
#######################################################################
# i386 specific tools
+NVRAMTOOL:=$(objutil)/nvramtool/nvramtool
-$(OPTION_TABLE_H): $(objutil)/options/build_opt_tbl $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout
+$(OPTION_TABLE_H): $(NVRAMTOOL) $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout
@printf " OPTION $(subst $(obj)/,,$(@))\n"
- $(objutil)/options/build_opt_tbl --config $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout --header $@
+ $(NVRAMTOOL) -y $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout -H $@
-$(obj)/cmos_layout.bin: $(objutil)/options/build_opt_tbl $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout
+$(obj)/cmos_layout.bin: $(NVRAMTOOL) $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout
@printf " OPTION $(subst $(obj)/,,$(@))\n"
- $(objutil)/options/build_opt_tbl --config $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout --binary $@
-
-$(objutil)/options/build_opt_tbl: $(top)/util/options/build_opt_tbl.c $(top)/src/include/pc80/mc146818rtc.h $(top)/src/include/boot/coreboot_tables.h
- @printf " HOSTCC $(subst $(obj)/,,$(@))\n"
- $(HOSTCC) $(HOSTCFLAGS) $< -o $@
+ $(NVRAMTOOL) -y $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout -L $@
#######################################################################
# Build the coreboot_ram (stage 2)
diff --git a/util/nvramtool/accessors/layout-text.c b/util/nvramtool/accessors/layout-text.c
index cbe698c..7b1bbd3 100644
--- a/util/nvramtool/accessors/layout-text.c
+++ b/util/nvramtool/accessors/layout-text.c
@@ -1,6 +1,12 @@
/*****************************************************************************\
* layout-text.c
*****************************************************************************
+ * Copyright (C) 2012, Vikram Narayanan
+ * Unified build_opt_tbl and nvramtool
+ * build_opt_tbl.c
+ * Copyright (C) 2003 Eric Biederman (ebiederm at xmission.com)
+ * Copyright (C) 2007-2010 coresystems GmbH
+ *
* Copyright (C) 2002-2005 The Regents of the University of California.
* Produced at the Lawrence Livermore National Laboratory.
* Written by Dave Peterson <dsp at llnl.gov> <dave_peterson at pobox.com>.
@@ -186,6 +192,7 @@ static int line_num;
static const char *layout_filename = NULL;
+#define ROUNDUP4(x) (x += (4 - (x % 4)))
/****************************************************************************
* set_layout_filename
*
@@ -218,6 +225,225 @@ void get_layout_from_file(void)
fclose(f);
}
+static int is_ident_nondigit(int c)
+{
+ int result;
+ switch(c) {
+ case 'A': case 'B': case 'C': case 'D':
+ case 'E': case 'F': case 'G': case 'H':
+ case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P':
+ case 'Q': case 'R': case 'S': case 'T':
+ case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z':
+ case 'a': case 'b': case 'c': case 'd':
+ case 'e': case 'f': case 'g': case 'h':
+ case 'i': case 'j': case 'k': case 'l':
+ case 'm': case 'n': case 'o': case 'p':
+ case 'q': case 'r': case 's': case 't':
+ case 'u': case 'v': case 'w': case 'x':
+ case 'y': case 'z':
+ case '_':
+ result = 1;
+ break;
+ default:
+ result = 0;
+ break;
+ }
+ return result;
+}
+
+static int is_ident(char *str)
+{
+ int result;
+ int ch;
+ ch = *str;
+ result = 0;
+ if (is_ident_nondigit(ch)) {
+ do {
+ str++;
+ ch = *str;
+ } while(ch && (is_ident_nondigit(ch) || (isdigit(ch))));
+ result = (ch == '\0');
+ }
+ return result;
+}
+
+int write_cmos_layout_bin(FILE *f)
+{
+ const cmos_entry_t *cmos_entry;
+ const cmos_enum_t *cmos_enum;
+ cmos_checksum_layout_t layout;
+ struct cmos_option_table table;
+ struct cmos_entries entry;
+ struct cmos_enums cenum;
+ struct cmos_checksum csum;
+ size_t sum = 0;
+ int len;
+
+ for (cmos_entry = first_cmos_entry(); cmos_entry != NULL;
+ cmos_entry = next_cmos_entry(cmos_entry)) {
+
+ if (cmos_entry == first_cmos_entry()) {
+ sum += sizeof(table);
+ table.header_length = sizeof(table);
+ table.tag = LB_TAG_CMOS_OPTION_TABLE;
+
+ if (fwrite((char *)&table, sizeof(table), 1, f) != 1) {
+ perror("Error writing image file");
+ goto err;
+ }
+ }
+
+ memset(&entry, 0, sizeof(entry));
+ entry.tag = LB_TAG_OPTION;
+ entry.config = cmos_entry->config;
+ entry.config_id = (uint32_t)cmos_entry->config_id;
+ entry.bit = cmos_entry->bit;
+ entry.length = cmos_entry->length;
+
+ if (!is_ident((char *)cmos_entry->name)) {
+ fprintf(stderr,
+ "Error - Name %s is an invalid identifier\n",
+ cmos_entry->name);
+ goto err;
+ }
+
+ memcpy(entry.name, cmos_entry->name, strlen(cmos_entry->name));
+ entry.name[strlen(cmos_entry->name)] = '\0';
+ len = strlen(cmos_entry->name) + 1;
+
+ if (len % 4)
+ ROUNDUP4(len);
+
+ entry.size = sizeof(entry) - CMOS_MAX_NAME_LENGTH + len;
+ sum += entry.size;
+ if (fwrite((char *)&entry, entry.size, 1, f) != 1) {
+ perror("Error writing image file");
+ goto err;
+ }
+ }
+
+ for (cmos_enum = first_cmos_enum();
+ cmos_enum != NULL; cmos_enum = next_cmos_enum(cmos_enum)) {
+ memset(&cenum, 0, sizeof(cenum));
+ cenum.tag = LB_TAG_OPTION_ENUM;
+ memcpy(cenum.text, cmos_enum->text, strlen(cmos_enum->text));
+ cenum.text[strlen(cmos_enum->text)] = '\0';
+ len = strlen((char *)cenum.text) + 1;
+
+ if (len % 4)
+ ROUNDUP4(len);
+
+ cenum.config_id = cmos_enum->config_id;
+ cenum.value = cmos_enum->value;
+ cenum.size = sizeof(cenum) - CMOS_MAX_TEXT_LENGTH + len;
+ sum += cenum.size;
+ if (fwrite((char *)&cenum, cenum.size, 1, f) != 1) {
+ perror("Error writing image file");
+ goto err;
+ }
+ }
+
+ layout.summed_area_start = cmos_checksum_start;
+ layout.summed_area_end = cmos_checksum_end;
+ layout.checksum_at = cmos_checksum_index;
+ checksum_layout_to_bits(&layout);
+
+ csum.tag = LB_TAG_OPTION_CHECKSUM;
+ csum.size = sizeof(csum);
+ csum.range_start = layout.summed_area_start;
+ csum.range_end = layout.summed_area_end;
+ csum.location = layout.checksum_at;
+ csum.type = CHECKSUM_PCBIOS;
+ sum += csum.size;
+
+ if (fwrite((char *)&csum, csum.size, 1, f) != 1) {
+ perror("Error writing image file");
+ goto err;
+ }
+
+ if (fseek(f, sizeof(table.tag), SEEK_SET) != 0) {
+ perror("Error while seeking");
+ goto err;
+ }
+
+ if (fwrite((char *)&sum, sizeof(table.tag), 1, f) != 1) {
+ perror("Error writing image file");
+ goto err;
+ }
+ return sum;
+
+err:
+ fclose(f);
+ exit(1);
+}
+
+void write_cmos_output_bin(const char *binary_filename)
+{
+ FILE *fp;
+
+ if ((fp = fopen(binary_filename, "wb")) == NULL) {
+ fprintf(stderr,
+ "%s: Can not open file %s for writing: "
+ "%s\n", prog_name, binary_filename, strerror(errno));
+ exit(1);
+ }
+ write_cmos_layout_bin(fp);
+ fclose(fp);
+}
+
+void write_cmos_layout_header(const char *header_filename)
+{
+ FILE *fp;
+ const cmos_entry_t *cmos_entry;
+ cmos_checksum_layout_t layout;
+
+ if ((fp = fopen(header_filename, "w+")) == NULL) {
+ fprintf(stderr,
+ "%s: Can't open file %s for writing: %s\n",
+ prog_name, header_filename, strerror(errno));
+ exit(1);
+ }
+
+ fprintf(fp, "/**\n * This is an autogenerated file. Do not EDIT.\n"
+ " * All changes made to this file will be lost.\n"
+ " * See mainboard's cmos.layout file.\n */\n"
+ "\n#ifndef __OPTION_TABLE_H\n"
+ "#define __OPTION_TABLE_H\n\n");
+
+ for (cmos_entry = first_cmos_entry(); cmos_entry != NULL;
+ cmos_entry = next_cmos_entry(cmos_entry)) {
+
+ if (!is_ident((char *)cmos_entry->name)) {
+ fprintf(stderr,
+ "Error - Name %s is an invalid identifier\n",
+ cmos_entry->name);
+ fclose(fp);
+ exit(1);
+ }
+
+ fprintf(fp, "#define CMOS_VSTART_%s\t%d\n",
+ cmos_entry->name, cmos_entry->bit);
+ fprintf(fp, "#define CMOS_VLEN_%s\t%d\n",
+ cmos_entry->name, cmos_entry->length);
+ }
+
+ layout.summed_area_start = cmos_checksum_start;
+ layout.summed_area_end = cmos_checksum_end;
+ layout.checksum_at = cmos_checksum_index;
+ checksum_layout_to_bits(&layout);
+
+ fprintf(fp, "\n#define LB_CKS_RANGE_START %d\n",
+ layout.summed_area_start / 8);
+ fprintf(fp, "#define LB_CKS_RANGE_END %d\n",
+ layout.summed_area_end / 8);
+ fprintf(fp, "#define LB_CKS_LOC %d\n",
+ layout.checksum_at / 8);
+ fprintf(fp, "\n#endif /* __OPTION_TABLE_H */\n");
+
+ fclose(fp);
+}
/****************************************************************************
* write_cmos_layout
*
diff --git a/util/nvramtool/accessors/layout-text.h b/util/nvramtool/accessors/layout-text.h
index 21997e9..e6b4397 100644
--- a/util/nvramtool/accessors/layout-text.h
+++ b/util/nvramtool/accessors/layout-text.h
@@ -37,5 +37,7 @@
void set_layout_filename(const char filename[]);
void get_layout_from_file(void);
void write_cmos_layout(FILE * f);
+void write_cmos_output_bin(const char *binary_filename);
+void write_cmos_layout_header(const char *header_filename);
#endif /* LAYOUT_FILE_H */
diff --git a/util/nvramtool/cli/nvramtool.c b/util/nvramtool/cli/nvramtool.c
index bcb10bb..f3fb16d 100644
--- a/util/nvramtool/cli/nvramtool.c
+++ b/util/nvramtool/cli/nvramtool.c
@@ -62,6 +62,8 @@ static void op_write_cmos_dump(void);
static void op_read_cmos_dump(void);
static void op_show_cmos_hex_dump(void);
static void op_show_cmos_dumpfile(void);
+static void op_write_cmos_layout_bin(void);
+static void op_write_cmos_layout_header(void);
static int list_one_param(const char name[], int show_name);
static int list_all_params(void);
static void list_param_enums(const char name[]);
@@ -86,9 +88,23 @@ static const op_fn_t op_fns[] = { op_show_version,
op_write_cmos_dump,
op_read_cmos_dump,
op_show_cmos_hex_dump,
- op_show_cmos_dumpfile
+ op_show_cmos_dumpfile,
+ op_write_cmos_layout_bin,
+ op_write_cmos_layout_header
};
+static void op_write_cmos_layout_bin(void)
+{
+ get_layout_from_file();
+ write_cmos_output_bin(nvramtool_op.param);
+}
+
+static void op_write_cmos_layout_header(void)
+{
+ get_layout_from_file();
+ write_cmos_layout_header(nvramtool_op.param);
+}
+
static const hexdump_format_t cmos_dump_format =
{ 16, 2, "", " | ", " ", " | ", '.' };
diff --git a/util/nvramtool/cli/opts.c b/util/nvramtool/cli/opts.c
index 4949649..8e920e8 100644
--- a/util/nvramtool/cli/opts.c
+++ b/util/nvramtool/cli/opts.c
@@ -41,7 +41,7 @@ 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::C:dD:e:hil::np:r:tvw:xX:y:Y";
+static const char getopt_string[] = "-ab:B:c::C:dD:e:hH:iL:l::np:r:tvw:xX:y:Y";
/****************************************************************************
* parse_nvramtool_args
@@ -100,6 +100,9 @@ void parse_nvramtool_args(int argc, char *argv[])
case 'h':
register_op(&op_found, NVRAMTOOL_OP_SHOW_USAGE, NULL);
break;
+ case 'H':
+ register_op(&op_found, NVRAMTOOL_OP_WRITE_HEADER_FILE, optarg);
+ break;
case 'i':
register_op(&op_found,
NVRAMTOOL_OP_CMOS_SET_PARAMS_STDIN, NULL);
@@ -108,6 +111,10 @@ void parse_nvramtool_args(int argc, char *argv[])
register_op(&op_found, NVRAMTOOL_OP_LBTABLE_SHOW_INFO,
handle_optional_arg(argc, argv));
break;
+ case 'L':
+ register_op(&op_found, NVRAMTOOL_OP_WRITE_BINARY_FILE,
+ optarg);
+ break;
case 'n':
register_op_modifier(NVRAMTOOL_MOD_SHOW_VALUE_ONLY,
NULL);
diff --git a/util/nvramtool/cli/opts.h b/util/nvramtool/cli/opts.h
index f46f254..a011ef1 100644
--- a/util/nvramtool/cli/opts.h
+++ b/util/nvramtool/cli/opts.h
@@ -48,7 +48,9 @@ typedef enum { NVRAMTOOL_OP_SHOW_VERSION = 0,
NVRAMTOOL_OP_WRITE_CMOS_DUMP,
NVRAMTOOL_OP_READ_CMOS_DUMP,
NVRAMTOOL_OP_SHOW_CMOS_HEX_DUMP,
- NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE
+ NVRAMTOOL_OP_SHOW_CMOS_DUMPFILE,
+ NVRAMTOOL_OP_WRITE_BINARY_FILE,
+ NVRAMTOOL_OP_WRITE_HEADER_FILE
} nvramtool_op_t;
typedef struct {
diff --git a/util/nvramtool/common.c b/util/nvramtool/common.c
index 91fcccc..15f8b0d 100644
--- a/util/nvramtool/common.c
+++ b/util/nvramtool/common.c
@@ -98,6 +98,8 @@ void usage(FILE * outfile)
"VALUE.\n"
" -l [ARG]: Show coreboot table info for ARG, or "
"all ARG choices.\n"
+ " -L OUTPUT_BIN Write CMOS layout file in binary format\n"
+ " -H OUTPUT_HDR Write CMOS layout file in header format\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"
diff --git a/util/nvramtool/layout.h b/util/nvramtool/layout.h
index d99275c..082c31b 100644
--- a/util/nvramtool/layout.h
+++ b/util/nvramtool/layout.h
@@ -46,10 +46,10 @@
#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_ENUM = 'e',
+ CMOS_ENTRY_HEX = 'h',
+ CMOS_ENTRY_STRING = 's',
+ CMOS_ENTRY_RESERVED = 'r',
} cmos_entry_config_t;
/* This represents a CMOS parameter. */
More information about the coreboot
mailing list