Skip to content

Commit 851919f

Browse files
committed
feat: Rename reset modes to use dash instead of underscore
1 parent ec12073 commit 851919f

12 files changed

+114
-67
lines changed

docs/en/espefuse/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Optional General Arguments Of Commands
5151
- ``--chip``, ``-c`` - Target chip type. If this argument is omitted, the tool automatically detects the chip type when connected. But if the command has a help option, the chip is not connected, and the default chip is ``esp32``, please specify the specific type of chip to get the correct help. Example of usage: ``-c esp32``, ``-c esp32c3``, ``-c esp32s2`` and others.
5252
- ``--baud``, ``-b`` - Serial port baud rate, the same as for esptool.
5353
- ``--port``, ``-p`` - Serial port device, for example: ``-p /dev/ttyUSB0`` (Linux and macOS) or ``-p COM1`` (Windows).
54-
- ``--before`` - What to do before connecting to the chip: ``default_reset``, ``no_reset``, ``esp32r1``, ``no_reset_no_sync``.
54+
- ``--before`` - What to do before connecting to the chip: ``default-reset``, ``no-reset``, ``esp32r1``, ``no-reset-no-sync``.
5555
- ``--debug``, ``-d`` - Show debugging information.
5656
- ``--virt`` - For host tests. The tool will work in the virtual mode (without connecting to a chip).
5757
- ``--path-efuse-file`` - For host tests. Use it together with ``--virt`` option. The tool will work in the virtual mode (without connecting to a chip) and save eFuse memory to a given file. If the file does not exists the tool creates it. To reset written eFuses just delete the file. Usage: ``--path-efuse-file efuse_memory.bin``.

docs/en/esptool/advanced-options.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Advanced Options
44
================
55

6-
The following advanced global configuration options can be used for all esptool commands. They are placed before the command name on the command line. For example, the option ``--before no_reset`` has to be placed before ``flash-id``. The command should look like this: ``esptool.py --before no_reset flash-id``.
6+
The following advanced global configuration options can be used for all esptool commands. They are placed before the command name on the command line. For example, the option ``--before no-reset`` has to be placed before ``flash-id``. The command should look like this: ``esptool.py --before no-reset flash-id``.
77

88
For basic/fundamental global configuration options, see the :ref:`options` page.
99

@@ -19,10 +19,10 @@ The ``--before`` argument allows you to specify whether the chip needs resetting
1919

2020
.. list::
2121

22-
* ``--before default_reset`` is the default, which uses DTR & RTS serial control lines (see :ref:`entering-the-bootloader`) to try to reset the chip into bootloader mode.
23-
* ``--before no_reset`` will skip DTR/RTS control signal assignments and just start sending a serial synchronisation command to the chip. This is useful if your chip doesn't have DTR/RTS, or for some serial interfaces (like Arduino board onboard serial) which behave differently when DTR/RTS are toggled.
24-
* ``--before no_reset_no_sync`` will skip DTR/RTS control signal assignments and skip also the serial synchronization command. This is useful if your chip is already running the :ref:`stub bootloader <stub>` and you want to avoid resetting the chip and uploading the stub again.
25-
:esp32c3 or esp32s3 or esp32c6 or esp32h2 or esp32p4 or esp32c5 or esp32c61: * ``--before usb_reset`` will use custom reset sequence for USB-JTAG-Serial (used for example for ESP chips connected through the USB-JTAG-Serial peripheral). Usually, this option doesn't have to be used directly. Esptool should be able to detect connection through USB-JTAG-Serial.
22+
* ``--before default-reset`` is the default, which uses DTR & RTS serial control lines (see :ref:`entering-the-bootloader`) to try to reset the chip into bootloader mode.
23+
* ``--before no-reset`` will skip DTR/RTS control signal assignments and just start sending a serial synchronisation command to the chip. This is useful if your chip doesn't have DTR/RTS, or for some serial interfaces (like Arduino board onboard serial) which behave differently when DTR/RTS are toggled.
24+
* ``--before no-reset-no-sync`` will skip DTR/RTS control signal assignments and skip also the serial synchronization command. This is useful if your chip is already running the :ref:`stub bootloader <stub>` and you want to avoid resetting the chip and uploading the stub again.
25+
:esp32c3 or esp32s3 or esp32c6 or esp32h2 or esp32p4 or esp32c5 or esp32c61: * ``--before usb-reset`` will use custom reset sequence for USB-JTAG-Serial (used for example for ESP chips connected through the USB-JTAG-Serial peripheral). Usually, this option doesn't have to be used directly. Esptool should be able to detect connection through USB-JTAG-Serial.
2626

