Author: stepan Date: 2008-11-30 15:52:46 +0100 (Sun, 30 Nov 2008) New Revision: 3783
Modified: trunk/coreboot-v2/src/config/Config.lb trunk/coreboot-v2/util/options/build_opt_tbl.c Log: ok, another attempt to the build_opt_tbl problem: - create temp files and move them afterwards - remove dummy option -b - fix usage - drop implicit creation of .c file if no --option is specified.
Now let's see if this fixes the issue. :-) We don't want to take 24s instead of 6s to build an image reliably (Yes, yes, I know Tiano takes over 20 minutes)
Signed-off-by: Stefan Reinauer stepan@coresystems.de Acked-by: Stefan Reinauer stepan@coresystems.de
Modified: trunk/coreboot-v2/src/config/Config.lb =================================================================== --- trunk/coreboot-v2/src/config/Config.lb 2008-11-29 15:07:15 UTC (rev 3782) +++ trunk/coreboot-v2/src/config/Config.lb 2008-11-30 14:52:46 UTC (rev 3783) @@ -183,7 +183,7 @@
makerule option_table.h option_table.c depends "build_opt_tbl $(MAINBOARD)/cmos.layout" - action "./build_opt_tbl -b --config $(MAINBOARD)/cmos.layout --header option_table.h --option option_table.c" + action "./build_opt_tbl --config $(MAINBOARD)/cmos.layout --header option_table.h --option option_table.c" end
if HAVE_OPTION_TABLE
Modified: trunk/coreboot-v2/util/options/build_opt_tbl.c =================================================================== --- trunk/coreboot-v2/util/options/build_opt_tbl.c 2008-11-29 15:07:15 UTC (rev 3782) +++ trunk/coreboot-v2/util/options/build_opt_tbl.c 2008-11-30 14:52:46 UTC (rev 3783) @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include <ctype.h> #include <errno.h> #include "../../src/include/pc80/mc146818rtc.h" @@ -10,6 +11,7 @@ #define INPUT_LINE_MAX 256 #define MAX_VALUE_BYTE_LENGTH 64
+#define TMPFILE_TEMPLATE "/tmp/build_opt_tbl_XXXXXX"
static unsigned char cmos_table[4096];
@@ -95,16 +97,15 @@ }
/* This routine displays the usage options */ -void display_usage(void) +void display_usage(char *name) { - printf("Usage build_opt_table [-b] [--option filename]\n"); - printf(" [--config filename]\n"); - printf(" [--header filename]\n"); - printf("b = build option_table.c\n"); - printf("--option = name of option table output file\n"); - printf("--config = build the definitions table from the given file\n"); - printf("--header = ouput a header file with the definitions\n"); - exit(1); + printf("Usage: %s [--config filename]\n", name); + printf(" [--option filename]\n"); + printf(" [--header filename]\n\n"); + printf("--config = Build the definitions table from the given file.\n"); + printf("--option = Output a C source file with the definitions.\n"); + printf("--header = Ouput a C header file with the definitions.\n"); + exit(1); }
@@ -213,6 +214,8 @@ char *option=0; char *header=0; FILE *fp; + int tmpfile; + char tmpfilename[32]; struct cmos_option_table *ct; struct cmos_entries *ce; struct cmos_enums *c_enums, *c_enums_start; @@ -233,39 +236,37 @@
for(i=1;i<argc;i++) { if(argv[i][0]!='-') { - display_usage(); + display_usage(argv[0]); } switch(argv[i][1]) { - case 'b': /* build the table */ - break; case '-': /* data is requested from a file */ switch(argv[i][2]) { case 'c': /* use a configuration file */ if(strcmp(&argv[i][2],"config")) { - display_usage(); + display_usage(argv[0]); } config=argv[++i]; break; case 'o': /* use a cmos definitions table file */ if(strcmp(&argv[i][2],"option")) { - display_usage(); + display_usage(argv[0]); } option=argv[++i]; break; case 'h': /* Output a header file */ if (strcmp(&argv[i][2], "header") != 0) { - display_usage(); + display_usage(argv[0]); } header=argv[++i]; break; default: - display_usage(); + display_usage(argv[0]); break; } break;
default: - display_usage(); + display_usage(argv[0]); break; } } @@ -482,52 +483,72 @@ ct->size += (cptr - (char *)(cmos_table + ct->size)); fclose(fp);
- /* test if an alternate file is to be created */ + /* See if we want to output a C source file */ if(option) { - if((fp=fopen(option,"w"))==NULL){ - fprintf(stderr, "Error - Can not open %s\n",option); + strcpy(tmpfilename, TMPFILE_TEMPLATE); + tmpfile = mkstemp(tmpfilename); + if(tmpfile == -1) { + perror("Error - Could not create temporary file"); exit(1); } - } - else { /* no, so use the default option_table.c */ - if((fp=fopen("option_table.c","w"))==NULL){ - fprintf(stderr, "Error - Can not open option_table.c\n"); - exit(1); + + if((fp=fdopen(tmpfile,"w"))==NULL){ + perror("Error - Could not open temporary file"); + unlink(tmpfilename); + exit(1); } + + /* write the header */ + if(!fwrite("unsigned char option_table[] = {",1,32,fp)) { + perror("Error - Could not write image file"); + fclose(fp); + unlink(tmpfilename); + exit(1); + } + /* write the array values */ + for(i=0;i<(ct->size-1);i++) { + if(!(i%10)) fwrite("\n\t",1,2,fp); + sprintf(buf,"0x%02x,",cmos_table[i]); + fwrite(buf,1,5,fp); + } + /* write the end */ + sprintf(buf,"0x%02x\n",cmos_table[i]); + fwrite(buf,1,4,fp); + if(!fwrite("};\n",1,3,fp)) { + perror("Error - Could not write image file"); + fclose(fp); + unlink(tmpfilename); + exit(1); + } + + fclose(fp); + if (rename(tmpfilename, option)) { + fprintf(stderr, "Error - Could not write %s: ", option); + perror(NULL); + unlink(tmpfilename); + exit(1); + } } - /* write the header */ - if(!fwrite("unsigned char option_table[] = {",1,32,fp)) { - fprintf(stderr, "Error - Could not write image file\n"); - fclose(fp); - exit(1); - } - /* write the array values */ - for(i=0;i<(ct->size-1);i++) { - if(!(i%10)) fwrite("\n\t",1,2,fp); - sprintf(buf,"0x%02x,",cmos_table[i]); - fwrite(buf,1,5,fp); - } - /* write the end */ - sprintf(buf,"0x%02x",cmos_table[i]); - fwrite(buf,1,4,fp); - if(!fwrite("};\n",1,3,fp)) { - fprintf(stderr, "Error - Could not write image file\n"); - fclose(fp); - exit(1); - }
- fclose(fp); - /* See if we also want to output a C header file */ if (header) { struct cmos_option_table *hdr; struct lb_record *ptr, *end; - fp = fopen(header, "w"); + + strcpy(tmpfilename, TMPFILE_TEMPLATE); + tmpfile = mkstemp(tmpfilename); + if(tmpfile == -1) { + perror("Error - Could not create temporary file"); + exit(1); + } + + fp = fdopen(tmpfile, "w"); if (!fp) { - fprintf(stderr, "Error Can not open %s: %s\n", - header, strerror(errno)); + perror("Error - Could not open temporary file"); + unlink(tmpfilename); exit(1); } + /* Get the cmos table header */ hdr = (struct cmos_option_table *)cmos_table; /* Walk through the entry records */ @@ -544,6 +565,8 @@ if (!is_ident((char *)ce->name)) { fprintf(stderr, "Invalid identifier: %s\n", ce->name); + fclose(fp); + unlink(tmpfilename); exit(1); } fprintf(fp, "#define CMOS_VSTART_%s %d\n", @@ -552,6 +575,13 @@ ce->name, ce->length); } fclose(fp); + + if (rename(tmpfilename, header)) { + fprintf(stderr, "Error - Could not write %s: ", header); + perror(NULL); + unlink(tmpfilename); + exit(1); + } } return(0); }