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:
| Piece | Where | Size |
|---|---|---|
cyclic_register/unregister/run | nix/uboot-k230-life/cyclic.h, k230_cyclic.c | about 90 lines |
route WATCHDOG_RESET() to cyclic_run() when CONFIG_K230_BOOT_LIFE_CYCLIC and not SPL | hunk to include/watchdog.h in 0006-k230-stage1-boot-life.patch | 8 lines |
| frame driver | src/boot_frame.c (bf_begin/bf_advance), nix/uboot-k230-life/k230_boot_life.c | existing 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):
udelay()(lib/time.c) callsWATCHDOG_RESET()once per call (and perCONFIG_WD_PERIODchunk). The K230 uses this genericudelay(no arch override; only x86’stsc_timer.cdefines__udelay). This is the main hook.- SD/eMMC reads. The board’s MMC is
snps_sdhcion the genericdrivers/mmc/sdhci.c.sdhci_transfer_data()polls withudelay(10)per iteration (up to 10^6 iterations), so a hookedudelaycallsschedule()roughly every 10 microseconds for the whole of everyext4load. The command-phase loop usesget_timer()withoutudelayandsdhci_resetand clock setup useudelay(1000).drivers/mmc/mmc.c,fs/ext4andcmd/ext4.ccontain noWATCHDOG_RESETof their own. - Autoboot countdown.
common/autoboot.cspins withtstc()andudelay, so the one-secondbootdelayalso calls it. - bootm legacy-image checks. The data CRC check (
Verifying Checksum) usescrc32_wd, but inlib/crc32.ctheWATCHDOG_RESET()inside it is only compiled#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG), so it is NOT a call site in this configuration. A 27 MB CRC at software speed is an uncovered gap of well under a second (estimate). - Decompression. None on this path: the boot files are an uncompressed
Linux image and an uncompressed ramdisk uImage
(
Image Type: ... (uncompressed)indocs/evidence/mainline-boot-splash/board/idle-kernel-serial-excerpt.txt). The LZMA, zlib and gunzip loops that do callWATCHDOG_RESETare not used. The ramdisk “Loading Ramdisk to …” step is amemmovewith no hook. - Console prompt. An idle
K230#prompt callststc()withoutudelay; the animation pauses there (acceptable: its frame budget also caps it).
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
- No sleep is added. The blocking loop adds
frames x frame_ms(2 s for 40 frames at 50 ms) plus compute. The cyclic loop adds only the callback CPU time that overlaps with waiting. SDHCI transfers continue under the controller’s own flow control while the CPU is in the callback; SDMA mode stalls at its 512 KiB boundary until the CPU rewrites the address, so a slow callback at that moment delays the read by up to one callback duration. The command-phase timeout (SDHCI_READ_STATUS_TIMEOUT, 1 s) and the data poll budget (10^6 x 10 us) are far larger than any callback. - Watchdog. None is enabled in this configuration (the macro was empty), so
routing it to
schedule()replaces no watchdog kick. If a watchdog were enabled later,schedule()would have to call it too (upstream’s does). - Timer. Deadlines use
get_ticks()(RISC-V timer, the same sourceudelayuses); no interrupt is involved. Callbacks run in the context of whoever calledudelay, so they must not sleep or touch MMC. The framework refuses to re-enter, so audelaycalled by the callback is harmless. - Per-call overhead when nothing is due is one tick read and compare, about 100 000 times a second during loads (estimate: under one percent).
- SPL is unaffected: the hook is compiled out under
CONFIG_SPL_BUILD, and the default.#uboot-k230output is unchanged.
What changes in the record and the handoff
- The last frame is no longer “generation N after a fixed 40 frames”. It is
whatever the cyclic hook drew before the kernel handoff. The hook stops from
ft_board_setup()(k230_boot_life_stop()), the last U-Boot code that runs before the jump, so the record Linux reads is final and its checksum matches the frame on the glass. Each publish is complete before the next frame starts; a callback cannot be interrupted mid-record. - Generation count at handoff therefore varies with load speed. Linux must not
assume a number; it already continues from whatever generation the record
carries (
life_load()). - If the user stops at the
K230#prompt, drawing pauses there (noudelaycall), the record stays valid, andk230_life stopfreezes it explicitly. - The ownership pause after U-Boot is unchanged by this decision: the panel
holds the last cyclic frame from
ft_board_setupuntil the Linux owner takes the scanout.
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:
include/watchdog.h(our hunk) made everyWATCHDOG_RESET()callcyclic_run(). That macro is reachable before relocation:__serial_getccalls it whenever the UART driver returns-EAGAIN(drivers/serial/serial-uclass.c),fgetc()calls it on every poll (common/console.c), andudelay()calls it (lib/time.c).cyclic_run()first readcyclic_head. For U-Boot proper,.bssis not cleared untilrelocate_code->clear_bss(arch/riscv/cpu/start.S), which runs afterboard_init_f. Before that,cyclic_headandcyclic_busyhold whatever DRAM held, and a warm reboot keeps DRAM contents.- A non-zero
cyclic_headmadecyclic_run()callget_ticks(), which panics whengd->timeris not yet set: exactly the message observed (lib/time.c,dm_timer_init()failing with -ENODEV).panic()itself callsudelay(), which callsWATCHDOG_RESET()again: the 8 804-line loop. - 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, andcyclic_run()is only reached from it). With input during early init the path ran, and.bsscontents 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): thereWATCHDOG_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.