evidence · 12.3 KiB

nostd-feasibility.md

Committed at docs/evidence/boot-text-effects/nostd-feasibility.md. This is what grounds the requirements that cite it.

Open raw source

A no_std ttfx engine for U-Boot: feasibility and a working host-side port

Evidence class: host build and test, plus riscv64imac machine code run under qemu-riscv64-static (user mode). Nothing here ran in U-Boot or on the board. Collected 2026-10-30. The answer to “can ttfx execute in U-Boot” is yes, bounded: the port is done on the host, the open items are board measurements and the U-Boot link, both of which wait for the stage 1 install plan.

What the port took

Upstream is ttfx 0.5.1 (commit 14ed274, MIT), 45 085 lines. It holds two engines: the original (src/engine, src/effects, src/utils: 4 953 + 14 556 + 3 881 lines) and the fast one (src/fx, 21 058 lines, threaded renderer, SIMD, std::arch). The CLI’s own parity suite checks the fast engine against the original one, so the original engine is the reference and the one ported; fx, cli.rs and main.rs stay std-only. The original engine’s frame source is already Effect::next_frame(&mut EngineCtx) -> Option<String>: a formatted ANSI frame per call, which is the unit this change moves around.

The patch (nix/ttfx-nostd/ttfx-nostd.patch, against 14ed274) is 73 files, +2 271 / -1 464 lines by git diff --numstat:

