Skip to content

Commit 798da72

Browse files
committed
v4.8.9
1 parent 7df5819 commit 798da72

36 files changed

+1256
-2091
lines changed

.github/workflows/test_esptool.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ jobs:
5151
steps:
5252
- name: Checkout
5353
uses: actions/checkout@master
54-
- name: Set up Python 3.12
54+
55+
- name: Set up Python 3.13
5556
uses: actions/setup-python@master
5657
with:
57-
python-version: 3.12
58+
python-version: 3.13
5859

5960
- name: Check if flasher stubs are up-to-date
6061
run: |

.gitlab-ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ build_docs:
518518
- changes:
519519
- "docs/**/*"
520520
- "CONTRIBUTING.rst"
521-
- "esptool/cmds.py"
522521
needs: []
523522
artifacts:
524523
when: always
@@ -527,7 +526,6 @@ build_docs:
527526
- docs/_build/*/*/html/*
528527
expire_in: 4 days
529528
script:
530-
- pip install . # esptool is needed for the automatic API documentation generation
531529
- cd docs
532530
- pip install -r requirements.txt --prefer-binary
533531
- build-docs -l en -t {esp8266,esp32,esp32s2,esp32c3,esp32s3,esp32c2,esp32c6,esp32h2,esp32p4,esp32c5,esp32c61}
@@ -555,7 +553,6 @@ deploy_docs_preview:
555553
- changes:
556554
- "docs/**/*"
557555
- "CONTRIBUTING.rst"
558-
- "esptool/cmds.py"
559556
variables:
560557
TYPE: "preview"
561558
DOCS_BUILD_DIR: "${CI_PROJECT_DIR}/docs/_build/"
@@ -573,7 +570,6 @@ deploy_docs_production:
573570
changes:
574571
- "docs/**/*"
575572
- "CONTRIBUTING.rst"
576-
- "esptool/cmds.py"
577573
variables:
578574
TYPE: "production"
579575
DOCS_BUILD_DIR: "${CI_PROJECT_DIR}/docs/_build/"

CONTRIBUTING.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ Please report bugs in ``esptool.py`` if you find them. However, before reporting
4444

4545
If you don’t find anything, please `open a new issue <https://github.com/espressif/esptool/issues/new/choose>`_.
4646

47-
.. _feature-requests:
48-
4947
Sending Feature Requests
5048
------------------------
5149

ci/pack_python.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
def main():
8+
89
# remove not needed for plain python use
910
shutil.rmtree("ci", ignore_errors=True)
1011
shutil.rmtree("docs", ignore_errors=True)

docs/conf_common.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@
2525
html_static_path = ["../_static"]
2626

2727
# Conditional content
28-
extensions += [
29-
"esp_docs.esp_extensions.dummy_build_system",
30-
"sphinx.ext.autodoc",
31-
"sphinx.ext.napoleon",
32-
]
28+
extensions += ["esp_docs.esp_extensions.dummy_build_system"]
3329

3430
ESP8266_DOCS = []
3531

docs/en/advanced-topics/serial-protocol.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{IDF_TARGET_SECURITY_INFO:default="32 bits ``flags``, 1 byte ``flash_crypt_cnt``, 7x1 byte ``key_purposes``, 32-bit word ``chip_id``, 32-bit word ``eco_version``", esp32s2="32 bits ``flags``, 1 byte ``flash_crypt_cnt``, 7x1 byte ``key_purposes`` "}
22

3-
.. _serial-protocol:
4-
53
Serial Protocol
64
===============
75

docs/en/esptool/advanced-commands.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ The ``write_flash`` command always verifies the MD5 hash of data which is writte
2020

2121
::
2222

23-
esptool.py verify_flash --diff 0x40000 my_app.elf-0x40000.bin
23+
esptool.py verify_flash --diff yes 0x40000 my_app.elf-0x40000.bin
2424

2525

26-
The ``--diff`` option specifies that if the files are different, the details should be printed to the console.
26+
The ``--diff yes`` option specifies that if the files are different, the details should be printed to the console.
2727

2828
.. note::
2929

