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)
23 tmp_buf[1] = buf[i+1];
24 tmp_buf[2] = buf[i+2];
25 tmp_buf[3] = buf[i+3];
31 tmp_buf[3] = 0x0; // padding
32 printf("3: i:%d size:%d\n\r", i, size);
36 tmp_buf[2] = 0x0; // padding
37 tmp_buf[3] = 0x0; // padding
38 printf("2: i:%d size:%d\n\r", i, size);
42 tmp_buf[1] = 0x0; // padding
43 tmp_buf[2] = 0x0; // padding
44 tmp_buf[3] = 0x0; // padding
45 printf("1: i:%d size:%d\n\r", i, size);
49 fprintf(out, "0x%08X, ", *((unsigned long *)(&tmp_buf[0])));
58 tmp_buf[0] = buf[i+3];
59 tmp_buf[1] = buf[i+2];
60 tmp_buf[2] = buf[i+1];
61 tmp_buf[3] = buf[i+0];
67 tmp_buf[0] = 0x0; // padding
71 tmp_buf[0] = 0x0; // padding
72 tmp_buf[1] = 0x0; // padding
76 tmp_buf[0] = 0x0; // padding
77 tmp_buf[1] = 0x0; // padding
78 tmp_buf[2] = 0x0; // padding
86 fprintf(out, "0x%08X, ", *((unsigned long *)(&tmp_buf[0])));
88 checksum = checksum ^ *((unsigned long *)(&tmp_buf[0]));
92 void write_rom(FILE *out, FILE *in)
96 unsigned char buffer[MAX_READ_SIZE];
103 size = fread(buffer, sizeof(unsigned char), sizeof(buffer), in);
106 //write_file(out, buffer, size, NULL, 0);
110 fprintf(out, "%08X\n", checksum);
114 else if (size<MAX_READ_SIZE)
117 write_file(out, buffer, size, NULL, 0);
118 fprintf(out, "%08X\n", checksum);
121 else if (size==MAX_READ_SIZE)
124 write_file(out, buffer, MAX_READ_SIZE, NULL, 0);
136 void write_array(FILE *out, FILE *in)
140 unsigned char buffer[MAX_READ_SIZE];
143 file_size = size = 0;
145 // fprintf(out, "#include \"80211core_sh.h\"\n");
146 fprintf(out, "const unsigned long zcFwImage[] = {\n");
149 size = fread(buffer, sizeof(unsigned char), sizeof(buffer), in);
155 fprintf(out, "0x%08X\n", checksum);
159 fprintf(out, "};\n");
160 fprintf(out, "\nconst unsigned long zcFwImageSize=%ld;\n", file_size);
164 else if (size<MAX_READ_SIZE)
168 write_file(out, buffer, size, NULL, 0);
169 fprintf(out, "0x%08X\n", checksum);
172 file_size += (4-(size%4));
175 fprintf(out, "};\n");
176 fprintf(out, "\nconst unsigned long zcFwImageSize=%ld;\n", file_size);
180 else if (size==MAX_READ_SIZE)
183 write_file(out, buffer, MAX_READ_SIZE, NULL, 0);
194 int main(int argc, char* argv[])
199 char input_file_name[80];
200 char output_file_name[80];
206 printf("\"bin2hex [input_file] [output_file] - gen array data\"!\n\r");
207 printf("\"bin2hex [input_file] [output_file] [rom]- gen rom code\"!\n\r");
210 strcpy(input_file_name, argv[1]);
211 strcpy(output_file_name, argv[2]);
213 printf("bin2h %s %s!\n\r", input_file_name, output_file_name);
216 if((in = fopen(input_file_name,"rb")) == NULL)
219 if((out = fopen(output_file_name,"wt")) == NULL)
222 // actually we don't really see what's the third param now,
224 write_rom(out, in); // for loading into RAM directly, e.g ROM code or patch code
226 write_array(out, in); // for generating firmware