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

11 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 5.

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 API + remote-daemon :8889 client (AES-256 +
                      token auth md5_crypt, cmd 0x7 install, cmd 0xd ssh toggle)
  alkane-flash/       transfer + write engines: SFTP/SSH-pipe dd, mtd writers,
                      eMMC raw, per-board packers (FIT/uImage/UBI), env-rewrite
                      discipline (stage -> size-gate -> single-block dd ->
                      byte-compare readback), readback verification
  alkane-artifacts/   artifact registry: manifest (sha256, board applicability,
                      source provenance), 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 5)
docs/                this plan, ADRs, safety-model

Key design decisions:

  • D1 — Recipes as data. Each {board, source-OS} recipe is a declarative pipeline (stage list + parameters) interpreted by the engine, mirroring the SDK's five-facts format (foothold, transfer, write target, verify, revert). Adding a board/OS pair is data + tests, not new control flow.
  • 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. Discovery + classification (M1 scope)

Port of tools/net-scan.py plus the two already-agreed upgrades:

  • Multi-subnet / CIDR-list targeting.
  • 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).
  • Probes: TCP 4028 (cgminer API), 80/8080 (vendor http), 8889 (WhatsMiner remote-daemon), 22 (SSH banner grab: dropbear/OpenSSH + algo fingerprint narrows the OS), plus WhatsMiner binary API cmd 0 read for model/firmware.
  • Output: machine inventory (ip, model, current fw family + version, board family guess, access level) feeding the install wizard.

Respect live-fleet-ops rules: rate-limited, no auth bursts, production ranges excluded by default.

5. GUI: the wxWidgets decision

Requirement: native cross-platform GUI, wxWidgets. 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).

6. Milestones

  • M0 — Scaffold + GUI decision. Workspace compiles, CI on gitea, ADRs for D1-D4, wx spike (Option B) executed, binding decision recorded.
  • M1 — Discovery + classification. Inventory table over a real bench subnet; the 9-board bench identifies correctly (S17 stock, S19 xil, S19j Pro bb, S19k Pro cv, S21 Pro aml, H3, H616, M50, WardenOS dev).
  • M2 — Artifact registry + verify-image. Manifest of the stock packages already on the bench (Antminer stock S17 package, WhatsMiner SD programs, powerplay .ubifs, vendor zips) with sha256; 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, SFTP 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 (remote-daemon install + package builder port + /data overlay), a113d (serial transfer + env discipline), 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).

7. 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.

8. 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?

9. References

  • ../alkane-sdk/main/docs/install-methods.md
  • ../alkane-sdk/main/install/from-firmware/README.md
  • ../alkane-sdk/main/boards/ (per-board metadata)
  • Bench wiki: bench-wiki/boards/ (per-board install/restore evidence)
  • Memory notes: MEMORY-SNAPSHOT/ (firmware-flows-captured, whatsminer-*)