toolkit: install from local/latest afw + from-stock/restore seams + fix zynq offsets

Integrate the SDK installer into the toolkit so it can put alkane-os on a
compatible miner (for now the Antminer S17 / zynq-7010) from a local .afw or an
auto-pulled latest release, and remove it (back to stock). Release host is the
self-hosted Gitea (GitHub is retired).

- FIX (brick risk): boards/zynq.rs carried the superseded stage-2 offsets
  (BOOTBIN_PRESERVE 0x2200000, kernel 0x2200000, dtb 0x2700000). Corrected to the
  live S17 / SDK-plan layout: BOOT.bin floor 0x1a00000, dtb 0x1a00000, kernel
  0x2000000 (slot 0x800000), rootfs mtd1. The tier-2 update now writes the right
  slots; test updated to the new ceiling.
- alkane-artifacts/fetch.rs: resolve and download the latest .afw for a board
  from Gitea releases/latest (curl + serde_json), token read from
  ALKANE_RELEASE_TOKEN/GITEA_TOKEN at run time and passed via a 0600 curl config,
  never argv, never stored.
- alkane-flash/stock.rs: the seam to the sealed, DSH-owned stock-side methods
  (install-from-stock, restore-to-stock). Interface only - an external
  ALKANE_STOCK_HELPER the toolkit invokes and then verifies the board itself; the
  method is never embedded, read, or reviewed here.
- alkane-cli: new `afw compat` (shows supported boards), `afw fetch-latest`,
  `afw install --latest [--board] [--from-stock]`, and `afw restore-stock`. The
  install/restore commands gate on a supported board. --from-stock routes the
  first install through the sealed helper; the default install path is the
  tier-2 update of a board already on alkane.
- docs/install.md documents the flow and the two env seams.

