commit 86fd5d8d4cd22bfb562b7f40811ea8a4522ca9fe Author: noah Date: Tue Sep 15 09:06:29 2026 -0600 Scaffold: workspace crates + implementation plan draft diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..022a2bbc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +Cargo.lock +.cargo/config.toml diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..ab1129f4 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,20 @@ +[workspace] +resolver = "2" +members = [ + "crates/alkane-core", + "crates/alkane-discovery", + "crates/alkane-access", + "crates/alkane-flash", + "crates/alkane-artifacts", + "crates/alkane-cli", +] + +[workspace.package] +version = "0.1.0" +edition = "2021" +license = "MIT OR Apache-2.0" + +[workspace.dependencies] +thiserror = "2" +serde = { version = "1", features = ["derive"] } +sha2 = "0.10" diff --git a/README.md b/README.md new file mode 100644 index 00000000..0ca396b3 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# alkane-toolkit + +Cross-platform desktop toolkit (Rust core, native GUI) to install **stock** or +**alkaneOS** firmware on ASIC miner control boards, whatever they currently run +(stock, Vnish/AnthillOS, Braiins OS+, LuxOS, ePIC, BixBit, WardenOS). + +Sibling to [alkane-sdk](https://gitea.bluefla.re/blueflare/alkane-sdk): the SDK +owns board knowledge and build outputs; this toolkit is the orchestration +engine and operator UI that executes its install recipes safely. + +## Status + +In planning. See `docs/IMPLEMENTATION-PLAN.md`. + +## Hard rules (from alkane-sdk `docs/install-methods.md`, encoded in code) + +1. Never write the bootloader/secure region. +2. Verify on a channel the installer does not control. +3. Reboot is root-only; a dropped SSH connection can be success. +4. A packer is per board; never reuse across boards. +5. Boot-switch handling is an explicit, verified step. diff --git a/crates/alkane-access/Cargo.toml b/crates/alkane-access/Cargo.toml new file mode 100644 index 00000000..3968da9e --- /dev/null +++ b/crates/alkane-access/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "alkane-access" +version.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +alkane-core = { path = "../alkane-core" } diff --git a/crates/alkane-access/src/lib.rs b/crates/alkane-access/src/lib.rs new file mode 100644 index 00000000..60eb655f --- /dev/null +++ b/crates/alkane-access/src/lib.rs @@ -0,0 +1 @@ +// alkane-access diff --git a/crates/alkane-artifacts/Cargo.toml b/crates/alkane-artifacts/Cargo.toml new file mode 100644 index 00000000..62307ec1 --- /dev/null +++ b/crates/alkane-artifacts/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "alkane-artifacts" +version.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +alkane-core = { path = "../alkane-core" } diff --git a/crates/alkane-artifacts/src/lib.rs b/crates/alkane-artifacts/src/lib.rs new file mode 100644 index 00000000..febec870 --- /dev/null +++ b/crates/alkane-artifacts/src/lib.rs @@ -0,0 +1 @@ +// alkane-artifacts diff --git a/crates/alkane-cli/Cargo.toml b/crates/alkane-cli/Cargo.toml new file mode 100644 index 00000000..75584240 --- /dev/null +++ b/crates/alkane-cli/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "alkane-cli" +version.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +alkane-core = { path = "../alkane-core" } diff --git a/crates/alkane-cli/src/lib.rs b/crates/alkane-cli/src/lib.rs new file mode 100644 index 00000000..c6a08f70 --- /dev/null +++ b/crates/alkane-cli/src/lib.rs @@ -0,0 +1,2 @@ +//! Headless driver over the same engine the GUI uses. +fn main() { println!("alkane-toolkit-cli: scaffold"); } diff --git a/crates/alkane-core/Cargo.toml b/crates/alkane-core/Cargo.toml new file mode 100644 index 00000000..04e84424 --- /dev/null +++ b/crates/alkane-core/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "alkane-core" +version.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +thiserror.workspace = true +serde.workspace = true diff --git a/crates/alkane-core/src/lib.rs b/crates/alkane-core/src/lib.rs new file mode 100644 index 00000000..55238eb6 --- /dev/null +++ b/crates/alkane-core/src/lib.rs @@ -0,0 +1 @@ +// alkane-core diff --git a/crates/alkane-discovery/Cargo.toml b/crates/alkane-discovery/Cargo.toml new file mode 100644 index 00000000..8982c4bc --- /dev/null +++ b/crates/alkane-discovery/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "alkane-discovery" +version.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +alkane-core = { path = "../alkane-core" } diff --git a/crates/alkane-discovery/src/lib.rs b/crates/alkane-discovery/src/lib.rs new file mode 100644 index 00000000..846d3578 --- /dev/null +++ b/crates/alkane-discovery/src/lib.rs @@ -0,0 +1 @@ +// alkane-discovery diff --git a/crates/alkane-flash/Cargo.toml b/crates/alkane-flash/Cargo.toml new file mode 100644 index 00000000..f222f51a --- /dev/null +++ b/crates/alkane-flash/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "alkane-flash" +version.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +alkane-core = { path = "../alkane-core" } diff --git a/crates/alkane-flash/src/lib.rs b/crates/alkane-flash/src/lib.rs new file mode 100644 index 00000000..f7b72c75 --- /dev/null +++ b/crates/alkane-flash/src/lib.rs @@ -0,0 +1 @@ +// alkane-flash diff --git a/docs/IMPLEMENTATION-PLAN.md b/docs/IMPLEMENTATION-PLAN.md new file mode 100644 index 00000000..dee0f50d --- /dev/null +++ b/docs/IMPLEMENTATION-PLAN.md @@ -0,0 +1,211 @@ +# 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-*)