2727
Reset After Operation: ``--after``
2828
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -31,11 +31,11 @@ The ``--after`` argument allows you to specify whether the chip should be reset
3131

3232
.. list::
3333

34-
* ``--after hard_reset`` is the default. The RTS serial control line is used to reset the chip into a normal boot sequence.
35-
:esp8266: * ``--after soft_reset`` runs the user firmware, but any subsequent reset will return to the serial bootloader. This was the reset behaviour in esptool v1.x.
36-
* ``--after no_reset`` leaves the chip in the serial bootloader, no reset is performed.
37-
* ``--after no_reset_stub`` leaves the chip in the stub bootloader, no reset is performed.
38-
:not esp8266 and not esp32 and not esp32h2 and not esp32c6: * ``--after watchdog_reset`` hard-resets the chip by triggering an internal watchdog reset. This is useful when the RTS control line is not available, especially in the USB-OTG and USB-Serial/JTAG modes. Use this if a chip is getting stuck in download mode when using the default reset method in USB-Serial/JTAG mode. Using this may cause the port to re-enumerate on Linux (e.g. ``/dev/ttyACM0`` -> ``/dev/ttyACM1``).
34+
* ``--after hard-reset`` is the default. The RTS serial control line is used to reset the chip into a normal boot sequence.
35+
:esp8266: * ``--after soft-reset`` runs the user firmware, but any subsequent reset will return to the serial bootloader. This was the reset behaviour in esptool v1.x.
36+
* ``--after no-reset`` leaves the chip in the serial bootloader, no reset is performed.
37+
* ``--after no-reset-stub`` leaves the chip in the stub bootloader, no reset is performed.
38+
:not esp8266 and not esp32 and not esp32h2 and not esp32c6: * ``--after watchdog-reset`` hard-resets the chip by triggering an internal watchdog reset. This is useful when the RTS control line is not available, especially in the USB-OTG and USB-Serial/JTAG modes. Use this if a chip is getting stuck in download mode when using the default reset method in USB-Serial/JTAG mode. Using this may cause the port to re-enumerate on Linux (e.g. ``/dev/ttyACM0`` -> ``/dev/ttyACM1``).
3939

4040

4141
Connect Loop

docs/en/esptool/flashing-firmware.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ ESP-IDF outputs the full esptool command used for flashing after the build is fi
5151
or
5252
idf.py -p PORT flash
5353
or
54-
python -m esptool --chip {IDF_TARGET_PATH_NAME} -b 460800 --before default_reset --after hard_reset write-flash --flash-mode dio --flash-size 2MB --flash-freq 40m {IDF_TARGET_BOOTLOADER_OFFSET} build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/hello_world.bin
54+
python -m esptool --chip {IDF_TARGET_PATH_NAME} -b 460800 --before default-reset --after hard-reset write-flash --flash-mode dio --flash-size 2MB --flash-freq 40m {IDF_TARGET_BOOTLOADER_OFFSET} build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/hello_world.bin
5555
or from the "esp-idf/examples/get-started/hello_world/build" directory
56-
python -m esptool --chip {IDF_TARGET_PATH_NAME} -b 460800 --before default_reset --after hard_reset write-flash "@flash_args"
56+
python -m esptool --chip {IDF_TARGET_PATH_NAME} -b 460800 --before default-reset --after hard-reset write-flash "@flash_args"
5757

5858
Arduino
5959
^^^^^^^
@@ -67,7 +67,7 @@ To do a verbose upload and see the exact esptool invocation, run ``pio run -v -t
6767

6868
::
6969

