flash: Zynq tier-2 update in place through the verified writer; verify-live for Zynq
verify / verify (pull_request) Skipped
source / check (pull_request) Successful in 4m24s

The Zynq tier-2 install wrote raw images at device-relative offsets on
/dev/mtd0 and /dev/mtd1. On the current alkane image those are stock-cfg and
alkane-cfg, not the boot regions, so it would have erased alkane-cfg first, and
its raw zImage/cpio are not bootable by the stock U-Boot. Its preflight only
checked that mtd0 and mtd1 existed.

- Add StockMethod::update_in_place: refuses a board not running alkane,
  re-registers the boot regions (as restore does), saves every slot locally
  before any erase, writes rootfs/dtb/kernel as the uImages the stock U-Boot
  boots via the shared target builder (BOOT.bin guard, md5 readback), reboots
  and waits for alkane. --dry-run reports the live storage map and the plan.
- boards::zynq keeps the manifest gate; the plan is now in absolute NAND slots
  with ceilings that leave room for the uImage header. The stale writer and
  preflight are removed.
- CLI: Zynq preflight/install use the new path before the generic user
  transport connects.
- verify-live gains a Zynq check (HTTP marker, case-insensitive, plus root SSH
  reporting alkane and the installed kernel; prints the kernel cmdline). It
  previously fell through to the CV1835 check.
- Tests for the protected alkane map, registered and split boot maps, slot
  overrun, and the BOOT.bin guard.