AreaFilesLinesWhat
src/effects/*.rs39+1 605 / -1 08737 effect configs: clap derives and #[arg] become cfg_attr(feature = "cli", ...); a generated impl Default per config (310 fields in 27 shapes: the defaults were only in the clap attributes); std:: paths to core::/alloc::
src/engine/*.rs13+212 / -161terminal.rs (Instant, io::Write printing, terminal size), effect.rs (run loops), ctx.rs (real clock), error.rs: gated behind std
src/utils/*.rs15+92 / -58HashMap::new to default, OnceLock, one write! to a Vec replaced, rng entropy and AVX-512 probe gated
new sys.rs, fmath.rs, prelude.rs; lib.rs, Cargo.toml6+362 / -158platform seams (below), features, registry by name

Hand-written logic is about 600 lines; the rest is mechanical and was produced by two scripts. Behaviour of the std CLI is unchanged: cargo test --release on the patched tree passes (37 unit + 11 integration tests) and --parity-dump output is byte-identical to the unpatched build for all 37 effects in both engines (TTFX_FX=1 and 0, seed 3, 35x38 canvas): 74 of 74.

What depended on std, and the replacement

std useCount in the ported treeReplacement
HashMap / HashSet (dozens of sites)keys are small ints, hashed with ttfx’s own deterministic FxHasherhashbrown (no default hasher, no random seed) behind sys::HashMap
thread_local!4 sites (visual pool, format scratch, appearance memo, origin id)thread_local_compat!: std’s macro with std, a lazily initialised single-thread static without; OnceLock shim likewise
Rc, RefCell, VecDeque, Vec, String, Box, format!everywherealloc
std::time::Instant, SystemTime, thread::sleep, env, terminal_size, io::WriteClock::Real, framerate pacing, terminal sizing, the ANSI writersgated behind std; the boot run uses Clock::Virtual, an explicit canvas and ignore_terminal_dimensions
signals, mallopt, threads, std::arch SIMDlib.rs runtime, fxstay in the std build only
clap339 #[arg] linescfg_attr(feature = "cli")

The feature layout is default = ["std", "cli", "all-effects"]; --no-default-features --features nostd is the engine on core + alloc + hashbrown + libm; effect-<name> features choose which of the 37 effects build_default(name) offers, so firmware images carry only the ones they play (size below). ttfx::effects::build_default and NAMES are the no-CLI entry points.

Floating point

66 files mention f32/f64; the calls are powf (61 uses, 39 in easing.rs, 8 in geometry.rs, 4 in spotlights), abs, sin, cos, sqrt, floor, ceil, fract, hypot and round_ties_even. So the effects do need floating point and, in no_std, libm: fmath.rs maps them to the libm crate (a port of musl’s math library). powf is the parity risk: the std CLI calls the platform’s libm (glibc), and the Python original’s results come from C pow. Measured: 0 differences in 37 effects x 2 seeds x 2 texts on the host (nostd-parity-full.txt), and 0 in 37 effects for the riscv64imac build under QEMU, but that is a finite sample, not a proof, so the design keeps a cell-grid hash check at the continuation point (below) and a replay fallback.

The U-Boot build and the FPU

The pinned U-Boot proper is built -march=rv64imac... -mabi=lp64: readelf -A of the built u-boot and spl/u-boot-spl reports rv64i2p1_m2p0_a2p1_c2p0_zicsr2p0_zifencei2p0_zmmul1p0_zaamo1p0_zalrsc1p0_zca1p0 and the ELF flags say “soft-float ABI”; the store path is the .#uboot-k230 output (readelf-A.txt beside the binary). Upstream’s arch/riscv/Makefile in the pinned tarball derives -march from the configured extensions (no F/D), and arch/riscv/cpu/start.S does not touch mstatus.FS, so the FPU is off and a hard-float object would trap on its first instruction. The Rust target must therefore be riscv64imac-unknown-none-elf, not riscv64gc (nixpkgs’ riscv64-embedded cross target is riscv64gc-unknown-none-elf, hard-float, and is unusable here). Doubles are then software: compiler_builtins supplies __adddf3, __muldf3 and friends, and IEEE basic operations are correctly rounded either way, which is why the frames match. Enabling the FPU in stage 1 (setting mstatus.FS, saving FP state around bootm) would be faster and is a firmware change this proposal does not take. Speed on the C908 in soft float: the same object code, run as a Linux static executable on the board, costs 32 ms for all 138 frames of wipe and at worst 3.08 ms per frame (beams) over the 37 effects (board-engine-bench.txt; every effect’s frames equal the std ttfx’s). That is Linux with caches on; U-Boot’s cache state is .

Size

libk230_ttfx_boot.a built opt-level = "z", LTO, panic = "abort", riscv64imac, position-independent, linked with --gc-sections (transcript: nostd-sizes.txt; sizes are the linked .text + .rodata; .eh_frame (17 to 50 KB, listed in nostd-sizes.txt) is unneeded with panic = "abort" and can be discarded at link time):

Effects compiled in.text.rodatatotal
wipe only107 20218 032125 234
8-effect subset (wipe middleout expand slide errorcorrect print decrypt scattered)175 31022 320197 630
all 37479 09440 952520 046

The U-Boot-proper slot is 1 048 576 bytes and the DMA-request candidate used 385 932 (docs/evidence/game-of-life/stage1-install-recovery-proposal.md on the Life branch), so a subset fits with room for Life, and all 37 effects leave about 140 KB. The slot is the binding constraint, so firmware carries a subset.

Memory

Peak heap per effect, measured with a counting allocator, over the K230 banner on a 35x38 canvas (k230_ttfx_boot example mem, host x86-64, so sizes of pointers match riscv64). Everything is still live at the end of a run, because ttfx interns each distinct visual in a pool that lives for the run:

effectframespeak heap KiBlive at end KiBhost ms
beams3218549854938
binarypath842119531195330
blackhole8942545254517
bouncyballs417178817888
bubbles521235523556
burn3249315931515
colorshift5282703270315
crumble4302553255317
decrypt7533260326014
errorcorrect274128012803
expand50148914893
fireworks12112521252115
highlight129109810982
laseretch494121551215520
matrix14521388138825
middleout94156615662
orbittingvolley1387168716874
overflow57149314923
pour2561666166613
print308184418443
rain235160716075
randomsequence241110111012
rings1398132361323685
scattered120158915894
slice176100010004
slide110152115213
smoke1806269626924
spotlights6011535153534
spray337181518157
swarm36553112311236
sweep2203816381630
synthgrid6296243624328
thunderstorm6233590359022
unstable250207220718
vhstape6872561256129
waves5124043404323
wipe138118811884

Most effects peak at 1 to 4 MiB; beams (8.5), burn (9.3), binarypath (12), laseretch (12) and rings (13) are the large ones. U-Boot proper’s pool is CONFIG_SYS_MALLOC_LEN, which the pinned common/Kconfig defaults to 0x400000 (4 MiB) and which the K230 defconfig does not override (CONFIG_SYS_MALLOC_F_LEN=0x40000 is the early pre-relocation pool). So the Rust side must not use U-Boot’s malloc as is. The library takes an arena from the host (ttfx_fw_init) with its own first-fit allocator, and the integration chooses either to raise CONFIG_SYS_MALLOC_LEN (to 32 MiB, say) and take the arena from it, or to point it at a fixed free DRAM range during stage 1. Which addresses are free is checked with the Life change’s memory-map tool; I have not done that here.

nix/ttfx-boot is a crate with a C ABI (ttfx_boot.h: ttfx_fw_init, ttfx_fw_new, ttfx_fw_next, ttfx_fw_free, and a host-provided ttfx_fw_panic). Built with cargo rustc --lib --crate-type staticlib --target riscv64imac-unknown-none-elf, -C relocation-model=pic (U-Boot is a PIE and relocates itself), panic = "abort". Linking --gc-sections with only a stub for ttfx_fw_panic resolved every symbol: no libc is needed, memcpy/memset come from compiler_builtins. Nixpkgs’ rustc has no std for that target, and the official rust-std tarball for the same version is refused by it (“found crate core compiled by an incompatible version of rustc”: the nixpkgs compiler reports built from a source tarball; that attempt failed in the sandbox and is why the derivation does not use it). nix/ttfx-boot/default.nix instead builds core, alloc and compiler_builtins from the matching rust-src with -Zbuild-std (the stable compiler under RUSTC_BOOTSTRAP=1), offline: cargo resolves the whole std workspace, so the vendor directory is the crate’s own lock plus library/Cargo.lock, both through importCargoLock. It applies the ttfx patch with applyPatches. nix build .#k230-ttfx-boot succeeded (output and a QEMU parity run of the 8-effect subset in nix-build-ttfx-boot.txt). U-Boot would then add the .a to PLATFORM_LIBS and a C glue file calling the ABI, on the model of the Life change’s k230_boot_life.c; that is a stage 1 edit and waits for the operator. The same crate builds hosted for riscv64-linux (nix build .#k230-ttfx-boot-hosted) and is linked into the Linux player.

Parity

tests/test_ttfx_nostd.py (output: nostd-parity-full.txt):

Limits