4 #define MAX_READ_SIZE 80
6 unsigned long checksum = 0;
8 void write_file(FILE *out, unsigned char *buf, unsigned long size, unsigned char *endian, unsigned char nl)
11 unsigned char tmp_buf[4];
13 for(i=0; i<size; i+=4)
22 tmp_buf[1] = buf[i+1];
23 tmp_buf[2] = buf[i+2];
24 tmp_buf[3] = buf[i+3];
26 fprintf(out, "0x%08X, ", *((unsigned long *)(&tmp_buf[0])));
33 tmp_buf[0] = buf[i+3];
34 tmp_buf[1] = buf[i+2];
35 tmp_buf[2] = buf[i+1];
36 tmp_buf[3] = buf[i+0];
37 fprintf(out, "0x%08X, ", *((unsigned long *)(&tmp_buf[0])));
39 checksum = checksum ^ *((unsigned long *)(&tmp_buf[0]));
43 void write_rom(FILE *out, FILE *in)
47 unsigned char buffer[MAX_READ_SIZE];
54 size = fread(buffer, sizeof(unsigned char), sizeof(buffer), in);
57 //write_file(out, buffer, size, NULL, 0);
61 fprintf(out, "%08X\n", checksum);
65 else if (size<MAX_READ_SIZE)
68 write_file(out, buffer, size, NULL, 1);
69 fprintf(out, "%08X\n", checksum);
72 else if (size==MAX_READ_SIZE)
75 write_file(out, buffer, MAX_READ_SIZE, NULL, 1);
87 void write_array(FILE *out, FILE *in, unsigned char hif)
91 unsigned char buffer[MAX_READ_SIZE];
96 // fprintf(out, "#include \"80211core_sh.h\"\n");
97 fprintf(out, "#include <stdint.h>\n");
98 fprintf(out, "const uint32_t zcFwImage[] = {\n");
101 size = fread(buffer, sizeof(unsigned char), sizeof(buffer), in);
107 fprintf(out, "0x%08X\n", checksum);
111 fprintf(out, "};\n");
112 fprintf(out, "\nconst unsigned long zcFwImageSize=%ld;\n", file_size);
116 else if (size<MAX_READ_SIZE)
120 write_file(out, buffer, size, NULL, hif);
121 fprintf(out, "0x%08X\n", checksum);
124 file_size += (4-(size%4));
127 fprintf(out, "};\n");
128 fprintf(out, "\nconst unsigned long zcFwImageSize=%ld;\n", file_size);
132 else if (size==MAX_READ_SIZE)
135 write_file(out, buffer, MAX_READ_SIZE, NULL, hif);
146 int main(int argc, char* argv[])
151 char input_file_name[80];
152 char output_file_name[80];
158 printf("\"bin2hex [input_file] [output_file] - gen array data\"!\n\r");
159 printf("\"bin2hex [input_file] [output_file] [rom]- gen rom code\"!\n\r");
162 strcpy(input_file_name, argv[1]);
163 strcpy(output_file_name, argv[2]);
165 printf("bin2h %s %s!\n\r", input_file_name, output_file_name);
167 if((in = fopen(input_file_name,"rb")) == NULL)
170 if((out = fopen(output_file_name,"wt")) == NULL)
173 if( !strcmp(argv[3],"rom"))
174 /* for loading into RAM directly, e.g ROM code or patch code */
177 if(!strcmp(argv[4],"usb"))
178 write_array(out, in, 1); /* for generating firmware (usb) */
179 else if (!strcmp(argv[4],"pci"))
180 write_array(out, in, 0); /* for generating firmware (pci) */
182 write_array(out, in, 1); /* Default case firmware (usb) */