docs/en/esptool/basic-commands.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Use the ``-e/--erase-all`` option to erase all flash sectors (not just the write
101101
Read Flash Contents: ``read_flash``
102102
-----------------------------------
103103

104-
The read_flash command allows reading back the contents of flash. The arguments to the command are an address, a size, and a file path to output to. For example, to read a full 2MB of attached flash:
104+
The read_flash command allows reading back the contents of flash. The arguments to the command are an address, a size, and a filename to dump the output to. For example, to read a full 2MB of attached flash:
105105

106106
::
107107

docs/en/esptool/scripting.rst

Lines changed: 10 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
Embedding into Custom Scripts
44
=============================
55

6-
``esptool.py`` can be easily integrated into Python applications or called from other Python scripts.
6+
``esptool.py``, ``espefuse.py``, and ``espsecure.py`` can easily be integrated into Python applications or called from other Python scripts.
77

8-
Using Esptool as a Python Module
9-
--------------------------------
10-
11-
The esptool module provides a comprehensive Python API for interacting with ESP chips programmatically. By leveraging the API, developers can automate tasks such as flashing firmware, reading device information, managing flash memory, or preparing and analyzing binary images. The API supports both high-level abstractions and low-level control.
12-
13-
Using the Command-Line Interface
14-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
16-
The most straightforward and basic integration option is to pass arguments to ``esptool.main()``. This workaround allows you to pass exactly the same arguments as you would on the CLI:
8+
While it currently does have a poor Python API, something which `#208 <https://github.com/espressif/esptool/issues/208>`_ will address, it allows for passing CLI arguments to ``esptool.main()``. This workaround makes integration very straightforward as you can pass exactly the same arguments as you would on the CLI:
179

1810
.. code-block:: python
1911
@@ -23,182 +15,16 @@ The most straightforward and basic integration option is to pass arguments to ``
2315
print("Using command ", " ".join(command))
2416
esptool.main(command)
2517
26-
Public API Reference
27-
^^^^^^^^^^^^^^^^^^^^
28-
29-
For more control and custom integration, esptool exposes a public API - a set of high-level functions that encapsulate common operations and simplify the interaction with the ESP chip. These functions are designed to be user-friendly and provide an intuitive way to work with the chip. The public API is the recommended way to interact with the chip programmatically.
30-
31-
Basic Workflow:
32-
33-
1. **Detect and Connect**: Use ``detect_chip()`` to automatically identify the connected ESP chip and establish a connection, or manually create and instantiate a specific ``ESPLoader`` object (e.g. ``ESP32ROM``) and establish a connection in two steps.
34-
2. **Run Stub Flasher (Optional)**: Upload and execute the :ref:`stub flasher <stub>` which provides enhanced functionality and speed.
35-
3. **Perform Operations**: Utilize the chip object's methods or public API command functions to interact with the device.
36-
4. **Reset and Cleanup**: Ensure proper reset and resource cleanup using context managers.
37-
38-
------------
39-
40-
This example demonstrates writing two binary files using high-level commands:
41-
42-
.. code-block:: python
43-
44-
from esptool.cmds import detect_chip, attach_flash, reset_chip, write_flash
45-
46-
PORT = "/dev/ttyACM0"
47-
BOOTLOADER = "bootloader.bin"
48-
FIRMWARE = "firmware.bin"
49-
50-
with detect_chip(PORT) as esp:
51-
esp = esp.run_stub() # Skip this line to avoid running the stub flasher
52-
attach_flash(esp) # Attach the flash memory chip, required for flash operations
53-
with open(BOOTLOADER, "rb") as bl_file, open(FIRMWARE, "rb") as fw_file:
54-
write_flash(esp, [(0, bl_file), (0x1000, fw_file)]) # Write the binary files
55-
reset_chip(esp, "hard_reset") # Reset the chip
56-
57-
- The ``esp`` object has to be replaced with the stub flasher object returned by ``esp.run_stub()`` when the stub flasher is activated. This step can be skipped if the stub flasher is not needed.
58-
- Running ``attach_flash(esp)`` is required for any flash-memory-related operations to work.
59-
- Using the ``esp`` object in a context manager ensures the port gets closed properly after the block is executed.
60-
61-
------------
62-
63-
The following example demonstrates running a series of flash memory operations in one go:
64-
65-
.. code-block:: python
66-
67-
from esptool.cmds import (
68-
erase_flash,
69-
attach_flash,
70-
flash_id,
71-
read_flash,
72-
reset_chip,
73-
verify_flash,
74-
write_flash,
75-
)
76-
from esptool.targets import ESP32ROM # Import the target class, e.g. ESP8266ROM, ESP32S3ROM, etc.
77-
78-
PORT = "/dev/ttyACM0"
79-
BOOTLOADER = "bootloader.bin"
80-
FIRMWARE = "firmware.bin"
81-
82-
with ESP32ROM(PORT) as esp:
83-
esp.connect() # Connect to the ESP chip, needed when ESP32ROM is instantiated directly
84-
esp = esp.run_stub() # Run the stub loader (optional)
85-
attach_flash(esp) # Attach the flash memory chip, required for flash operations
86-
flash_id(esp) # Print information about the flash chip
87-
erase_flash(esp) # Erase the flash memory first
88-
with open(BOOTLOADER, "rb") as bl_file, open(FIRMWARE, "rb") as fw_file:
89-
write_flash(esp, [(0, bl_file), (0x1000, fw_file)]) # Write the binary files
90-
verify_flash(esp, [(0, bl_file), (0x1000, fw_file)]) # Verify the written data
91-
read_flash(esp, 0x0, 0x2400, "output.bin") # Read the flash memory into a file
92-
reset_chip(esp, "hard_reset") # Reset the chip
93-
94-
- 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.
95-
- Multiple operations can be chained together in a single context manager block.
96-
97-
------------
98-
99-
**The following section provides a detailed reference for the public API functions.**
100-
101-
Chip Control Operations
102-
"""""""""""""""""""""""
103-
104-
.. autofunction:: esptool.cmds.detect_chip
105-
106-
.. autofunction:: esptool.cmds.load_ram
107-
108-
.. autofunction:: esptool.cmds.run
109-
110-
.. autofunction:: esptool.cmds.reset_chip
111-
112-
------------
113-
114-
Chip Information Operations
115-
"""""""""""""""""""""""""""
116-
117-
.. autofunction:: esptool.cmds.chip_id
118-
119-
.. autofunction:: esptool.cmds.get_security_info
120-
121-
.. autofunction:: esptool.cmds.read_mac
12218
123-
------------
124-
125-
Flash Memory Manipulation Operations
126-
""""""""""""""""""""""""""""""""""""
127-
128-
.. autofunction:: esptool.cmds.attach_flash
129-
130-
.. autofunction:: esptool.cmds.flash_id
131-
132-
.. autofunction:: esptool.cmds.read_flash
133-
134-
.. autofunction:: esptool.cmds.write_flash
135-
136-
.. autofunction:: esptool.cmds.erase_flash
137-
138-
.. autofunction:: esptool.cmds.erase_region
139-
140-
.. autofunction:: esptool.cmds.verify_flash
141-
142-
.. autofunction:: esptool.cmds.read_flash_status
143-
144-
.. autofunction:: esptool.cmds.write_flash_status
145-
146-
.. autofunction:: esptool.cmds.read_flash_sfdp
147-
148-
------------
149-
150-
Memory Operations
151-
"""""""""""""""""
152-
153-
.. autofunction:: esptool.cmds.read_mem
154-
155-
.. autofunction:: esptool.cmds.write_mem
156-
157-
.. autofunction:: esptool.cmds.dump_mem
158-
159-
------------
160-
161-
Binary Image Manipulation Operations
162-
""""""""""""""""""""""""""""""""""""
163-
164-
The following commands can run without the need for a connected chip:
165-
166-
.. autofunction:: esptool.cmds.elf2image
167-
168-
.. autofunction:: esptool.cmds.merge_bin
169-
170-
.. autofunction:: esptool.cmds.image_info
171-
172-
.. autofunction:: esptool.cmds.make_image
173-
174-
------------
175-
176-
Utility Functions
177-
"""""""""""""""""
178-
179-
.. autofunction:: esptool.cmds.version
180-
181-
------------
182-
183-
For more information, refer to the command implementations in `esptool/cmds.py <https://github.com/espressif/esptool/blob/master/esptool/cmds.py>`_.
184-
185-
186-
Low-Level API Reference
187-
^^^^^^^^^^^^^^^^^^^^^^^
188-
189-
.. warning::
190-
191-
The low-level API provides more control but requires a deeper understanding of the ESP chip, the esptool internals, and the :ref:`serial protocol <serial-protocol>`. It is recommended to use the public API functions for most use cases.
192-
193-
Also, the low-level internals are not a part of the public API, so they may change in between releases.
194-
195-
Please submit a :ref:`feature request <feature-requests>` if you are missing something from the officially supported API.
19+
Using Esptool as a Python Module
20+
--------------------------------
19621

197-
For granular control and more configuration freedom, you can directly access the low-level methods and attributes of the ``ESPLoader`` object and create your own routines. The following is an example of a custom routine to flash the {IDF_TARGET_NAME}:
22+
The following is an example on how to use esptool as a Python module and leverage its Python API to flash the {IDF_TARGET_NAME}:
19823

19924
.. note::
20025

201-
This example code is a very basic implementation of ``esptool.py -p /dev/ttyACM0 write_flash 0x10000 firmware.bin``
26+
This example code functionally equivalent to ``esptool.py -p /dev/ttyACM0 write_flash 0x10000 firmware.bin``
27+
20228

20329
.. code-block:: python
20430
@@ -218,7 +44,7 @@ For granular control and more configuration freedom, you can directly access the
21844
description = esp.get_chip_description()
21945
features = esp.get_chip_features()
22046
print(f"Detected ESP on port {PORT}: {description}")
221-
print("Features:", ", ".join(features))
47+
print(f"Features: {", ".join(features)}")
22248
22349
esp = esp.run_stub()
22450
with open(BIN_FILE, 'rb') as binary:
@@ -234,15 +60,12 @@ For granular control and more configuration freedom, you can directly access the
23460
# Pad the last block
23561
block = block + bytes([0xFF]) * (esp.FLASH_WRITE_SIZE - len(block))
23662
esp.flash_block(block, i + FLASH_ADDRESS)
237-
progress_callback(i / total_size * 100)
63+
progress_callback(float(i + len(block)) / total_size * 100)
23864
esp.flash_finish()
23965
24066
# Reset the chip out of bootloader mode
24167
esp.hard_reset()
24268
243-
------------
244-
245-
For more information, refer to the methods of the ``ESPLoader`` class in `esptool/loader.py <https://github.com/espressif/esptool/blob/master/esptool/loader.py>`_.
24669
24770
.. _logging:
24871

@@ -254,7 +77,6 @@ Esptool allows redirecting output by implementing a custom logger class. This ca
25477
.. code-block:: python
25578
25679
from esptool.logger import log, TemplateLogger
257-
import sys
25880
25981
class CustomLogger(TemplateLogger):
26082
log_to_file = True
@@ -277,7 +99,7 @@ Esptool allows redirecting output by implementing a custom logger class. This ca
27799
def error(self, message):
278100
self.print(message, file=sys.stderr)
279101
280-
def print_overwrite(self, message, last_line=False):
102+
def print_overwrite(self, message, last_line):
281103
# Overwriting not needed, print normally
282104
self.print(message)
283105
@@ -302,8 +124,4 @@ To ensure compatibility with esptool, the custom logger should re-implement (or
302124
- ``print_overwrite``: Handles message overwriting (can be a simple ``print()`` if overwriting is not needed).
303125
- ``set_progress``: Handles percentage updates of long-running operations - ``write_flash``, ``read_flash``, and ``dump_mem`` (useful for GUI visualisation, e.g. as a progress bar).
304126

305-
.. autoclass:: esptool.logger.EsptoolLogger
306-
:members: print, note, warning, error, print_overwrite, set_progress
307-
:member-order: bysource
308-
309127
These methods are essential for maintaining proper integration and behavior with esptool. Additionally, all calls to the logger should be made using ``log.print()`` (or the respective method, such as ``log.info()`` or ``log.warning()``) instead of the standard ``print()`` function to ensure the output is routed through the custom logger. This ensures consistency and allows the custom logger to handle all output appropriately. You can further customize this logger to fit your application's needs, such as integrating with GUI components or advanced logging frameworks.

docs/en/index.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ The flasher stub is a small program included with esptool that replaces the orig
1212
* Prepare binary executable images ready for flashing.
1313
* Analyze, assemble, and merge binary images.
1414

15-
``esptool.py`` can be used both as a command-line tool and as a Python library. The command-line is the most common way to use the tool, and is the primary focus of this documentation. To use it as a library, see the :ref:`scripting <scripting>` section.
16-
1715
This document describes using ``esptool.py`` with the {IDF_TARGET_NAME} SoC. To switch to a different SoC target, choose target from the dropdown in the upper left.
1816

1917
Quick Start

0 commit comments

Comments
 (0)