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>



git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3783 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Stefan Reinauer 2008-11-30 14:52:46 +00:00 committed by Stefan Reinauer
parent 70a1f735a9
commit b4eb4fb6b0
2 changed files with 83 additions and 53 deletions

View File

@ -183,7 +183,7 @@ end
makerule option_table.h option_table.c makerule option_table.h option_table.c
depends "build_opt_tbl $(MAINBOARD)/cmos.layout" 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 end
if HAVE_OPTION_TABLE if HAVE_OPTION_TABLE

View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include "../../src/include/pc80/mc146818rtc.h" #include "../../src/include/pc80/mc146818rtc.h"
@ -10,6 +11,7 @@
#define INPUT_LINE_MAX 256 #define INPUT_LINE_MAX 256
#define MAX_VALUE_BYTE_LENGTH 64 #define MAX_VALUE_BYTE_LENGTH 64
#define TMPFILE_TEMPLATE "/tmp/build_opt_tbl_XXXXXX"
static unsigned char cmos_table[4096]; static unsigned char cmos_table[4096];
@ -95,16 +97,15 @@ void test_for_entry_overlaps(void *entry_start, void *entry_end)
} }
/* This routine displays the usage options */ /* 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("Usage: %s [--config filename]\n", name);
printf(" [--config filename]\n"); printf(" [--option filename]\n");
printf(" [--header filename]\n"); printf(" [--header filename]\n\n");
printf("b = build option_table.c\n"); printf("--config = Build the definitions table from the given file.\n");
printf("--option = name of option table output file\n"); printf("--option = Output a C source file with the definitions.\n");
printf("--config = build the definitions table from the given file\n"); printf("--header = Ouput a C header file with the definitions.\n");
printf("--header = ouput a header file with the definitions\n"); exit(1);
exit(1);
} }
@ -213,6 +214,8 @@ int main(int argc, char **argv)
char *option=0; char *option=0;
char *header=0; char *header=0;
FILE *fp; FILE *fp;
int tmpfile;
char tmpfilename[32];
struct cmos_option_table *ct; struct cmos_option_table *ct;
struct cmos_entries *ce; struct cmos_entries *ce;
struct cmos_enums *c_enums, *c_enums_start; struct cmos_enums *c_enums, *c_enums_start;
@ -233,39 +236,37 @@ int main(int argc, char **argv)
for(i=1;i<argc;i++) { for(i=1;i<argc;i++) {
if(argv[i][0]!='-') { if(argv[i][0]!='-') {
display_usage(); display_usage(argv[0]);
} }
switch(argv[i][1]) { switch(argv[i][1]) {
case 'b': /* build the table */
break;
case '-': /* data is requested from a file */ case '-': /* data is requested from a file */
switch(argv[i][2]) { switch(argv[i][2]) {
case 'c': /* use a configuration file */ case 'c': /* use a configuration file */
if(strcmp(&argv[i][2],"config")) { if(strcmp(&argv[i][2],"config")) {
display_usage(); display_usage(argv[0]);
} }
config=argv[++i]; config=argv[++i];
break; break;
case 'o': /* use a cmos definitions table file */ case 'o': /* use a cmos definitions table file */
if(strcmp(&argv[i][2],"option")) { if(strcmp(&argv[i][2],"option")) {
display_usage(); display_usage(argv[0]);
} }
option=argv[++i]; option=argv[++i];
break; break;
case 'h': /* Output a header file */ case 'h': /* Output a header file */
if (strcmp(&argv[i][2], "header") != 0) { if (strcmp(&argv[i][2], "header") != 0) {
display_usage(); display_usage(argv[0]);
} }
header=argv[++i]; header=argv[++i];
break; break;
default: default:
display_usage(); display_usage(argv[0]);
break; break;
} }
break; break;
default: default:
display_usage(); display_usage(argv[0]);
break; break;
} }
} }
@ -482,52 +483,72 @@ int main(int argc, char **argv)
ct->size += (cptr - (char *)(cmos_table + ct->size)); ct->size += (cptr - (char *)(cmos_table + ct->size));
fclose(fp); fclose(fp);
/* test if an alternate file is to be created */ /* See if we want to output a C source file */
if(option) { if(option) {
if((fp=fopen(option,"w"))==NULL){ strcpy(tmpfilename, TMPFILE_TEMPLATE);
fprintf(stderr, "Error - Can not open %s\n",option); tmpfile = mkstemp(tmpfilename);
if(tmpfile == -1) {
perror("Error - Could not create temporary file");
exit(1); 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);
}
}
/* 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); 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);
}
}
/* See if we also want to output a C header file */ /* See if we also want to output a C header file */
if (header) { if (header) {
struct cmos_option_table *hdr; struct cmos_option_table *hdr;
struct lb_record *ptr, *end; struct lb_record *ptr, *end;
fp = fopen(header, "w");
if (!fp) { strcpy(tmpfilename, TMPFILE_TEMPLATE);
fprintf(stderr, "Error Can not open %s: %s\n", tmpfile = mkstemp(tmpfilename);
header, strerror(errno)); if(tmpfile == -1) {
perror("Error - Could not create temporary file");
exit(1); exit(1);
} }
fp = fdopen(tmpfile, "w");
if (!fp) {
perror("Error - Could not open temporary file");
unlink(tmpfilename);
exit(1);
}
/* Get the cmos table header */ /* Get the cmos table header */
hdr = (struct cmos_option_table *)cmos_table; hdr = (struct cmos_option_table *)cmos_table;
/* Walk through the entry records */ /* Walk through the entry records */
@ -544,6 +565,8 @@ int main(int argc, char **argv)
if (!is_ident((char *)ce->name)) { if (!is_ident((char *)ce->name)) {
fprintf(stderr, "Invalid identifier: %s\n", fprintf(stderr, "Invalid identifier: %s\n",
ce->name); ce->name);
fclose(fp);
unlink(tmpfilename);
exit(1); exit(1);
} }
fprintf(fp, "#define CMOS_VSTART_%s %d\n", fprintf(fp, "#define CMOS_VSTART_%s %d\n",
@ -552,6 +575,13 @@ int main(int argc, char **argv)
ce->name, ce->length); ce->name, ce->length);
} }
fclose(fp); fclose(fp);
if (rename(tmpfilename, header)) {
fprintf(stderr, "Error - Could not write %s: ", header);
perror(NULL);
unlink(tmpfilename);
exit(1);
}
} }
return(0); return(0);
} }