2 * ee2ihex, convert eeprom content to intel hex
4 * author: hackbard@hackdaworld.org
6 * build: gcc -Wall -O3 -o ee2ihex ee2ihex.c
7 * usage: ./ee2ihex foo.iic > foo.ihx
15 #include <sys/types.h>
19 int hexdump(unsigned char *buf,int len) {
24 printf("%02x ",buf[i]);
29 int asciidump(unsigned char *buf,int len) {
34 printf("%c ",(buf[i]<0x20)||(buf[i]>0x7e)?'.':buf[i]);
39 int main(int argc,char **argv) {
46 unsigned short ihxaddr;
51 unsigned char buf[1024];
53 fd=open(argv[1],O_RDONLY);
59 /* verify eeprom image */
62 printf("header too small\n");
67 printf("wrong boot byte: %02x\n",buf[0]);
71 printf("# ihex file, source eeprom file: %s\n",argv[1]);
73 printf("# header:\n");
86 perror("read len/addr");
90 len=(buf[0]<<8)|(buf[1]);
92 ihxaddr=(buf[2]<<8)|buf[3];
99 ihxlen=(len>=0x10)?0x10:len;
102 printf(":%02x%02x%02x%02x",ihxlen,addrh,addrl,0);
103 crc=ihxlen+addrh+addrl;
105 ret=read(fd,buf,ihxlen);
111 for(i=0;i<ihxlen;i++) {
112 printf("%02x",buf[i]);
118 printf("%02x\n",crc);
127 printf(":00000001ff\n");