X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Ffpga.git;a=blobdiff_plain;f=fx2%2Fee2ihex.c;fp=fx2%2Fee2ihex.c;h=d438b43092984da06cfee6f8cc89754b1c456d8e;hp=0000000000000000000000000000000000000000;hb=bdea9cbc1343bec0c7f993f3dcde9e23fe9e3569;hpb=0544bb04468bc99232d9cad31d2238d23488e524 diff --git a/fx2/ee2ihex.c b/fx2/ee2ihex.c new file mode 100644 index 0000000..d438b43 --- /dev/null +++ b/fx2/ee2ihex.c @@ -0,0 +1,132 @@ +/* + * ee2ihex, convert eeprom content to intel hex + * + * author: hackbard@hackdaworld.org + * + * build: gcc -Wall -O3 -o ee2ihex ee2ihex.c + * usage: ./ee2ihex foo.iic > foo.ihx + * + */ + + +#include +#include +#include +#include +#include +#include + +int hexdump(unsigned char *buf,int len) { + + int i; + + for(i=0;i0x7e)?'.':buf[i]); + + return 0; +} + +int main(int argc,char **argv) { + + int i; + int fd; + int ret; + int size=0; + unsigned short len; + unsigned short ihxaddr; + unsigned char addrl; + unsigned char addrh; + unsigned char ihxlen; + unsigned char crc; + unsigned char buf[1024]; + + fd=open(argv[1],O_RDONLY); + if(fd<0) { + perror("fd open"); + return fd; + } + + /* verify eeprom image */ + ret=read(fd,buf,8); + if(ret!=8) { + printf("header too small\n"); + return -1; + } + + if(buf[0]!=0xc2) { + printf("wrong boot byte: %02x\n",buf[0]); + return -1; + } + + printf("# ihex file, source eeprom file: %s\n",argv[1]); + printf("#\n"); + printf("# header:\n"); + printf("# "); + hexdump(buf,8); + printf(" | "); + asciidump(buf,8); + printf("\n"); + printf("#\n"); + printf("\n"); + + size=0; + + while(ret) { + ret=read(fd,buf,4); + if(ret!=4) { + perror("read len/addr"); + return ret; + } + + len=(buf[0]<<8)|(buf[1]); + crc=0x00; + ihxaddr=(buf[2]<<8)|buf[3]; + + if(buf[0]&(1<<7)) + goto END; + + while(len) { + + ihxlen=(len>=0x10)?0x10:len; + addrh=ihxaddr>>8; + addrl=ihxaddr&0xff; + printf(":%02x%02x%02x%02x",ihxlen,addrh,addrl,0); + crc=ihxlen+addrh+addrl; + + ret=read(fd,buf,ihxlen); + if(ret!=ihxlen) { + perror("read data"); + return ret; + } + + for(i=0;i