README.md

minitoo-forth #

A self-hosting FORTH kernel that lives in a 6.5 KB code cave of the Divoom MiniToo's firmware (Actions ATS2831, ARMv7-M Thumb-2). The kernel wakes on a magic Bluetooth command (0x0407), runs one FORTH line per packet through a return-into-dispatcher shim, and prints the result back over SPP — alongside the device's normal operation.

The seam: the MiniToo's OTA updates are checksum-only (an additive byte-sum, u32, no signature, no crypto). That's how a custom kernel gets in.

Where it stands: the kernel works end to end in simulation — 3 4 + . routes 7 back over SPP, proven through the exact device path. Flashing custom firmware onto silicon has eluded us: every software route is closed or mapped, and the open roads are all hardware (DFU, boot straps) or the no-flash ACE complement (RAM is executable; the device configures no MPU). The recon is complete enough that the open moves are named, not guessed.

The firmware binary is not bundled (recover it via firmware/MANIFEST.md). Neither are the decompiled APK sources nor the datasheet PDFs — every vendor asset is recovered on demand.


What this is #

The Divoom MiniToo is a Bluetooth gadget: an Actions ATS2831 (ARMv7-M Thumb-2, the "T2" silicon family) hung off a JieLi AC690N USB bridge, driving a 160×128 IPS panel. Its firmware updates over the air. The OTA scheme is a checksum. The whole project rests on that single fact: a self-hosting FORTH kernel can be patched into a code cave of that firmware, delivered by OTA, and run alongside the device's normal operation, answering FORTH over the same Bluetooth channel that feeds it.

Where it stands:

  • The kernel works end to end in simulation. 3 4 + . → 7 over SPP, proven through the exact device path: packet → handler → shim → INTERPRET → + → . → EMIT → SPP. The wire framing is byte-identical to a reference and round-trip sim-proven with the host tool.
  • Flashing custom firmware onto silicon has eluded us. Every software route has been closed or mapped. The SPP OTA path is provably gated shut by a bootloader-seeded catch-22; the SD path is a misnamed dead end; the USB-DFU path rests on an unresolved topology contradiction. The remaining routes are hardware, or the no-flash ACE complement.
  • The recon maps the full attack surface. The hardware surface is mapped, the calling convention is prologue-proven, the FORTH-callable addresses are resolved, the attack surface is catalogued. What remains is one button-combo test, one HCI capture, or one controlled-buffer landing.

The checksum exploit #

OTA is an additive byte-sum, u32. Range is sum(bytes[0 : filesize-4]), stored little-endian at the trailing four bytes. No signature, no crypto: forgeable. Proven empirically against the real firmware: sum(bytes[0:0x120e01]) == 0x0690596a == stored. The verifier function is at 0x008d22 (Thumb). The full structure (boot header, the two code caves, the DIVOOMUPDATE trailer) is in firmware/MANIFEST.md.

The kernel lives in code cave A at 0x004690 — 6512 bytes of 0xFF erased-flash padding, bordered by rodata strings. It overwrites only padding, so file size is unchanged; after patching, firmware_patcher.py recomputes the checksum over the new bytes and self-verifies. (A second cave at 0x6340, 3264 B, sits unused — held in reserve.)

The wakeup: the BT dispatcher's sink handler at 0x5f04e is patched with a b.w into a shim. Magic command 0x0407 wakes the kernel; every real command is preserved (no collision, pinned by the patch tests). The patch is one branch.


How we hunted #

Each rule below came from a bug that bit.

  • We HUNT, we don't pass. Tests attack edges and document dragons. A bug found becomes a green-documentation test or an xfail trophy, never a patch that hides it. The first suite asserted only the final stack value and forgave the whole process; that meta-bug birthed the trapnet.
  • Compose stable subassemblies; don't inline copies. An inlined . ran away; composed of proven UM/MOD, >R, R>, EMIT, it didn't. The parable of the watchmakers.
  • Measure the subassembly with the correct harness before blaming it. Every "DOT is broken" panic was a harness bug — wrong base, wrong start address, wrong dict seeding. The body was correct throughout.
  • Be observable, never obscure. Tee output to a file; don't head away the signal. Phantom state thrives in hidden output.
  • Pick the smallest proof that closes the question. Symexec was scoped for a lock-recursion question; a 95-line reachability scan closed it first. The expensive build lost the veto.
  • Hunt → formalize, not formalize → hunt. Formal methods earn their keep where the open question justifies them (see below). And the discipline that kept the silicon alive through days of probing: never delegate the load-bearing claim — to an agent, or to a first framing.

