[coreboot] [commit] r6268 - in trunk: src/arch/x86 src/arch/x86/boot src/arch/x86/include/arch src/include src/pc80 util/cbfstool util/options

repository service svn at coreboot.org
Tue Jan 18 14:56:36 CET 2011


Author: oxygene
Date: Tue Jan 18 14:56:36 2011
New Revision: 6268
URL: https://tracker.coreboot.org/trac/coreboot/changeset/6268

Log:
Move option table (cmos.layout's binary representation)
to CBFS and adapt coreboot to use it.

Comments by Stefan and Mathias taken into account (except for
the build time failure if the table is missing when it should
exist and the "memory leak" in build_opt_tbl)

Signed-off-by: Patrick Georgi <patrick.georgi at secunet.com>
Acked-by: Stefan Reinauer <stepan at coreboot.org>

Modified:
   trunk/src/arch/x86/Makefile.inc
   trunk/src/arch/x86/boot/coreboot_table.c
   trunk/src/arch/x86/include/arch/coreboot_tables.h
   trunk/src/include/cbfs.h
   trunk/src/pc80/mc146818rtc.c
   trunk/src/pc80/mc146818rtc_early.c
   trunk/util/cbfstool/cbfs.h
   trunk/util/options/build_opt_tbl.c

Modified: trunk/src/arch/x86/Makefile.inc
==============================================================================
--- trunk/src/arch/x86/Makefile.inc	Tue Jan 18 13:14:08 2011	(r6267)
+++ trunk/src/arch/x86/Makefile.inc	Tue Jan 18 14:56:36 2011	(r6268)
@@ -27,7 +27,10 @@
 
 OPTION_TABLE_H:=
 ifeq ($(CONFIG_HAVE_OPTION_TABLE),y)
-ramstage-srcs += $(obj)/option_table.c
+cbfs-files-y += $(obj)/cmos_layout.bin
+$(obj)/cmos_layout.bin-name = cmos_layout.bin
+$(obj)/cmos_layout.bin-type = 0x01aa
+
 OPTION_TABLE_H:=$(obj)/option_table.h
 endif
 
@@ -64,7 +67,7 @@
 		$(CBFSTOOL) $@ add $(call extract_nth,1,$(file)) $(call extract_nth,2,$(file)) $(call extract_nth,3,$(file)) $(call extract_nth,4,$(file)); )
 prebuilt-files = $(foreach file,$(cbfs-files), $(call extract_nth,1,$(file)))
 
-$(obj)/coreboot.pre1: $(obj)/coreboot.bootblock $(prebuilt-files) $(CBFSTOOL)
+$(obj)/coreboot.pre1: $(obj)/coreboot.bootblock $$(prebuilt-files) $(CBFSTOOL)
 	rm -f $@
 	$(CBFSTOOL) $@ create $(CONFIG_COREBOOT_ROMSIZE_KB)K $(obj)/coreboot.bootblock
 	$(prebuild-files)
@@ -121,9 +124,9 @@
 	@printf "    OPTION     $(subst $(obj)/,,$(@))\n"
 	$(objutil)/options/build_opt_tbl --config $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout --header $@
 
-$(obj)/option_table.c: $(objutil)/options/build_opt_tbl $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout
+$(obj)/cmos_layout.bin: $(objutil)/options/build_opt_tbl $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout
 	@printf "    OPTION     $(subst $(obj)/,,$(@))\n"
