Skip to content

Commit

Permalink
Added option to check for possible overlapping during write_flash o…
Browse files Browse the repository at this point in the history
…peration.

If there's a need to flash overlapping data, can be done by running esptool.py write_flash multiple times.

Commits from Pull Request #176
  • Loading branch information
Slavey Karadzhov authored and projectgus committed Feb 8, 2017
1 parent bf58c88 commit 3fb8eb7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,19 @@ def __call__(self, parser, namespace, values, option_string=None):
except IndexError:
raise argparse.ArgumentError(self,'Must be pairs of an address and the binary filename to write there')
pairs.append((address, argfile))

# Sort the addresses and check for overlapping
end = 0
for address, argfile in sorted(pairs):
argfile.seek(0,2) # seek to end
size = argfile.tell()
argfile.seek(0)
sector_start = address & ~(ESPLoader.FLASH_SECTOR_SIZE - 1)
sector_end = ((address + size + ESPLoader.FLASH_SECTOR_SIZE - 1) & ~(ESPLoader.FLASH_SECTOR_SIZE - 1)) - 1
if sector_start < end:
message = 'Detected overlap at address: 0x%x for file: %s' % (address, argfile.name)
raise argparse.ArgumentError(self, message)
end = sector_end
setattr(namespace, self.dest, pairs)


Expand Down
13 changes: 13 additions & 0 deletions test/test_esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ def test_length_not_aligned_4bytes(self):
def test_length_not_aligned_4bytes_no_compression(self):
self.run_esptool("write_flash -u 0x0 images/%s" % NODEMCU_FILE)

def test_write_overlap(self):
output = self.run_esptool_error("write_flash 0x0 images/bootloader.bin 0x1000 images/one_kb.bin")
self.assertIn("Detected overlap at address: 0x1000 ", output)

def test_write_sector_overlap(self):
# These two 1KB files don't overlap, but they do both touch sector at 0x1000 so should fail
output = self.run_esptool_error("write_flash 0xd00 images/one_kb.bin 0x1d00 images/one_kb.bin")
self.assertIn("Detected overlap at address: 0x1d00", output)

def test_write_no_overlap(self):
output = self.run_esptool("write_flash 0x0 images/bootloader.bin 0x2000 images/one_kb.bin")
self.assertNotIn("Detected overlap at address", output)

class TestFlashSizes(EsptoolTestCase):

def test_high_offset(self):
Expand Down

0 comments on commit 3fb8eb7

Please sign in to comment.