|
39 | 39 | import traceback |
40 | 40 |
|
41 | 41 | from esptool.cmds import ( |
| 42 | + DETECTED_FLASH_SIZES, |
42 | 43 | chip_id, |
43 | 44 | detect_chip, |
44 | 45 | detect_flash_size, |
@@ -526,7 +527,9 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect): |
526 | 527 | add_spi_connection_arg(parser_read_flash) |
527 | 528 | parser_read_flash.add_argument("address", help="Start address", type=arg_auto_int) |
528 | 529 | parser_read_flash.add_argument( |
529 | | - "size", help="Size of region to dump", type=arg_auto_int |
| 530 | + "size", |
| 531 | + help="Size of region to dump. Use `ALL` to read to the end of flash.", |
| 532 | + type=arg_auto_size, |
530 | 533 | ) |
531 | 534 | parser_read_flash.add_argument("filename", help="Name of binary dump") |
532 | 535 | parser_read_flash.add_argument( |
@@ -570,8 +573,9 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect): |
570 | 573 | ) |
571 | 574 | parser_erase_region.add_argument( |
572 | 575 | "size", |
573 | | - help="Size of region to erase (must be multiple of 4096)", |
574 | | - type=arg_auto_int, |
| 576 | + help="Size of region to erase (must be multiple of 4096). " |
| 577 | + "Use `ALL` to erase to the end of flash.", |
| 578 | + type=arg_auto_size, |
575 | 579 | ) |
576 | 580 |
|
577 | 581 | parser_merge_bin = subparsers.add_parser( |
@@ -827,6 +831,23 @@ def flash_xmc_startup(): |
827 | 831 | "than 16MB, in case of failure use --no-stub." |
828 | 832 | ) |
829 | 833 |
|
| 834 | + if getattr(args, "size", "") == "all": |
| 835 | + if esp.secure_download_mode: |
| 836 | + raise FatalError( |
| 837 | + "Detecting flash size is not supported in secure download mode. " |
| 838 | + "Set an exact size value." |
| 839 | + ) |
| 840 | + # detect flash size |
| 841 | + flash_id = esp.flash_id() |
| 842 | + size_id = flash_id >> 16 |
| 843 | + size_str = DETECTED_FLASH_SIZES.get(size_id) |
| 844 | + if size_str is None: |
| 845 | + raise FatalError( |
| 846 | + "Detecting flash size failed. Set an exact size value." |
| 847 | + ) |
| 848 | + print(f"Detected flash size: {size_str}") |
| 849 | + args.size = flash_size_bytes(size_str) |
| 850 | + |
830 | 851 | if esp.IS_STUB and hasattr(args, "address") and hasattr(args, "size"): |
831 | 852 | if args.address + args.size > 0x1000000: |
832 | 853 | print( |
@@ -871,6 +892,11 @@ def arg_auto_int(x): |
871 | 892 | return int(x, 0) |
872 | 893 |
|
873 | 894 |
|
| 895 | +def arg_auto_size(x): |
| 896 | + x = x.lower() |
| 897 | + return x if x == "all" else arg_auto_int(x) |
| 898 | + |
| 899 | + |
874 | 900 | def get_port_list(): |
875 | 901 | if list_ports is None: |
876 | 902 | raise FatalError( |
|
0 commit comments