diff --git a/Makefile b/Makefile index 97492ac..8cda8f4 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC=clang CFLAGS=-Wall -std=c99 -pedantic OBJS = kk_ihex.o -BINS = bin2ihex bbin2ihex +BINS = bin2ihex all: $(BINS) diff --git a/bin2ihex.c b/bin2ihex.c index 7223a87..b0553be 100644 --- a/bin2ihex.c +++ b/bin2ihex.c @@ -8,6 +8,8 @@ #include #include +//#define IHEX_WRITE_INITIAL_EXTENDED_ADDRESS_RECORD + int main (void) { struct ihex_state ihex; @@ -16,6 +18,9 @@ main (void) { ihex_init(&ihex); ihex_write_at_address(&ihex, 0); +#ifdef IHEX_WRITE_INITIAL_EXTENDED_ADDRESS_RECORD + ihex.flags |= IHEX_FLAG_ADDRESS_OVERFLOW; +#endif while ((count = fread(buf, 1, sizeof(buf), stdin))) { ihex_write_bytes(&ihex, buf, count); } diff --git a/kk_ihex.c b/kk_ihex.c index f1cdcd3..47e16de 100644 --- a/kk_ihex.c +++ b/kk_ihex.c @@ -108,13 +108,13 @@ ihex_linear_address (struct ihex_state *ihex) { static char * ihex_buffer_linear_address (char *w, const ihex_segment_t address_msb) { - unsigned int sum = IHEX_EXTENDED_LINEAR_ADDRESS_RECORD; + unsigned int sum = IHEX_EXTENDED_LINEAR_ADDRESS_RECORD + 2; - *w++ = IHEX_START; // : - w = ihex_buffer_byte(w, 0); // data + *w++ = IHEX_START; // : + w = ihex_buffer_byte(w, 2); // length w = ihex_buffer_byte(w, 0); // address msb w = ihex_buffer_byte(w, 0); // address lsb - w = ihex_buffer_byte(w, sum); // record type + w = ihex_buffer_byte(w, IHEX_EXTENDED_LINEAR_ADDRESS_RECORD); // record type w = ihex_buffer_word(w, address_msb, &sum); // high bytes of 32-bit address w = ihex_buffer_byte(w, 0x100U - sum); // checksum return ihex_buffer_newline(w); @@ -122,13 +122,13 @@ ihex_buffer_linear_address (char *w, const ihex_segment_t address_msb) { static char * ihex_buffer_segment_address (char *w, const ihex_segment_t segment) { - unsigned int sum = IHEX_EXTENDED_SEGMENT_ADDRESS_RECORD; + unsigned int sum = IHEX_EXTENDED_SEGMENT_ADDRESS_RECORD + 2; *w++ = IHEX_START; // : - w = ihex_buffer_byte(w, 0); // data + w = ihex_buffer_byte(w, 2); // length w = ihex_buffer_byte(w, 0); // address msb w = ihex_buffer_byte(w, 0); // address lsb - w = ihex_buffer_byte(w, sum); // record type + w = ihex_buffer_byte(w, IHEX_EXTENDED_SEGMENT_ADDRESS_RECORD); // record type w = ihex_buffer_word(w, segment, &sum); // segment selector w = ihex_buffer_byte(w, 0x100U - sum); // checksum return ihex_buffer_newline(w); @@ -140,7 +140,7 @@ ihex_buffer_segment_address (char *w, const ihex_segment_t segment) { static char * ihex_buffer_end_of_file (char *w) { *w++ = IHEX_START; // : - w = ihex_buffer_byte(w, 0); // data + w = ihex_buffer_byte(w, 0); // length w = ihex_buffer_byte(w, 0); // address msb w = ihex_buffer_byte(w, 0); // address lsb w = ihex_buffer_byte(w, IHEX_END_OF_FILE_RECORD); // record type diff --git a/kk_ihex.h b/kk_ihex.h index 23f7b89..a895396 100644 --- a/kk_ihex.h +++ b/kk_ihex.h @@ -21,6 +21,14 @@ * may be overwritten immediately after `ihex_flush_buffer` returns; * it must be copied if it needs to be preserved. * + * For outputs larger than 64KiB, 32-bit linear addresses are output. Normally + * the initial linear extended address record of zero is NOT written - it can + * be forced by setting `ihex->flags |= IHEX_FLAG_ADDRESS_OVERFLOW` before + * writing the first byte. + * + * Gaps in the data may be created by calling `ihex_write_at_address` with the + * new starting address without calling `ihex_end_write` in between. + * * * Copyright (c) 2013 Kimmo Kulovesi, http://arkku.com/ * Provided with absolutely no warranty, use at your own risk only. @@ -46,7 +54,7 @@ struct ihex_state { uint8_t data[IHEX_LINE_LENGTH]; }; -#define IHEX_FLAG_ADDRESS_OVERFLOW 1 +#define IHEX_FLAG_ADDRESS_OVERFLOW 1 // 16-bit address overflow enum ihex_record_type { IHEX_DATA_RECORD,