1 /* This short program is written by David Zhou to convert a boot table to a
2 header file so DSP code can be easily included by the host software. The host
3 will boot DSP ultimately through HPI. SRIO, EMAC, etc.
4 E.g.:
6 hex6x DspCode.rmd ==> DspCode.btbl
7 Bttbl2Hfile DspCode.btbl DspCode.h
9 Meanwhile, it can also generate a binary image if desired.
10 Bttbl2Hfile DspCode.btbl DspCode.h DspCode.bin
11 */
12 #include <stdio.h>
13 #include <string.h>
15 int asciiByte (unsigned char c)
16 {
17 if ((c >= '0') && (c <= '9'))
18 return (1);
20 if ((c >= 'A') && (c <= 'F'))
21 return (1);
23 if ((c >= 'a') && (c <= 'f'))
24 return (1);
26 return (0);
27 }
30 int toNum (unsigned char c)
31 {
32 if ((c >= '0') && (c <= '9'))
33 return (c - '0');
35 else if ((c >= 'A') && (c <= 'F'))
36 return (c - 'A'+10);
38 else return (c - 'a' + 10);
39 }
42 int main (int argc, char *argv[])
43 {
44 FILE *strin;
45 FILE *strout;
46 FILE *strbin;
48 int i=0;
49 char linein[132];
50 char lineout[200];
51 char *pin, *pout;
52 unsigned int value;
54 /* Verify the number of args */
55 if ((argc != 3) && (argc != 4)) {
56 printf ("usage: %s inputfile output_header_file\n", argv[0]);
57 printf ("Or: \n");
58 printf ("usage: %s inputfile output_header_file output_binary_file\n", argv[0]);
59 return (-1);
60 }
62 /* Open all the files */
63 strin = fopen (argv[1], "rb");
64 if (strin == NULL) {
65 printf ("could not open input file %s\n", argv[1]);
66 return (-1);
67 }
69 strout = fopen (argv[2], "wb+");
70 if (strout == NULL) {
71 printf ("could not open file %s to write\n", argv[2]);
72 return (-1);
73 }
75 if(argc == 4){
76 strbin = fopen (argv[3], "wb+");
77 if (strbin == NULL) {
78 printf ("could not open file %s to write\n", argv[3]);
79 return (-1);
80 }
81 }
83 /* Ignore the first two lines */
84 fgets (linein, 132, strin);
85 fgets (linein, 132, strin);
87 while(feof(strin)==0) {
88 fgets (linein, 132, strin);
89 if(!asciiByte(linein[0])) break; /* if not ASCII, end */
91 pin = linein;
92 pout = lineout;
93 strcpy(lineout," ");
95 while(1) {
96 *pout++ ='0';
97 *pout++ ='x';
99 if(argc == 4) {
100 value = (toNum(*pin))<<4 | toNum(*(pin+1));
101 fputc(value,strbin);
102 }
104 *pout++ = *pin++;
105 *pout++ = *pin++;
106 if(*pin==' ') pin++;
107 *pout++ = ',';
108 *pout++ = ' ';
109 if(*pin == 0x0D) break;
110 if(*pin == 0x0A) break;
111 if(*pin == 0x00) break;
112 if(*pin == EOF) break;
113 }
115 /* next line */
116 *pout++=0x0d;
117 *pout++=0x0a;
118 *pout++=0x00;
120 /* save it */
121 fprintf(strout, lineout);
122 }
124 fclose(strin);
125 fclose(strout);
127 if(argc == 4) {
128 fclose(strbin);
129 }
131 return (0);
132 }