-	$(objutil)/options/build_opt_tbl --config $(top)/src/mainboard/$(MAINBOARDDIR)/cmos.layout --option $@
+	$(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"

Modified: trunk/src/arch/x86/boot/coreboot_table.c
==============================================================================
--- trunk/src/arch/x86/boot/coreboot_table.c	Tue Jan 18 13:14:08 2011	(r6267)
+++ trunk/src/arch/x86/boot/coreboot_table.c	Tue Jan 18 14:56:36 2011	(r6268)
@@ -542,11 +542,14 @@
 
 #if (CONFIG_USE_OPTION_TABLE == 1)
 	{
-		struct lb_record *rec_dest = lb_new_record(head);
-		/* Copy the option config table, it's already a lb_record... */
-		memcpy(rec_dest,  &option_table, option_table.size);
-		/* Create cmos checksum entry in coreboot table */
-		lb_cmos_checksum(head);
+		struct cmos_option_table option_table = cbfs_find_file("cmos_layout.bin", 0x1aa);
+		if (option_table) {
+			struct lb_record *rec_dest = lb_new_record(head);
+			/* Copy the option config table, it's already a lb_record... */
+			memcpy(rec_dest,  &option_table, option_table.size);
+			/* Create cmos checksum entry in coreboot table */
+			lb_cmos_checksum(head);
+		}
 	}
 #endif
 	/* Record where RAM is located */

Modified: trunk/src/arch/x86/include/arch/coreboot_tables.h
==============================================================================
--- trunk/src/arch/x86/include/arch/coreboot_tables.h	Tue Jan 18 13:14:08 2011	(r6267)
+++ trunk/src/arch/x86/include/arch/coreboot_tables.h	Tue Jan 18 14:56:36 2011	(r6268)
@@ -16,8 +16,6 @@
  */
 struct lb_memory *get_lb_mem(void);
 
-extern struct cmos_option_table option_table;
-
 /* defined by mainboard.c if the mainboard requires extra resources */
 int add_mainboard_resources(struct lb_memory *mem);
 int add_northbridge_resources(struct lb_memory *mem);

Modified: trunk/src/include/cbfs.h
==============================================================================
--- trunk/src/include/cbfs.h	Tue Jan 18 13:14:08 2011	(r6267)
+++ trunk/src/include/cbfs.h	Tue Jan 18 14:56:36 2011	(r6268)
@@ -71,6 +71,9 @@
 #define CBFS_TYPE_VSA        0x51
 #define CBFS_TYPE_MBI        0x52
 #define CBFS_TYPE_MICROCODE  0x53
+#define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
+#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
+
 
 /** this is the master cbfs header - it need to be
     located somewhere in the bootblock.  Where it

Modified: trunk/src/pc80/mc146818rtc.c
==============================================================================
--- trunk/src/pc80/mc146818rtc.c	Tue Jan 18 13:14:08 2011	(r6267)
+++ trunk/src/pc80/mc146818rtc.c	Tue Jan 18 14:56:36 2011	(r6268)
@@ -4,6 +4,7 @@
 #include <string.h>
 #if CONFIG_USE_OPTION_TABLE
 #include "option_table.h"
+#include <cbfs.h>
 #endif
 
 /* control registers - Moto names
@@ -217,7 +218,6 @@
 
 int get_option(void *dest, const char *name)
 {
-	extern struct cmos_option_table option_table;
 	struct cmos_option_table *ct;
 	struct cmos_entries *ce;
 	size_t namelen;
@@ -227,7 +227,7 @@
 	namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
 
 	/* find the requested entry record */
-	ct=&option_table;
+	ct=cbfs_find_file("cmos_layout.bin", CMOS_COMPONENT_CMOS_LAYOUT);
 	ce=(struct cmos_entries*)((unsigned char *)ct + ct->header_length);
 	for(;ce->tag==LB_TAG_OPTION;
 		ce=(struct cmos_entries*)((unsigned char *)ce + ce->size)) {

Modified: trunk/src/pc80/mc146818rtc_early.c
==============================================================================
--- trunk/src/pc80/mc146818rtc_early.c	Tue Jan 18 13:14:08 2011	(r6267)
+++ trunk/src/pc80/mc146818rtc_early.c	Tue Jan 18 14:56:36 2011	(r6268)
@@ -65,7 +65,7 @@
 
 	if (cmos_error() || !cmos_chksum_valid()) {
 #if CONFIG_USE_CMOS_RECOVERY
-		char *cmos_default = cbfs_find_file("cmos.default", 0xaa);
+		char *cmos_default = cbfs_find_file("cmos.default", CBFS_COMPONENT_CMOS_DEFAULT);
 		if (cmos_default) {
 			printk_warning("WARNING - CMOS CORRUPTED. RESTORING DEFAULTS.\n");
 			/* First 14 bytes are reserved for

Modified: trunk/util/cbfstool/cbfs.h
==============================================================================
--- trunk/util/cbfstool/cbfs.h	Tue Jan 18 13:14:08 2011	(r6267)
+++ trunk/util/cbfstool/cbfs.h	Tue Jan 18 14:56:36 2011	(r6268)
@@ -77,6 +77,7 @@
 #define CBFS_COMPONENT_MBI        0x52
 #define CBFS_COMPONENT_MICROCODE  0x53
 #define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
+#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
 
 /* The deleted type is chosen to be a value
  * that can be written in a FLASH from all other

Modified: trunk/util/options/build_opt_tbl.c
==============================================================================
--- trunk/util/options/build_opt_tbl.c	Tue Jan 18 13:14:08 2011	(r6267)
+++ trunk/util/options/build_opt_tbl.c	Tue Jan 18 14:56:36 2011	(r6268)
@@ -33,7 +33,7 @@
 #define INPUT_LINE_MAX 256
 #define MAX_VALUE_BYTE_LENGTH 64
 
-#define TMPFILE_LEN 256
+#define TMPFILE_LEN 25600
 #define TMPFILE_TEMPLATE "/build_opt_tbl_XXXXXX"
 
 static unsigned char cmos_table[4096];
@@ -142,8 +142,9 @@
 	printf("                       [--option filename]\n");
 	printf("                       [--header filename]\n\n");
 	printf("--config = Build the definitions table from the given file.\n");
+	printf("--binary = Output a binary file with the definitions.\n");
 	printf("--option = Output a C source file with the definitions.\n");
-	printf("--header = Ouput a C header file with the definitions.\n");
+	printf("--header = Output a C header file with the definitions.\n");
 	exit(1);
 }
 
@@ -253,6 +254,7 @@
 {
 	int i;
 	char *config=0;
+	char *binary=0;
 	char *option=0;
 	char *header=0;
 	FILE *fp;
@@ -288,6 +290,12 @@
                                                 }
                                                 config=argv[++i];
                                                 break;
+                                        case 'b':  /* Emit a binary file */
+                                                if(strcmp(&argv[i][2],"binary")) {
+                                                        display_usage(argv[0]);
+                                                }
+                                                binary=argv[++i];
+                                                break;
                                         case 'o':  /* use a cmos definitions table file */
                                                 if(strcmp(&argv[i][2],"option")) {
                                                         display_usage(argv[0]);
@@ -519,8 +527,7 @@
 	/* See if we want to output a C source file */
 	if(option) {
 		int err=0;
-		strncpy(tempfilename, dirname(strdup(option)), TMPFILE_LEN);
-	        strncat(tempfilename, TMPFILE_TEMPLATE, TMPFILE_LEN);
+		snprintf(tempfilename, TMPFILE_LEN, "%s%s", dirname(strdup(option)), TMPFILE_TEMPLATE);
 		tempfile = mkstemp(tempfilename);
 		if(tempfile == -1) {
                         perror("Error - Could not create temporary file");
@@ -566,13 +573,46 @@
 		}
 	}
 
+	/* See if we also want to output a binary file */
+	if(binary) {
+		int err=0;
+		snprintf(tempfilename, TMPFILE_LEN, "%s%s", dirname(strdup(binary)), TMPFILE_TEMPLATE);
+		tempfile = mkstemp(tempfilename);
+		if(tempfile == -1) {
+                        perror("Error - Could not create temporary file");
+                        exit(1);
+		}
+
+		if((fp=fdopen(tempfile,"wb"))==NULL){
+			perror("Error - Could not open temporary file");
+			unlink(tempfilename);
+			exit(1);
+		}
+
+		/* write the array values */
+		if(!fwrite(cmos_table, (int)(ct->size-1), 1, fp)) {
+        	        perror("Error - Could not write image file");
+        	        fclose(fp);
+			unlink(tempfilename);
+        	        exit(1);
+		}
+
+        	fclose(fp);
+		UNLINK_IF_NECESSARY(binary);
+		if (rename(tempfilename, binary)) {
+			fprintf(stderr, "Error - Could not write %s: ", binary);
+			perror(NULL);
+			unlink(tempfilename);
+			exit(1);
+		}
+	}
+
 	/* See if we also want to output a C header file */
 	if (header) {
 		struct cmos_option_table *hdr;
 		struct lb_record *ptr, *end;
 
-		strncpy(tempfilename, dirname(strdup(header)), TMPFILE_LEN);
-	        strncat(tempfilename, TMPFILE_TEMPLATE, TMPFILE_LEN);
+		snprintf(tempfilename, TMPFILE_LEN, "%s%s", dirname(strdup(header)), TMPFILE_TEMPLATE);
 		tempfile = mkstemp(tempfilename);
 		if(tempfile == -1) {
 			perror("Error - Could not create temporary file");




More information about the coreboot mailing list