2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #define MAX_READ_SIZE 80
41 uint32_t checksum = 0;
43 void write_file(FILE *out, unsigned char *buf, uint32_t size, unsigned char *endian, unsigned char nl)
46 unsigned char tmp_buf[4];
48 for(i=0; i<size; i+=4)
57 tmp_buf[1] = buf[i+1];
58 tmp_buf[2] = buf[i+2];
59 tmp_buf[3] = buf[i+3];
61 fprintf(out, "0x%08X, ", *((uint32_t *)(&tmp_buf[0])));
68 tmp_buf[0] = buf[i+3];
69 tmp_buf[1] = buf[i+2];
70 tmp_buf[2] = buf[i+1];
71 tmp_buf[3] = buf[i+0];
72 fprintf(out, "0x%08X, ", *((uint32_t *)(&tmp_buf[0])));
74 checksum = checksum ^ *((uint32_t *)(&tmp_buf[0]));
78 void write_rom(FILE *out, FILE *in)
82 unsigned char buffer[MAX_READ_SIZE];
89 size = fread(buffer, sizeof(unsigned char), sizeof(buffer), in);
92 //write_file(out, buffer, size, NULL, 0);
96 fprintf(out, "%08X\n", checksum);
100 else if (size<MAX_READ_SIZE)
103 write_file(out, buffer, size, NULL, 1);
104 fprintf(out, "%08X\n", checksum);
107 else if (size==MAX_READ_SIZE)
110 write_file(out, buffer, MAX_READ_SIZE, NULL, 1);
122 void write_array(FILE *out, FILE *in, unsigned char hif)
126 unsigned char buffer[MAX_READ_SIZE];
129 file_size = size = 0;
131 // fprintf(out, "#include \"80211core_sh.h\"\n");
132 fprintf(out, "#include <stdint.h>\n");
133 fprintf(out, "const uint32_t zcFwImage[] = {\n");
136 size = fread(buffer, sizeof(unsigned char), sizeof(buffer), in);
142 fprintf(out, "0x%08X\n", checksum);
146 fprintf(out, "};\n");
147 fprintf(out, "\nconst uint32_t zcFwImageSize=%ld;\n", file_size);
151 else if (size<MAX_READ_SIZE)
155 write_file(out, buffer, size, NULL, hif);
156 fprintf(out, "0x%08X\n", checksum);
159 file_size += (4-(size%4));
162 fprintf(out, "};\n");
163 fprintf(out, "\nconst uint32_t zcFwImageSize=%ld;\n", file_size);
167 else if (size==MAX_READ_SIZE)
170 write_file(out, buffer, MAX_READ_SIZE, NULL, hif);
181 int main(int argc, char* argv[])
186 char input_file_name[80];
187 char output_file_name[80];
193 printf("\"bin2hex [input_file] [output_file] - gen array data\"!\n\r");
194 printf("\"bin2hex [input_file] [output_file] [rom]- gen rom code\"!\n\r");
197 strcpy(input_file_name, argv[1]);
198 strcpy(output_file_name, argv[2]);
200 printf("bin2h %s %s!\n\r", input_file_name, output_file_name);
202 if((in = fopen(input_file_name,"rb")) == NULL)
205 if((out = fopen(output_file_name,"wt")) == NULL)
208 if( !strcmp(argv[3],"rom"))
209 /* for loading into RAM directly, e.g ROM code or patch code */
212 if(!strcmp(argv[4],"usb"))
213 write_array(out, in, 1); /* for generating firmware (usb) */
214 else if (!strcmp(argv[4],"pci"))
215 write_array(out, in, 0); /* for generating firmware (pci) */
217 write_array(out, in, 1); /* Default case firmware (usb) */