URL
https://opencores.org/ocsvn/minsoc/minsoc/trunk
Subversion Repositories minsoc
Compare Revisions
- This comparison shows the changes necessary to convert path
/minsoc/branches/rc-1.0/sw/utils
- from Rev 37 to Rev 109
- ↔ Reverse comparison
Rev 37 → Rev 109
/Makefile
0,0 → 1,58
#*$$HEADER*# |
#******************************************************************************# |
#* *# |
#* H E A D E R I N F O R M A T I O N *# |
#* *# |
#******************************************************************************# |
|
## Project Name : ORPSoC v2 |
## File Name : Makefile |
## Prepared By : |
## Project Start : |
|
#*$$COPYRIGHT NOTICE*# |
#******************************************************************************# |
#* *# |
#* C O P Y R I G H T N O T I C E *# |
#* *# |
#******************************************************************************# |
#* |
# This library is free software; you can redistribute it and/or |
# modify it under the terms of the GNU Lesser General Public |
# License as published by the Free Software Foundation; |
# version 2.1 of the License, a copy of which is available from |
# http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt. |
# |
# This library is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
# Lesser General Public License for more details. |
# |
# You should have received a copy of the GNU Lesser General Public |
# License along with this library; if not, write to the Free Software |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
# |
#*$$DESCRIPTION*# |
#******************************************************************************# |
#* *# |
#* D E S C R I P T I O N *# |
#* *# |
#******************************************************************************# |
## |
## Makefile for the ORPSoC software utilities |
## |
|
PROGRAMS = bin2c bin2srec bin2flimg bin2hex bin2vmem |
# NB: 'loader' not in that list |
|
CC = gcc |
CFLAGS = -O2 -Wall |
|
% : %.c |
@/bin/rm -f $@ |
$(CC) -o $@ $(CFLAGS) $< |
|
all: $(PROGRAMS) |
|
clean: |
/bin/rm -f $(PROGRAMS) *~ *.bak |
Makefile
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: bin2vmem.c
===================================================================
--- bin2vmem.c (nonexistent)
+++ bin2vmem.c (revision 109)
@@ -0,0 +1,159 @@
+/*$$HEADER*/
+/******************************************************************************/
+/* */
+/* H E A D E R I N F O R M A T I O N */
+/* */
+/******************************************************************************/
+
+// Project Name : ORPSoC v2
+// File Name : bin2vmem.c
+// Prepared By : jb, jb@orsoc.se
+// Project Start : 2009-05-13
+
+/*$$COPYRIGHT NOTICE*/
+/******************************************************************************/
+/* */
+/* C O P Y R I G H T N O T I C E */
+/* */
+/******************************************************************************/
+/*
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation;
+ version 2.1 of the License, a copy of which is available from
+ http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/*$$DESCRIPTION*/
+/******************************************************************************/
+/* */
+/* D E S C R I P T I O N */
+/* */
+/******************************************************************************/
+//
+// Generates VMEM output to stdout from binary images.
+// Use with redirection like: ./bin2vmem app.bin > app.vmem
+// To change either the number of bytes per word or word per line, change
+// the following defines.
+// Currently output is WORD addressed, NOT byte addressed
+// eg: @00000000 00000000 00000000 00000000 00000000
+// @00000004 00000000 00000000 00000000 00000000
+// @00000008 00000000 00000000 00000000 00000000
+// @0000000c 00000000 00000000 00000000 00000000
+// etc..
+//
+
+#define WORDS_PER_LINE 4
+#define BYTES_PER_WORD 4
+
+#include
+#include
+#include
+
+int main(int argc, char **argv)
+{
+
+ FILE *fd;
+ int c;
+ int i = 0;
+ int write_size_word=0; // Disabled by default
+ int filename_index=1;
+ unsigned int image_size;
+
+ // Counters keeping track of what we've printed
+ int current_addr = 0;
+ int word_counter = 0;
+ int byte_counter = 0;
+
+ if(argc < 2) {
+ fprintf(stderr,"\n\tInsufficient options.\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");
+ exit(1);
+ }
+
+ fd = fopen( argv[filename_index], "r" );
+
+ if (fd == NULL) {
+ fprintf(stderr,"failed to open input file: %s\n",argv[1]);
+ exit(1);
+ }
+
+ fseek(fd, 0, SEEK_END);
+ image_size = ftell(fd);
+ fseek(fd,0,SEEK_SET);
+
+ 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
+ printf("@%8x", current_addr);
+ printf("%8x", image_size);
+ 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
+ //for(i=0;i<4;i++)
+ // c=fgetc(fd);
+ i=0;
+ int starting_new_line = 1;
+ // Now write out the binary data to VMEM format: @ADDRESSS XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
+ while ((c = fgetc(fd)) != EOF) {
+ if (starting_new_line)
+ {
+ // New line - print the current addr and then increment it
+ printf("@%.8x", current_addr);
+ //current_addr += WORDS_PER_LINE * BYTES_PER_WORD;
+ current_addr += WORDS_PER_LINE;
+ starting_new_line = 0;
+ }
+ if (byte_counter == 0)
+ printf(" ");
+
+ printf("%.2x", (unsigned int) c); // now print the actual char
+
+ byte_counter++;
+
+ if (byte_counter == BYTES_PER_WORD)
+ {
+ word_counter++;
+ byte_counter=0;
+ }
+ if (word_counter == WORDS_PER_LINE)
+ {
+ printf("\n");
+ word_counter = 0;
+ starting_new_line = 1;
+ }
+ }
+
+ return 0;
+}
bin2vmem.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: bin2hex.c
===================================================================
--- bin2hex.c (nonexistent)
+++ bin2hex.c (revision 109)
@@ -0,0 +1,152 @@
+/*$$HEADER*/
+/******************************************************************************/
+/* */
+/* H E A D E R I N F O R M A T I O N */
+/* */
+/******************************************************************************/
+
+// Project Name : ORPSoC v2
+// File Name : bin2hex.c
+// Prepared By :
+// Project Start :
+
+/*$$COPYRIGHT NOTICE*/
+/******************************************************************************/
+/* */
+/* C O P Y R I G H T N O T I C E */
+/* */
+/******************************************************************************/
+/*
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation;
+ version 2.1 of the License, a copy of which is available from
+ http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/*$$DESCRIPTION*/
+/******************************************************************************/
+/* */
+/* D E S C R I P T I O N */
+/* */
+/******************************************************************************/
+//
+// Generates basic ASCII hex output to stdout from binary file input
+// Compile and run the program with no options for usage.
+//
+
+#include
+#include
+#include
+/* Number of bytes before line is broken
+ For example if target flash is 8 bits wide,
+ define BREAK as 1. If it is 16 bits wide,
+ define it as 2 etc.
+*/
+#define BREAK 1
+
+int main(int argc, char **argv)
+{
+
+ FILE *fd;
+ int c;
+ int i = 0;
+ int write_size_word=0; // Disabled by default
+ int filename_index=1;
+ int bytes_per_line=1;
+ int bytes_per_line_index=2;
+ unsigned int image_size;
+
+ if(argc < 3) {
+ fprintf(stderr,"\n\tInsufficient options.\n");
+ fprintf(stderr,"\tPlease specify, in this order: a binary file to\n");
+ fprintf(stderr,"\tconvert and the number of bytes of data to putput\n");
+ fprintf(stderr,"\tper line.\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);
+ }
+
+ if(argc == 4)
+ {
+ if (strcmp("-size_word", argv[3]) == 0)
+ // We will calculate the number of bytes first
+ write_size_word=1;
+ }
+
+ fd = fopen( argv[filename_index], "r" );
+
+ bytes_per_line = atoi(argv[bytes_per_line_index]);
+
+ if ((bytes_per_line == 0) || (bytes_per_line > 8))
+ {
+ fprintf(stderr,"bytes per line incorrect or missing: %s\n",argv[bytes_per_line_index]);
+ exit(1);
+ }
+
+ // Now subtract 1 from bytes_per_line
+ //if (bytes_per_line == 2)
+ // bytes_per_line--;
+
+ if (fd == NULL) {
+ fprintf(stderr,"failed to open input file: %s\n",argv[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==bytes_per_line){ printf("\n"); i=0; }
+ printf("%.2x",(image_size >> 16) & 0xff);
+ if(++i==bytes_per_line){ printf("\n"); i=0; }
+ printf("%.2x",(image_size >> 8) & 0xff);
+ if(++i==bytes_per_line){ printf("\n"); i=0; }
+ printf("%.2x",(image_size) & 0xff);
+ if(++i==bytes_per_line){ 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) {
+ printf("%.2x", (unsigned int) c);
+ if (++i == bytes_per_line) {
+ printf("\n");
+ i = 0;
+ }
+ }
+
+ return 0;
+}
bin2hex.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: bin2srec.c
===================================================================
--- bin2srec.c (nonexistent)
+++ bin2srec.c (revision 109)
@@ -0,0 +1,99 @@
+/*$$HEADER*/
+/******************************************************************************/
+/* */
+/* H E A D E R I N F O R M A T I O N */
+/* */
+/******************************************************************************/
+
+// Project Name : ORPSoC v2
+// File Name : bin2srec.c
+// Prepared By :
+// Project Start :
+
+/*$$COPYRIGHT NOTICE*/
+/******************************************************************************/
+/* */
+/* C O P Y R I G H T N O T I C E */
+/* */
+/******************************************************************************/
+/*
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation;
+ version 2.1 of the License, a copy of which is available from
+ http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/*$$DESCRIPTION*/
+/******************************************************************************/
+/* */
+/* D E S C R I P T I O N */
+/* */
+/******************************************************************************/
+//
+// Generates SREC file output to stdout from binary file
+//
+
+#include
+#include
+
+#define SMARK "S214"
+#define SADDR 0x000000
+#define INIT_ADDR 0x100100
+#define SCHKSUM 0xff
+
+int main(int argc, char **argv)
+{
+
+ FILE *fd;
+ int c, j;
+ unsigned long addr = INIT_ADDR;
+ unsigned char chksum;
+
+ if(argc < 2) {
+ fprintf(stderr,"no input file specified\n");
+ exit(1);
+ }
+ if(argc > 2) {
+ fprintf(stderr,"too many input files (more than one) specified\n");
+ exit(1);
+ }
+
+ fd = fopen( argv[1], "r" );
+ if (fd == NULL) {
+ fprintf(stderr,"failed to open input file: %s\n",argv[1]);
+ exit(1);
+ }
+
+ while (!feof(fd)) {
+ j = 0;
+ chksum = SCHKSUM;
+ printf("%s%.6lx", SMARK, addr);
+ while (j < 16) {
+ c = fgetc(fd);
+ if (c == EOF) {
+ c = 0;
+ }
+ printf("%.2x", c);
+ chksum -= c;
+ j++;
+ }
+
+ chksum -= addr & 0xff;
+ chksum -= (addr >> 8) & 0xff;
+ chksum -= (addr >> 16) & 0xff;
+ chksum -= 0x14;
+ printf("%.2x\r\n", chksum);
+ addr += 16;
+ }
+ return 0;
+}
bin2srec.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: bin2flimg.c
===================================================================
--- bin2flimg.c (nonexistent)
+++ bin2flimg.c (revision 109)
@@ -0,0 +1,92 @@
+/*$$HEADER*/
+/******************************************************************************/
+/* */
+/* H E A D E R I N F O R M A T I O N */
+/* */
+/******************************************************************************/
+
+// Project Name : ORPSoC v2
+// File Name : bin2flimg.c
+// Prepared By :
+// Project Start :
+
+/*$$COPYRIGHT NOTICE*/
+/******************************************************************************/
+/* */
+/* C O P Y R I G H T N O T I C E */
+/* */
+/******************************************************************************/
+/*
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation;
+ version 2.1 of the License, a copy of which is available from
+ http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/*$$DESCRIPTION*/
+/******************************************************************************/
+/* */
+/* D E S C R I P T I O N */
+/* */
+/******************************************************************************/
+//
+// Generate flimg output to stdout from binary file input
+//
+
+#include
+#include
+
+int main(int argc, char **argv)
+{
+
+ FILE *fd;
+ int c, j, width;
+ unsigned long word;
+
+ if(argc < 3) {
+ fprintf(stderr,"no input file specified\n");
+ exit(1);
+ }
+ if(argc > 3) {
+ fprintf(stderr,"too many input files (more than one) specified\n");
+ exit(1);
+ }
+
+ width = atoi(argv[1]);
+
+ fd = fopen( argv[2], "r" );
+ if (fd == NULL) {
+ fprintf(stderr,"failed to open input file: %s\n",argv[1]);
+ exit(1);
+ }
+
+ while (!feof(fd)) {
+ j = 0;
+ word = 0;
+ while (j < width) {
+ c = fgetc(fd);
+ if (c == EOF) {
+ c = 0;
+ }
+ word = (word << 8) + c;
+ j++;
+ }
+ if(width == 1)
+ printf("%.2lx\n", word);
+ else if(width == 2)
+ printf("%.4lx\n", word);
+ else
+ printf("%.8lx\n", word);
+ }
+ return 0;
+}
bin2flimg.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: bin2c.c
===================================================================
--- bin2c.c (nonexistent)
+++ bin2c.c (revision 109)
@@ -0,0 +1,70 @@
+/*$$HEADER*/
+/******************************************************************************/
+/* */
+/* H E A D E R I N F O R M A T I O N */
+/* */
+/******************************************************************************/
+
+// Project Name : ORPSoC v2
+// File Name : bin2c.c
+// Prepared By :
+// Project Start :
+
+/*$$COPYRIGHT NOTICE*/
+/******************************************************************************/
+/* */
+/* C O P Y R I G H T N O T I C E */
+/* */
+/******************************************************************************/
+/*
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation;
+ version 2.1 of the License, a copy of which is available from
+ http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/*$$DESCRIPTION*/
+/******************************************************************************/
+/* */
+/* D E S C R I P T I O N */
+/* */
+/******************************************************************************/
+//
+// Generate C file containing binary data in hex format in an array
+//
+
+#include
+
+int main(void)
+{
+
+ int c, i = 0;
+
+ printf("#ifdef HAVE_CONFIG_H\n");
+ printf("# include \"config.h\"\n");
+ printf("#endif\n\n");
+ printf("#ifdef EMBED\n");
+
+ printf("unsigned char flash_data[] = {\n");
+
+ while((c = getchar()) != EOF) {
+ printf("0x%.2x, ", c);
+ if(!(i % 32))
+ printf("\n");
+ i++;
+ }
+
+ printf(" };\n");
+ printf("#endif\n");
+ return(0);
+}
bin2c.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property