Skip to content

Commit c7f85b5

Browse files
Blogpost: Esptool v5 updates (#453)
Co-authored-by: Radim Karniš <[email protected]>
1 parent 0d2c909 commit c7f85b5

File tree

8 files changed

+142
-0
lines changed

8 files changed

+142
-0
lines changed
38.4 KB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: Radim Karniš
3+
---
81.6 KB
Loading
218 KB
Loading
186 KB
Loading

content/blog/esptool-v5/index.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
title: "esptool: Updates about the upcoming v5 major release"
3+
date: 2025-04-01T12:05:21+01:00
4+
showAuthor: False
5+
authors:
6+
- "radim-karnis"
7+
tags: ["esptool", "tools"]
8+
summary: "esptool v5, currently under development by Espressif, boosts its new public API and customizable logging capabilities for developers. The new version brings enhancements for users as well. Contributions are welcome, preview out now."
9+
---
10+
11+
## Introduction
12+
13+
[esptool](https://github.com/espressif/esptool) is Espressif's versatile command-line utility and Python library that serves as a Swiss Army knife for ESP chips. If you're flashing any of the ESP8266 or ESP32-series SoCs, you're likely already using `esptool` under the hood of a framework or IDE, even without realizing it.
14+
15+
This tool provides developers with everything needed to:
16+
17+
- Read, write, erase, and verify binary firmware data.
18+
- Manipulate ROM memory and registers.
19+
- Fetch chip information (MAC, flash chip info, security info, eFuses).
20+
- Convert, analyze, assemble, and merge binary executable images.
21+
- Perform chip diagnostics and provisioning (including secure boot and flash encryption).
22+
23+
You can learn more about `esptool` and how to use it in its [documentation](https://docs.espressif.com/projects/esptool/).
24+
25+
`esptool`'s next evolutionary step is the upcoming `v5` major release, which is currently being developed in the [repository master branch](https://github.com/espressif/esptool). It will bring significant improvements for both developers and users.
26+
27+
{{< alert icon="circle-info" cardColor="#b3e0f2" iconColor="#04a5e5">}}
28+
`esptool` `v5` is still under active development, with a planned release in **May 2025**.
29+
{{< /alert >}}
30+
31+
When released, it will first be available in the `ESP-IDF` `v6` major release, with adoption by Arduino and other frameworks to follow.
32+
33+
A [migration guide](https://docs.espressif.com/projects/esptool/en/latest/migration-guide.html) is provided to help users transition from `v4` when the stable release arrives. In the meantime, adventurous users can try a preview by installing the development version:
34+
35+
```bash
36+
pip install esptool~=5.0.dev0
37+
```
38+
39+
## Updates for developers
40+
41+
Until now, `esptool` was primarily a command-line tool with limited Python integration. While powerful when used manually, its convoluted structure made embedding esptool into scripts or applications cumbersome. Developers often resorted to subprocess calls or workarounds, sacrificing reliability and flexibility.
42+
43+
With `v5`, this changes. The new public API transforms esptool into a true library, enabling:
44+
45+
- **Direct programmatic control** – No more CLI wrapping or output parsing.
46+
- **Structured workflows** – Chain operations like `backup flash` -> `erase flash` -> `write flash` -> `verify flash` in one session.
47+
- **Type-safe API** – Auto-completion and error checking in IDEs.
48+
- **Customizable logging** – Integrate output with GUIs or logging systems.
49+
50+
`esptool` `v5` introduces enhancements for developers who need to integrate ESP chip programming into their Python applications. The new public API provides both high-level convenience functions and low-level control, while the customizable logging enables integration with GUIs and automated systems. Let's have a look at the new features!
51+
52+
### Public API
53+
54+
A set of high-level functions that encapsulate common operations and simplify the interaction with the ESP chip is now introduced as a public API. 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.
55+
56+
For most use cases, the `esptool.cmds` module offers simplified access to common operations. The following example demonstrates a chained workflow that would otherwise require 5 individual runs of `esptool` on the command line:
57+
58+
```python
59+
from esptool.cmds import (
60+
attach_flash, detect_chip, erase_flash, flash_id, read_flash,
61+
reset_chip, run_stub, verify_flash, write_flash
62+
)
63+
64+
PORT = "/dev/ttyUSB0"
65+
BOOTLOADER = "bootloader.bin"
66+
FIRMWARE = "firmware.bin"
67+
68+
with detect_chip(PORT) as esp:
69+
esp = run_stub(esp) # Upload and run the stub flasher (optional)
70+
attach_flash(esp) # Attach the flash memory chip, required for flash operations
71+
flash_id(esp) # Print information about the flash chip
72+
read_flash(esp, 0x0, 0x8000, "bl_backup.bin") # Backup the loaded bootloader
73+
erase_flash(esp) # Erase the flash memory
74+
write_flash(esp, [(0, BOOTLOADER), (0x10000, FIRMWARE)]) # Write binary data
75+
verify_flash(esp, [(0, BOOTLOADER), (0x10000, FIRMWARE)]) # Verify written data
76+
reset_chip(esp, "hard_reset") # Reset the chip and execute the loaded app
77+
```
78+
79+
Key features of the Public API:
80+
81+
- Context manager support for automatic resource cleanup.
82+
- Flexible input types (file paths, bytes, or file-like objects).
83+
- Multiple operations can be chained together as long as an `esp` object exists.
84+
85+
For full instructions and detailed API reference, please see the [related documentation](https://docs.espressif.com/projects/esptool/en/latest/esptool/scripting.html).
86+
87+
### Custom logger integration
88+
89+
`esptool` `v5` introduces a flexible logging system that replaces the previous hardcoded console output. It allows redirecting output by implementing a custom logger class. This can be useful when integrating `esptool` with graphical user interfaces or other systems where the default console output is not appropriate.
90+
91+
By extending or re-implementing the `esptool` logger you can achieve:
92+
- Output redirection to any system (GUI, web, log files).
93+
- Progress reporting hooks for visual feedback (e.g., GUI progress bars filling up during long operations).
94+
95+
For an example of a custom logger class and its specifics, please see the [related documentation](https://docs.espressif.com/projects/esptool/en/latest/esptool/scripting.html#redirecting-output-with-a-custom-logger).
96+
97+
## Updates for users
98+
99+
While the developer-focused improvements in `esptool` `v5` are substantial, users relying on the command-line interface will also benefit from a more polished and user-friendly experience. Here’s what’s in store:
100+
101+
- **Colored and re-imagined output** - The command-line interface now features colored output with indentation to make it easier to use the tool and distinguish between informational messages, warnings, and errors at a glance.
102+
103+
{{< figure
104+
default=true
105+
src="colored-output.webp"
106+
>}}
107+
108+
- **Collapsing output stages** - Long operations like flashing or verifying large binaries used to flood the terminal with repetitive status updates. With collapsing output stages, logs are condensed into concise, single-line summaries that update in place when a given operation successfully finishes.
109+
110+
{{< figure
111+
default=true
112+
src="folding-stage.webp"
113+
>}}
114+
115+
- **More Error Messages and Bug Fixes** - More edge cases are now covered with meaningful notes, warnings, or error messages.
116+
- **Progress Bars** - To provide better visual feedback, ASCII progress bars are introduced for time-consuming tasks like reading or writing flash memory.
117+
118+
{{< figure
119+
default=true
120+
src="warnings-progress.webp"
121+
>}}
122+
123+
- **`espefuse` and `espsecure` improvements** - All of the listed improvements are also happening in the bundled tools for eFuse manipulation (`espefuse`) and flash encryption / secure boot management (`espsecure`).
124+
125+
- The team at Espressif is working hard to polish the mentioned features and to add new ones. Some of the new planned updates include a clean rewrite of the flasher stub and fast-reflashing capabilities (uploading only the changed parts of firmware, instead of the whole binary), among other enhancements.
126+
127+
## Call for contributions
128+
129+
We’re actively seeking contributors to help shape `esptool` `v5`. Whether you’re a developer interested in IDE integrations, a CI/CD expert who can test automation workflows, or a maintainer for less-common platforms, your skills are welcome! To get involved, check out the [esptool GitHub repository](https://github.com/espressif/esptool), and feel free to report issues, suggest features, or submit pull requests.
86.7 KB
Loading

data/authors/radim-karnis.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "Radim Karniš",
3+
"bio": "Software Engineer at Espressif Systems",
4+
"image": "img/authors/radim-karnis.webp",
5+
"social": [
6+
{ "github": "https://github.com/radimkarnis" },
7+
{ "linkedin": "https://www.linkedin.com/in/radim-karnis/" },
8+
{ "twitter": "https://twitter.com/RadimKarnis" }
9+
]
10+
}

0 commit comments

Comments
 (0)