The trapnet — four layers, so these bug classes can never hide again. Gap poison: every unwritten image byte is 0xDEDE (UDF), not 0x00 (NOP); fall-through traps instead of sliding into the next word. Always-on guards: the harness hook fires every instruction — underflow past DSTACK_TOP, stack collision of data into return, UcError on wild-branch/null-deref. assert_clean: reached-HALT ∧ no underflow ∧ no collision ∧ no fault; default-on. The rule: keep the layers honest.

The bootstrapped toolchain. London-school TDD, bottom-up: write the failing test, emit the simplest Thumb that passes, cross-check every encoding against clang -target armv7m-none-eabi. Python emits verified bytes, Unicorn verifies behavior. The register convention was pinned early and never broken: R12=IP, R11=data-stack (grows down), R10=return-stack (grows down), R9=entry scratch. The kernel builds to build/kernel.bin (1684 B / 6512 B cave, 25%); tests load those exact bytes — clang (the assembler) is a build-time concern, never a test-time concern.

Hunt → formalize — the meta-finding. Three formal-methods lanes were attempted; the lesson was bigger than any result. A static stack-effect checker catches the Dragon-2 class (stray DROPs in colon-word branches → underflow) before execution, across all branch paths. Bounded abstract interpretation (machine-checked Hoare triples via real Unicorn, each with a positive control and a buggy-variant hunt test) verified ~35 of 38 primitives. But the lock-recursion question — "only a real device run can settle it" — was closed by a 95-line capstone + BFS reachability scan: 89 functions reachable from the dispatcher path, zero transitive calls to the held primitive. Re-entry is a necessary condition for recursive deadlock; re-entry is provably absent. The planned angr/Unicorn symexec harness was deliberately not built. Formal methods earn their keep where the question is genuinely open; a cheaper proof closes it first. The London tests handed the formalization ~80% of its setup — spec, oracle, negative controls, debugging anchor — for free.

Static analysis in the loop. ruff runs over src/ and test/ with bug classes on (F821 undefined names, F811 redefinition, E722 bare except) and the intentional idioms silenced in config — the kit.add(name, a, SRC); a += 0x20 asm-builder stepper and the placeholder-free f-strings in recon scripts are deliberate, not lint debt. The bug classes that stay on have earned their keep more than once: an F811 caught a shadowed import, an F841 surfaced a duplicate SRAM-address naming in kernel_builder.py (dead locals OUTLEN/STATE/INIDX mirroring the canonical S_* module constants — harmless, but a knolling sin and a refactor waiting to happen). And it was refusing to ship a test that ruff-class reasoning exposed as a no-op that cracked open dragon #11 above. The tools hunt too; keep them in the cybernetic loop, and never auto-fix what you haven't read.


What we proved #

question answer evidence
does the kernel compute and print? yes — 3 4 + . → 7 over SPP test/test_dot_hunt.py
is the wire framing device-correct? yes — byte-identical to reference + round-trip sim-proven test/test_minitoo_forth.py, tools/minitoo_forth.py
is the calling convention known? yes — AAPCS, prologue-proven; arg counts resolved docs/silicon-surface.md
can we flash over SPP? NO — bootloader-seeded catch-22 gate docs/flash-delivery.md (BT-SPP OTA)
can we flash via SD (app fw)? NO — name misleads; verifier reads internal flash docs/flash-delivery.md
can FORTH reach the display? yes — next_mode 0x14a32, set_pixel 0x23c44, framebuffer 0x12896 docs/silicon-surface.md
can FORTH reach DMA? yes, designable — DMA base 0xC00C0000, 5 channels docs/silicon-surface.md
can FORTH reach the BT radio? yes — BLE_ADV toggling 0x9212; full HCI surface docs/silicon-surface.md (BT radio + USB)
is RAM executable (no MPU)? yes — the ACE foundation docs/ace-frontier.md (execution environment)
can SPP/JPEG give code exec? two confirmed crashes; ACE open docs/ace-frontier.md (SPP-delivered surface)

