x86: let 32bit use apic_ops too - fix
[linux-2.6/mini2440.git] / drivers / atm / fore200e_mkfirm.c
blob520e14b488ffedfefee122629e1c23af6c7d0f2a
1 /*
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.
8 */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <sys/types.h>
13 #include <time.h>
15 char* default_basename = "pca200e"; /* was initially written for the PCA-200E firmware */
16 char* default_infname = "<stdin>";
17 char* default_outfname = "<stdout>";
19 char* progname;
20 int verbose = 0;
21 int inkernel = 0;
24 void usage(void)
26 fprintf(stderr,
27 "%s: [-v] [-k] [-b basename ] [-i firmware.bin] [-o firmware.c]\n",
28 progname);
29 exit(-1);
33 int main(int argc, char** argv)
35 time_t now;
36 char* infname = NULL;
37 char* outfname = NULL;
38 char* basename = NULL;
39 FILE* infile;
40 FILE* outfile;
41 unsigned firmsize;
42 int c;
44 progname = *(argv++);
46 while (argc > 1) {
47 if ((*argv)[0] == '-') {
48 switch ((*argv)[1]) {
49 case 'i':
50 if (argc-- < 3)
51 usage();
52 infname = *(++argv);
53 break;
54 case 'o':
55 if (argc-- < 3)
56 usage();
57 outfname = *(++argv);
58 break;
59 case 'b':
60 if (argc-- < 3)
61 usage();
62 basename = *(++argv);
63 break;
64 case 'v':
65 verbose = 1;
66 break;
67 case 'k':
68 inkernel = 1;
69 break;
70 default:
71 usage();
74 else {
75 usage();
77 argc--;
78 argv++;
81 if (infname != NULL) {
82 infile = fopen(infname, "r");
83 if (infile == NULL) {
84 fprintf(stderr, "%s: can't open %s for reading\n",
85 progname, infname);
86 exit(-2);
89 else {
90 infile = stdin;
91 infname = default_infname;
94 if (outfname) {
95 outfile = fopen(outfname, "w");
96 if (outfile == NULL) {
97 fprintf(stderr, "%s: can't open %s for writing\n",
98 progname, outfname);
99 exit(-3);
102 else {
103 outfile = stdout;
104 outfname = default_outfname;
107 if (basename == NULL)
108 basename = default_basename;
110 if (verbose) {
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 );
116 time(&now);
117 fprintf(outfile, "/*\n generated by %s from %s on %s"
118 " DO NOT EDIT!\n*/\n\n",
119 progname, infname, ctime(&now));
121 if (inkernel)
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 );
128 c = getc(infile);
129 fprintf(outfile,"\t0x%02x", c);
130 firmsize = 1;
132 while ((c = getc(infile)) >= 0) {
134 if (firmsize++ % 8)
135 fprintf(outfile,", 0x%02x", c);
136 else
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 );
145 if (infile != stdin)
146 fclose(infile);
147 if (outfile != stdout)
148 fclose(outfile);
150 if(verbose)
151 fprintf(stderr, "%s: firmware size = %u\n", progname, firmsize);
153 exit(0);