ESP Flasher Stub is a set of small firmware programs (stubs) that run on Espressif ESP chips to enable fast and reliable flash programming via esptool and esp-serial-flasher. When esptool connects to an ESP chip, it uploads the flasher stub into the chip's RAM. The stub then takes over communication, providing faster flash operations and additional features compared to the chip's built-in ROM bootloader.
This project has replaced the deprecated legacy flasher stub of esptool and is the default flasher stub since esptool v5.3.
- Architecture - Firmware architecture, source code structure, modules, and build system internals
- Development Guide - Contributing guidelines, testing, CI/CD, and release process
- Plugin System - Runtime-loadable plugin architecture and guide for adding new plugins
- NAND Flash Support - NAND flash programming support (preview)
- SPI Transport - SPI slave transport plugin for esp-serial-flasher
- SDIO Transport - SDIO transport plugin
| Architecture | Chips |
|---|---|
| Xtensa | ESP32, ESP32-S2, ESP32-S3 |
| RISC-V | ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61, ESP32-H2, ESP32-H21, ESP32-H4, ESP32-P4, ESP32-P4 (rev1), ESP32-S31 |
| Xtensa (LX106) | ESP8266 |
The pre-built regular stub JSON files are available from two sources:
- GitHub Releases – Download the JSON files for all supported chips from the releases page.
- npm – Install the
esp-flasher-stubpackage for use in JavaScript/TypeScript projects.
The project depends on esp-stub-lib as a git submodule. Make sure to initialize it before building:
git submodule update --init --recursive
The following toolchains must be set up and available in your PATH:
There is a convenience script for AMD64 Linux machines to download and install them into the toolchains directory:
mkdir -p toolchains
cd toolchains
../tools/setup_toolchains.shThen source the export script in every terminal where the project is used:
. ./tools/export_toolchains.shpyelftools is needed for ELF file analysis. Install it in a virtual environment:
python -m venv venv
source venv/bin/activate
pip install pyelftoolsActivate the virtual environment in every terminal where the project is used:
source venv/bin/activateNote
Target tests only: Running or building the target tests in unittests/target/ additionally
requires esptool (pip install esptool). It is used
to convert compiled ELF files to loadable binaries (elf2image) and to upload them to hardware
(load_ram). Host tests (unittests/host/) have no esptool dependency.
mkdir -p build cmake . -B build -G Ninja -DTARGET_CHIP=esp32s2 # Replace with your desired chip, e.g. esp32, esp8266 ninja -C build
./tools/build_all_chips.sh
The SPI transport lets esp-serial-flasher talk to the stub over the SPI download interface. It is a transport plugin, so the stub carries its code only when the host loads it. The regular build embeds it in <target>.json for every chip that supports it; no build option is needed.
The SDIO transport lets a host talk to the stub over the SDIO download interface. Like SPI, it is a transport plugin that the regular build embeds in <target>.json for ESP32-C5, ESP32-C6 and ESP32-C61.
-
Install the latest esptool from the
masterbranch as described in Testing the Latest Code. -
Obtain the flasher stub binaries as JSON files either from the releases page or from the artifacts of your pull request.
-
Replace the esptool JSON files in the
esptool/targets/stub_flasherdirectory with the obtained JSON files.Example copy command (adjust the path to your esptool directory):
cp build-*/*.json ~/esptool/esptool/targets/stub_flasher/2/
The flasher stub operates through upload, initialization, handshake (OHAI over the selected transport), and a command loop that handles flash, memory, register, and SPI operations. UART and USB transports use SLIP framing; SDIO and SPI use raw command frames. For details, see the Architecture document.
Read the Contributing section of the Development Guide before you open an issue or a pull request.
See the Releasing section of the Development Guide.
This document and the attached source code are released as Free Software under either the Apache License Version 2 or MIT License at your option.