URL
https://opencores.org/ocsvn/eco32/eco32/trunk
Subversion Repositories eco32
Compare Revisions
- This comparison shows the changes necessary to convert path
/eco32/trunk
- from Rev 233 to Rev 234
- ↔ Reverse comparison
Rev 233 → Rev 234
/tools/bit2mcs/bit2mcs.c
0,0 → 1,189
/* |
* bit2mcs.c -- convert Xilinx bitfile data to Intel hex records |
*/ |
|
|
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <stdarg.h> |
|
|
unsigned char bitHeader[13] = { |
0x00, 0x09, 0x0F, 0xF0, |
0x0F, 0xF0, 0x0F, 0xF0, |
0x0F, 0xF0, 0x00, 0x00, |
0x01 |
}; |
|
|
void error(char *fmt, ...) { |
va_list ap; |
|
va_start(ap, fmt); |
printf("Error: "); |
vprintf(fmt, ap); |
printf("\n"); |
va_end(ap); |
exit(1); |
} |
|
|
unsigned int getCount2(FILE *infile) { |
unsigned char b1, b2; |
|
b1 = fgetc(infile); |
b2 = fgetc(infile); |
return ((unsigned int) b1 << 8) | (unsigned int) b2; |
} |
|
|
unsigned int getCount4(FILE *infile) { |
unsigned char b1, b2, b3, b4; |
|
b1 = fgetc(infile); |
b2 = fgetc(infile); |
b3 = fgetc(infile); |
b4 = fgetc(infile); |
return ((unsigned int) b1 << 24) | ((unsigned int) b2 << 16) | |
((unsigned int) b3 << 8) | ((unsigned int) b4 << 0); |
} |
|
|
void show(char *name, FILE *infile, int count) { |
int c; |
|
printf("%s", name); |
while (count--) { |
c = fgetc(infile); |
if (c >= 0x20 && c <= 0x7E) { |
printf("%c", c); |
} |
} |
printf("\n"); |
} |
|
|
unsigned char mirror(unsigned char n) { |
unsigned char m; |
int i; |
|
m = 0; |
for (i = 0; i < 8; i++) { |
m <<= 1; |
if (n & 1) { |
m |= 1; |
} |
n >>= 1; |
} |
return m; |
} |
|
|
int main(int argc, char *argv[]) { |
char *endptr; |
unsigned int loadAddr; |
FILE *infile; |
FILE *outfile; |
int numBytes, i; |
int c; |
unsigned char lineData[16]; |
unsigned int chksum; |
int totalBytes; |
|
if (argc != 4) { |
printf("Usage: %s <load addr, hex> <input file> <output file>\n", |
argv[0]); |
exit(1); |
} |
loadAddr = strtoul(argv[1], &endptr, 16); |
if (*endptr != '\0') { |
error("illegal load address %s", argv[1]); |
} |
infile = fopen(argv[2], "rb"); |
if (infile == NULL) { |
error("cannot open input file %s", argv[2]); |
} |
outfile = fopen(argv[3], "wt"); |
if (outfile == NULL) { |
error("cannot open output file %s", argv[3]); |
} |
/* 13 bytes header */ |
for (i = 0; i < 13; i++) { |
if (fgetc(infile) != bitHeader[i]) { |
error("input file header is not a '.bit' header"); |
} |
} |
/* section 'a' */ |
if (fgetc(infile) != 'a') { |
error("section 'a' not found"); |
} |
i = getCount2(infile); |
show("design name:\t\t", infile, i); |
/* section 'b' */ |
if (fgetc(infile) != 'b') { |
error("section 'b' not found"); |
} |
i = getCount2(infile); |
show("part name:\t\t", infile, i); |
/* section 'c' */ |
if (fgetc(infile) != 'c') { |
error("section 'c' not found"); |
} |
i = getCount2(infile); |
show("creation date:\t\t", infile, i); |
/* section 'd' */ |
if (fgetc(infile) != 'd') { |
error("section 'd' not found"); |
} |
i = getCount2(infile); |
show("creation time:\t\t", infile, i); |
/* section 'e' */ |
if (fgetc(infile) != 'e') { |
error("section 'e' not found"); |
} |
i = getCount4(infile); |
printf("bit stream size:\t0x%08X\n", i); |
totalBytes = 0; |
while (1) { |
if ((loadAddr & 0xFFFF) == 0) { |
fprintf(outfile, ":02000004"); |
fprintf(outfile, "%04X", loadAddr >> 16); |
chksum = 0x02 + 0x04 + |
((loadAddr >> 24) & 0xFF) + |
((loadAddr >> 16) & 0xFF); |
fprintf(outfile, "%02X\n", (-chksum) & 0xFF); |
} |
chksum = 0; |
for (numBytes = 0; numBytes < 16; numBytes++) { |
c = fgetc(infile); |
if (c == EOF) { |
break; |
} |
c = mirror(c & 0xFF); |
lineData[numBytes] = c; |
chksum += c; |
} |
if (numBytes == 0) { |
break; |
} |
totalBytes += numBytes; |
fprintf(outfile, ":%02X%04X00", numBytes, loadAddr & 0xFFFF); |
for (i = 0; i < numBytes; i++) { |
fprintf(outfile, "%02X", lineData[i]); |
} |
chksum += numBytes; |
chksum += ((loadAddr >> 8) & 0xFF) + |
((loadAddr >> 0) & 0xFF); |
fprintf(outfile, "%02X\n", (-chksum) & 0xFF); |
loadAddr += numBytes; |
if (c == EOF) { |
break; |
} |
} |
fprintf(outfile, ":00000001FF\n"); |
fclose(infile); |
fclose(outfile); |
printf("bytes converted:\t0x%08X\n", totalBytes); |
return 0; |
} |
/tools/bit2mcs/intelhex.pdf
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
tools/bit2mcs/intelhex.pdf
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: tools/bit2mcs/Makefile
===================================================================
--- tools/bit2mcs/Makefile (nonexistent)
+++ tools/bit2mcs/Makefile (revision 234)
@@ -0,0 +1,19 @@
+#
+# Makefile for bitfile to Intel hex converter
+#
+
+BUILD = ../../build
+
+.PHONY: all install clean
+
+all: bit2mcs
+
+install: bit2mcs
+ mkdir -p $(BUILD)/bin
+ cp bit2mcs $(BUILD)/bin
+
+bit2mcs: bit2mcs.c
+ gcc -m32 -g -Wall -o bit2mcs bit2mcs.c
+
+clean:
+ rm -f *~ bit2mcs
Index: tools/Makefile
===================================================================
--- tools/Makefile (revision 233)
+++ tools/Makefile (revision 234)
@@ -4,7 +4,7 @@
BUILD = ../build
-DIRS = bin2exo bin2mcs bit2exo chrgen dspmem
+DIRS = bin2exo bin2mcs bit2exo bit2mcs chrgen dspmem
.PHONY: all install clean
/tools/bin2mcs/bin2mcs.c
48,13 → 48,15
if (outfile == NULL) { |
error("cannot open output file %s", argv[3]); |
} |
fprintf(outfile, ":02000004"); |
fprintf(outfile, "%04X", loadAddr >> 16); |
chksum = 0x02 + 0x04 + |
((loadAddr >> 24) & 0xFF) + |
((loadAddr >> 16) & 0xFF); |
fprintf(outfile, "%02X\n", (-chksum) & 0xFF); |
while (1) { |
if ((loadAddr & 0xFFFF) == 0) { |
fprintf(outfile, ":02000004"); |
fprintf(outfile, "%04X", loadAddr >> 16); |
chksum = 0x02 + 0x04 + |
((loadAddr >> 24) & 0xFF) + |
((loadAddr >> 16) & 0xFF); |
fprintf(outfile, "%02X\n", (-chksum) & 0xFF); |
} |
chksum = 0; |
for (numBytes = 0; numBytes < 16; numBytes++) { |
c = fgetc(infile); |