OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /eco32/tags/eco32-0.26/tools/bin2mcs
    from Rev 254 to Rev 270
    Reverse comparison

Rev 254 → Rev 270

/Makefile
0,0 → 1,19
#
# Makefile for binary to Intel hex converter
#
 
BUILD = ../../build
 
.PHONY: all install clean
 
all: bin2mcs
 
install: bin2mcs
mkdir -p $(BUILD)/bin
cp bin2mcs $(BUILD)/bin
 
bin2mcs: bin2mcs.c
gcc -g -Wall -o bin2mcs bin2mcs.c
 
clean:
rm -f *~ bin2mcs
/bin2mcs.c
0,0 → 1,89
/*
* bin2mcs.c -- convert binary data to Intel hex records
*/
 
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
 
 
void error(char *fmt, ...) {
va_list ap;
 
va_start(ap, fmt);
printf("Error: ");
vprintf(fmt, ap);
printf("\n");
va_end(ap);
exit(1);
}
 
 
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;
 
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]);
}
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;
}
lineData[numBytes] = c;
chksum += c;
}
if (numBytes == 0) {
break;
}
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);
return 0;
}
/intelhex.pdf Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
intelhex.pdf Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.