diff --git a/crates/alkane-cli/src/main.rs b/crates/alkane-cli/src/main.rs index bb50cb36..ab8df05c 100644 --- a/crates/alkane-cli/src/main.rs +++ b/crates/alkane-cli/src/main.rs @@ -989,23 +989,22 @@ fn run_restore_stock(args: &[String]) -> Result<(), Box> let host = opts.value("host").ok_or("--host is required")?.to_owned(); let firmware = opts.value("stock-firmware").ok_or( "--stock-firmware is required \ - (SD recovery image SD_Antminer-*.zip, which includes the device tree)", + (an OTA update .tar.gz or an SD recovery .zip for this board)", )?; // Restore reaches the alkane board over SSH as root; the board credential is // supplied via --password-file / ALKANE_BOARD_PASSWORD(_FILE). let password = read_board_password(&opts)?; - // Parse the genuine vendor package into the stock images to write back. + // Parse the genuine vendor package for the stock kernel + rootfs. The kernel + // device tree is not in distributable Bitmain firmware; the toolkit supplies + // the correct per-board dtb, so any genuine package (OTA or SD) works here. let fw = stock_firmware::parse(Path::new(firmware))?; - let dtb = fw.dtb.as_deref().ok_or( - "this firmware package has no device tree; use the Bitmain SD recovery \ - image (SD_Antminer-S17-*.zip), which includes devicetree.dtb", - )?; println!("stock firmware: {}", fw.summary()); if opts.flag("dry-run") { - println!("DRY RUN: would restore {host} to stock by writing the stock dtb, kernel and"); - println!("rootfs back to NAND (BOOT.bin preserved). Re-run with --confirm FLASH."); + println!("DRY RUN: would restore {host} to stock by writing the genuine stock kernel"); + println!("and rootfs plus the per-board device tree back to NAND (BOOT.bin preserved)."); + println!("Re-run with --confirm FLASH."); return Ok(()); } if opts.value("confirm") != Some("FLASH") { @@ -1013,7 +1012,6 @@ fn run_restore_stock(args: &[String]) -> Result<(), Box> } println!("restoring {host} to genuine stock from {firmware} (network-only)..."); let images = RestoreImages { - dtb, kernel: &fw.kernel, rootfs: &fw.rootfs, }; diff --git a/crates/alkane-flash/src/stock.rs b/crates/alkane-flash/src/stock.rs index 21c2acf3..19d7024a 100644 --- a/crates/alkane-flash/src/stock.rs +++ b/crates/alkane-flash/src/stock.rs @@ -31,11 +31,14 @@ pub enum StockError { Io(String), } -/// The genuine Bitmain stock images to write back when restoring to stock, -/// parsed from a vendor firmware package by `stock_firmware`. Borrowed so the -/// large rootfs is not copied before the method needs it. +/// The genuine Bitmain stock kernel and rootfs to write back when restoring to +/// stock, parsed from a vendor firmware package (OTA or SD) by `stock_firmware`. +/// The matching NAND device tree is NOT taken from the package: Bitmain never +/// ships the kernel device tree in its distributable firmware (it is factory- +/// provisioned and preserved by every update), so the method supplies the +/// correct per-board dtb itself. Borrowed so the large rootfs is not copied +/// before the method needs it. pub struct RestoreImages<'a> { - pub dtb: &'a [u8], pub kernel: &'a [u8], pub rootfs: &'a [u8], } diff --git a/crates/alkane-flash/src/stock_method.rs b/crates/alkane-flash/src/stock_method.rs index c16b42a8..2d575585 100644 --- a/crates/alkane-flash/src/stock_method.rs +++ b/crates/alkane-flash/src/stock_method.rs @@ -51,9 +51,16 @@ struct StockAsset { sha256: &'static str, } -// The stock kernel/dtb/rootfs are no longer carried as assets: restore now -// writes the genuine Bitmain stock images supplied by the caller. Only the -// NAND-exposing helper (below) is still fetched. +// Restore writes the genuine Bitmain kernel and rootfs supplied by the caller. +// Two small per-board pieces are not in Bitmain's distributable firmware and are +// fetched: the NAND-exposing helper, and the kernel device tree (factory- +// provisioned, preserved by every vendor update, so never shipped in an OTA/SD +// package). The dtb is what pairs the genuine kernel/rootfs to the board's +// partition layout; writing the wrong one reboot-loops the board. +const ASSET_DTB: StockAsset = StockAsset { + file: "blob-1.bin", + sha256: "10a0199be8a638c4bf319a623362a89b6bee38f732ab00204df499a2f25ad2ea", +}; const ASSET_MTD_PATCH: StockAsset = StockAsset { file: "blob-4.bin", sha256: "51cfa6806ac0618d67a3d6f2383bc755c67507958c578fc899a25e589c9cf444", @@ -1837,6 +1844,11 @@ impl StockMethod for Method { return Ok(()); } + // The kernel device tree is not in Bitmain's distributable firmware, so + // use the correct per-board dtb (fetched + verified) rather than anything + // from the caller's package. The genuine kernel and rootfs come from the + // package the caller parsed. + let dtb = stock_asset(&ASSET_DTB)?; // The brick-sensitive boot regions are not exposed to Linux on alkane; // get_mtd_map re-registers them so the stock images can be written back. let map = get_mtd_map(host, password)?; @@ -1853,7 +1865,7 @@ impl StockMethod for Method { "stock-dtb.bin", ABS_DTB, DTB_SLOT, - Cow::Owned(images.dtb.to_vec()), + Cow::Owned(dtb), ), ( "kernel", diff --git a/crates/alkane-gui/src/stock_ops.rs b/crates/alkane-gui/src/stock_ops.rs index cadb3494..6caef6a1 100644 --- a/crates/alkane-gui/src/stock_ops.rs +++ b/crates/alkane-gui/src/stock_ops.rs @@ -212,16 +212,9 @@ fn restore_one(ip: &str, firmware: &Path, password: Option<&str>) -> (bool, Stri Ok(f) => f, Err(e) => return (false, format!("firmware: {e}")), }; - let Some(dtb) = fw.dtb.as_deref() else { - return ( - false, - "this package has no device tree; use the Bitmain SD recovery image \ - (SD_Antminer-S17-*.zip), which includes devicetree.dtb" - .to_string(), - ); - }; + // The device tree comes from the toolkit's per-board asset, not the package, + // so any genuine Bitmain firmware (OTA or SD) provides a usable kernel+rootfs. let images = RestoreImages { - dtb, kernel: &fw.kernel, rootfs: &fw.rootfs, }; diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index 75638f46..0763d33b 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -2737,7 +2737,7 @@ impl App { root.add( Widget::static_text( dlg, - "Genuine Bitmain stock firmware file (SD recovery image\nSD_Antminer-S17-*.zip, which includes the device tree):", + "Genuine Bitmain stock firmware file for this board\n(an OTA update .tar.gz or an SD recovery .zip):", ), 0, sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_TOP, diff --git a/docs/install.md b/docs/install.md index 398f4a13..66334536 100644 --- a/docs/install.md +++ b/docs/install.md @@ -79,16 +79,27 @@ reads them back (md5), and never writes `/dev/mtd0` below `0x1a00000` ## Remove (back to stock) ``` -export ALKANE_RELEASE_TOKEN= alkane-cli afw restore-stock --host \ + --stock-firmware \ --password-file --confirm FLASH ``` -Returning an aftermarket board to genuine stock is also done by the toolkit -itself, over the network. It uses the same per-board assets (fetched/cached as -above from the now-public assets repo, so no token is needed) and the board's -alkane root credential (`--password-file`, or -`ALKANE_BOARD_PASSWORD`/`ALKANE_BOARD_PASSWORD_FILE`). You then verify +Returning an aftermarket board to genuine stock is done by the toolkit itself, +over the network. It writes the genuine Bitmain stock **kernel and rootfs** - +parsed from a vendor firmware file you supply with `--stock-firmware` (an OTA +update `.tar.gz` or an SD recovery `.zip` for the board) - back to NAND, +preserving BOOT.bin. + +The one piece that is NOT in Bitmain's distributable firmware is the kernel +**device tree**: it is factory-provisioned and preserved by every vendor update, +so no OTA/SD package ships it. The toolkit supplies the correct per-board dtb +itself (fetched + verified from the public assets repo, so no token is needed) +and pairs it with the genuine kernel/rootfs. The board's alkane root credential +is given with `--password-file` (or +`ALKANE_BOARD_PASSWORD`/`ALKANE_BOARD_PASSWORD_FILE`). + +After a restore the board returns to stock under its stock MAC and typically +takes a new DHCP lease, so it may not reappear on the same address; verify independently that the board no longer answers as alkane and presents its stock OS.