/* * this application adds an EST header to a binary file * to allow downloading straight binary files into * target ram */ #include #include typedef struct { char id[8]; char startaddr[4]; char endaddr[4]; char reserved[16]; } ESTHEADER; main(int argc, char **argv) { FILE *theFile, *newFile; int byteCount = 0; unsigned char theByte; char newFileName[256]; ESTHEADER newHeader; int address,i; if(argc != 3) { fprintf(stderr, "USAGE: bin2bin [filename] [address]\n"); exit(1); } if ( !(theFile = fopen(argv[1], "r")) ) { fprintf(stderr, "Unable to open file %s\n", argv[1]); exit(1); } while (fread(&theByte, 1, 1, theFile)) byteCount++; fprintf(stdout, "File size: %d\n", byteCount); rewind(theFile); strcpy(newFileName, argv[1]); strcat(newFileName, ".bin"); if ( !(newFile = fopen(newFileName, "w")) ) { fprintf(stderr, "Unable to open file %s\n", newFileName); exit(1); } strcpy(newHeader.id, "ESTFBINR"); address = (int) strtol(argv[2], NULL, 16); fprintf(stdout, "Loading to location 0x%08X\n", address); newHeader.startaddr[0] = (char) (address >> 24); newHeader.startaddr[1] = (char) (address >> 16); newHeader.startaddr[2] = (char) (address >> 8); newHeader.startaddr[3] = (char) (address); address += byteCount; newHeader.endaddr[0] = (char) (address >> 24); newHeader.endaddr[1] = (char) (address >> 16); newHeader.endaddr[2] = (char) (address >> 8); newHeader.endaddr[3] = (char) (address); for(i=0; i<16; i++) newHeader.reserved[i] = 0; fwrite(&newHeader, sizeof(newHeader), 1, newFile); for(i=0; i