X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=util%2Foptions%2Fbuild_opt_tbl.c;h=b89bb4f1d52be4e834d43c284a2430fe96ade93e;hb=a8f0f5120b69e02eff5337932b92771363d159a5;hp=1d218df4ee411759e84ea79524551ffa7643f223;hpb=10ec0fed8e3336d52ab35f8da91a2a9423d3e969;p=coreboot.git diff --git a/util/options/build_opt_tbl.c b/util/options/build_opt_tbl.c index 1d218df4e..b89bb4f1d 100644 --- a/util/options/build_opt_tbl.c +++ b/util/options/build_opt_tbl.c @@ -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 @@ static void display_usage(char *name) 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 main(int argc, char **argv) { int i; char *config=0; + char *binary=0; char *option=0; char *header=0; FILE *fp; @@ -274,6 +276,7 @@ int main(int argc, char **argv) int enum_length; int len; char buf[16]; + char val; for(i=1;ibit,&ce->length,&uc,&ce->config_id,&ce->name[0]); @@ -519,8 +529,7 @@ int main(int argc, char **argv) /* 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"); @@ -534,7 +543,7 @@ int main(int argc, char **argv) } /* write the header */ - if(!fwrite("unsigned char option_table[] = {",1,32,fp)) { + if(fwrite("unsigned char option_table[] = {",1,32,fp) != 32) { perror("Error - Could not write image file"); fclose(fp); unlink(tempfilename); @@ -542,14 +551,14 @@ int main(int argc, char **argv) } /* write the array values */ for(i=0; i<(int)(ct->size-1); i++) { - if(!(i%10) && !err) err=!fwrite("\n\t",1,2,fp); + if(!(i%10) && !err) err=(fwrite("\n\t",1,2,fp) != 2); sprintf(buf,"0x%02x,",cmos_table[i]); - if(!err) err=!fwrite(buf,1,5,fp); + if(!err) err=(fwrite(buf,1,5,fp) != 5); } /* write the end */ sprintf(buf,"0x%02x\n",cmos_table[i]); - if(!err) err=!fwrite(buf,1,4,fp); - if(!fwrite("};\n",1,3,fp)) { + if(!err) err=(fwrite(buf,1,4,fp) != 4); + if(fwrite("};\n",1,3,fp) != 3) { perror("Error - Could not write image file"); fclose(fp); unlink(tempfilename); @@ -566,13 +575,46 @@ int main(int argc, char **argv) } } + /* 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) != 1) { + 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");