From b1316b2bd9ccbb0dbc5544a19c5f105f7e8ea7a7 Mon Sep 17 00:00:00 2001 From: Noah <2+noah@noreply.gitea.bluefla.re> Date: Fri, 6 Nov 2026 08:35:39 -0600 Subject: [PATCH] Fix from-stock preflight: recognize AM335x stock, size-only mtd-map, honest dry-run targets Three fixes found running the real tier-3 preflight against the stock .64 board: - preflight fingerprint ended in 'ls ' which exits 1 on a stock board (none exist), failing the whole command; append '|| true'. - classify() only knew the Amlogic stock kernel (4.9.38); the AM335x stock is 3.8.13+ with an Antminer model line - recognize both so source-os matches the plan's stock-bitmain. - the mtd-map check compared the vendor label (spl/u-boot/...) to the mtdN device name and so always failed on real hardware; validate live geometry by index+size against the plan's partitions instead (labels are board-specific, not in our map). - dry-run message now lists the real write targets from the plan (was a hard-coded 'mtd8, mtd6 and mtd7' that omitted mtd4 on tier 3). Preflight + dry-run now PASS against the live stock board (all 10 checks). Unit suite still 41 green. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01B1W6qHxYpv7yf7Ah57g4rQ --- crates/alkane-cli/src/main.rs | 8 +++++++- crates/alkane-flash/src/boards/am335x.rs | 19 ++++++++++++------- crates/alkane-flash/src/preflight.rs | 9 ++++++++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/crates/alkane-cli/src/main.rs b/crates/alkane-cli/src/main.rs index 22ff3eaa..98129d5a 100644 --- a/crates/alkane-cli/src/main.rs +++ b/crates/alkane-cli/src/main.rs @@ -463,7 +463,13 @@ fn run_install(args: &[String]) -> Result<(), Box> { AmInstallOutcome::DryRun(report) => { print!("{}", report.render()); println!("DRY RUN: no board erase or write was performed."); - println!("Re-run with --confirm FLASH to write mtd8, mtd6 and mtd7."); + let targets = plan + .targets + .iter() + .map(|t| t.partition.name.as_str()) + .collect::>() + .join(", "); + println!("Re-run with --confirm FLASH to write {targets}."); } AmInstallOutcome::Installed(receipt) => { for backup in &receipt.backups { diff --git a/crates/alkane-flash/src/boards/am335x.rs b/crates/alkane-flash/src/boards/am335x.rs index eceb565d..c019232f 100644 --- a/crates/alkane-flash/src/boards/am335x.rs +++ b/crates/alkane-flash/src/boards/am335x.rs @@ -580,7 +580,8 @@ pub fn preflight( let fingerprint = remote.user_command( "uname -r; echo __MODEL__; cat /proc/device-tree/model 2>/dev/null; echo; \ echo __RELEASE__; cat /etc/os-release 2>/dev/null; \ - ls /etc/alkane-release /etc/ouros-release /etc/bos_version /etc/fw-info 2>/dev/null", + ls /etc/alkane-release /etc/ouros-release /etc/bos_version /etc/fw-info 2>/dev/null \ + || true", Duration::from_secs(20), )?; let text = String::from_utf8_lossy(&fingerprint).into_owned(); @@ -622,16 +623,20 @@ pub fn preflight( )?) .into_owned(); let mtd = parse_proc_mtd(&mtd_text); - let map_ok = MTD_MAP.iter().all(|(name, _, size, ..)| { - mtd.get(*name) - .map(|entry: &(u64, String)| entry.0 == *size && entry.1 == *name) - .unwrap_or(false) - }); + // Validate the live geometry against the plan's partitions by index+size. + // The vendor labels (spl, u-boot, kernel, ...) are board-specific and are + // not part of our map, so only the mtdN index and its size are checked. + let map_ok = plan.partitions.len() == mtd.len() + && plan.partitions.iter().all(|part| { + mtd.get(&part.name) + .map(|entry: &(u64, String)| entry.0 == part.size) + .unwrap_or(false) + }); checks.push(AmCheck { name: "mtd-map".to_owned(), ok: map_ok, detail: if map_ok { - "12 partitions match the captured map".to_owned() + format!("{} partitions match the plan geometry by size", plan.partitions.len()) } else { format!("partition table differs: {mtd_text}") }, diff --git a/crates/alkane-flash/src/preflight.rs b/crates/alkane-flash/src/preflight.rs index 729328f3..ef8f7e55 100644 --- a/crates/alkane-flash/src/preflight.rs +++ b/crates/alkane-flash/src/preflight.rs @@ -354,7 +354,14 @@ pub(crate) fn classify(kernel: &str, release: &str, all: &str) -> String { if all.contains("/etc/fw-info") || release.contains("Vnish") || release.contains("AnthillOS") { return "vnish".to_owned(); } - if kernel.contains("4.9.38") || all.contains("update-daemon") || all.contains("rroot") { + // Stock Bitmain control boards: Amlogic stock is kernel 4.9.38; the AM335x + // (BeagleBone-class) stock is kernel 3.8.13+ with an "Antminer" model line. + if kernel.contains("4.9.38") + || kernel.starts_with("3.8.13") + || all.contains("update-daemon") + || all.contains("rroot") + || all.to_lowercase().contains("antminer") + { return "stock-bitmain".to_owned(); } "unknown".to_owned()