Files
alkane-toolkit/docs/IMPLEMENTATION-PLAN.md
T

17 KiB

alkane-toolkit — Implementation Plan

Version 0.1, drafted 2026-09-14. Status: DRAFT for review.

1. Mission

A cross-platform desktop application that installs stock or alkaneOS onto ASIC miner control boards, whatever they currently run — stock, Vnish/ AnthillOS, Braiins OS+, LuxOS, ePIC UMC, BixBit, WardenOS — with the safety rules that keep every transition reversible enforced in code, not in prose.

alkane-toolkit is the mechanization of alkane-sdk's install/from-firmware/ recipes. The SDK owns board knowledge, packers, and build outputs; the toolkit owns discovery, foothold, execution, verification, and the operator UI. Nothing in the toolkit re-derives board facts; it loads them from the SDK.

2. Ground truth this is built on

Sources (all CONFIRMED unless tagged):

  • alkane-sdk/main/docs/install-methods.md — universal invariants, per-board flows, boot-switch discipline, anti-brick floor.
  • alkane-sdk/main/install/from-firmware/README.md — universal install pattern and the root-vector table per source firmware.
  • alkane-sdk/main/boards/ — 7 board families: am335x-bb, zynq-7010, cv1835, a113d, allwinner-h3/h6/h616 (status: bake).
  • Bench-corpus install evidence: stock restores (S17 NAND restore verified 2026-09-14), WhatsMiner network install (0x9a5ba57c package, remote-daemon cmd 7), WhatsMiner /data overlay persistence, BixBit SSH SD images, aml stock live capture, Braiins cv bootloader.

The universal pattern (from the SDK, implemented as pipeline stages)

discover -> classify(board, soc, running-fw, chip) -> foothold(root)
         -> pack(board, image) -> backup -> transfer -> write
         -> verify-write -> boot-switch -> reboot
         -> verify-live(marker, independent channel) -> verify-persist(N>=2 power cycles)

Root vectors per source firmware (SDK table, toolkit implements)

Source In-band root Mechanism
Braiins OS+ yes root SSH, empty password (first boot on aml)
ePIC UMC OS yes vendor default root:letmein
LuxOS yes unauthenticated OTA-source hijack
Vnish / AnthillOS no removal API -> land on stock -> stock->ours
Bitmain stock yes (owned hw) update-daemon loopback RCE via SSH forward
WhatsMiner stock restricted admin uid-300; root via rooted SD or /data overlay

The five invariants (enforced in Rust types, not docs)

  1. Never write the bootloader/secure region (AM335x/Zynq/A113D NAND loader partitions, CV1835 boot0, H616 eFuse). PartitionSpec carries a secure: bool; the write engine refuses secure targets unconditionally.
  2. Verify on an independent channel — positive marker match, then a liveness probe the installer did not control, then >= 2 unattended power cycles (persist gate).
  3. Reboot is root-only; dropped SSH can be success. The reboot stage treats a connection timeout as a candidate success and re-classifies via the liveness channel.
  4. Packer is per board. PackFormat is a board-owned enum (legacy uImage ramdisk, FIT, UBI/UBIFS, raw-partition dd); cross-board use is a compile- time non-representable state.
  5. Boot-switch is an explicit verified stage — recorded false positive (Amlogic UBI volume-name trap) encoded as a regression test.

3. Architecture

Cargo workspace, core in Rust, GUI per section 6.

crates/
  alkane-core/        domain: Board, SocFamily, SourceOs, TargetOs, Artifact,
                      Pathway, PipelineStage, PartitionSpec, Invariant checks
  alkane-discovery/   LAN discovery + classification (port of tools/net-scan.py,
                      incl. the two pending upgrades: multi-subnet/CIDR and the
                      ARP/ICMP pre-pass for link-up-but-silent boards)
  alkane-access/      foothold: SSH (russh) with legacy algo support
                      (diffie-hellman-group1-sha1, ssh-rsa, aes128-cbc for old
                      stock), credential table, Bitmain :4028 API client,
                      WhatsMiner :4028 update_firmware client (md5crypt token +
                      SHA256(pwd_md5) AES-ECB, u32-LE chunk framing, live-
                      verified; the 8889 binary daemon stays out: key unknown),
                      update-daemon loopback RCE driver, serial-transport mode
                      (a113d ethernet RX broken on bench units; serial
                      base64/bzip2 push ~10 KiB/s is proven)
  alkane-flash/       transfer + write engines: SSH exec-channel `cat >` pipes
                      (stock busyboxes have no SFTP server and no wget/tftp/nc;
                      use SFTP only where the OS provides it), mtd writers,
                      eMMC raw, per-board packers (FIT/uImage/UBI), env-rewrite
                      discipline (stage -> size-gate -> single-block dd ->
                      byte-compare readback), readback verification, LuxOS =
                      official installer as subprocess + ed25519 inject
                      watcher port, IMAGEWTY patching = debugfs subprocess
                      first (Rust ext4 writer later)
  alkane-artifacts/   artifact registry: manifest (sha256, board applicability,
                      source provenance; seed committed at
                      crates/alkane-artifacts/data/manifest-seed.csv), 
                      verify-image port (magic/min-size/integrity), 
                      stock-package library from the bench corpus
  alkane-cli/         headless driver for bench + scripting (`alkane-toolkit-cli`)