Verified on an S17 (Zynq-7010): dry run, install from a RAM-booted alkane,
NAND boot confirmed on the serial console, verify-live PASS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
This commit is contained in:
2026-11-12 11:49:53 -06:00
co-authored by Claude Opus 5.5
parent f63127d633
commit dc787f1f3b
5 changed files with 753 additions and 396 deletions
+126 -48
View File
@@ -14,8 +14,8 @@ use alkane_flash::boards::am335x::{
self as am335x, Am335xPlan, AmInstallOptions, AmInstallOutcome, AmRestoreOptions,
};
use alkane_flash::boards::cv1835::Cv1835Plan;
use alkane_flash::boards::zynq::{self, ZynqInstallOptions, ZynqOutcome, ZynqPlan};
use alkane_flash::stock::RestoreImages;
use alkane_flash::boards::zynq::{self, ZynqPlan};
use alkane_flash::stock::{InPlaceOptions, InPlaceOutcome, RestoreImages};
use alkane_flash::stock_firmware;
use alkane_flash::boards::a113d::{self, A113dInstallOptions, A113dOutcome, A113dPlan};
use alkane_flash::install::{
@@ -422,6 +422,28 @@ fn run_preflight(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
.first()
.ok_or("usage: alkane-cli afw preflight <file> --host <ip>")?;
let verified = load_afw(path, &opts)?;
// Zynq is reached through the compiled-in method (root SSH, boot regions
// re-registered), not the generic user transport below.
if zynq::owns_board(&verified.manifest.board) {
let host = opts.value("host").ok_or("--host is required")?;
let plan = ZynqPlan::from_afw(&verified)?;
println!("{}", plan.render());
let password = read_board_password(&opts)?;
let options = InPlaceOptions {
dry_run: true,
reboot: false,
backup_dir: None,
};
match stock::update_in_place(host, &verified, password.as_deref(), &options) {
Ok(InPlaceOutcome::DryRun(report)) => print!("{report}"),
Ok(InPlaceOutcome::Updated(_)) => {
return Err("internal error: preflight reported a write".into())
}
Err(e) => return Err(format!("preflight failed; do not write: {e}").into()),
}
println!("preflight is read-only; no write performed");
return Ok(());
}
let (ssh, _secret) = ssh_options(&opts, DEFAULT_USER)?;
let mut transport = SshTransport::connect(ssh, true)?;
if am335x::owns_board(&verified.manifest.board) {
@@ -433,15 +455,6 @@ fn run_preflight(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
}
return Ok(());
}
if zynq::owns_board(&verified.manifest.board) {
let plan = ZynqPlan::from_afw(&verified)?;
let report = zynq::preflight(&plan, &mut transport, opts.value("host").unwrap_or(""))?;
print!("{}", report.render());
if !report.ok() {
return Err("preflight failed; do not write".into());
}
return Ok(());
}
if a113d::owns_board(&verified.manifest.board) {
let plan = A113dPlan::from_afw(&verified)?;
let report = a113d::preflight(&plan, &mut transport, opts.value("host").unwrap_or(""))?;
@@ -470,6 +483,61 @@ fn run_preflight(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
/// Update a Zynq board that already runs alkane, in place, through the
/// compiled-in method: it re-registers the boot regions (not exposed to Linux on
/// alkane), keeps a copy of every slot before any erase, writes the kernel and
/// rootfs as the uImages the stock U-Boot boots, reads each back, and never
/// writes BOOT.bin. A board on stock is refused (use --from-stock).
fn install_zynq_in_place(
verified: &VerifiedAfw,
opts: &Opts,
) -> Result<(), Box<dyn std::error::Error>> {
let host = opts.value("host").ok_or("--host is required")?.to_owned();
let plan = ZynqPlan::from_afw(verified)?;
println!("{}", plan.render());
let dry_run = opts.flag("dry-run");
if !dry_run && opts.value("confirm") != Some("FLASH") {
return Err("refusing to write without --confirm FLASH (use --dry-run to inspect)".into());
}
let backup_dir = opts
.value("backup-dir")
.map(PathBuf::from)
.unwrap_or_else(|| platform::config_path("backups"));
let password = read_board_password(opts)?;
let options = InPlaceOptions {
dry_run,
reboot: !opts.flag("no-reboot"),
backup_dir: Some(backup_dir),
};
match stock::update_in_place(&host, verified, password.as_deref(), &options)? {
InPlaceOutcome::DryRun(report) => {
print!("{report}");
println!("DRY RUN: no board erase or write was performed.");
println!("Re-run with --confirm FLASH to write rootfs, dtb and kernel (BOOT.bin preserved).");
}
InPlaceOutcome::Updated(receipt) => {
for held in &receipt.backups {
println!(
"held {} abs 0x{:x} ({} B) {} md5 {}",
held.name,
held.absolute,
held.size,
held.path.display(),
held.md5
);
}
println!("all read-backs matched before reboot; BOOT.bin never touched");
if receipt.rebooted {
println!("board rebooted and answered as alkane again (SSH banner)");
print!("{}", zynq_verify_hint(&host));
} else {
println!("reboot skipped (--no-reboot); the new images run after the next reboot");
}
}
}
Ok(())
}
/// Install onto a board currently on stock via the from-stock install method.
fn install_from_stock_flow(
verified: &VerifiedAfw,
@@ -498,11 +566,23 @@ fn install_from_stock_flow(
);
stock::install_from_stock(host, afw, verified, password.as_deref())?;
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");
if zynq::owns_board(&verified.manifest.board) {
print!("{}", zynq_verify_hint(host));
} else {
println!("verify the board is now reachable as alkane:");
println!(" alkane-cli afw verify-live --host {host} --timeout 300");
}
Ok(())
}
/// How to confirm a Zynq board came up on alkane.
fn zynq_verify_hint(host: &str) -> String {
format!(
"verify independently:\n\
\x20 alkane-cli afw verify-live <the .afw> --host {host} --password-file <alkane root pw> --timeout 300\n"
)
}
fn run_install(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let opts = parse_args(
args,
@@ -537,6 +617,9 @@ fn run_install(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let host = opts.value("host").ok_or("--host is required")?.to_owned();
return install_from_stock_flow(&verified, &host, &path, &opts);
}
if zynq::owns_board(&verified.manifest.board) {
return install_zynq_in_place(&verified, &opts);
}
let (ssh, _secret) = ssh_options(&opts, DEFAULT_USER)?;
let mut transport = SshTransport::connect(ssh, true)?;
let backup_dir = opts
@@ -593,39 +676,6 @@ fn run_install(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
}
return Ok(());
}
if zynq::owns_board(&verified.manifest.board) {
let plan = ZynqPlan::from_afw(&verified)?;
println!("{}", plan.render());
let install_options = ZynqInstallOptions {
dry_run: opts.flag("dry-run"),
confirm: opts.value("confirm").map(str::to_owned),
no_reboot: opts.flag("no-reboot"),
backup_dir,
};
match zynq::install(&plan, &mut transport, &install_options, opts.value("host").unwrap_or(""))? {
ZynqOutcome::DryRun(report) => {
print!("{}", report.render());
println!("DRY RUN: no board erase or write was performed.");
let targets = plan.targets.iter().map(|t| t.image_name.as_str()).collect::<Vec<_>>().join(", ");
println!("Re-run with --confirm FLASH to write {targets} (BOOT.bin preserved).");
}
ZynqOutcome::Installed(receipt) => {
for backup in &receipt.backups {
println!(
"held {} {} offset 0x{:x} md5 {}",
backup.image_name, backup.path.display(), backup.offset, backup.md5
);
}
println!("all read-backs matched before reboot; BOOT.bin never touched");
if receipt.rebooted {
println!("reboot issued; an SSH drop here is the success signature");
} else {
println!("reboot skipped (--no-reboot)");
}
}
}
return Ok(());
}
if a113d::owns_board(&verified.manifest.board) {
let plan = A113dPlan::from_afw(&verified)?;
println!("{}", plan.render());
@@ -722,7 +772,16 @@ fn run_verify_live(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let (board, marker, kernel_version) = if let Some(path) = opts.positionals.first() {
let verified = load_afw(path, &opts)?;
let board = verified.manifest.board.clone();
if board == "am335x" {
if zynq::owns_board(&board) {
let plan = ZynqPlan::from_afw(&verified)?;
(
board,
opts.value("marker").unwrap_or(&plan.marker).to_owned(),
opts.value("kernel-version")
.unwrap_or(&plan.kernel_version)
.to_owned(),
)
} else if board == "am335x" {
let plan = Am335xPlan::from_afw(&verified)?;
(
board,
@@ -745,6 +804,8 @@ fn run_verify_live(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let board = requested_board.clone().unwrap_or_else(|| "cv1835".to_owned());
let (marker, kernel) = if board == "am335x" {
("Alkane".to_owned(), "6.18.48".to_owned())
} else if zynq::owns_board(&board) {
("Alkane".to_owned(), String::new())
} else {
("CVBOOT".to_owned(), String::new())
};
@@ -760,12 +821,29 @@ fn run_verify_live(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
}
}
let host = opts.value("host").ok_or("--host is required")?.to_owned();
let (ssh, _secret) = ssh_options(&opts, DEFAULT_USER)?;
let timeout = opts
.value("timeout")
.map(str::parse::<u64>)
.transpose()?
.unwrap_or(DEFAULT_TIMEOUT);
if zynq::owns_board(&board) {
// Zynq is checked through the compiled-in method's root SSH (the host
// key changes on every reflash, so it is not pinned) plus the web page.
let password = read_board_password(&opts)?;
let report = stock::verify_zynq_live(
&host,
password.as_deref(),
&marker,
&kernel_version,
Duration::from_secs(timeout),
)?;
print!("{}", report.render());
if !report.ok() {
return Err("live verification failed: HTTP marker and SSH did not both confirm alkane".into());
}
return Ok(());
}
let (ssh, _secret) = ssh_options(&opts, DEFAULT_USER)?;
if board == "am335x" {
let report = am335x::verify_live(
&host,