File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -560,15 +560,24 @@ def write_flash(esp, args):
560
560
print ("Will flash %s uncompressed" % argfile .name )
561
561
compress = False
562
562
563
- if args .no_stub :
564
- print ("Erasing flash..." )
565
- image = pad_to (
566
- argfile .read (), esp .FLASH_ENCRYPTED_WRITE_ALIGN if encrypted else 4
567
- )
563
+ image = argfile .read ()
564
+
568
565
if len (image ) == 0 :
569
566
print ("WARNING: File %s is empty" % argfile .name )
570
567
continue
571
568
569
+ image = pad_to (image , esp .FLASH_ENCRYPTED_WRITE_ALIGN if encrypted else 4 )
570
+
571
+ if args .no_stub :
572
+ print ("Erasing flash..." )
573
+
574
+ # It is not possible to write to not aligned addresses without stub,
575
+ # so there are added 0xFF (erase) bytes at the beginning of the image
576
+ # to align it.
577
+ bytes_over = address % esp .FLASH_SECTOR_SIZE
578
+ address -= bytes_over
579
+ image = b"\xFF " * bytes_over + image
580
+
572
581
if not esp .secure_download_mode and not esp .get_secure_boot_enabled ():
573
582
image = _update_image_flash_params (esp , address , args , image )
574
583
else :
Original file line number Diff line number Diff line change @@ -667,6 +667,15 @@ def test_erase_before_write(self):
667
667
assert "Chip erase completed successfully" in output
668
668
assert "Hash of data verified" in output
669
669
670
+ @pytest .mark .quick_test
671
+ def test_flash_not_aligned_nostub (self ):
672
+ output = self .run_esptool ("--no-stub write_flash 0x1 images/one_kb.bin" )
673
+ assert (
674
+ "WARNING: Flash address 0x00000001 is not aligned to a 0x1000 byte flash sector. 0x1 bytes before this address will be erased."
675
+ in output
676
+ )
677
+ assert "Hard resetting via RTS pin..." in output
678
+
670
679
671
680
@pytest .mark .skipif (
672
681
arg_chip in ["esp8266" , "esp32" ],
You can’t perform that action at this time.
0 commit comments