The OTA wall, in one sentence. The OTA-accept gate is b17 = ([dev_ctx+9] == fileType(packet[1])) ? 0 : 1, decompile-verified at the 0x98 handler. [dev_ctx+9] is seeded by the bootloader/BT-ROM at boot (the dev_ctx list head has readers but no writers in the application binary); every command that could rewrite it must first pass the gate that reads it. A true catch-22 — no SPP command can flip the byte that unlocks OTA. Six live probes confirmed every lever dead; the gate's accept-set is fully decoded ([dev_ctx+9] ∈ {0,1,5,6,7}), and the one open lead (value 5, gate-accepted but no known SPP writer) is named in docs/flash-delivery.md.


Documented hazards #

These are not patched. Each is a green test or an xfail that documents the hazard in the executable suite, per the rule above.

  1. @ on an empty stack → null-deref crash (needs bounds checking)
  2. WORD buffer overflow — a 300-byte token overflows PAD
  3. u32 max in NUMBER — r0*10 overflows past 9 digits, flag stays true
  4. EXECUTE of 0 → silent vector-table deref (reboot on device)
  5. CALL with no null-target guard → 0 CALL reboots
  6. DUMP with no length cap → uncontrolled memory walk → fault
  7. ; without : corrupts the dict region (no mode guard)
  8. EXECUTE of a Thumb-marked address (0x411 not 0x410) → misaligned deref
  9. UM/MOD divide-by-zero → quotient 0xFFFFFFFF, remainder = dividend
  10. . on INT_MIN → NEGATE overflows to itself; unsigned divmod still prints -2147483648 correctly
  11. The base-sensitivity classifier has a blind spot. _is_base_sensitive flags labels and branches, but : and ; materialise DOCOL/EXIT absolute addresses via movw/movt with no label — so the classifier marks them base-free while their bytes legitimately differ across bases. The dragon hid for free inside a test that asserted "branch-free words are byte- identical" and then, hitting these counterexamples, gave up with "no assertion to fail here." The rewritten test (test_only_address_embedding_words_differ_across_bases) inverts the property: a word may differ across bases only if it embeds a code address, and the known address-embedders (:, ;) are a named, deliberate allowlist — any new member is a classifier regression to investigate, not append. Found by putting ruff in the loop and refusing to ship a no-op.

Plus the silicon-side dragons, which are open — not trophies, but the honest gaps the project does not pretend to close. They are the next section.


What is still open #

The rule is to document the blocker, not hack around it. These are the blockers. docs/flash-delivery.md is the master surface; read it first when the question is "how do we get the patched firmware onto silicon."

Silicon flash — the eluded goal. The kernel is built and sim-proven; the wire is device-proven; the SPP flash path is provably gated shut. The open flash roads are all hardware, and two of them are entangled by a contradiction that must be resolved first:

  • USB DFU (button combo) — premise contested. The Actions DFU recon is sound (10d6:10d6 enumeration, a Vol+/Vol− combo — confirmed present on the device), but docs/silicon-surface.md says all USB lives on the JieLi bridge, which would make the Actions chip unreachable over USB regardless of button combo. Resolve the topology before any test (see "The contradiction" in docs/flash-delivery.md).
  • The JieLi AC690N coprocessor — the knolling gap. The one chip between us and the USB connector; it has had zero dedicated recon. The JL↔Actions link, its USB class, its own upgrade mode — all unknown. Investigate before any USB test (see "DFU, boot straps, JTAG" in docs/flash-delivery.md).
  • Boot straps (SD-card / JTAG) — deferred. Need the device opened. GPIO straps from the ATS2819 datasheet, pp. 16–20. Held back as fallbacks.

The r7 register-state gate. The 0x83 handler reads fileType from r7; the dispatcher doesn't set it. Whether the app's BT stack leaves r7 pointing at the packet buffer is visible in the disassembly but out of reach of flat emulation. An HCI capture of the app doing a real OTA settles it; until then it's a hypothesis, not a finding.

The ACE complement road — needs no flash. A RAM-resident exploit sidesteps the bootloader gate entirely, viable because the device configures no MPU (RAM is executable). Two SPP-delivered JPEG crash vectors are confirmed live and reproducible; whether the controlled bytes land somewhere controllable is the open ACE question. The full attack surface — execution environment, parser targets, function-pointer dispatch sites, the SD-delivered codec surface (~17 format decoders), the SBC decoder, the BrakTooth lead (CVE-2021-28135, chip-family match, untested), the chip-ID false trail — is catalogued in docs/ace-frontier.md and docs/ace-frontier.md.

