Line 1... |
Line 1... |
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
|
#include <string.h>
|
/* Number of bytes before line is broken
|
/* Number of bytes before line is broken
|
For example if target flash is 8 bits wide,
|
For example if target flash is 8 bits wide,
|
define BREAK as 1. If it is 16 bits wide,
|
define BREAK as 1. If it is 16 bits wide,
|
define it as 2 etc.
|
define it as 2 etc.
|
*/
|
*/
|
Line 12... |
Line 12... |
{
|
{
|
|
|
FILE *fd;
|
FILE *fd;
|
int c;
|
int c;
|
int i = 0;
|
int i = 0;
|
|
int write_size_word=1; // ON BY DEFAULT NOW!
|
|
int filename_index=1;
|
|
unsigned int image_size;
|
|
|
if(argc < 2) {
|
if(argc < 2) {
|
fprintf(stderr,"no input file specified\n");
|
fprintf(stderr,"\n\tInsufficient options.\n");
|
|
fprintf(stderr,"\tPlease specify binary file to convert.\n");
|
|
fprintf(stderr,"\tOptionally specify the option -size_word to output,\n");
|
|
fprintf(stderr,"\tthe size of the image in the first 4 bytes. This is\n");
|
|
fprintf(stderr,"\tused by some of the new OR1k bootloaders.\n\n");
|
exit(1);
|
exit(1);
|
}
|
}
|
if(argc > 2) {
|
|
fprintf(stderr,"too many input files (more than one) specified\n");
|
if(argc == 3)
|
exit(1);
|
{
|
|
if (strcmp("-size_word", argv[1]) == 0)
|
|
{
|
|
filename_index=2;
|
|
write_size_word=1;
|
}
|
}
|
|
else if (strcmp("-size_word", argv[2]) == 0)
|
|
{
|
|
filename_index=1;
|
|
write_size_word=1;
|
|
}
|
|
}
|
|
|
|
fd = fopen( argv[filename_index], "r" );
|
|
|
fd = fopen( argv[1], "r" );
|
|
if (fd == NULL) {
|
if (fd == NULL) {
|
fprintf(stderr,"failed to open input file: %s\n",argv[1]);
|
fprintf(stderr,"failed to open input file: %s\n",argv[1]);
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
|
if (write_size_word)
|
|
{
|
|
// or1200 startup method of determining size of boot image we're copying by reading out
|
|
// the very first word in flash is used. Determine the length of this file
|
|
fseek(fd, 0, SEEK_END);
|
|
image_size = ftell(fd);
|
|
fseek(fd,0,SEEK_SET);
|
|
|
|
// Now we should have the size of the file in bytes. Let's ensure it's a word multiple
|
|
image_size+=3;
|
|
image_size &= 0xfffffffc;
|
|
|
|
// Sanity check on image size
|
|
if (image_size < 8){
|
|
fprintf(stderr, "Bad binary image. Size too small\n");
|
|
return 1;
|
|
}
|
|
|
|
// Now write out the image size
|
|
i=0;
|
|
printf("%.2x",(image_size >> 24) & 0xff);
|
|
if(++i==BREAK){ printf("\n"); i=0; }
|
|
printf("%.2x",(image_size >> 16) & 0xff);
|
|
if(++i==BREAK){ printf("\n"); i=0; }
|
|
printf("%.2x",(image_size >> 8) & 0xff);
|
|
if(++i==BREAK){ printf("\n"); i=0; }
|
|
printf("%.2x",(image_size) & 0xff);
|
|
if(++i==BREAK){ printf("\n"); i=0; }
|
|
}
|
|
|
|
// Fix for the current bootloader software! Skip the first 4 bytes of application data. Hopefully it's not important. 030509 -- jb
|
|
for(i=0;i<4;i++)
|
|
c=fgetc(fd);
|
|
|
|
i=0;
|
|
|
|
// Now write out the binary data to hex format
|
while ((c = fgetc(fd)) != EOF) {
|
while ((c = fgetc(fd)) != EOF) {
|
printf("%.2x", (unsigned int) c);
|
printf("%.2x", (unsigned int) c);
|
if (++i == BREAK) {
|
if (++i == BREAK) {
|
printf("\n");
|
printf("\n");
|
i = 0;
|
i = 0;
|