Skip to content

Commit 47198e3

Browse files
authored
V5.1.0
2 parents b887723 + ea35a1c commit 47198e3

File tree

102 files changed

+1730
-816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1730
-816
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ b57f69bd13222b1753446a0f7c17386eda1dc2c9
1616

1717
# Fixing linter issues
1818
2e4e77cde269379f3aba2e1344c912f47c5974de
19+
20+
# ruff pyupgrade refactoring
21+
206970acf821635dbf9adfba99537ac420fef4d2

.github/copilot-instructions.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Copilot Instructions for esptool
2+
3+
This document provides essential information for coding agents working on the esptool repository to minimize exploration time and avoid common pitfalls.
4+
5+
## Repository Overview
6+
7+
**What esptool does:** esptool is a Python-based, open-source, platform-independent serial utility for flashing, provisioning, and interacting with Espressif SoCs (ESP32, ESP8266, and variants). It provides four main command-line tools:
8+
- `esptool.py` - Main flashing and chip interaction tool
9+
- `espefuse.py` - eFuse (one-time programmable memory) management
10+
- `espsecure.py` - Security-related operations (signing, encryption)
11+
- `esp_rfc2217_server.py` - RFC2217 serial-over-TCP server
12+
13+
**Project type:** Python 3.10+ package with console entry points, using setuptools build system and Click/rich_click for CLI interfaces. Supports ESP32, ESP32-S2, ESP32-S3, ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-H2, ESP32-P4, ESP8266, and other Espressif chips.
14+
15+
**Repository size:** ~200 files, primarily Python code with some binary stub flasher files and YAML configuration files.
16+
17+
## Build and Development Setup
18+
19+
### Essential Commands (always run in this order)
20+
21+
1. **Install dependencies:**
22+
```bash
23+
python -m pip install --upgrade pip
24+
pip install 'setuptools>=64'
25+
pip install --extra-index-url https://dl.espressif.com/pypi -e .[dev]
26+
```
27+
**Critical:** Always use the extra index URL for Espressif-specific packages. Installation may take 2-3 minutes due to cryptography compilation.
28+
29+
2. **Build the project:**
30+
```bash
31+
python setup.py build
32+
```
33+
This creates build/ directory with compiled Python packages.
34+
35+
3. **Verify installation works:**
36+
```bash
37+
esptool.py --help
38+
espefuse.py --help
39+
espsecure.py --help
40+
esp_rfc2217_server.py --help
41+
```
42+
43+
### Testing
44+
45+
**Quick host-based tests (no hardware required, ~2-3 minutes):**
46+
```bash
47+
pytest -m host_test
48+
```
49+
This runs: test_imagegen.py, test_image_info.py, test_mergebin.py, test_modules.py, test_espsecure.py
50+
51+
**HSM tests (requires SoftHSM2 setup):**
52+
```bash
53+
pytest test/test_espsecure_hsm.py
54+
```
55+
56+
**Virtual eFuse tests (safe, no real hardware affected):**
57+
```bash
58+
pytest test_espefuse.py --chip esp32
59+
```
60+
61+
**Hardware tests (requires real ESP devices, NOT safe for CI):**
62+
```bash
63+
pytest test_esptool.py --port /dev/ttyUSB0 --chip esp32 --baud 230400
64+
```
65+
66+
### Code Quality and Pre-commit
67+
68+
**Install pre-commit hooks:**
69+
```bash
70+
pip install pre-commit
71+
pre-commit install -t pre-commit -t commit-msg
72+
```
73+
74+
**Run all checks:**
75+
```bash
76+
pre-commit run --all-files
77+
```
78+
79+
**Individual checks:**
80+
- `python -m ruff check .` - Linting (replaces flake8)
81+
- `python -m ruff format .` - Code formatting (replaces black)
82+
- `python -m mypy esptool/ espefuse/ espsecure/` - Type checking
83+
84+
## Project Architecture and Layout
85+
86+
### Key Directories
87+
- **Root scripts** (`esptool.py`, `espefuse.py`, etc.) - Thin wrapper scripts for backward compatibility
88+
- **`esptool/`** - Main flashing tool package
89+
- `targets/` - Chip-specific implementations (ESP32, ESP8266, etc.)
90+
- `targets/stub_flasher/1/` and `targets/stub_flasher/2/` - Binary flasher stubs for each chip (JSON format)
91+
- `cmds.py` - Command implementations
92+
- `loader.py` - Core chip communication logic
93+
- **`espefuse/`** - eFuse management tool
94+
- `efuse/` - Chip-specific eFuse definitions
95+
- `efuse_defs/` - YAML eFuse definition files
96+
- **`espsecure/`** - Security operations tool
97+
- **`test/`** - Comprehensive test suite
98+
- `images/` - Test firmware images and binaries
99+
- `elf2image/` - ELF to image conversion test cases
100+
- **`ci/`** - CI/CD scripts and helpers
101+
- **`docs/`** - Sphinx documentation
102+
103+
### Configuration Files
104+
- **`pyproject.toml`** - Main project configuration (dependencies, build system, tool settings)
105+
- **`.pre-commit-config.yaml`** - Pre-commit hook configuration
106+
- **`.github/workflows/`** - GitHub Actions CI workflows
107+
- **`.gitlab-ci.yml`** - GitLab CI configuration
108+
109+
### Dependencies
110+
**Runtime:** bitstring, cryptography>=43.0.0, pyserial>=3.3, reedsolo, PyYAML, intelhex, rich_click, click<9
111+
**Development:** pyelftools, coverage, pre-commit, pytest, pytest-rerunfailures, requests, czespressif
112+
113+
## Validation and CI/CD
114+
115+
### GitHub Actions Workflows
116+
- **`test_esptool.yml`** - Main test suite (Python 3.10-3.13 matrix, host tests, pre-commit)
117+
- **`build_esptool.yml`** - Build binaries for multiple platforms
118+
- **`dangerjs.yml`** - PR review automation
119+
120+
### Pre-commit Checks (must pass for PR acceptance)
121+
1. **ruff** - Python linting and formatting
122+
2. **mypy** - Type checking (excludes wrapper scripts)
123+
3. **sphinx-lint** - Documentation linting
124+
4. **codespell** - Spell checking
125+
5. **conventional-precommit-linter** - Commit message format validation
126+
127+
### Common Build Issues and Solutions
128+
- **Network timeouts during pip install:** Use `--timeout 300` flag or retry. The Espressif PyPI index (https://dl.espressif.com/pypi) may be slow.
129+
- **Missing cryptography:** Ensure you have build tools installed (`apt-get install build-essential` on Ubuntu)
130+
- **Import errors:** Always install with `-e .[dev]` for development work
131+
- **Test failures on first run:** Some tests download flasher stubs; retry if network issues occur
132+
- **ModuleNotFoundError for rich_click:** Means dependencies aren't installed; run pip install command above
133+
- **SoftHSM2 errors:** For HSM tests, run `./ci/setup_softhsm2.sh` after installing softhsm2 package
134+
135+
## Code Style and Standards
136+
137+
- **Line length:** 88 characters (Black style)
138+
- **Linting:** ruff (configured in pyproject.toml)
139+
- **Formatting:** ruff format (replaces black)
140+
- **Type hints:** mypy checking enabled (partial coverage)
141+
- **Commit messages:** Conventional Commits format required
142+
143+
## Hardware Testing Notes
144+
145+
**NEVER run hardware tests in CI or on unknown devices.** Hardware tests can:
146+
- Erase flash memory permanently
147+
- Modify eFuses (one-time programmable, irreversible)
148+
- Brick devices if interrupted
149+
150+
Only use `test_esptool.py` and `test_esptool_sdm.py` on dedicated test hardware with explicit `--port`, `--chip`, and `--baud` parameters.
151+
152+
## Performance Considerations
153+
154+
- **esptool operations:** Can take 10-60 seconds for large flash operations
155+
- **cryptography compilation:** 2-3 minutes during initial pip install
156+
- **Host tests:** ~2-3 minutes total runtime
157+
- **Build process:** ~30 seconds for clean build
158+
159+
## Environment Variables
160+
161+
esptool recognizes these environment variables for default behavior:
162+
- **`ESPTOOL_CHIP`** - Default chip type (auto, esp32, esp8266, etc.)
163+
- **`ESPTOOL_PORT`** - Default serial port
164+
- **`ESPTOOL_BAUD`** - Default baud rate
165+
- **`ESPTOOL_FF`** - Default flash frequency
166+
- **`ESPTOOL_FM`** - Default flash mode
167+
- **`ESPTOOL_FS`** - Default flash size
168+
- **`ESPTOOL_BEFORE`** - Default reset mode before operation
169+
- **`ESPTOOL_AFTER`** - Default reset mode after operation
170+
171+
For testing:
172+
- **`ESPTOOL_TEST_USB_OTG`** - Enable USB OTG testing mode
173+
- **`ESPTOOL_TEST_FLASH_SIZE`** - Minimum flash size for large flash tests
174+
175+
## Trust These Instructions
176+
177+
These instructions are current as of the repository state and have been validated against the actual build system, CI/CD workflows, and documentation. Only search for additional information if:
178+
1. Commands fail with errors not covered here
179+
2. You need chip-specific information not in the targets/ directory
180+
3. You encounter new hardware or features not documented
181+
182+
For chip-specific behavior, always check `esptool/targets/` directory first before searching elsewhere.

.github/workflows/test_esptool.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,3 @@ jobs:
6666
run: |
6767
./ci/download_flasher_stubs.py
6868
git diff --exit-code
69-
70-
lint_esptool:
71-
runs-on: ubuntu-22.04
72-
steps:
73-
- name: Checkout
74-
uses: actions/checkout@master
75-
76-
- name: Set up Python 3.10
77-
uses: actions/setup-python@master
78-
with:
79-
python-version: "3.10"
80-
81-
- name: Run pre-commit hooks
82-
run: |
83-
pip install --extra-index-url https://dl.espressif.com/pypi -e .[dev]
84-
pre-commit run --all-files

.gitlab-ci.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,15 @@ target_esp32c5:
438438
script:
439439
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32C5 --chip esp32c5 --baud 115200
440440

441+
target_esp32c5_32mb:
442+
extends: .target_esptool_test
443+
tags:
444+
- esptool_esp32c5_32mb_target
445+
variables:
446+
ESPTOOL_TEST_FLASH_SIZE: "32"
447+
script:
448+
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32C5_32MB --chip esp32c5 --baud 115200
449+
441450
# ESP32C61
442451
target_esp32c61:
443452
extends: .target_esptool_test
@@ -516,7 +525,7 @@ combine_reports:
516525

517526
build_docs:
518527
stage: build_docs
519-
image: python:3.12-bookworm # 3.12 is the last version with imghdr
528+
image: python:3.13-bookworm
520529
tags:
521530
- build_docs
522531
rules:
@@ -540,7 +549,7 @@ build_docs:
540549

541550
.deploy_docs_template:
542551
stage: deploy_docs
543-
image: python:3.12-bookworm # 3.12 is the last version with imghdr
552+
image: python:3.13-bookworm
544553
tags:
545554
- deploy
546555
needs:

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
ci:
2+
autofix_commit_msg: |
3+
Apply automatic fixes from pre-commit hooks
4+
autofix_prs: true
5+
autoupdate_commit_msg: 'ci: Bump pre-commit hooks'
6+
autoupdate_schedule: quarterly
7+
18
repos:
29
- repo: https://github.com/astral-sh/ruff-pre-commit
310
rev: v0.9.6
@@ -31,5 +38,6 @@ repos:
3138
stages: [commit-msg]
3239
args:
3340
- --allow-breaking
41+
3442
default_stages: [pre-commit]
3543
default_install_hook_types: [pre-commit, commit-msg]

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,46 @@
2020
</div>
2121
<hr>
2222

23+
## v5.1.0 (2025-09-15)
24+
25+
### ✨ New Features
26+
27+
- **espefuse**: Support ESP32-P4 ECO5 (v3.0) *(Konstantin Kondrashov - 40f103c)*
28+
- **esp32p4**: Add support for ESP32-P4.ECO5 *(Jaroslav Safka - 6c10050)*
29+
- **esp32c5**: Add support for >16 MB flash sizes *(Roland Dobai - 8e2b94e)*
30+
- **espefuse**: Add custom key purposes for ESP32C6/C5/P4 *(Konstantin Kondrashov - c6ce0bc)*
31+
- **espefuse**: Support burning ECDSA_384 keys *(Konstantin Kondrashov - 4a9a3d8)*
32+
- **espefuse**: Clean up limitation for BLOCK9 usage *(Konstantin Kondrashov - d63e3db)*
33+
- **espefuse**: Adds support for burning 512-bit keys for C5 *(Konstantin Kondrashov - 468de5c)*
34+
35+
### 🐛 Bug Fixes
36+
37+
- **espefuse**: Update CLI to support rich-click 1.9.0 *(Peter Dragun - 2ae5535)*
38+
- **espsecure**: Fix printing key digest in signature info *(Radim Karniš - 7e53596)*
39+
- **espefuse**: Fixes re-connection issue in check-error via UJS port *(Konstantin Kondrashov - a160468)*
40+
- **write_flash**: Make write flash mem independent *(Jaroslav Safka - d19413c)*
41+
- **elf2image**: Handle ELF files with zero program header counts *(Tormod Volden - d27ce37)*
42+
- **espsecure**: Extract public key version 1 in RAW format *(Peter Dragun - 6cfced8)*
43+
- **espsecure**: Allow signing multiple files in one go *(Peter Dragun - 0177d61)*
44+
- **elf2image**: Fix --pad-to-size argument parsing *(Peter Dragun - 66a1377)*
45+
- **espefuse**: Disable programming and usage of XTS-AES-256 efuse key for ESP32-C5 *(harshal.patil - c85a93d)*
46+
- **esp32c5**: Erase during flashing above 16MB *(Jaroslav Burian - d65a24e)*
47+
- **espsecure**: Add support for python-pkcs11 9.0+ *(Peter Dragun - 3ea646f)*
48+
- Use correct error codes for ROM errors *(Jaroslav Burian - da4346b)*
49+
- Handle deprecated options with "=" before value *(Peter Dragun - f05fb62)*
50+
- stop exit 0 when being called programmatically *(Fu Hanxi - d8ae230)*
51+
52+
### 📖 Documentation
53+
54+
- **set_flash_voltage**: Disable for non-related chips *(Radim Karniš - cd2c98e)*
55+
- bump up esp_docs to 2.1 *(Jaroslav Safka - bb8cd9b)*
56+
- Add chip type detection explanation *(Jaroslav Safka - 528f605)*
57+
58+
### 🔧 Code Refactoring
59+
60+
- set up and apply pyupgrade ruff rules *(copilot-swe-agent[bot] - 206970a)*
61+
62+
2363
## v5.0.2 (2025-07-30)
2464

2565
### 🐛 Bug Fixes

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
A Python-based, open-source, platform-independent serial utility for flashing, provisioning, and interacting with Espressif SoCs.
44

55
[![Test esptool](https://github.com/espressif/esptool/actions/workflows/test_esptool.yml/badge.svg?branch=master)](https://github.com/espressif/esptool/actions/workflows/test_esptool.yml) [![Build esptool](https://github.com/espressif/esptool/actions/workflows/build_esptool.yml/badge.svg?branch=master)](https://github.com/espressif/esptool/actions/workflows/build_esptool.yml)
6+
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/espressif/esptool/master.svg)](https://results.pre-commit.ci/latest/github/espressif/esptool/master)
67

78
## Documentation
89

ci/download_flasher_stubs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"STUB_SET_VERSION": "1",
1313
"DOWNLOAD_URL": "https://github.com/espressif/esptool-legacy-flasher-stub/releases/download",
1414
"TAG_URL": "https://github.com/espressif/esptool-legacy-flasher-stub/releases/tag",
15-
"VERSION": "v1.6.0",
15+
"VERSION": "v1.8.0",
1616
"FILE_LIST": (
1717
"esp32",
1818
"esp32c2",
@@ -21,6 +21,7 @@
2121
"esp32c6",
2222
"esp32c61",
2323
"esp32h2",
24+
"esp32p4rc1",
2425
"esp32p4",
2526
"esp32s2",
2627
"esp32s3",

ci/patch_dev_release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def patch_file(path, new_version):
1313
assert ".dev" in new_version
1414
new_version = new_version.lstrip("v")
1515

16-
with open(path, "r") as fin:
16+
with open(path) as fin:
1717
lines = fin.readlines()
1818

1919
for i, line in enumerate(lines, start=0):
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
blockdiag chip_type_detection_chart {
2+
node_height = 40;
3+
node_width = 150;
4+
span_width = 40;
5+
span_height = 45;
6+
default_fontsize = 12
7+
orientation = portrait;
8+
edge_layout = flowchart;
9+
default_group_color = none;
10+
11+
// nodes
12+
start [label = "Start", shape = flowchart.terminator];
13+
get_chip_id [label = "get chip-id by\nget-security-info", shape = box];
14+
id_success_cond [label = "Success?", shape = flowchart.condition];
15+
reg_success_cond [label = "Success?", shape = flowchart.condition];
16+
find_by_id [label = "Find ID in list", shape = box];
17+
18+
get_magic_reg [label = "Read magic register", shape = box];
19+
find_by_reg [label = "Find magic number\nin list", shape = box];
20+
21+
try_esp32s2 [label = "detected ESP32-S2\nin SDM", shape = box];
22+
23+
finish [label = "Finish", shape = flowchart.terminator];
24+
25+
// edges
26+
start -> get_chip_id -> id_success_cond;
27+
id_success_cond -> find_by_id [label = "Yes"];
28+
find_by_id -> finish;
29+
30+
id_success_cond -> get_magic_reg [label = "No"];
31+
get_magic_reg -> reg_success_cond;
32+
reg_success_cond -> find_by_reg [label = "Yes"];
33+
find_by_reg -> finish;
34+
reg_success_cond -> try_esp32s2 [label = "No"];
35+
36+
try_esp32s2 -> finish
37+
}

0 commit comments

Comments
 (0)