mirror of
https://github.com/espressif/esptool.git
synced 2025-10-21 06:40:00 +08:00
fix: Erase non-aligned bytes with --no-stub
This enables writing to non-aligned address by way of erasing the bytes before it to the closest aligned address.
This commit is contained in:

committed by
Radim Karniš

parent
d83dd3be6e
commit
c984aa905d
@@ -560,15 +560,24 @@ def write_flash(esp, args):
|
||||
print("Will flash %s uncompressed" % argfile.name)
|
||||
compress = False
|
||||
|
||||
if args.no_stub:
|
||||
print("Erasing flash...")
|
||||
image = pad_to(
|
||||
argfile.read(), esp.FLASH_ENCRYPTED_WRITE_ALIGN if encrypted else 4
|
||||
)
|
||||
image = argfile.read()
|
||||
|
||||
if len(image) == 0:
|
||||
print("WARNING: File %s is empty" % argfile.name)
|
||||
continue
|
||||
|
||||
image = pad_to(image, esp.FLASH_ENCRYPTED_WRITE_ALIGN if encrypted else 4)
|
||||
|
||||
if args.no_stub:
|
||||
print("Erasing flash...")
|
||||
|
||||
# It is not possible to write to not aligned addresses without stub,
|
||||
# so there are added 0xFF (erase) bytes at the beginning of the image
|
||||
# to align it.
|
||||
bytes_over = address % esp.FLASH_SECTOR_SIZE
|
||||
address -= bytes_over
|
||||
image = b"\xFF" * bytes_over + image
|
||||
|
||||
if not esp.secure_download_mode and not esp.get_secure_boot_enabled():
|
||||
image = _update_image_flash_params(esp, address, args, image)
|
||||
else:
|
||||
|
@@ -667,6 +667,15 @@ class TestFlashing(EsptoolTestCase):
|
||||
assert "Chip erase completed successfully" in output
|
||||
assert "Hash of data verified" in output
|
||||
|
||||
@pytest.mark.quick_test
|
||||
def test_flash_not_aligned_nostub(self):
|
||||
output = self.run_esptool("--no-stub write_flash 0x1 images/one_kb.bin")
|
||||
assert (
|
||||
"WARNING: Flash address 0x00000001 is not aligned to a 0x1000 byte flash sector. 0x1 bytes before this address will be erased."
|
||||
in output
|
||||
)
|
||||
assert "Hard resetting via RTS pin..." in output
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
arg_chip in ["esp8266", "esp32"],
|
||||
|
Reference in New Issue
Block a user