From 9c49fa91af191efb62cf6d20cda1e10f3dfe584e Mon Sep 17 00:00:00 2001 From: Noah <2+noah@noreply.gitea.bluefla.re> Date: Mon, 16 Nov 2026 17:28:37 -0600 Subject: [PATCH] style: rustfmt the a113d flash engine + CLI (cargo fmt) #52's verify never actually ran before (the alkane-verify runner was offline), so cargo fmt --check was never enforced on this branch. Apply rustfmt to the three flagged files (alkane-cli main.rs, alkane-flash aml_ubi.rs and zynq_nand.rs) to match the toolkit's CI fmt gate. No behavioural change; vendored thirdparty/ is untouched (CI only formats the named crates). Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i --- crates/alkane-cli/src/main.rs | 76 ++++++++++++++++++------ crates/alkane-flash/src/aml_ubi.rs | 18 +++--- crates/alkane-flash/src/zynq_nand.rs | 89 +++++++++++++++++++--------- 3 files changed, 131 insertions(+), 52 deletions(-) diff --git a/crates/alkane-cli/src/main.rs b/crates/alkane-cli/src/main.rs index 6c58d8a5..513c1e21 100644 --- a/crates/alkane-cli/src/main.rs +++ b/crates/alkane-cli/src/main.rs @@ -22,8 +22,8 @@ use alkane_flash::preflight::{preflight, PreflightOptions}; use alkane_flash::stock; use alkane_flash::stock::{InPlaceOptions, InPlaceOutcome, RestoreImages}; use alkane_flash::stock_firmware; -use alkane_flash::zynq_nand; use alkane_flash::transport::{Remote, RootMethod, SshOptions, SshTransport}; +use alkane_flash::zynq_nand; use std::collections::{BTreeMap, BTreeSet}; use std::fs; use std::path::{Path, PathBuf}; @@ -1042,7 +1042,10 @@ fn latest_backup(dir: &Path) -> Option { /// 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)"), - ("a113d", "Antminer BHB42XXX / S19k Pro (Amlogic A113D/AXG control board)"), + ( + "a113d", + "Antminer BHB42XXX / S19k Pro (Amlogic A113D/AXG control board)", + ), ]; fn is_supported(board: &str) -> bool { @@ -1128,7 +1131,9 @@ fn run_restore_stock(args: &[String]) -> Result<(), Box> None => { if opts.flag("dry-run") { println!("DRY RUN: would restore {host} to stock by flipping the A113D boot flag"); - println!("(no stock firmware needed; the untouched stock boot partition is booted)."); + println!( + "(no stock firmware needed; the untouched stock boot partition is booted)." + ); println!("Re-run with --confirm FLASH."); return Ok(()); } @@ -1138,7 +1143,9 @@ fn run_restore_stock(args: &[String]) -> Result<(), Box> println!("restoring {host} to genuine stock (A113D flag flip, network-only)..."); match stock::restore_aml_flag(&host, password.as_deref()) { Ok(()) => { - println!("restore reported success (boot flag cleared; stock boots via storeboot)."); + println!( + "restore reported success (boot flag cleared; stock boots via storeboot)." + ); println!("verify independently: the board should present genuine stock"); println!("(cgminer API on :4028, lighttpd 401 on :80, dropbear 2018.x)."); return Ok(()); @@ -1186,9 +1193,7 @@ fn run_restore_stock(args: &[String]) -> Result<(), Box> fn run_root_run(args: &[String]) -> Result<(), Box> { let opts = parse_args(args, ssh_values(), &[])?; let host = opts.value("host").ok_or("--host is required")?.to_owned(); - let cmd = opts - .positionals - .join(" "); + let cmd = opts.positionals.join(" "); if cmd.trim().is_empty() { return Err("usage: alkane-cli afw root-run --host ".into()); } @@ -1203,7 +1208,11 @@ fn run_root_run(args: &[String]) -> Result<(), Box> { /// backup, write the boot slots and reboot. Drives the DSH root-on-stock /// primitive; board must be on stock (credential root/root). fn run_nand_install(args: &[String]) -> Result<(), Box> { - let opts = parse_args(args, &[ssh_values(), &["confirm"]].concat(), &["allow-unsigned"])?; + let opts = parse_args( + args, + &[ssh_values(), &["confirm"]].concat(), + &["allow-unsigned"], + )?; let host = opts.value("host").ok_or("--host is required")?.to_owned(); let afw_path = opts .positionals @@ -1211,18 +1220,33 @@ fn run_nand_install(args: &[String]) -> Result<(), Box> { .ok_or("usage: alkane-cli afw nand-install --host --confirm FLASH")?; let verified = load_afw(afw_path, &opts)?; if !zynq::owns_board(&verified.manifest.board) { - return Err(format!("nand-install is zynq-7010 only, not {}", verified.manifest.board).into()); + return Err(format!( + "nand-install is zynq-7010 only, not {}", + verified.manifest.board + ) + .into()); } if opts.value("confirm") != Some("FLASH") { return Err("refusing to install without --confirm FLASH".into()); } - let kernel = verified.image("kernel").ok_or("afw missing kernel image")?.1; + let kernel = verified + .image("kernel") + .ok_or("afw missing kernel image")? + .1; let dtb = verified.image("dtb").ok_or("afw missing dtb image")?.1; - let rootfs = verified.image("rootfs").ok_or("afw missing rootfs image")?.1; + let rootfs = verified + .image("rootfs") + .ok_or("afw missing rootfs image")? + .1; let password = read_board_password(&opts)?; - println!("installing {} onto stock board {host} (readable NAND path)...", verified.manifest.board); + println!( + "installing {} onto stock board {host} (readable NAND path)...", + verified.manifest.board + ); zynq_nand::install_from_stock(&host, kernel, dtb, rootfs, password.as_deref())?; - println!("install reported success (on-board stock backup carved; boot slots written; rebooting)."); + println!( + "install reported success (on-board stock backup carved; boot slots written; rebooting)." + ); print!("{}", zynq_verify_hint(&host)); Ok(()) } @@ -1231,9 +1255,15 @@ fn run_nand_install(args: &[String]) -> Result<(), Box> { /// back to the boot slots over SSH (board on alkane). Needs the alkane image /// that exposes the boot partitions. fn run_nand_restore_stock(args: &[String]) -> Result<(), Box> { - let opts = parse_args(args, &[ssh_values(), &["confirm", "stock-firmware"]].concat(), &["dry-run"])?; + let opts = parse_args( + args, + &[ssh_values(), &["confirm", "stock-firmware"]].concat(), + &["dry-run"], + )?; let host = opts.value("host").ok_or("--host is required")?.to_owned(); - let firmware = opts.value("stock-firmware").ok_or("--stock-firmware is required")?; + let firmware = opts + .value("stock-firmware") + .ok_or("--stock-firmware is required")?; let fw = stock_firmware::parse(Path::new(firmware))?; println!("stock firmware: {}", fw.summary()); if opts.value("confirm") != Some("FLASH") { @@ -1241,8 +1271,16 @@ fn run_nand_restore_stock(args: &[String]) -> Result<(), Box Result<(), Box password.as_deref(), std::time::Duration::from_secs(300), )?; - println!("restore-from-onboard reported success. Verify independently the board answers as stock."); + println!( + "restore-from-onboard reported success. Verify independently the board answers as stock." + ); Ok(()) } diff --git a/crates/alkane-flash/src/aml_ubi.rs b/crates/alkane-flash/src/aml_ubi.rs index 87ee2163..30044bcb 100644 --- a/crates/alkane-flash/src/aml_ubi.rs +++ b/crates/alkane-flash/src/aml_ubi.rs @@ -53,8 +53,7 @@ const FLAG_MAGIC: [u8; 4] = *b"ALAN"; const KRNADDR: &str = "0x1200000"; const FDTADDR: &str = "0x8000000"; const RDADDR: &str = "0x8100000"; -const ALK_BOOTARGS: &str = - "console=ttyAML0,115200 earlycon=meson,0xff803000 no_console_suspend"; +const ALK_BOOTARGS: &str = "console=ttyAML0,115200 earlycon=meson,0xff803000 no_console_suspend"; /// The on-board basenames inside the nvdata UBI volume's `alkane/` directory. const ALKANE_DIR: &str = "alkane"; @@ -110,8 +109,8 @@ impl AlkaneShell { root_method: crate::transport::RootMethod::Auto, update_daemon_port: None, }; - let transport = SshTransport::connect(options, true) - .map_err(|e| StockError::Network(e.to_string()))?; + let transport = + SshTransport::connect(options, true).map_err(|e| StockError::Network(e.to_string()))?; Ok(AlkaneShell { transport, _secret: secret, @@ -607,7 +606,10 @@ mod tests { #[test] fn env_roundtrips_with_crc() { let vars = vec![ - ("bootcmd".to_owned(), "run checkalk; run storeboot".to_owned()), + ( + "bootcmd".to_owned(), + "run checkalk; run storeboot".to_owned(), + ), ("bootdelay".to_owned(), "1".to_owned()), ("checkalk".to_owned(), checkalk_value()), ]; @@ -616,8 +618,10 @@ mod tests { let stored = u32::from_le_bytes([blob[0], blob[1], blob[2], blob[3]]); assert_eq!(crc32(&blob[4..]), stored); let parsed = parse_env(&blob); - assert_eq!(parsed.iter().find(|(k, _)| k == "bootcmd").unwrap().1, - "run checkalk; run storeboot"); + assert_eq!( + parsed.iter().find(|(k, _)| k == "bootcmd").unwrap().1, + "run checkalk; run storeboot" + ); assert!(parsed.iter().any(|(k, _)| k == "checkalk")); } diff --git a/crates/alkane-flash/src/zynq_nand.rs b/crates/alkane-flash/src/zynq_nand.rs index 999c22b7..10d7a5ed 100644 --- a/crates/alkane-flash/src/zynq_nand.rs +++ b/crates/alkane-flash/src/zynq_nand.rs @@ -157,8 +157,8 @@ impl AlkaneShell { root_method: crate::transport::RootMethod::Auto, update_daemon_port: None, }; - let transport = SshTransport::connect(options, true) - .map_err(|e| StockError::Network(e.to_string()))?; + let transport = + SshTransport::connect(options, true).map_err(|e| StockError::Network(e.to_string()))?; Ok(AlkaneShell { transport, _secret: secret, @@ -225,11 +225,7 @@ fn read_mtd_table(sh: &mut dyn Shell) -> Result, StockError> { .and_then(|h| u64::from_str_radix(h, 16).ok()) .ok_or_else(|| StockError::Method(format!("bad /proc/mtd line: {line}")))?; let _erase = it.next(); - let name = line - .split('"') - .nth(1) - .unwrap_or("") - .to_owned(); + let name = line.split('"').nth(1).unwrap_or("").to_owned(); let base = match sysfs_offset(sh, dev) { Some(off) => off, None => cursor, @@ -257,11 +253,7 @@ fn sysfs_offset(sh: &mut dyn Shell, dev: &str) -> Option { /// Find the partition that contains `abs` and holding at least `len` bytes from /// there; return (device, relative offset). -fn locate<'a>( - table: &'a [Mtd], - abs: u64, - len: u64, -) -> Result<(&'a str, u64), StockError> { +fn locate<'a>(table: &'a [Mtd], abs: u64, len: u64) -> Result<(&'a str, u64), StockError> { for m in table { if abs >= m.base && abs < m.base + m.size { let rel = abs - m.base; @@ -335,7 +327,9 @@ fn write_abs( if o.contains("WROTE") { Ok(()) } else { - Err(StockError::Method(format!("{label}: erase/write failed: {o}"))) + Err(StockError::Method(format!( + "{label}: erase/write failed: {o}" + ))) } })?; let readlen = round_up(data.len() as u64, PAGE); @@ -513,7 +507,13 @@ fn carve_backup(sh: &mut dyn Shell, table: &[Mtd]) -> Result, } -fn write_boot_slots( - sh: &mut dyn Shell, - table: &[Mtd], - img: &BootImages, -) -> Result<(), StockError> { +fn write_boot_slots(sh: &mut dyn Shell, table: &[Mtd], img: &BootImages) -> Result<(), StockError> { // rootfs, dtb, kernel order: an interrupted run never leaves a new rootfs // under an old kernel. if img.rootfs_uimage.len() as u64 > SLOT_ROOTFS { @@ -623,7 +619,9 @@ pub fn install_from_stock( password: password.map(str::to_owned), }; if first_token(&sh.exec("id -u")?) != "0" { - return Err(StockError::Auth("did not obtain root on the stock board".into())); + return Err(StockError::Auth( + "did not obtain root on the stock board".into(), + )); } let table = read_mtd_table(&mut sh)?; // Carve the genuine-stock backup from the live stock NAND before any write. @@ -674,7 +672,14 @@ pub fn restore_to_stock( "no stock dtb supplied and no on-board backup to take one from".into(), ) })?; - copy_abs(&mut sh, &table, manifest.dtb_abs, OFF_DTB, manifest.dtb_len, "dtb")?; + copy_abs( + &mut sh, + &table, + manifest.dtb_abs, + OFF_DTB, + manifest.dtb_len, + "dtb", + )?; } } write_abs(&mut sh, &table, OFF_KERNEL, kernel_uimage, "kernel")?; @@ -703,14 +708,34 @@ pub fn restore_from_onboard(host: &str, password: Option<&str>) -> Result<(), St let manifest = read_backup_manifest(&mut sh, &table)? .ok_or_else(|| StockError::Method("no complete on-board stock backup".into()))?; // Copy within NAND: backup region -> boot slots. - copy_abs(&mut sh, &table, manifest.rootfs_abs, OFF_ROOTFS, manifest.rootfs_len, "rootfs")?; - copy_abs(&mut sh, &table, manifest.dtb_abs, OFF_DTB, manifest.dtb_len, "dtb")?; - copy_abs(&mut sh, &table, manifest.kernel_abs, OFF_KERNEL, manifest.kernel_len, "kernel")?; + copy_abs( + &mut sh, + &table, + manifest.rootfs_abs, + OFF_ROOTFS, + manifest.rootfs_len, + "rootfs", + )?; + copy_abs( + &mut sh, + &table, + manifest.dtb_abs, + OFF_DTB, + manifest.dtb_len, + "dtb", + )?; + copy_abs( + &mut sh, + &table, + manifest.kernel_abs, + OFF_KERNEL, + manifest.kernel_len, + "kernel", + )?; reboot(&mut sh); Ok(()) } - #[cfg(test)] mod tests { use super::*; @@ -751,8 +776,18 @@ mod tests { #[test] fn locate_maps_absolute_to_partition() { let table = vec![ - Mtd { dev: "mtd0".into(), base: 0x0, size: 0x2800000, name: "x".into() }, - Mtd { dev: "mtd1".into(), base: 0x2800000, size: 0x2000000, name: "y".into() }, + Mtd { + dev: "mtd0".into(), + base: 0x0, + size: 0x2800000, + name: "x".into(), + }, + Mtd { + dev: "mtd1".into(), + base: 0x2800000, + size: 0x2000000, + name: "y".into(), + }, ]; assert_eq!(locate(&table, 0x2000000, 100).unwrap(), ("mtd0", 0x2000000)); assert_eq!(locate(&table, 0x2800000, 100).unwrap(), ("mtd1", 0));