~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/atm/fore200e_mkfirm.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2   $Id: fore200e_mkfirm.c,v 1.1 2000/02/21 16:04:32 davem Exp $
  3 
  4   mkfirm.c: generates a C readable file from a binary firmware image
  5 
  6   Christophe Lizzi (lizzi@{csti.fr, cnam.fr}), June 1999.
  7   
  8   This software may be used and distributed according to the terms
  9   of the GNU General Public License, incorporated herein by reference.
 10 */
 11 
 12 #include <stdio.h>
 13 #include <sys/types.h>
 14 #include <sys/time.h>
 15 
 16 char* default_basename = "pca200e"; /* was initially written for the PCA-200E firmware */
 17 char* default_infname  = "<stdin>";
 18 char* default_outfname = "<stdout>";
 19 
 20 char* progname;
 21 int   verbose  = 0;
 22 int   inkernel = 0;
 23 
 24 
 25 void usage(void)
 26 {
 27     fprintf(stderr,
 28             "%s: [-v] [-k] [-b basename ] [-i firmware.bin] [-o firmware.c]\n",
 29             progname);
 30     exit(-1);
 31 }
 32 
 33 
 34 int main(int argc, char** argv)
 35 {
 36     time_t   now;
 37     char*    infname  = NULL;
 38     char*    outfname = NULL;
 39     char*    basename = NULL;
 40     FILE*    infile;
 41     FILE*    outfile;
 42     unsigned firmsize;
 43     int      c;
 44 
 45     progname = *(argv++);
 46     
 47     while (argc > 1) {
 48         if ((*argv)[0] == '-') {
 49             switch ((*argv)[1]) {
 50             case 'i':
 51                 if (argc-- < 3)
 52                     usage();
 53                 infname = *(++argv);
 54                 break;
 55             case 'o':
 56                 if (argc-- < 3)
 57                     usage();
 58                 outfname = *(++argv);
 59                 break;
 60             case 'b':
 61                 if (argc-- < 3)
 62                     usage();
 63                 basename = *(++argv);
 64                 break;
 65             case 'v':
 66                 verbose = 1;
 67                 break;
 68             case 'k':
 69                 inkernel = 1;
 70                 break;
 71             default:
 72                 usage();
 73             }
 74         }
 75         else {
 76             usage();
 77         }
 78         argc--;
 79         argv++;
 80     }
 81     
 82     if (infname != NULL) {
 83         infile = fopen(infname, "r");
 84         if (infile == NULL) {
 85             fprintf(stderr, "%s: can't open %s for reading\n",
 86                     progname, infname);
 87             exit(-2);
 88         }
 89     }
 90     else {
 91         infile = stdin;
 92         infname = default_infname;
 93     }
 94 
 95     if (outfname) {
 96         outfile = fopen(outfname, "w");
 97         if (outfile == NULL) {
 98             fprintf(stderr, "%s: can't open %s for writing\n",
 99                     progname, outfname);
100             exit(-3);
101         }
102     }
103     else {
104         outfile = stdout;
105         outfname = default_outfname;
106     }
107 
108     if (basename == NULL)
109         basename = default_basename;
110 
111     if (verbose) {
112         fprintf(stderr, "%s: input file = %s\n", progname, infname );
113         fprintf(stderr, "%s: output file = %s\n", progname, outfname );
114         fprintf(stderr, "%s: firmware basename = %s\n", progname, basename );
115     }
116 
117     time(&now);
118     fprintf(outfile, "/*\n  generated by %s from %s on %s"
119             "  DO NOT EDIT!\n*/\n\n",
120             progname, infname, ctime(&now));
121 
122     if (inkernel)
123         fprintf(outfile, "#include <linux/init.h>\n\n" );
124     
125     /* XXX force 32 bit alignment? */
126     fprintf(outfile, "const unsigned char%s %s_data[] = {\n", 
127             inkernel ? " __initdata" : "", basename );
128     
129     c = getc(infile);
130     fprintf(outfile,"\t0x%02x", c);
131     firmsize = 1;
132     
133     while ((c = getc(infile)) >= 0) {
134         
135         if (firmsize++ % 8)
136             fprintf(outfile,", 0x%02x", c);
137         else
138             fprintf(outfile,",\n\t0x%02x", c);
139     }
140 
141     fprintf(outfile, "\n};\n\n");
142 
143     fprintf(outfile, "const unsigned int%s %s_size = %u;\n",
144             inkernel ? " __initdata" : "", basename, firmsize );
145 
146     if (infile != stdin)
147         fclose(infile);
148     if (outfile != stdout)
149         fclose(outfile);
150 
151     if(verbose)
152         fprintf(stderr, "%s: firmware size = %u\n", progname, firmsize);
153 
154     exit(0);
155 }
156 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.