From: Pavel Pisa Date: Mon, 22 Dec 2014 17:40:07 +0000 (+0100) Subject: usb_sendhex: extend support for I32HEX format variant. X-Git-Url: http://rtime.felk.cvut.cz/gitweb/fpga/lx-cpu1/lx-rocon.git/commitdiff_plain/8fc2b50396c6472afdc2342fabfea08e8b841edf usb_sendhex: extend support for I32HEX format variant. Signed-off-by: Pavel Pisa --- diff --git a/host/app/usb_sendhex/usb_sendhex.c b/host/app/usb_sendhex/usb_sendhex.c index c297822..257c3ed 100644 --- a/host/app/usb_sendhex/usb_sendhex.c +++ b/host/app/usb_sendhex/usb_sendhex.c @@ -75,8 +75,9 @@ typedef struct tform_file int buf_addr; int buf_bytes; FILE *file; - char *line_buf; + unsigned char *line_buf; int line_addr; + int ext_base_addr; int line_bytes; int line_offs; int start_addr; @@ -180,6 +181,7 @@ int tform_init(tform_file *tform, int buf_len) tform->buf_bytes = 0; tform->read = NULL; tform->done = NULL; + tform->ext_base_addr = 0; return 0; } @@ -209,7 +211,8 @@ int tform_read_ihex(tform_file *tform) int cn, len = 0; int addr = 0; unsigned u, v; - char *p, *r; + char *p; + unsigned char *r; char *line = NULL; size_t line_len = 0; @@ -267,7 +270,7 @@ int tform_read_ihex(tform_file *tform) checksum += ihex_type = u; - if (ihex_type == 0 || ihex_type == 1) + if ((ihex_type >= 0) && (ihex_type <= 5)) { r = tform->line_buf; @@ -307,7 +310,31 @@ int tform_read_ihex(tform_file *tform) if (ihex_type == 1) { tform->line_bytes = 0; - tform->start_addr = tform->line_addr; + if(tform->start_addr == -1) + tform->start_addr = tform->line_addr; + } + + tform->line_addr+=tform->ext_base_addr; + + if((ihex_type >= 2) && (ihex_type <= 5)) + { + cn = tform->line_bytes; + r = tform->line_buf; + addr = 0; + + while(cn-- > 0) + { + addr <<= 8; + addr += *(r++); + } + if(ihex_type == 2) + tform->ext_base_addr=addr << 4; + else if(ihex_type == 4) + tform->ext_base_addr = addr << 16; + else if(ihex_type == 5) + tform->start_addr = addr; + + tform->line_bytes = 0; } } } @@ -732,6 +759,7 @@ int upload_file(char *file_name, char *format) unsigned long mem_adr = mem_start; unsigned long mem_len = mem_length; unsigned long len; + unsigned long ext_addr = 0; /* for Intel HEX format */ struct timeval time1, time2; struct timezone tz; @@ -824,12 +852,40 @@ int upload_file(char *file_name, char *format) while (i < len) { + unsigned long a = mem_adr + i; + + if ((a & ~0xFFFF) != ext_addr) + { + unsigned long val; + unsigned char b; + + ext_addr = a & ~0xFFFF; + val = ext_addr >> 16; + l = 2; + val >>= 16; + while (val != 0) + { + val >>= 8; + l++; + } + fprintf(file, ":%02X000004", l); + csum = l + 4; + val = ext_addr >> 16; + while (l--) + { + b = (val >> (8 * l)) & 0xff; + fprintf(file, "%02X", b); + csum += b; + } + fprintf(file, "%02X\n", (-csum) & 0xFF); + } + l = len - i; if (l > 16) l = 16; - csum = l + (mem_adr + i) + ((mem_adr + i) >> 8); - fprintf(file, ":%02X%04lX00", l, (mem_adr + i) & 0xffff); + csum = l + a + (a >> 8); + fprintf(file, ":%02X%04lX00", l, a & 0xffff); while (l--) { @@ -879,6 +935,9 @@ int upload_file(char *file_name, char *format) printf("Upload time %lu.%lu s\n", dus / 1000000, dus % 1000000); } + if (fmt == fmt_ihex) + fprintf(file, ":00000001FF\n"); + if (file_name) fclose(file);