style: rustfmt the a113d flash engine + CLI (cargo fmt)
source / check (pull_request) Skipped
verify / verify (pull_request) Canceled after 0s
verify / verify-windows (pull_request) Canceled after 0s

#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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
This commit is contained in:
2026-11-16 17:28:37 -06:00
co-authored by Claude Opus 4.8
parent fbeb6dc328
commit 9c49fa91af
3 changed files with 131 additions and 52 deletions
+11 -7
View File
@@ -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"));
}
+62 -27
View File
@@ -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<Vec<Mtd>, 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<u64> {
/// 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<BackupManifest, Sto
rootfs_abs: r_dst,
rootfs_len,
};
write_abs(sh, table, BK_MANIFEST, &manifest.encode(), "stock-backup-manifest")?;
write_abs(
sh,
table,
BK_MANIFEST,
&manifest.encode(),
"stock-backup-manifest",
)?;
Ok(manifest)
}
@@ -569,11 +569,7 @@ struct BootImages {
rootfs_uimage: Vec<u8>,
}
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));