2 mkfirm.c: generates a C readable file from a binary firmware image
4 Christophe Lizzi (lizzi@{csti.fr, cnam.fr}), June 1999.
6 This software may be used and distributed according to the terms
7 of the GNU General Public License, incorporated herein by reference.
12 #include <sys/types.h>
15 char* default_basename = "pca200e"; /* was initially written for the PCA-200E firmware */
16 char* default_infname = "<stdin>";
17 char* default_outfname = "<stdout>";
27 "%s: [-v] [-k] [-b basename ] [-i firmware.bin] [-o firmware.c]\n",
33 int main(int argc, char** argv)
37 char* outfname = NULL;
38 char* basename = NULL;
47 if ((*argv)[0] == '-') {
81 if (infname != NULL) {
82 infile = fopen(infname, "r");
84 fprintf(stderr, "%s: can't open %s for reading\n",
91 infname = default_infname;
95 outfile = fopen(outfname, "w");
96 if (outfile == NULL) {
97 fprintf(stderr, "%s: can't open %s for writing\n",
104 outfname = default_outfname;
107 if (basename == NULL)
108 basename = default_basename;
111 fprintf(stderr, "%s: input file = %s\n", progname, infname );
112 fprintf(stderr, "%s: output file = %s\n", progname, outfname );
113 fprintf(stderr, "%s: firmware basename = %s\n", progname, basename );
117 fprintf(outfile, "/*\n generated by %s from %s on %s"
118 " DO NOT EDIT!\n*/\n\n",
119 progname, infname, ctime(&now));
122 fprintf(outfile, "#include <linux/init.h>\n\n" );
124 /* XXX force 32 bit alignment? */
125 fprintf(outfile, "const unsigned char%s %s_data[] = {\n",
126 inkernel ? " __initdata" : "", basename );
129 fprintf(outfile,"\t0x%02x", c);
132 while ((c = getc(infile)) >= 0) {
135 fprintf(outfile,", 0x%02x", c);
137 fprintf(outfile,",\n\t0x%02x", c);
140 fprintf(outfile, "\n};\n\n");
142 fprintf(outfile, "const unsigned int%s %s_size = %u;\n",
143 inkernel ? " __initdata" : "", basename, firmsize );
147 if (outfile != stdout)
151 fprintf(stderr, "%s: firmware size = %u\n", progname, firmsize);