$ uname -a A_BLOG_ABOUT_UNIX_TOOLS_AND_THE_BEAUTY_OF_SIMPLE_SYSTEMS
SYS.YEAR  2026
← Back to articles
2026-09-10ARTICLE

Esp Hal Webfs

WebFS — USB-provisioned ESP32-C3 blog

Native FreeBSD Rust firmware serves immutable files with GET and HEAD only. There is no network publisher, update key, OTA endpoint or writable filesystem. HTTP remains a LAN prototype; removing publishing does not make it Internet-safe.

Build

The checkout /home/wongk/esp32c3-webfs is mounted as /project in the esp32c3 jail. Keep the separate Linux jail and ZFS keyserver environment intact.

doas bastille start esp32c3  # only if stopped
doas jexec esp32c3 sh /project/scripts/build-freebsd.sh

The script uses fresh private build directories, locked native Rust dependencies, and the riscv32imc-unknown-none-elf target. It runs host tests before packaging. Wi-Fi credentials are embedded from firmware/secrets/config.json (mode 600). The old update.key is no longer read or embedded; any existing copy is retained and ignored. Configured binaries and full-flash backups still contain Wi-Fi secrets.

Outputs inside the jail at /build/artifacts are visible on the host at /usr/local/bastille/jails/esp32c3/root/build/artifacts:

  • firmware.bin: merged bootloader, partition table and app; flash at 0.
  • webfs-blog.elf: application executable.
  • mkwebfs: native packer and image validator.
  • site.wfs: example site. Select your blog explicitly instead when flashing.

Pack and provision

Pack only the static generator's public output, never private source files.

doas /usr/local/bastille/jails/esp32c3/root/build/artifacts/mkwebfs \
  /path/to/public -b 8 -o /tmp/blog.wfs
doas /usr/local/bastille/jails/esp32c3/root/build/artifacts/mkwebfs \
  --check /tmp/blog.wfs

The single WebFS partition starts at 0x1e0000 and spans 0x220000 bytes (2,228,224 bytes / 2,176 KiB), ending exactly at 4 MiB. It replaces both slots, the journal and unused tail. The WebFS v2 file format remains compatible.

Stop serial readers and identify the board before flashing. /dev/cuaU1 was verified as ESP32-C3 revision 0.4, MAC 90:70:69:ad:77:f4; rediscover after USB changes.

doas usbconfig
doas stty -f /dev/cuaU1.init raw -hupcl 115200
doas esptool --chip esp32c3 -p /dev/cuaU1 chip-id
cd /home/wongk/esp32c3-webfs
doas sh scripts/flash-freebsd.sh /dev/cuaU1 \
  /usr/local/bastille/jails/esp32c3/root/build/artifacts \
  /home/wongk/esp32c3-webfs/artifacts/blog.wfs

The third argument selects a site; omitting it selects the example site.wfs. The script validates the image before writing, backs up all 4 MiB privately, erases the WebFS region, writes firmware at 0 and the site at 0x1e0000, verifies both and resets. Content changes now require USB/serial and an intentional outage. Interrupted provisioning requires reflashing from the retained image/backup; there is no transactional journal. scripts/publish.py and sequences are removed.

Status, restart and stop

Last DHCP IP: 192.168.3.225. DHCP hostname: webfs-blog. No mDNS service.

curl --noproxy '*' --compressed http://192.168.3.225/ -o /tmp/blog.html
curl --noproxy '*' -I -H 'Accept-Encoding: gzip' http://192.168.3.225/
doas python3.12 scripts/diagnostics/serial-raw.py /dev/cuaU1

Missing files return 404; write methods return 405, including /update. Gzip-only assets require Accept-Encoding: gzip, otherwise 406 is expected. The console prints DHCP changes and uptime; check the router lease if attached after startup. The reader sets raw mode and clears HUPCL. Recheck .init settings after USB re-enumeration: earlier terminal hangup was followed by unavailable service.

Restart with RESET or, after stopping readers, esptool chip-id with --after hard-reset. Stop by disconnecting device power. Stopping the jail or reader does not intentionally stop firmware. For ROM download, hold BOOT/GPIO9 while resetting, then release BOOT. No eFuse or debug-lock settings were changed.

See docs/validation.md and webfs-perf.md. Older publishing/transactional-update plans in the historical investigation are superseded by this USB-only policy.

Verified USB-only release (2026-09-10)

The 92-file blog at artifacts/blog.wfs (623656 bytes) was provisioned and every asset fetched with two concurrent clients matched its stored bytes exactly. All 19 native host tests passed. POST/PUT/DELETE/PATCH on update paths returned 405, GETs on removed paths returned 404, and HEAD returned 200 without a body. A normal GET completed in 56 ms while another client held incomplete headers. The old publish key was confirmed absent from the new binary. HTTP continued after detaching the serial reader with raw mode and HUPCL disabled.

Application size: 505168 bytes. Merged firmware SHA-256: 34e4a18d5166301b962a069955d91e31d7f9ada90c57d4faca0cee4887999cf7. Blog SHA-256: 97749f365ac3e2e9d22a20f74903183ed968fbc5223a43f17a1d570222a0ce0b. Private pre-migration backup inside the jail: /build/artifacts/pre-webfs-20260910T183957Z.bin.

The tested blog is smaller than 1 MiB; the host test exercises a 1.2 MB asset across the former slot boundary. Sustained Internet/overload qualification has not been performed for this release. See webfs-perf.md for historical diagnostics; network-publishing instructions there are superseded by this USB-only release.