5 #define MAX_READ_SIZE 80
9 void write_file(FILE *out, unsigned char *buf, uint32_t size, unsigned char *endian, unsigned char nl)
12 unsigned char tmp_buf[4];
14 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];
27 fprintf(out, "0x%08X, ", *((uint32_t *)(&tmp_buf[0])));
34 tmp_buf[0] = buf[i+3];
35 tmp_buf[1] = buf[i+2];
36 tmp_buf[2] = buf[i+1];
37 tmp_buf[3] = buf[i+0];
38 fprintf(out, "0x%08X, ", *((uint32_t *)(&tmp_buf[0])));
40 checksum = checksum ^ *((uint32_t *)(&tmp_buf[0]));
44 void write_rom(FILE *out, FILE *in)
48 unsigned char buffer[MAX_READ_SIZE];
55 size = fread(buffer, sizeof(unsigned char), sizeof(buffer), in);
58 //write_file(out, buffer, size, NULL, 0);
62 fprintf(out, "%08X\n", checksum);
66 else if (size<MAX_READ_SIZE)
69 write_file(out, buffer, size, NULL, 1);
70 fprintf(out, "%08X\n", checksum);
73 else if (size==MAX_READ_SIZE)
76 write_file(out, buffer, MAX_READ_SIZE, NULL, 1);
88 void write_array(FILE *out, FILE *in, unsigned char hif)
92 unsigned char buffer[MAX_READ_SIZE];
97 // fprintf(out, "#include \"80211core_sh.h\"\n");
98 fprintf(out, "#include <stdint.h>\n");
99 fprintf(out, "const uint32_t zcFwImage[] = {\n");
102 size = fread(buffer, sizeof(unsigned char), sizeof(buffer), in);
108 fprintf(out, "0x%08X\n", checksum);
112 fprintf(out, "};\n");
113 fprintf(out, "\nconst uint32_t zcFwImageSize=%ld;\n", file_size);
117 else if (size<MAX_READ_SIZE)
121 write_file(out, buffer, size, NULL, hif);
122 fprintf(out, "0x%08X\n", checksum);
125 file_size += (4-(size%4));
128 fprintf(out, "};\n");
129 fprintf(out, "\nconst uint32_t zcFwImageSize=%ld;\n", file_size);
133 else if (size==MAX_READ_SIZE)
136 write_file(out, buffer, MAX_READ_SIZE, NULL, hif);
147 int main(int argc, char* argv[])
152 char input_file_name[80];
153 char output_file_name[80];
159 printf("\"bin2hex [input_file] [output_file] - gen array data\"!\n\r");
160 printf("\"bin2hex [input_file] [output_file] [rom]- gen rom code\"!\n\r");
163 strcpy(input_file_name, argv[1]);
164 strcpy(output_file_name, argv[2]);
166 printf("bin2h %s %s!\n\r", input_file_name, output_file_name);
168 if((in = fopen(input_file_name,"rb")) == NULL)
171 if((out = fopen(output_file_name,"wt")) == NULL)
174 if( !strcmp(argv[3],"rom"))
175 /* for loading into RAM directly, e.g ROM code or patch code */
178 if(!strcmp(argv[4],"usb"))
179 write_array(out, in, 1); /* for generating firmware (usb) */
180 else if (!strcmp(argv[4],"pci"))
181 write_array(out, in, 0); /* for generating firmware (pci) */
183 write_array(out, in, 1); /* Default case firmware (usb) */