@@ -478,19 +478,32 @@ def write_flash(esp, args):
478
478
"Use --force to override the warning."
479
479
)
480
480
481
- # verify file sizes fit in flash
482
- flash_end = flash_size_bytes (
483
- detect_flash_size (esp ) if args .flash_size == "keep" else args .flash_size
481
+ set_flash_size = (
482
+ flash_size_bytes (args .flash_size )
483
+ if args .flash_size not in ["detect" , "keep" ]
484
+ else None
484
485
)
485
- if flash_end is not None : # Not in secure download mode
486
+ if esp .secure_download_mode :
487
+ flash_end = set_flash_size
488
+ else : # Check against real flash chip size if not in SDM
489
+ flash_end_str = detect_flash_size (esp )
490
+ flash_end = flash_size_bytes (flash_end_str )
491
+ if set_flash_size and set_flash_size > flash_end :
492
+ print (
493
+ f"WARNING: Set --flash_size { args .flash_size } "
494
+ f"is larger than the available flash size of { flash_end_str } ."
495
+ )
496
+
497
+ # Verify file sizes fit in the set --flash_size, or real flash size if smaller
498
+ flash_end = min (set_flash_size , flash_end ) if set_flash_size else flash_end
499
+ if flash_end is not None :
486
500
for address , argfile in args .addr_filename :
487
501
argfile .seek (0 , os .SEEK_END )
488
502
if address + argfile .tell () > flash_end :
489
503
raise FatalError (
490
- "File %s (length %d) at offset %d "
491
- "will not fit in %d bytes of flash. "
492
- "Use --flash_size argument, or change flashing address."
493
- % (argfile .name , argfile .tell (), address , flash_end )
504
+ f"File { argfile .name } (length { argfile .tell ()} ) at offset "
505
+ f"{ address } will not fit in { flash_end } bytes of flash. "
506
+ "Change the --flash_size argument, or flashing address."
494
507
)
495
508
argfile .seek (0 )
496
509
@@ -955,9 +968,7 @@ def get_key_from_value(dict, val):
955
968
ESP8266V2FirmwareImage .IMAGE_V2_MAGIC ,
956
969
]:
957
970
raise FatalError (
958
- "This is not a valid image " "(invalid magic number: {:#x})" .format (
959
- magic
960
- )
971
+ f"This is not a valid image (invalid magic number: { magic :#x} )"
961
972
)
962
973
963
974
if args .chip == "auto" :
0 commit comments