evidence · 12.3 KiB

uboot-cyclic.md

Committed at docs/evidence/game-of-life/uboot-cyclic.md. This is what grounds the requirements that cite it.

Open raw source

U-Boot cyclic callbacks for the stage-1 animation

Research of 2026-10-30 over the source this repo builds (.#uboot-k230: U-Boot 2022.10 plus Canaan’s overlay plus patches 0001-0005, reconstructed from the fetched tarball and the pinned SDK commit) and over earlier board captures. Source reading and a host/cross compile only. Nothing here was measured on the board; every timing figure marked “estimate” is UNVERIFIED until the board is back and a run is captured.

Does the tree have the cyclic framework?

No. common/cyclic.c, include/cyclic.h, CONFIG_CYCLIC and schedule() do not exist in 2022.10 (upstream added them for v2023.01). The only related symbol is CONFIG_CMD_MX_CYCLIC, an unrelated memory test. There is no schedule() anywhere in the tree.

What 2022.10 does have is WATCHDOG_RESET() (include/watchdog.h). With neither CONFIG_WATCHDOG nor CONFIG_HW_WATCHDOG (the k230 defconfig sets neither) it expands to {}. That macro is exactly the call site upstream later turned into schedule().

Correction found by the first full build: the tree does contain a function-like #define schedule() in the USB gadget compat headers (used by cmd/usb_mass_storage.c), so defining a schedule() of our own broke that file. The back-port therefore omits schedule() and WATCHDOG_RESET() calls cyclic_run() directly; upstream’s name is not provided here.

Backport size

Small, because the port only needs the API shape:

PieceWhereSize
cyclic_register/unregister/runnix/uboot-k230-life/cyclic.h, k230_cyclic.cabout 90 lines
route WATCHDOG_RESET() to cyclic_run() when CONFIG_K230_BOOT_LIFE_CYCLIC and not SPLhunk to include/watchdog.h in 0006-k230-stage1-boot-life.patch8 lines
frame driversrc/boot_frame.c (bf_begin/bf_advance), nix/uboot-k230-life/k230_boot_life.cexisting code, restructured

Names and signatures follow upstream (cyclic_register(c, func, delay_us, name), cyclic_unregister(c), schedule()), so moving the vendor tree to 2023.01 or later means deleting cyclic.h/k230_cyclic.c and the watchdog.h hunk and enabling CONFIG_CYCLIC. Differences from upstream are listed in the header: no hlist, no gd field, no cyclic command, a run-level re-entrancy guard, deadlines in timer ticks.

Honest scope of “backport”: a full port of upstream’s common/cyclic.c with its gd->cyclic_list, cyclic_init() in the init_sequence_r, the cyclic shell command and the many tree-wide WATCHDOG_RESET-to-schedule edits would be a few hundred lines across 8 to 10 files and would touch global_data.h; none of that is needed to run one callback, so it was not done.

Where schedule() actually runs on the K230 boot path

By source reading (this tree, K230 defconfig; no board measurement):

The boot window and realistic frame rate

From the captured warm-boot log (idle-kernel-serial-excerpt.txt, a hold run, so inter-command gaps are the driver’s, but each read time is U-Boot’s own): logo.xrgb 118 ms; Image 42 745 856 bytes in 1 773 ms (23 MiB/s); initrd.uimg 27 330 502 bytes in 1 136 ms (22.9 MiB/s); dtb 6 ms; firmware 17 ms. So the SD reads alone are about 3.1 s of udelay-driven polling, preceded by the one-second bootdelay (also udelay-driven) and followed by the checksum and relocation phase (uncovered, short).

Because the hook fires about every 10 microseconds, the callback rate is bounded by the period requested and by callback cost, not by hook frequency. Callback cost (estimate, not measured): one Life generation is about 44 000 cells x 9 bit reads, a few milliseconds to low tens of milliseconds on the C908, plus a differential redraw and a flush of the changed pixel rows only (dirty_off/ dirty_len, src/boot_frame.h). A period of 80 ms (about 12 frames per second) therefore costs somewhere under 25 percent of the CPU during loads; at roughly 4 s of window that is on the order of 40 to 50 frames, to be confirmed. The build prints mean and max callback microseconds at bootm so the first board run measures this directly.

Cost against boot time, watchdog and timer constraints

What changes in the record and the handoff

Fallback

CONFIG_K230_BOOT_LIFE_CYCLIC=n builds the blocking driver only. With it on, k230_life block runs the blocking loop by hand, and if the cyclic session cannot start (window outside the reservation, bad configuration) the glue falls back to the blocking loop and says so.

For the text-effects producer

Any bf_source (src/boot_frame.h) runs under this hook unchanged: draw into the target in start()/step(), report the changed byte range in dirty_off/dirty_len, publish a record with the common prefix. The callback budget is the constraint: a step that costs more than a few tens of milliseconds holds up the SD reads at SDMA boundaries. Do all heavy work (layout, rasterising glyphs) in start(), before the first frame, and keep step() incremental.

Evidence still needed (board offline at the time of writing)

Serial capture of k230_life and of a normal boot with boot_life=1 showing the cyclic stopped at generation N after M callbacks, mean X us, max Y us line; boot time with and without the animation measured from the serial timestamps; and a camera or operator view of the frames. None exists.

Board hang of 2026-10-30 and its cause (source analysis; fix not yet run on the board)

What was observed (serial console, ucon.py; the transcript is not committed because it can also hold other board output): the first reboot after installing the opt-in U-Boot (cyclic build, boot_life unset) booted normally. A second reboot, made with \r written to the console every 50 ms from before the reset, printed the identical SPL lines (imge: uboot load to 0 ... len=5efc5 / len=bc590), then no U-Boot 2022.10 banner, then Could not initialize timer (err -19) 8 804 times in 120 s; afterwards the console was silent and SSH timed out.

Cause, by reading the tree that was built:

  1. include/watchdog.h (our hunk) made every WATCHDOG_RESET() call cyclic_run(). That macro is reachable before relocation: __serial_getc calls it whenever the UART driver returns -EAGAIN (drivers/serial/serial-uclass.c), fgetc() calls it on every poll (common/console.c), and udelay() calls it (lib/time.c).
  2. cyclic_run() first read cyclic_head. For U-Boot proper, .bss is not cleared until relocate_code -> clear_bss (arch/riscv/cpu/start.S), which runs after board_init_f. Before that, cyclic_head and cyclic_busy hold whatever DRAM held, and a warm reboot keeps DRAM contents.
  3. A non-zero cyclic_head made cyclic_run() call get_ticks(), which panics when gd->timer is not yet set: exactly the message observed (lib/time.c, dm_timer_init() failing with -ENODEV). panic() itself calls udelay(), which calls WATCHDOG_RESET() again: the 8 804-line loop.
  4. Why it appeared only once: the dormant first boot had no console input, so no early WATCHDOG_RESET() ran (the macro was {} in the old U-Boot, and cyclic_run() is only reached from it). With input during early init the path ran, and .bss contents decided whether the panic fired. This also explains why the old U-Boot never hung under the same \r/space hammering (tools/splash-uboot-session.py, docs/evidence/mainline-boot-splash/board/uboot-hold-poke-serial-excerpt.txt): there WATCHDOG_RESET() expands to nothing.

That early console input is the trigger is the coordinator’s hypothesis; the uninitialised .bss read is the mechanism the source shows. Neither has been reproduced on the board: this is a source-level conclusion.

Fix (in the tree, not yet installed): cyclic_run() now returns immediately unless gd->flags & GD_FLG_RELOC (set by initr_reloc, after clear_bss) and gd->timer is set. No state is read before that. A full local cross build of u-boot.bin with the fix succeeds (not a nix build, not evidence of boot).

Rule for any producer that hooks WATCHDOG_RESET: that macro runs in pre-relocation code; a hook may not read .bss/.data state, call get_ticks(), or call anything that needs the DM timer until relocated. Test procedure while the fix is unproven on hardware: interrupt autoboot with a single keypress sent only after the U-Boot 2022.10 banner appears, never with input before it.