2 $Id: fore200e_mkfirm.c,v 1.1 2000/02/21 16:04:32 davem Exp $
4 mkfirm.c: generates a C readable file from a binary firmware image
6 Christophe Lizzi (lizzi@{csti.fr, cnam.fr}), June 1999.
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
14 #include <sys/types.h>
17 char* default_basename = "pca200e"; /* was initially written for the PCA-200E firmware */
18 char* default_infname = "<stdin>";
19 char* default_outfname = "<stdout>";
29 "%s: [-v] [-k] [-b basename ] [-i firmware.bin] [-o firmware.c]\n",
35 int main(int argc, char** argv)
39 char* outfname = NULL;
40 char* basename = NULL;
49 if ((*argv)[0] == '-') {
83 if (infname != NULL) {
84 infile = fopen(infname, "r");
86 fprintf(stderr, "%s: can't open %s for reading\n",
93 infname = default_infname;
97 outfile = fopen(outfname, "w");
98 if (outfile == NULL) {
99 fprintf(stderr, "%s: can't open %s for writing\n",
106 outfname = default_outfname;
109 if (basename == NULL)
110 basename = default_basename;
113 fprintf(stderr, "%s: input file = %s\n", progname, infname );
114 fprintf(stderr, "%s: output file = %s\n", progname, outfname );
115 fprintf(stderr, "%s: firmware basename = %s\n", progname, basename );
119 fprintf(outfile, "/*\n generated by %s from %s on %s"
120 " DO NOT EDIT!\n*/\n\n",
121 progname, infname, ctime(&now));
124 fprintf(outfile, "#include <linux/init.h>\n\n" );
126 /* XXX force 32 bit alignment? */
127 fprintf(outfile, "const unsigned char%s %s_data[] = {\n",
128 inkernel ? " __initdata" : "", basename );
131 fprintf(outfile,"\t0x%02x", c);
134 while ((c = getc(infile)) >= 0) {
137 fprintf(outfile,", 0x%02x", c);
139 fprintf(outfile,",\n\t0x%02x", c);
142 fprintf(outfile, "\n};\n\n");
144 fprintf(outfile, "const unsigned int%s %s_size = %u;\n",
145 inkernel ? " __initdata" : "", basename, firmsize );
149 if (outfile != stdout)
153 fprintf(stderr, "%s: firmware size = %u\n", progname, firmsize);