70-
".../.platformio/penv/bin/python" ".../.platformio/packages/tool-esptoolpy/esptool.py" --chip {IDF_TARGET_PATH_NAME} --port "/dev/cu.usbserial001" --baud 921600 --before default_reset --after hard_reset write-flash -z --flash-mode dio --flash-freq 40m --flash-size detect {IDF_TARGET_BOOTLOADER_OFFSET} .../.platformio/packages/framework-arduinoespressif32/tools/sdk/bin/bootloader_dio_40m.bin 0x8000 .../project_folder/.pio/build/esp32doit-devkit-v1/partitions.bin 0xe000 .../.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/esp32doit-devkit-v1/firmware.bin
70+
".../.platformio/penv/bin/python" ".../.platformio/packages/tool-esptoolpy/esptool.py" --chip {IDF_TARGET_PATH_NAME} --port "/dev/cu.usbserial001" --baud 921600 --before default-reset --after hard-reset write-flash -z --flash-mode dio --flash-freq 40m --flash-size detect {IDF_TARGET_BOOTLOADER_OFFSET} .../.platformio/packages/framework-arduinoespressif32/tools/sdk/bin/bootloader_dio_40m.bin 0x8000 .../project_folder/.pio/build/esp32doit-devkit-v1/partitions.bin 0xe000 .../.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/esp32doit-devkit-v1/firmware.bin
7171

7272

7373
Flashing
@@ -77,7 +77,7 @@ If you split the output, you'll find the ``write-flash`` command with a list of
7777

7878
Change ``PORT`` to the name of :ref:`actually used serial port <serial-port>` and run the command. A successful flash looks like this::
7979

80-
$ python -m esptool -p /dev/tty.usbserial-0001 -b 460800 --before default_reset --after hard_reset --chip {IDF_TARGET_PATH_NAME} write-flash --flash-mode dio --flash-size detect --flash-freq 40m {IDF_TARGET_BOOTLOADER_OFFSET} build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/hello_world.bin
80+
$ python -m esptool -p /dev/tty.usbserial-0001 -b 460800 --before default-reset --after hard-reset --chip {IDF_TARGET_PATH_NAME} write-flash --flash-mode dio --flash-size detect --flash-freq 40m {IDF_TARGET_BOOTLOADER_OFFSET} build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/hello_world.bin
8181
esptool.py v4.8.1
8282
Serial port /dev/tty.usbserial-0001:
8383
Connecting.........

docs/en/esptool/scripting.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ This example demonstrates writing two binary files using high-level commands:
5252
attach_flash(esp) # Attach the flash memory chip, required for flash operations
5353
with open(BOOTLOADER, "rb") as bl_file, open(FIRMWARE, "rb") as fw_file:
5454
write_flash(esp, [(0, bl_file), (0x1000, fw_file)]) # Write the binary files
55-
reset_chip(esp, "hard_reset") # Reset the chip
55+
reset_chip(esp, "hard-reset") # Reset the chip
5656
5757
- The ``esp`` object has to be replaced with the stub flasher object returned by ``run_stub(esp)`` when the stub flasher is activated. This step can be skipped if the stub flasher is not needed.
5858
- Running ``attach_flash(esp)`` is required for any flash-memory-related operations to work.
@@ -90,7 +90,7 @@ The following example demonstrates running a series of flash memory operations i
9090
write_flash(esp, [(0, bl_file), (0x1000, fw_file)]) # Write the binary files
9191
verify_flash(esp, [(0, bl_file), (0x1000, fw_file)]) # Verify the written data
9292
read_flash(esp, 0x0, 0x2400, "output.bin") # Read the flash memory into a file
93-
reset_chip(esp, "hard_reset") # Reset the chip
93+
reset_chip(esp, "hard-reset") # Reset the chip
9494
9595
- This example doesn't use ``detect_chip()``, but instantiates a ``ESP32ROM`` class directly. This is useful when you know the target chip in advance. In this scenario ``esp.connect()`` is required to establish a connection with the device.
9696
- Multiple operations can be chained together in a single context manager block.

docs/en/migration-guide.rst

+23
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ A significant amount of changes have been made to the log styling and formatting
215215
1. Make sure to adjust any of your scripts, asserts, CI workflows, or others to accommodate the new/changed format of messages. If you are parsing the log output (not recommended), consider importing esptool as a module and using the public API (see :ref:`here <scripting>`) to get the information you need.
216216

217217

218+
Reset Mode Renaming
219+
###################
220+
221+
Choices for the ``--before`` and ``--after`` options have been renamed to use ``-`` instead of ``_`` as a separator (e.g., ``default_reset`` -> ``default-reset``).
222+
223+
224+
**Migration Steps:**
225+
226+
1. Replace all underscores in the ``--before`` and ``--after`` options with ``-`` in your scripts.
227+
228+
218229
espsecure.py ``v5`` Migration Guide
219230
***********************************
220231

