diff --git a/docs/en/esptool/basic-commands.rst b/docs/en/esptool/basic-commands.rst index ead5ac208..33070671a 100644 --- a/docs/en/esptool/basic-commands.rst +++ b/docs/en/esptool/basic-commands.rst @@ -113,6 +113,11 @@ It is also possible to autodetect flash size by using ``ALL`` as size. The above esptool.py -p PORT -b 460800 read_flash 0 ALL flash_contents.bin +.. note:: + + When using the ``read_flash`` command in combination with the ``--no-stub`` argument, it may be necessary to also set the ``--flash_size`` argument to ensure proper reading of the flash contents by the ROM. + + .. note:: If ``write_flash`` updated the boot image's :ref:`flash mode and flash size ` during flashing then these bytes may be different when read back. diff --git a/esptool/__init__.py b/esptool/__init__.py index ffe6db787..2227f5762 100644 --- a/esptool/__init__.py +++ b/esptool/__init__.py @@ -217,7 +217,12 @@ def add_spi_connection_arg(parent): default="0xFFFFFFFF", ) - def add_spi_flash_subparsers(parent, allow_keep, auto_detect): + def add_spi_flash_subparsers( + parent: argparse.ArgumentParser, + allow_keep: bool, + auto_detect: bool, + size_only: bool = False, + ): """Add common parser arguments for SPI flash properties""" extra_keep_args = ["keep"] if allow_keep else [] @@ -234,33 +239,35 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect): extra_fs_message = "" flash_sizes = [] - parent.add_argument( - "--flash_freq", - "-ff", - help="SPI Flash frequency", - choices=extra_keep_args - + [ - "80m", - "60m", - "48m", - "40m", - "30m", - "26m", - "24m", - "20m", - "16m", - "15m", - "12m", - ], - default=os.environ.get("ESPTOOL_FF", "keep" if allow_keep else None), - ) - parent.add_argument( - "--flash_mode", - "-fm", - help="SPI Flash mode", - choices=extra_keep_args + ["qio", "qout", "dio", "dout"], - default=os.environ.get("ESPTOOL_FM", "keep" if allow_keep else "qio"), - ) + if not size_only: + parent.add_argument( + "--flash_freq", + "-ff", + help="SPI Flash frequency", + choices=extra_keep_args + + [ + "80m", + "60m", + "48m", + "40m", + "30m", + "26m", + "24m", + "20m", + "16m", + "15m", + "12m", + ], + default=os.environ.get("ESPTOOL_FF", "keep" if allow_keep else None), + ) + parent.add_argument( + "--flash_mode", + "-fm", + help="SPI Flash mode", + choices=extra_keep_args + ["qio", "qout", "dio", "dout"], + default=os.environ.get("ESPTOOL_FM", "keep" if allow_keep else "qio"), + ) + parent.add_argument( "--flash_size", "-fs", @@ -540,7 +547,9 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect): parser_read_flash = subparsers.add_parser( "read_flash", help="Read SPI flash content" ) - add_spi_connection_arg(parser_read_flash) + add_spi_flash_subparsers( + parser_read_flash, allow_keep=True, auto_detect=True, size_only=True + ) parser_read_flash.add_argument("address", help="Start address", type=arg_auto_int) parser_read_flash.add_argument( "size", diff --git a/esptool/targets/esp32.py b/esptool/targets/esp32.py index fd8e3f518..690fdbb91 100644 --- a/esptool/targets/esp32.py +++ b/esptool/targets/esp32.py @@ -329,11 +329,17 @@ def read_flash_slow(self, offset, length, progress_fn): data = b"" while len(data) < length: block_len = min(BLOCK_LEN, length - len(data)) - r = self.check_command( - "read flash block", - self.ESP_READ_FLASH_SLOW, - struct.pack("