161.22. espflash-4.6.0
Flash an ESP32 or ESP8266 over its own ROM bootloader, and watch its serial output
| Version | 4.6.0, release 1 |
| Shelf | embedded — Microcontroller and bare-metal development: cross toolchains, C libraries, flashers, debug probes and serial consoles |
| Phase | 41_system (System), 481 of 1047 in build order |
| Licence | MIT OR Apache-2.0 |
| Homepage | https://github.com/esp-rs/espflash |
| Build time | 3.5 SBU |
| Installed size | 16.5 MiB in 3 files |
| Recipe | ports/core/embedded/espflash/kpkgbuild |
About
espflash is the esp-rs project’s flasher for Espressif chips, written in Rust: one program that drives the ROM bootloader of an ESP32-family chip over its USB serial port to write an application ELF or a binary into the chip’s flash, read and erase flash, and convert partition tables, and its monitor shows the device’s serial output. It reaches the same bootloader as Espressif’s Python reference tool, python3-esptool, without its Python dependencies. Three kinds of code for the chip are compiled into the program as the source publishes them: the flasher stubs it uploads into the chip’s RAM to speed up writing, the second-stage bootloaders it writes ahead of an application, and the ROM ELF files monitor resolves backtrace addresses against; see What is built from source.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/embedded.txt:
The bootloader route for an ESP32 or ESP8266. Espressif's own esptool is the reference and is python reaching
cryptography— seven new python ports and a compiled crypto stack to write a binary down a serial line; espflash is Espressif's Rust flasher, one binary, driving the same ROM bootloader.
Sources
espflash-4.6.0.tar.gz(17.8 MiB)
sha2564d6fd3b57e7fc33480df9e4db403352632a3d8af486ed2721a8f5ab3c666195e
upstream: https://github.com/esp-rs/espflash/archive/refs/tags/v4.6.0.tar.gz
archive copy: sources-2/embedded--espflash-4.6.0.tar.gzespflash-vendor-4.6.0.tar.xz(31.5 MiB)
sha256209d8fbd41ffc804aa83013064e2fa27e7b49cc1466fe40fbcde42925c91f5cc
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-2/embedded--espflash-vendor-4.6.0.tar.xz
Dependencies
Depends on: rust.
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install espflash'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/embedded/espflash.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/embedded/espflash
echo '4d6fd3b57e7fc33480df9e4db403352632a3d8af486ed2721a8f5ab3c666195e espflash-4.6.0.tar.gz' | sha256sum -c -
echo '209d8fbd41ffc804aa83013064e2fa27e7b49cc1466fe40fbcde42925c91f5cc espflash-vendor-4.6.0.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/espflash
SRC=$SRC_ROOT/espflash-4.6.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf espflash-4.6.0.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz
export CARGO_HOME="$SRC_ROOT/.cargo"
export RUSTFLAGS="-C target-feature=-crt-static"
export CARGO_NET_OFFLINE=true
cargo build --release --frozen --offline --bin espflash
install -Dm755 target/release/espflash $PKG/usr/bin/espflash
The switches, and why each is set:
--bin espflash— Builds only theespflashprogram from upstream’s workspace, which also holdscargo-espflash, the same tool as a cargo subcommand for flashing a Rust project, andxtask, upstream’s own maintenance tasks.CARGO_NET_OFFLINE=true— Cargo’s environment form ofnet.offline, the same as--offlineon the command line.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/espflash, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf espflash-4.6.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/espflash, and runs the triggers its paths call for.
Contents
Installed programs: espflash.
Installed directories: /usr/share/licenses/espflash.
Notes
This release supports the ESP32 and its C, H, P and S series, and not the ESP8266, which python3-esptool flashes. The serial port is opened through the serialport crate with its default features off, so no libudev is linked. The kdos user reaches USB serial adapters through the dialout group, which fs/etc/udev/rules.d/70-kdos-serial.rules gives each one.