@@ -261,3 +272,15 @@ The public API of ``espsecure.py`` has been updated to provide a more consistent
261272
or if you were mocking the args object, now you don't have to do that and you can pass parameters directly to the function like:
262273
``sign_data(data=data, key=key, ...)``.
263274
2. Replace the ``custom_commandline`` parameter with ``argv`` in the ``main`` function call.
275+
276+
espefuse.py ``v5`` Migration Guide
277+
***********************************
278+
279+
Reset Mode Renaming
280+
###################
281+
282+
Choices for the ``--before`` option have been renamed to use ``-`` instead of ``_`` as a separator (e.g., ``default_reset`` -> ``default-reset``).
283+
284+
**Migration Steps:**
285+
286+
1. Replace all underscores in the ``--before`` option with ``-`` in your scripts.

espefuse/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def main(custom_commandline=None, esp=None):
197197
init_parser.add_argument(
198198
"--before",
199199
help="What to do before connecting to the chip",
200-
choices=["default_reset", "usb_reset", "no_reset", "no_reset_no_sync"],
201-
default="default_reset",
200+
choices=["default-reset", "usb-reset", "no-reset", "no-reset-no-sync"],
201+
default="default-reset",
202202
)
203203

204204
init_parser.add_argument(

esptool/__init__.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
AnyIntType,
9696
OptionEatAll,
9797
MutuallyExclusiveOption,
98+
ResetModeType,
9899
SpiConnectionType,
99100
AutoHex2BinType,
100101
AddrFilenamePairType,
@@ -312,17 +313,17 @@ def check_flash_size(esp: ESPLoader, address: int, size: int) -> None:
312313
)
313314
@click.option(
314315
"--before",
315-
type=click.Choice(["default_reset", "usb_reset", "no_reset", "no_reset_no_sync"]),
316-
default=os.environ.get("ESPTOOL_BEFORE", "default_reset"),
316+
type=ResetModeType(["default-reset", "usb-reset", "no-reset", "no-reset-no-sync"]),
317+
default=os.environ.get("ESPTOOL_BEFORE", "default-reset"),
317318
help="Which reset to perform before connecting to the chip.",
318319
)
319320
@click.option(
320321
"--after",
321322
"-a",
322-
type=click.Choice(
323-
["hard_reset", "soft_reset", "no_reset", "no_reset_stub", "watchdog_reset"]
323+
type=ResetModeType(
324+
["hard-reset", "soft-reset", "no-reset", "no-reset-stub", "watchdog-reset"]
324325
),
325-
default=os.environ.get("ESPTOOL_AFTER", "hard_reset"),
326+
default=os.environ.get("ESPTOOL_AFTER", "hard-reset"),
326327
help="Which reset to perform after operation is finished.",
327328
)
328329
@click.option(
@@ -384,7 +385,7 @@ def prepare_esp_object(ctx):
384385

385386
log.stage()
386387

387-
if ctx.obj["before"] != "no_reset_no_sync":
388+
if ctx.obj["before"] != "no-reset-no-sync":
388389
initial_baud = min(
389390
ESPLoader.ESP_ROM_BAUD, ctx.obj["baud"]
390391
) # don't sync faster than the default baud rate
@@ -1047,7 +1048,7 @@ def connect_loop(
10471048
chip: str,
10481049
max_retries: int,
10491050
trace: bool = False,
1050-
before: str = "default_reset",
1051+
before: str = "default-reset",
10511052
):
10521053
chip_class = CHIP_DEFS[chip]
10531054
esp = None
@@ -1095,7 +1096,7 @@ def get_default_connected_device(
10951096
initial_baud: int,
10961097
chip: str = "auto",
10971098
trace: bool = False,
1098-
before: str = "default_reset",
1099+
before: str = "default-reset",
10991100
):
11001101
_esp = None
11011102
for each_port in reversed(serial_list):

esptool/cli_util.py

+17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ def convert(
2424
return super().convert(value, param, ctx)
2525

2626

27+
class ResetModeType(click.Choice):
28+
"""Custom type to accept reset mode names with underscores as separators
29+
for compatibility with v4"""
30+
31+
def convert(self, value: str, param: click.Parameter, ctx: click.Context) -> Any:
32+
if "_" in value:
33+
new_value = value.replace("_", "-")
34+
if new_value not in self.choices:
35+
raise click.BadParameter(f"{value} is not a valid reset mode.")
36+
log.warning(
37+
f"Deprecated: Choice '{value}' for option '--{param.name}' is "
38+
f"deprecated. Use '{new_value}' instead."
39+
)
40+
return new_value
41+
return super().convert(value, param, ctx)
42+
43+
2744
class AnyIntType(click.ParamType):
2845
"""Custom type to parse any integer value - decimal, hex, octal, or binary"""
2946

esptool/cmds.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
def detect_chip(
8888
port: str = ESPLoader.DEFAULT_PORT,
8989
baud: int = ESPLoader.ESP_ROM_BAUD,
90-
connect_mode: str = "default_reset",
90+
connect_mode: str = "default-reset",
9191
trace_enabled: bool = False,
9292
connect_attempts: int = DEFAULT_CONNECT_ATTEMPTS,
9393
) -> ESPLoader:
@@ -99,8 +99,8 @@ def detect_chip(
9999
port: The serial port to use for communication.
100100
baud: The baud rate for serial communication.
101101
connect_mode: The chip reset method to perform when connecting to the ESP device
102-
(``"default_reset"``, ``"usb_reset"``,
103-
``"no_reset"``, ``"no_reset_no_sync"``)
102+
(``"default-reset"``, ``"usb-reset"``,
103+
``"no-reset"``, ``"no-reset-no-sync"``)
104104
trace_enabled: Enables or disables tracing for debugging purposes.
105105
connect_attempts: Number of connection attempts before failing.
106106
@@ -1558,30 +1558,30 @@ def get_security_flag_status(flag_name, flags_value):
15581558
log.print("USB Access: Disabled")
15591559

15601560

1561-
def reset_chip(esp: ESPLoader, reset_mode: str = "hard_reset") -> None:
1561+
def reset_chip(esp: ESPLoader, reset_mode: str = "hard-reset") -> None:
15621562
"""
15631563
Reset the ESP device.
15641564
15651565
Args:
15661566
esp: Initiated esp object connected to a real device.
15671567
reset_mode: Reset mode to use (
1568-
``"hard_reset"``: perform a hard reset using the RTS control line,
1569-
``"soft_reset"``: perform a soft reset,
1570-
``"no_reset"``: stay in bootloader,
1571-
``"no_reset_stub"``: stay in flasher stub,
1572-
``"watchdog_reset"``: perform a hard reset utilizing a software watchdog.
1568+
``"hard-reset"``: perform a hard reset using the RTS control line,
1569+
``"soft-reset"``: perform a soft reset,
1570+
``"no-reset"``: stay in bootloader,
1571+
``"no-reset-stub"``: stay in flasher stub,
1572+
``"watchdog-reset"``: perform a hard reset utilizing a software watchdog.
15731573
)
15741574
15751575
"""
1576-
if reset_mode == "hard_reset":
1576+
if reset_mode == "hard-reset":
15771577
esp.hard_reset()
1578-
elif reset_mode == "soft_reset":
1578+
elif reset_mode == "soft-reset":
15791579
log.print("Soft resetting...")
15801580
# flash_finish will trigger a soft reset
15811581
esp.soft_reset(False)
1582-
elif reset_mode == "no_reset_stub":
1582+
elif reset_mode == "no-reset-stub":
15831583
log.print("Staying in flasher stub.")
1584-
elif reset_mode == "watchdog_reset":
1584+
elif reset_mode == "watchdog-reset":
15851585
if esp.secure_download_mode:
15861586
log.warning(
15871587
"Watchdog hard reset is not supported in Secure Download Mode, "
@@ -1590,7 +1590,7 @@ def reset_chip(esp: ESPLoader, reset_mode: str = "hard_reset") -> None:
15901590
esp.hard_reset()
15911591
else:
15921592
esp.watchdog_reset()
1593-
elif reset_mode == "no_reset":
1593+
elif reset_mode == "no-reset":
15941594
log.print("Staying in bootloader.")
15951595
if esp.IS_STUB:
15961596
esp.soft_reset(True) # Exit the stub flasher back to ROM loader

0 commit comments

Comments
 (0)