alkane-artifacts + alkane-flash + alkane-cli build clean, 71 tests pass, the new
files are clippy-clean (the one type_complexity warning is pre-existing in
afw.rs, untouched). No emojis.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BdKQBPjAXpCwmigUov5eQk
This commit is contained in:
2026-11-10 22:12:47 -06:00
co-authored by Claude Opus 4.8
parent 462ced01a6
commit 400edbe913
7 changed files with 542 additions and 17 deletions
+144 -7
View File
@@ -6,6 +6,8 @@
//! the command line. This program never prints a credential value.
use alkane_artifacts::afw::{verify_afw, VerifiedAfw, VerifyOptions};
use alkane_artifacts::fetch::{self, ReleaseSource};
use alkane_flash::stock;
use alkane_artifacts::{seed_manifest, verify_file};
use alkane_core::platform;
use alkane_flash::boards::am335x::{
@@ -450,12 +452,46 @@ fn run_preflight(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
/// Install onto a board currently on stock via the sealed from-stock method.
fn install_from_stock_flow(
verified: &VerifiedAfw,
host: &str,
afw: &Path,
opts: &Opts,
) -> Result<(), Box<dyn std::error::Error>> {
if opts.flag("dry-run") {
println!(
"DRY RUN: would install {} onto stock board {host} via the sealed from-stock method ({})",
verified.manifest.board,
afw.display()
);
return Ok(());
}
if opts.value("confirm") != Some("FLASH") {
return Err("refusing to install from stock without --confirm FLASH".into());
}
if !stock::available() {
return Err(
"no stock helper configured: set ALKANE_STOCK_HELPER to the dsh-provided from-stock installer".into(),
);
}
println!(
"installing {} onto stock board {host} (sealed from-stock method)...",
verified.manifest.board
);
stock::install_from_stock(host, afw)?;
println!("from-stock install reported success.");
println!("verify the board is now reachable as alkane:");
println!(" alkane-cli afw verify-live --host {host} --timeout 300");
Ok(())
}
fn run_install(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let opts = parse_args(
args,
&[
ssh_values(),
&["held-backup", "backup-dir", "confirm", "expect-board"],
&["held-backup", "backup-dir", "confirm", "expect-board", "board"],
]
.concat(),
&[
@@ -464,13 +500,26 @@ fn run_install(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
"check-golden",
"dry-run",
"no-reboot",
"latest",
"from-stock",
],
)?;
let path = opts
.positionals
.first()
.ok_or("usage: alkane-cli afw install <file> --host <ip> --dry-run|--confirm FLASH")?;
let verified = load_afw(path, &opts)?;
let path = resolve_afw_source(&opts)?;
let verified = load_afw(&path.to_string_lossy(), &opts)?;
if !is_supported(&verified.manifest.board) {
return Err(format!(
"{} is not a supported install target (see: alkane-cli afw compat)",
verified.manifest.board
)
.into());
}
// A board on stock: the first install goes through the sealed from-stock
// method; the tier-2 partition-write path below is for a board already on
// alkane.
if opts.flag("from-stock") {
let host = opts.value("host").ok_or("--host is required")?.to_owned();
return install_from_stock_flow(&verified, &host, &path, &opts);
}
let (ssh, _secret) = ssh_options(&opts, DEFAULT_USER)?;
let mut transport = SshTransport::connect(ssh, true)?;
let backup_dir = opts
@@ -856,12 +905,95 @@ fn latest_backup(dir: &Path) -> Option<PathBuf> {
entries.pop()
}
/// Boards this toolkit can install alkane onto, with the miner each is the
/// control board for. The install/restore gate is the .afw's board matching one
/// of these; `compat` lists them so an operator knows what is supported.
const SUPPORTED: &[(&str, &str)] = &[("zynq-7010", "Antminer S17 (Xilinx Zynq-7010 control board)")];
fn is_supported(board: &str) -> bool {
SUPPORTED.iter().any(|(b, _)| *b == board)
}
fn run_compat(_args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
println!("alkane-os install is supported on:");
for (board, miner) in SUPPORTED {
println!(" {board:<12} {miner}");
}
println!("\nInstall a local bundle: alkane-cli afw install <file.afw> --host <ip> --confirm FLASH");
println!("Install the latest build: alkane-cli afw install --latest --board zynq-7010 --host <ip> --confirm FLASH");
println!("Remove (back to stock): alkane-cli afw restore-stock --host <ip> --confirm FLASH");
Ok(())
}
fn download_dir() -> PathBuf {
platform::config_path("downloads")
}
/// Fetch the latest alkane-os .afw for a board from Gitea into the cache.
fn run_fetch_latest(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let opts = parse_args(args, &["board", "output"], &[])?;
let board = opts.value("board").unwrap_or("zynq-7010");
if !is_supported(board) {
return Err(format!("{board} is not a supported install target (see: alkane-cli afw compat)").into());
}
let dest = opts.value("output").map(PathBuf::from).unwrap_or_else(download_dir);
let path = fetch::fetch_latest_afw(&ReleaseSource::alkane_os(), board, &dest)?;
println!("fetched {}", path.display());
Ok(())
}
/// Resolve the .afw either from `--latest` (fetch from Gitea) or a positional
/// file path.
fn resolve_afw_source(opts: &Opts) -> Result<PathBuf, Box<dyn std::error::Error>> {
if opts.flag("latest") {
let board = opts.value("board").unwrap_or("zynq-7010");
if !is_supported(board) {
return Err(format!("{board} is not a supported install target (see: alkane-cli afw compat)").into());
}
println!("fetching the latest {board} release from Gitea...");
let path = fetch::fetch_latest_afw(&ReleaseSource::alkane_os(), board, &download_dir())?;
println!("using {}", path.display());
return Ok(path);
}
opts.positionals
.first()
.map(PathBuf::from)
.ok_or_else(|| "usage: alkane-cli afw install <file>|--latest --host <ip> --confirm FLASH".into())
}
/// Return an alkane board to genuine stock via the sealed stock-restore method,
/// then leave the independent verification to the operator/bench.
fn run_restore_stock(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let opts = parse_args(args, &["host", "confirm"], &["dry-run"])?;
let host = opts.value("host").ok_or("--host is required")?;
if !stock::available() {
return Err(
"no stock helper configured: set ALKANE_STOCK_HELPER to the dsh-provided restore helper".into(),
);
}
if opts.flag("dry-run") {
println!("DRY RUN: would restore {host} to stock via the sealed restore-to-stock method");
return Ok(());
}
if opts.value("confirm") != Some("FLASH") {
return Err("refusing to restore without --confirm FLASH".into());
}
println!("restoring {host} to stock (sealed method)...");
stock::restore_to_stock(host)?;
println!("restore-to-stock reported success.");
println!("verify independently: the board should no longer answer as alkane (no alkane console/API),");
println!("and should present its genuine stock OS. Confirm over the network or serial before reuse.");
Ok(())
}
fn run_afw(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let subcommand = args.first().ok_or(
"usage: alkane-cli afw <verify|inspect|plan|preflight|install|verify-live|restore>",
"usage: alkane-cli afw <compat|fetch-latest|verify|inspect|plan|preflight|install|verify-live|restore|restore-stock>",
)?;
let rest = &args[1..];
match subcommand.as_str() {
"compat" => run_compat(rest),
"fetch-latest" => run_fetch_latest(rest),
"verify" => run_verify(rest),
"inspect" => run_inspect(rest),
"plan" => run_plan(rest),
@@ -869,6 +1001,7 @@ fn run_afw(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
"install" => run_install(rest),
"verify-live" => run_verify_live(rest),
"restore" => run_restore(rest),
"restore-stock" => run_restore_stock(rest),
other => Err(format!("unknown afw subcommand {other}").into()),
}
}
@@ -901,6 +1034,10 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
if command == "-h" || command == "--help" || command == "help" {
println!(
"usage:\n alkane-cli verify-artifact <manifest-path> <local-file>\n \
alkane-cli afw compat\n \
alkane-cli afw fetch-latest [--board zynq-7010] [--output <dir>]\n \
alkane-cli afw install --latest [--board zynq-7010] --host <ip> --confirm FLASH [--from-stock] [ssh options]\n \
alkane-cli afw restore-stock --host <ip> --confirm FLASH\n \
alkane-cli afw verify <file> [--allow-unsigned] [--expect-board <board>]\n \
alkane-cli afw inspect <file> [--allow-unsigned]\n \
alkane-cli afw plan <file> --host <ip> [ssh options]\n \