From 2addfa02ee8a5cc4a761fb110dc848579671a47d Mon Sep 17 00:00:00 2001 From: Nico Bollen Date: Fri, 6 Jan 2023 11:02:36 +0100 Subject: [PATCH 1/3] allow to ignore leaving fill pattern bytes out of hex file --- include/intelhex.h | 2 +- src/intelhex.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/intelhex.h b/include/intelhex.h index 428a701..84d23b1 100644 --- a/include/intelhex.h +++ b/include/intelhex.h @@ -67,7 +67,7 @@ namespace intelhex value_type& operator[](address_type); //Array access operator value_type get(address_type); // Return the value at address - void set(address_type, value_type); // Set the value at address + void set(address_type, value_type, bool ignore_fill=false); // Set the value at address void load(const std::string&); // Load from a file void read(std::istream &); // Read data from an input stream diff --git a/src/intelhex.cc b/src/intelhex.cc index f4f0ebb..674a3b6 100644 --- a/src/intelhex.cc +++ b/src/intelhex.cc @@ -56,9 +56,9 @@ namespace intelhex } // Set the value at address or create a new element using value - void hex_data::set(address_type address, value_type value) + void hex_data::set(address_type address, value_type value, bool ignore_fill) { - if( value == fill() ) // Handle fill values + if( !ignore_fill && value == fill() ) // Handle fill values { erase(address); // If the address is already set, erase it return; From 7fa876c11e1125720201312800df97542e1db6db Mon Sep 17 00:00:00 2001 From: Nico Bollen Date: Sun, 16 Jun 2024 20:35:07 +0200 Subject: [PATCH 2/3] correct logic for is_set function --- src/intelhex.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intelhex.cc b/src/intelhex.cc index f4f0ebb..e7d01cb 100644 --- a/src/intelhex.cc +++ b/src/intelhex.cc @@ -290,7 +290,7 @@ namespace intelhex while( (i!=blocks.rend()) && (i->first > addr)) ++i; - if( (addr - i->first) > i->second.size() ) + if( (addr - i->first) >= i->second.size() ) return false; else return true; From ccf17c2ed04dfdd70a11953c6608357b68d83976 Mon Sep 17 00:00:00 2001 From: Nico Bollen Date: Mon, 5 Aug 2024 10:30:36 +0200 Subject: [PATCH 3/3] do not endless hang when empty hex file is used for compacting --- src/intelhex.cc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/intelhex.cc b/src/intelhex.cc index 6b34659..971f93f 100644 --- a/src/intelhex.cc +++ b/src/intelhex.cc @@ -93,19 +93,21 @@ namespace intelhex // Merge adjacent blocks void hex_data::compact() { - iterator previous = blocks.begin(); - iterator i = previous; - - for(++i; i != blocks.end(); ++i) - { - if( (previous->first + previous->second.size()) == i->first ) - { - previous->second.insert(previous->second.end(), i->second.begin(), i->second.end()); - blocks.erase(i); - i = previous; - } - previous = i; - } + if (blocks.size() > 0) { + iterator previous = blocks.begin(); + iterator i = previous; + + for(++i; i != blocks.end(); ++i) + { + if( (previous->first + previous->second.size()) == i->first ) + { + previous->second.insert(previous->second.end(), i->second.begin(), i->second.end()); + blocks.erase(i); + i = previous; + } + previous = i; + } + } } // Delete all allocated memory