Line 49... |
Line 49... |
// @00000004 00000000 00000000 00000000 00000000
|
// @00000004 00000000 00000000 00000000 00000000
|
// @00000008 00000000 00000000 00000000 00000000
|
// @00000008 00000000 00000000 00000000 00000000
|
// @0000000c 00000000 00000000 00000000 00000000
|
// @0000000c 00000000 00000000 00000000 00000000
|
// etc..
|
// etc..
|
//
|
//
|
|
// OR
|
|
//
|
|
// Output a list of the words, one per line, as Synplify appears to like
|
|
// specify this option with the -synfmt switch on the command line after
|
|
// the input file
|
|
// eg: ./bin2vmem data.bin -synfmt > data.vmem
|
|
//
|
|
|
#define WORDS_PER_LINE 4
|
#define WORDS_PER_LINE 4
|
#define BYTES_PER_WORD 4
|
#define BYTES_PER_WORD 4
|
|
|
|
#define FILENAME_CMDLINE_INDEX 1
|
|
#define FMT_CMDLINE_INDEX 2
|
|
|
|
#define FMT_WITH_ADDR 0
|
|
#define FMT_SYN 1
|
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <string.h>
|
#include <string.h>
|
|
|
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
Line 64... |
Line 77... |
|
|
FILE *fd;
|
FILE *fd;
|
int c;
|
int c;
|
int i = 0;
|
int i = 0;
|
int write_size_word=0; // Disabled by default
|
int write_size_word=0; // Disabled by default
|
int filename_index=1;
|
|
unsigned int image_size;
|
unsigned int image_size;
|
|
int output_fmt = FMT_WITH_ADDR; // 0 - standard 4 per line with address, 1 - synfmt
|
|
|
// Counters keeping track of what we've printed
|
// Counters keeping track of what we've printed
|
int current_addr = 0;
|
int current_addr = 0;
|
int word_counter = 0;
|
int word_counter = 0;
|
int byte_counter = 0;
|
int byte_counter = 0;
|
|
|
if(argc < 2) {
|
if(argc < 2) {
|
fprintf(stderr,"\n\tInsufficient options.\n");
|
fprintf(stderr,"\n\tInsufficient options.\n");
|
fprintf(stderr,"\tPlease specify a binary file to convert to VMEM\n");
|
fprintf(stderr,"\tPlease specify a binary file to convert to VMEM\n");
|
fprintf(stderr,"\n\tbin2vmem - creates vmem output to stdout from bin\n");
|
fprintf(stderr,"\n\tbin2vmem - creates vmem output to stdout from bin\n");
|
|
fprintf(stderr,"\n\tBy default the output is word addressed 32-bit words\n");
|
|
fprintf(stderr,"\tSpecify -synfmt on the command line after the filename\n");
|
|
fprintf(stderr,"\tto output in the alterative format, which is a simple\n");
|
|
fprintf(stderr,"\tlist of the data words.\n");
|
|
|
|
fprintf(stderr,"\n");
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
fd = fopen( argv[filename_index], "r" );
|
fd = fopen( argv[FILENAME_CMDLINE_INDEX], "r" );
|
|
|
|
if (argc > 2) // check for the -synfmt switch
|
|
{
|
|
if (strcmp("-synfmt", argv[FMT_CMDLINE_INDEX]) == 0)
|
|
output_fmt = FMT_SYN; // synthesis friendly format - single column, no addr
|
|
}
|
|
|
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);
|
}
|
}
|
Line 113... |
Line 138... |
// Now write out the image size
|
// Now write out the image size
|
printf("@%8x", current_addr);
|
printf("@%8x", current_addr);
|
printf("%8x", image_size);
|
printf("%8x", image_size);
|
current_addr += WORDS_PER_LINE * BYTES_PER_WORD;
|
current_addr += WORDS_PER_LINE * BYTES_PER_WORD;
|
}
|
}
|
else
|
|
{
|
|
}
|
|
|
|
|
|
// Fix for the current bootloader software! Skip the first 4 bytes of application data. Hopefully it's not important. 030509 -- jb
|
// 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++)
|
//for(i=0;i<4;i++)
|
// c=fgetc(fd);
|
// c=fgetc(fd);
|
i=0;
|
i=0;
|
int starting_new_line = 1;
|
int starting_new_line = 1;
|
// Now write out the binary data to VMEM format: @ADDRESSS XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
|
// Now write out the binary data to specified format. Either
|
|
// more complicated, addressed format:
|
|
// VMEM format: @ADDRESSS XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
|
|
// or simple, synplifyfriendly format which is just a list of
|
|
// the words
|
|
|
while ((c = fgetc(fd)) != EOF) {
|
while ((c = fgetc(fd)) != EOF) {
|
|
|
|
if (output_fmt == FMT_WITH_ADDR) // Default format
|
|
{
|
|
|
if (starting_new_line)
|
if (starting_new_line)
|
{
|
{
|
// New line - print the current addr and then increment it
|
// New line - print the current addr and then increment it
|
printf("@%.8x", current_addr);
|
printf("@%.8x", current_addr);
|
//current_addr += WORDS_PER_LINE * BYTES_PER_WORD;
|
|
current_addr += WORDS_PER_LINE;
|
current_addr += WORDS_PER_LINE;
|
starting_new_line = 0;
|
starting_new_line = 0;
|
}
|
}
|
if (byte_counter == 0)
|
if (byte_counter == 0)
|
printf(" ");
|
printf(" ");
|
Line 151... |
Line 182... |
{
|
{
|
printf("\n");
|
printf("\n");
|
word_counter = 0;
|
word_counter = 0;
|
starting_new_line = 1;
|
starting_new_line = 1;
|
}
|
}
|
|
} // End of FMT_WITH_ADDR
|
|
else if (output_fmt == FMT_SYN) // simple list of data words
|
|
{
|
|
printf("%.2x", (unsigned int) c); // now print the actual char
|
|
byte_counter++;
|
|
if (byte_counter == BYTES_PER_WORD)
|
|
{
|
|
printf("\n");
|
|
byte_counter=0;
|
|
}
|
|
}
|
|
|
|
|
}
|
}
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|