gui/                 native GUI (decision in section 6)
docs/                this plan, ADRs, safety-model

Key design decisions:

  • D1 — Recipes and board knowledge as data, consumed from alkane-sdk. Each {board, source-OS} recipe is a declarative pipeline (stage list + parameters) interpreted by the engine. The SDK already publishes the machine-readable half: boards/*/board.yml (SoC, arch, boot.partitions, install capabilities, firmware-install sources) and install/from-firmware/<board>/README.md (foothold, transfer, write, verify, revert). The toolkit parses these rather than duplicating them; persistence/ MTD tables (empty placeholders today) get materialized from board.yml + wiki/40-boot-os-and-build/board-os-matrix.md into the same machine-readable store.
  • D2 — Every stage is idempotent-or-resumable and produces an audit log entry (what, where, checksum before/after) so a failed install can be resumed or rolled back from the same state the log describes.
  • D3 — Reuse, don't rewrite, WhatMiner package building. The proven Python builders (scratch/wm-install-build/wm_package_builder.py, build_rooted_data.py, edit_wm_imagewty_h3.py) are ported to Rust with byte-for-byte output equivalence tests against captured vendor packages.
  • D4 — CLI first. Every GUI action maps 1:1 to a CLI verb; the GUI is a view. This keeps the bench (headless) and the operator (GUI) on one engine.

4. Bench-validated pathway matrix (what the engine must express)

From bench-wiki/boards/ + MEMORY-SNAPSHOT/ — each row is proven on our bench, so the recipe data format must carry all of this without special cases:

Board (SoC) Proven installs Foothold on stock Transfer Hard rules
am335x-bb (S19j Pro) 5/5 network-only (stock, LuxOS, ePIC, Braiins, Vnish → OurOS), round-tripped miner:miner + update-daemon loopback RCE SSH/SFTP autoboot abort = ESC with 1 s window (catcher first, then power); mtd0-3 never written; bootloader written last; no SD boot proven — NAND is the only net
zynq-7010 (S19) stock→OurOS, Vnish→OurOS network-only miner:miner + loopback RCE SSH/SFTP PS RSA eFuse is per-unit — read 0xF800D010 before planning; FIT unverified branch is the entry; autoboot 0 s (keys must pre-flood); stock console echoes but no getty
zynq-7010 (S17) stock NAND restore verified by CRC through U-Boot (2026-09-14) stock root with EMPTY password; legacy SSH algos (dh-group1-sha1, ssh-rsa, aes128-cbc) ymodem over serial for NAND writes; SSH for userspace board mtd char/block reads return EIO — verify only via U-Boot nand read+crc32; ymodem splits at ≤2047 blocks; reboot -f no-ops from RAM-boot (sysrq b)
a113d (BHB42XXX) 5/5 miner:miner + loopback RCE; amlenv.py edits env in-band over SSH (/dev/nand_env) SSH (net), U-Boot env is the boot switch UBI volume name is order-dependent (nvdada_log/umc_os_rootfs/overlay) — detect live, never hardcode; per-OS DHCP lease differs (false DARK trap — a failed self-report downgrades to WARNING, SSH fingerprint decides)
a113d hardened (S21 Pro) stock restore via env swap; two root paths miner:miner; daemon injection char-whitelisted (dead) — use eclipse/updatem forged {type:root} package → sudoers → root SSH or serial-only (base64/bzip2, ~10 KiB/s, ~11 min install) stock busybox has no wget/nc/tftp/curl/gzip/xz; console arg must be ttyAML0+meson earlycon or the board boots blind and the install looks failed
cv1835 (S19k Pro) 3/3 buildable (LuxOS no asset, ePIC wrong silicon excluded) miner:miner + /nvdata/rroot (non-permanent — p7 reformat destroys it; gate on rroot -c id) or loopback RCE SSH pipe (cat >, busybox has no wget/tftp/nc) Vnish/Braiins are RAM overlays on stock kernel — exit while overlay is live; eMMC boot0 eFuse-hook units cannot SD-recover; golden copy at raw LBA 0x300000 is the only net; serial catch needs 3 ms flood
allwinner H3/H6/H616 (WhatsMiner) rooted /data overlay survives genuine reinstall (proven on H616); genuine network update executed on H3 + H616 admin:admin uid-300 shell; root via /data/rootshell overlay (persists) or rooted SD image 4028 API update_firmware (AES-ECB + md5crypt token, ≤1 MB chunks); IMAGEWTY SD-burn for rooted card package format 0x9A5BA57C forgeable (MD5+CRC only); 8889 binary daemon AES key unknown — not implementable, use 4028; H616 payload key eFuse/OP-TEE-bound; H3 rootfs.fex LUKS (only /data slices editable); random MAC → DHCP moves

Fleet classification fingerprints: Antminer-family 4028 speaks {"command":...}; WhatsMiner speaks {"cmd":"get_version"} and rejects the other dialect — the cheapest reliable family split. SSH banner + KEX offering narrows OS generation (old stock = legacy-only algos).

5. Discovery + classification (M1 scope)

Scan engine = vendored asic-rs 0.8.1 (Apache-2.0, 256foundation; see ADR-0003): MinerFactory with subnet configuration, scan_stream() discovery, per-firmware entries for Antminer (stock, Braiins, Vnish, LuxOS, ePIC...), WhatsMiner, Marathon, Bitaxe and more, typed miner data (hashrate, temps, fans, power, pools). Our net-scan.py knowledge is folded in rather than ported line-for-line:

  • Multi-subnet / CIDR-list targeting (scan-ranges editor feeds it, per docs/UI-SPEC.md).
  • ARP/ICMP pre-pass so link-up-but-silent boards surface as a distinct row (a board we can identify but not log into is a restore candidate, not invisible) — ours to add; asic-rs only reports responders.
  • Our classification additions: install-pathway availability, foothold state, family splits asic-rs does not model (the command vs cmd :4028 dialect split, SSH banner/KEX generation fingerprint).
  • live-fleet-ops guardrails around the scan loop: rate limiting, no auth bursts, production ranges excluded unless explicitly enabled.

6. GUI: the wxWidgets decision

Requirement: native cross-platform GUI, wxWidgets vendored into the repo (ADR-0003, wx 3.3.3 pristine + patch queue). Primary view is fixed by the operator in docs/UI-SPEC.md (KPI header, scan-ranges editor, Excel-style filter panel, columns panel; sortable/drag-reorderable table with row checkboxes, IP pinned first, default order: hashrate, power, chip temp, cooling, firmware, pool worker, rest). Rust binding reality (checked crates.io 2026-09-14):

  • wxRust 0.0.1-alpha, unmaintained since 2022.
  • wx-rs 0.2.0 (2023, self-contained), ~6k downloads.

Neither is production-grade. Two ways to honor the requirement:

  • Option A (recommended): thin C++ wxWidgets shell + Rust core. gui/ is a small C++17 wx app (~1-2k lines: frames, lists, wizard, event glue) that calls the Rust core through a small stable C ABI exported by alkane-core (cdylib; header generated with cbindgen). All logic, safety invariants, and tests live in Rust. The shell holds zero business logic. wxWidgets is used as intended, on the mature C++ API, on all three OSes.
  • Option B: pure-Rust via wx-rs. Time-boxed spike first (M0): a window
    • tree/list + wizard + worker-thread progress + cancel, built and run on Linux and Windows. If the spike holds, keep pure Rust; otherwise fall back to A without having lost the week.

The plan proceeds on A as the default with the B spike as a gate in M0; the call is reversible until M3 (first GUI milestone).

7. Milestones

  • M0 — Scaffold + GUI decision. Workspace compiles (done), CI on gitea, ADRs (drafted), wx spike (Option B) executed against the vendored wx 3.3.3 + UI-SPEC table, binding decision recorded. Vendoring done: asic-rs 0.8.1 (cargo-vendored), wxWidgets 3.3.3 (pristine + patches/).
  • M1 — Discovery + classification. asic-rs MinerFactory integrated; KPI header + sortable table render the live bench (9 boards: S17 stock, S19 xil, S19j Pro bb, S19k Pro cv, S21 Pro aml, H3, H616, M50, WardenOS dev); scan-ranges editor, filter panel, columns panel per UI-SPEC; ARP/ICMP pre-pass added for silent boards; the per-OS-DHCP-lease false-DARK rule respected.
  • M2 — Artifact registry + verify-image. Seed manifest committed (14 artifacts with sha256: WhatsMiner SD programs, Bitmain stock zip, ePIC powerplay, BixBit .bmu set, forged WM packages, LuxOS installer); remaining: bulk archives (3.7 GB / 624 MB), firmware-analysis/downloads/ per-model corpus, and the verify-image magic/size/integrity checks.
  • M3 — First full pathway: zynq-7010. stock -> stock restore (proven on C49, the S17) and any-supported-source -> alkaneOS once the SDK's zynq artifacts exist. Foothold, exec-channel transfer, mtd write with readback verify, boot-switch, liveness + persist gates. This milestone exercises every invariant for real.
  • M4 — SD recovery builders. Port make-sd-*.sh + guided SD flow (generate image, verify, burn, boot instructions).
  • M5 — Remaining families. WhatsMiner (4028 update_firmware client + package builder port + /data overlay), a113d (serial transport + env discipline + hardened-S21 updatem vector), cv1835 (SSH pipe + p1 FIT), am335x-bb.
  • M6 — GUI completeness. Fleet view, install wizard with per-stage progress/abort, audit log viewer, cross-platform packaging.

Each milestone ends with a bench validation run against the 9-board fleet (none of which are live earners without explicit authorization).

v0 scope note: no alkaneOS build exists yet (SDK boards are in bake status; no rootfs/fit/uImage outputs). v0 therefore ships discovery + classification + stock<->stock installs + SD recovery; the alkaneOS target activates the same pipeline with different artifact references.

8. Safety model (non-negotiables encoded at M0)

  • secure partition writes are refused by the engine, not gated by the UI.
  • Console-attached requirement: any stage that touches kernel/boot-adjacent regions requires the operator to confirm a live serial console; the stage is blocked otherwise (standing order: never flash blind; both bricks were at the untestable U-Boot->kernel handoff).
  • Production fleet protection: discovery excludes RFC1918 ranges not explicitly enabled; no parallel auth attempts against a live earner.
  • Teardown of a live earner requires explicit operator authorization in the audit log (bench rule: always teardown .89/.106-class boards).
  • Every artifact is verified (sha256 + format magic) before any byte is written; verify-write on an independent channel after.

9. Open questions (for the operator)

  1. GUI binding: proceed with Option A default, or run the Option B spike first? (Plan assumes A with the spike as a cheap gate.)
  2. Target OS matrix for GUI packaging: Linux + Windows + macOS all three?
  3. "Install stock" set: which stock versions are canonical per board (the bench corpus has asicto stock packages for S17; S19/S19j Pro/S19k Pro/S21 stock packages need collection or the vnish cdn mirror)?
  4. alkaneOS artifact source: install waits on SDK board builds leaving bake status — v0 ships stock-restore + discovery until then?

10. References

  • ../alkane-sdk/main/docs/install-methods.md (invariants)
  • ../alkane-sdk/main/install/from-firmware/README.md (pattern + root vectors)
  • ../alkane-sdk/main/boards/ (board.yml: partitions, install capabilities)
  • Bench wiki: bench-wiki/boards/ (per-board install/restore evidence)
  • Memory notes: MEMORY-SNAPSHOT/ (firmware-flows-captured, whatsminer-*, cb4-sd-boot-bixbit-ssh, aml-stock-live-capture)
  • Tooling to port: tools/net-scan.py, scratch/cb6-api-re/wm_package_builder.py, scratch/wm-install-build/wm_install_client.py, scratch/wm-install-build/ IMAGEWTY editors, tools/luxos-inject-install.sh
  • Artifact seed manifest: crates/alkane-artifacts/data/manifest-seed.csv