/* This short program is written by David Zhou to convert a boot table to a header file so DSP code can be easily included by the host software. The host will boot DSP ultimately through HPI. SRIO, EMAC, etc. E.g.: hex6x DspCode.rmd ==> DspCode.btbl Bttbl2Hfile DspCode.btbl DspCode.h Meanwhile, it can also generate a binary image if desired. Bttbl2Hfile DspCode.btbl DspCode.h DspCode.bin */ #include #include int asciiByte (unsigned char c) { if ((c >= '0') && (c <= '9')) return (1); if ((c >= 'A') && (c <= 'F')) return (1); if ((c >= 'a') && (c <= 'f')) return (1); return (0); } int toNum (unsigned char c) { if ((c >= '0') && (c <= '9')) return (c - '0'); else if ((c >= 'A') && (c <= 'F')) return (c - 'A'+10); else return (c - 'a' + 10); } int main (int argc, char *argv[]) { FILE *strin; FILE *strout; FILE *strbin; int i=0; char linein[132]; char lineout[200]; char *pin, *pout; unsigned int value; /* Verify the number of args */ if ((argc != 3) && (argc != 4)) { printf ("usage: %s inputfile output_header_file\n", argv[0]); printf ("Or: \n"); printf ("usage: %s inputfile output_header_file output_binary_file\n", argv[0]); return (-1); } /* Open all the files */ strin = fopen (argv[1], "rb"); if (strin == NULL) { printf ("could not open input file %s\n", argv[1]); return (-1); } strout = fopen (argv[2], "wb+"); if (strout == NULL) { printf ("could not open file %s to write\n", argv[2]); return (-1); } if(argc == 4){ strbin = fopen (argv[3], "wb+"); if (strbin == NULL) { printf ("could not open file %s to write\n", argv[3]); return (-1); } } /* Ignore the first two lines */ fgets (linein, 132, strin); fgets (linein, 132, strin); while(feof(strin)==0) { fgets (linein, 132, strin); if(!asciiByte(linein[0])) break; /* if not ASCII, end */ pin = linein; pout = lineout; strcpy(lineout," "); while(1) { *pout++ ='0'; *pout++ ='x'; if(argc == 4) { value = (toNum(*pin))<<4 | toNum(*(pin+1)); fputc(value,strbin); } *pout++ = *pin++; *pout++ = *pin++; if(*pin==' ') pin++; *pout++ = ','; *pout++ = ' '; if(*pin == 0x0D) break; if(*pin == 0x0A) break; if(*pin == 0x00) break; if(*pin == EOF) break; } /* next line */ *pout++=0x0d; *pout++=0x0a; *pout++=0x00; /* save it */ fprintf(strout, lineout); } fclose(strin); fclose(strout); if(argc == 4) { fclose(strbin); } return (0); }