The five PC-relative wall functions (SD/SPI/FAT writers). No static tooling resolves them — capstone, r2's aaa, movw/movt pairing, literal-pool hunt, brute-forcing every 4-byte cell, and Ghidra headless (3674 functions, 218 932 instructions) all returned zero hits. Closing them needs a Ghidra GUI session (interactive decompile) or an HCI capture. This is the documented frontier (docs/ace-frontier.md).

DMA — real but invisible. The MB/s audio path needs it, but it lives in precompiled DrvLib with no C labels. Two paths to a DMA word: datasheet PEEK/POKE of channel descriptors, or a Ghidra GUI session to find the DrvLib setup function.

z3 and the universal wall. The 32-iteration UM/MOD divmod loop returns UNKNOWN from z3's quantifier-free bitvector solver after a 600 s timeout. Universal coverage of UM/MOD lives at the probabilistic hypothesis-sweep layer, not the proof layer — closeable only by loop induction or a specialized tactic, neither attempted.


The map #

src/                 the kernel — primitives, colon words, patcher, harness
test/                the hunt — tests that attack edges and document dragons
docs/                the evidence layer — recon findings, one file per question
tools/               live host tools (.py) + Ghidra recon scripts
firmware/            base firmware asset + datasheets (all gitignored — see MANIFEST.md)
firmware/MANIFEST.md firmware structure, provenance, and asset acquisition

The evidence layer (docs/) — each findings doc is self-contained and faithful about what's proven vs inferred vs open, knolled under the three questions the project turns on. The index is docs/README.md; read docs/flash-delivery.md first when the question is "how do we get the patched firmware onto silicon."

Runnable tools (tools/*.py) — run with uv run (host extras: uv sync --extra host):

tools/minitoo_forth.py    ← THE host tool: device controls + FORTH prompt + raw hatch
tools/minitoo_bt.py       ← macOS IOBluetooth RFCOMM transport (PyObjC)
tools/probe_cleanup.py    ← cancel any in-flight OTA (run before/after OTA probes)
tools/probe_gateway.py    ← the routing-verifier (frame[3]=0x04 selects the dispatcher)
tools/reach_scan.py       ← the lock-recursion reachability scan (89 fns, zero re-entry)
tools/cc_recon.py         ← static calling-convention recon
tools/z3_um_mod_spike.py  ← the z3 negative-result spike (UM/MOD UNKNOWN after 600s)

The tests split into two families. Canonical-kernel tests load build/kernel.bin once per session (via conftest.py) and exercise the real bytes that ship in the cave. Hunt tests (ImageKit + hand-rollers) build custom adversarial images — gap poison, word isolation — by design, to attack edges the canonical kernel wouldn't show.


Quick start #

uv sync --extra dev          # core deps + pytest
make test                    # sync + build kernel + run suite (544 pass)
make force                   # rebuild the kernel unconditionally

The kernel builds to build/kernel.bin (1684 B / 6512 B cave, 25%). Tests load the precompiled binary — clang (the assembler) is a build-time concern, never a test-time concern.

The two hooks (one-time, per clone — git doesn't track .git/hooks/):

ln -sf ../../hooks/pre-commit .git/hooks/pre-commit   # ~3s: ruff + 51 high-signal tests
ln -sf ../../hooks/pre-push   .git/hooks/pre-push     # ~35s: full suite + ruff bug-classes

The commit gate is fast (kernel build + staleness guard + the 3 4 + . → 7 proof + the trapnet + size budget); the push gate is the full net. A docs-only commit skips the gate entirely.

To talk to a live device (macOS):

uv sync --extra host         # adds pyserial + IOBluetooth + z3
uv run python tools/minitoo_forth.py ping
uv run python tools/minitoo_forth.py repl

The firmware binary isn't in this repo — recover it (and the APK, and the datasheet URLs) from firmware/MANIFEST.md. test_firmware_patcher.py skips itself until firmware/flag41007.bin is present; everything else runs without it.

╰( ✖┳✖ )╯🔥 The kernel computes and prints. The wire is proven. The wall is flashing silicon — and every road to it is mapped, with the open ones named, including the no-flash ACE complement. ( ˘ ³˘)♥ (´。• ᵕ •。`) {★}