flash: restore uses the correct per-board device tree, not the package's
The kernel device tree is never in Bitmain's distributable firmware: all OTA packages ship none, and the SD recovery image preserves the factory dtb rather than writing one. The device tree I was taking from the SD recovery package was its SD-boot dtb (a different partition layout), which does not match the genuine rootfs and reboot-loops the board. Fix: restore now takes only the genuine kernel + rootfs from the vendor package (RestoreImages drops the dtb field), and the method supplies the correct per-board device tree itself (fetched + verified from the public assets repo, the same way the NAND-exposing helper is fetched). This pairs genuine kernel/rootfs with the factory dtb that matches their partition layout. Any genuine package now works (an OTA .tar.gz as well as an SD .zip), since the package's own dtb is no longer needed. cli/gui: --stock-firmware / the uninstall dialog no longer require a package with a device tree. docs updated. NOTE: not yet hardware-verified - the bench S17 is mid-recovery (serial-link hardware issue) and must be brought back before this can be proven on the board. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
This commit is contained in:
@@ -989,23 +989,22 @@ fn run_restore_stock(args: &[String]) -> Result<(), Box<dyn std::error::Error>>
|
|||||||
let host = opts.value("host").ok_or("--host is required")?.to_owned();
|
let host = opts.value("host").ok_or("--host is required")?.to_owned();
|
||||||
let firmware = opts.value("stock-firmware").ok_or(
|
let firmware = opts.value("stock-firmware").ok_or(
|
||||||
"--stock-firmware <genuine Bitmain firmware file> is required \
|
"--stock-firmware <genuine Bitmain firmware file> 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
|
// Restore reaches the alkane board over SSH as root; the board credential is
|
||||||
// supplied via --password-file / ALKANE_BOARD_PASSWORD(_FILE).
|
// supplied via --password-file / ALKANE_BOARD_PASSWORD(_FILE).
|
||||||
let password = read_board_password(&opts)?;
|
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 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());
|
println!("stock firmware: {}", fw.summary());
|
||||||
|
|
||||||
if opts.flag("dry-run") {
|
if opts.flag("dry-run") {
|
||||||
println!("DRY RUN: would restore {host} to stock by writing the stock dtb, kernel and");
|
println!("DRY RUN: would restore {host} to stock by writing the genuine stock kernel");
|
||||||
println!("rootfs back to NAND (BOOT.bin preserved). Re-run with --confirm FLASH.");
|
println!("and rootfs plus the per-board device tree back to NAND (BOOT.bin preserved).");
|
||||||
|
println!("Re-run with --confirm FLASH.");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if opts.value("confirm") != Some("FLASH") {
|
if opts.value("confirm") != Some("FLASH") {
|
||||||
@@ -1013,7 +1012,6 @@ fn run_restore_stock(args: &[String]) -> Result<(), Box<dyn std::error::Error>>
|
|||||||
}
|
}
|
||||||
println!("restoring {host} to genuine stock from {firmware} (network-only)...");
|
println!("restoring {host} to genuine stock from {firmware} (network-only)...");
|
||||||
let images = RestoreImages {
|
let images = RestoreImages {
|
||||||
dtb,
|
|
||||||
kernel: &fw.kernel,
|
kernel: &fw.kernel,
|
||||||
rootfs: &fw.rootfs,
|
rootfs: &fw.rootfs,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,11 +31,14 @@ pub enum StockError {
|
|||||||
Io(String),
|
Io(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The genuine Bitmain stock images to write back when restoring to stock,
|
/// The genuine Bitmain stock kernel and rootfs to write back when restoring to
|
||||||
/// parsed from a vendor firmware package by `stock_firmware`. Borrowed so the
|
/// stock, parsed from a vendor firmware package (OTA or SD) by `stock_firmware`.
|
||||||
/// large rootfs is not copied before the method needs it.
|
/// 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 struct RestoreImages<'a> {
|
||||||
pub dtb: &'a [u8],
|
|
||||||
pub kernel: &'a [u8],
|
pub kernel: &'a [u8],
|
||||||
pub rootfs: &'a [u8],
|
pub rootfs: &'a [u8],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,9 +51,16 @@ struct StockAsset {
|
|||||||
sha256: &'static str,
|
sha256: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The stock kernel/dtb/rootfs are no longer carried as assets: restore now
|
// Restore writes the genuine Bitmain kernel and rootfs supplied by the caller.
|
||||||
// writes the genuine Bitmain stock images supplied by the caller. Only the
|
// Two small per-board pieces are not in Bitmain's distributable firmware and are
|
||||||
// NAND-exposing helper (below) is still fetched.
|
// 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 {
|
const ASSET_MTD_PATCH: StockAsset = StockAsset {
|
||||||
file: "blob-4.bin",
|
file: "blob-4.bin",
|
||||||
sha256: "51cfa6806ac0618d67a3d6f2383bc755c67507958c578fc899a25e589c9cf444",
|
sha256: "51cfa6806ac0618d67a3d6f2383bc755c67507958c578fc899a25e589c9cf444",
|
||||||
@@ -1837,6 +1844,11 @@ impl StockMethod for Method {
|
|||||||
return Ok(());
|
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;
|
// 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.
|
// get_mtd_map re-registers them so the stock images can be written back.
|
||||||
let map = get_mtd_map(host, password)?;
|
let map = get_mtd_map(host, password)?;
|
||||||
@@ -1853,7 +1865,7 @@ impl StockMethod for Method {
|
|||||||
"stock-dtb.bin",
|
"stock-dtb.bin",
|
||||||
ABS_DTB,
|
ABS_DTB,
|
||||||
DTB_SLOT,
|
DTB_SLOT,
|
||||||
Cow::Owned(images.dtb.to_vec()),
|
Cow::Owned(dtb),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"kernel",
|
"kernel",
|
||||||
|
|||||||
@@ -212,16 +212,9 @@ fn restore_one(ip: &str, firmware: &Path, password: Option<&str>) -> (bool, Stri
|
|||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => return (false, format!("firmware: {e}")),
|
Err(e) => return (false, format!("firmware: {e}")),
|
||||||
};
|
};
|
||||||
let Some(dtb) = fw.dtb.as_deref() else {
|
// The device tree comes from the toolkit's per-board asset, not the package,
|
||||||
return (
|
// so any genuine Bitmain firmware (OTA or SD) provides a usable kernel+rootfs.
|
||||||
false,
|
|
||||||
"this package has no device tree; use the Bitmain SD recovery image \
|
|
||||||
(SD_Antminer-S17-*.zip), which includes devicetree.dtb"
|
|
||||||
.to_string(),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
let images = RestoreImages {
|
let images = RestoreImages {
|
||||||
dtb,
|
|
||||||
kernel: &fw.kernel,
|
kernel: &fw.kernel,
|
||||||
rootfs: &fw.rootfs,
|
rootfs: &fw.rootfs,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2737,7 +2737,7 @@ impl App {
|
|||||||
root.add(
|
root.add(
|
||||||
Widget::static_text(
|
Widget::static_text(
|
||||||
dlg,
|
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,
|
0,
|
||||||
sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_TOP,
|
sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_TOP,
|
||||||
|
|||||||
+17
-6
@@ -79,16 +79,27 @@ reads them back (md5), and never writes `/dev/mtd0` below `0x1a00000`
|
|||||||
## Remove (back to stock)
|
## Remove (back to stock)
|
||||||
|
|
||||||
```
|
```
|
||||||
export ALKANE_RELEASE_TOKEN=<your-gitea-token>
|
|
||||||
alkane-cli afw restore-stock --host <miner-ip> \
|
alkane-cli afw restore-stock --host <miner-ip> \
|
||||||
|
--stock-firmware <genuine-Bitmain-firmware> \
|
||||||
--password-file <alkane-root-pw> --confirm FLASH
|
--password-file <alkane-root-pw> --confirm FLASH
|
||||||
```
|
```
|
||||||
|
|
||||||
Returning an aftermarket board to genuine stock is also done by the toolkit
|
Returning an aftermarket board to genuine stock is done by the toolkit itself,
|
||||||
itself, over the network. It uses the same per-board assets (fetched/cached as
|
over the network. It writes the genuine Bitmain stock **kernel and rootfs** -
|
||||||
above from the now-public assets repo, so no token is needed) and the board's
|
parsed from a vendor firmware file you supply with `--stock-firmware` (an OTA
|
||||||
alkane root credential (`--password-file`, or
|
update `.tar.gz` or an SD recovery `.zip` for the board) - back to NAND,
|
||||||
`ALKANE_BOARD_PASSWORD`/`ALKANE_BOARD_PASSWORD_FILE`). You then verify
|
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
|
independently that the board no longer answers as alkane and presents its stock
|
||||||
OS.
|
OS.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user