Skip to content

feat(cli): add fbuild buildfs — LittleFS/SPIFFS image from data/ (#1358) - #1788

Merged
zackees merged 1 commit into
mainfrom
agent/buildfs
Oct 29, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/buildfs

Conversation

@zackees

@zackees zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member

What

fbuild buildfs — build a flash filesystem image (LittleFS/SPIFFS) from a
project's data/, the fbuild equivalent of PlatformIO's buildfs target.
This is the image-assembly half of #1358; flashing (uploadfs) is deliberately
not in this PR (see "Not in this PR").

fbuild buildfs                      # -> <build>/<env>/release/littlefs.bin
fbuild buildfs --check-only         # size plan only, no tool run
fbuild buildfs --partitions my.csv --filesystem littlefs -o fs.bin

Behaviour

  • Inputs = everything under data/ (or data_dir from platformio.ini).
    fbuild blob pointers (.fetch, JSON .lnk) are resolved and packed under
    their projected name (foo.png.lnk → /foo.png); the pointer itself is
    never packed.
  • Plain-text .lnk files (FastLED's on-device asset links) are ordinary
    data and do ship. They are classified by content, not extension: a .lnk
    starting with { is an fbuild manifest, anything else is device data.
  • A pointer that does not parse is a hard error, naming the file — during
    development a malformed .fetch was silently copied into the image, which
    would hand the device a pointer where it expects content. That is now
    BuildFailed and covered by tests.
  • Partition = board_build.partitions (project-relative, then the
    framework's tools/partitions/), else the framework default.csv;
    --partitions overrides. The row is selected by subtype
    (spiffs/littlefs/0x82/0x83) or --fs-partition <label>.
  • Size check before the tool runs: files are page-aligned, each path
    segment costs a directory entry, LittleFS metadata blocks are reserved, and
    the total is compared with the partition size. Oversized data/ fails with
    the shortfall in bytes instead of failing to mount at runtime.
  • Tool resolution: --tool, then the PlatformIO package
    (tool-mklittlefs / tool-mkspiffs), then PATH.
  • Format defaults to the partition subtype; --filesystem overrides and
    warns when it disagrees with the table (the firmware mounts what the table
    declares).
  • --json emits a machine-readable plan/summary.

Proof (real, on this host)

Unit tests — 18 new, all green:

test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 398 filtered out

End-to-end with the host's real mklittlefs (ver. 05d49dc, PlatformIO
tool-mklittlefs) on a scratch project with data/README.txt,
data/assets/logo.png (5000 B) and a plain-text data/font.lnk:

$ fbuild buildfs <proj> --partitions <proj>/partitions.csv --json
{
  "content_bytes": 5033,
  "estimated_image_bytes": 14848,
  "files": [{"bytes": 16, "relative": "README.txt"},
            {"bytes": 5000, "relative": "assets/logo.png"},
            {"bytes": 17, "relative": "font.lnk"}],
  "filesystem": "littlefs",
  "image": ".../.fbuild/build/esp32dev/release/littlefs.bin",
  "image_bytes": 1048576,
  "partition": {"label": "fs", "offset": 3211264, "size": 1048576},
  "tool": "/home/niteris/.platformio/packages/tool-mklittlefs/mklittlefs"
}

$ mklittlefs -l littlefs.bin
16      /README.txt
<dir>   /assets
5000    /assets/logo.png
17      /font.lnk

Image size equals the fs partition size (1048576), as LittleFS requires. A
valid-but-unfetchable .fetch pointer aborts with the download error instead
of shipping the pointer (exit 1); an oversized data/ fails before tool
resolution:

data/ does not fit the 'fs' filesystem partition: needs ~..., partition holds
1048576 (over by ... bytes). Use a partition table with a larger filesystem
region, or shrink data/.

Gates: cargo fmt --all -- --check clean, cargo clippy --workspace --all-targets -- -D warnings clean, run_dylint --package fbuild-cli clean,
platform boundary rows=44, check_test_layout.py ok,
check_dylint_allowlists.py ok, bash test on the full workspace: 3974 passed, 0 failed, rc=0 (47 test binaries).

Not in this PR

uploadfs — flashing the image to the filesystem partition through esptool.
That is a daemon deploy operation (region selection + progress plumbing), so it
belongs in its own PR rather than making the image builder depend on the deploy
path. #1358 stays open for it; the partition reader and fs_tool_args are
reusable there.

Also unchanged: partition-table generation for boards that have no filesystem
region (the CSV must declare one; the error names the requirement), and
FFat/Teensy/AVR targets (no usable flash FS / unsupported by PIO's target).

Refs #1358

…ata/

PlatformIO's buildfs target had no fbuild equivalent (#1358),
so there was no path from a sketch's data/ directory to an on-device
filesystem.

`fbuild buildfs` packs data/ (or data_dir) into a LittleFS/SPIFFS image
sized from the board's partition CSV:

- fbuild blob pointers (.fetch / JSON .lnk) are resolved and packed under
  their projected name; the pointer never ships, and a pointer that does not
  parse is a build error rather than a file the device would receive instead
  of its content.
- plain-text .lnk files are FastLED's on-device asset links, classified by
  content, and ship as data.
- the filesystem partition is selected by label or by spiffs/littlefs subtype
  (including the 0x82/0x83 encodings); an oversized data/ fails with the
  byte shortfall before any image tool runs.
- mklittlefs/mkspiffs are resolved from --tool, the PlatformIO package, then
  PATH; --check-only reports the size plan without running the tool.

Flashing the image (uploadfs) stays in #1358; it belongs to the daemon deploy
path, not the image builder.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit f4bb0f1 Oct 29, 2026
29 checks passed
@zackees
zackees deleted the agent/buildfs branch October 29, 2026 21:50
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant