feat(gui): post-install verify, flash-plan checklist; backend helpers
Stock->alkane re-scan flicker: after a successful install the just-installed
boards are held in a "verifying alkane..." state and a stock re-scan row is
suppressed until the board answers as alkane, with a bounded give-up window.
Fixes the board re-scanning as stock before finally showing alkane.
Flash-plan checklist: picking a local .afw in the install dialog now detects
the flash tier and shows a [x]/[ ] checklist of what it overwrites (U-Boot /
Kernel / Userspace), read from the bundle manifest. Verified end-to-end under
a virtual display: a zynq-7010 .afw shows tier 2, U-Boot preserved, kernel and
userspace written.
Backend helpers (alkane-artifacts, additive, unit-tested):
- AfwManifest::flash_plan() -> FlashPlan { tier, writes_uboot, writes_kernel,
writes_userspace }.
- ReleaseSource::for_repo(owner, repo) and ReleaseInfo::compatible_boards /
is_compatible_with, for the upcoming any-repo picker with board-compat
detection.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
This commit is contained in:
@@ -155,6 +155,54 @@ pub struct AfwManifest {
|
||||
pub notes: Option<String>,
|
||||
}
|
||||
|
||||
/// What an `.afw` bundle overwrites on the target, derived from its manifest.
|
||||
///
|
||||
/// Tiers mirror the flash tiers: 1 = update (userspace / HAL only, no kernel or
|
||||
/// bootloader write), 2 = kernel (kernel, dtb and boot images; bootloader
|
||||
/// preserved), 3 = bootloader (U-Boot/SPL is rewritten as well).
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct FlashPlan {
|
||||
pub tier: u8,
|
||||
pub writes_uboot: bool,
|
||||
pub writes_kernel: bool,
|
||||
pub writes_userspace: bool,
|
||||
}
|
||||
|
||||
impl AfwManifest {
|
||||
/// Compute the flash tier and the regions this bundle overwrites. Pure
|
||||
/// computation over the parsed manifest; no device or file access.
|
||||
///
|
||||
/// - `writes_uboot`: `bootloader_policy` is [`BootloaderPolicy::Include`]
|
||||
/// (anything but `Preserve`), or an image with role `bootloader` exists.
|
||||
/// - `writes_kernel`: an image with role `kernel`, `dtb` or `boot` exists.
|
||||
/// - `writes_userspace`: an image with role `rootfs` exists.
|
||||
/// - `tier`: 3 if `writes_uboot`, else 2 if `writes_kernel`, else 1.
|
||||
pub fn flash_plan(&self) -> FlashPlan {
|
||||
let has_role = |roles: &[&str]| {
|
||||
self.images
|
||||
.iter()
|
||||
.any(|image| roles.contains(&image.role.as_str()))
|
||||
};
|
||||
let writes_uboot =
|
||||
self.bootloader_policy != BootloaderPolicy::Preserve || has_role(&["bootloader"]);
|
||||
let writes_kernel = has_role(&["kernel", "dtb", "boot"]);
|
||||
let writes_userspace = has_role(&["rootfs"]);
|
||||
let tier = if writes_uboot {
|
||||
3
|
||||
} else if writes_kernel {
|
||||
2
|
||||
} else {
|
||||
1
|
||||
};
|
||||
FlashPlan {
|
||||
tier,
|
||||
writes_uboot,
|
||||
writes_kernel,
|
||||
writes_userspace,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct AfwMember {
|
||||
pub name: String,
|
||||
@@ -1080,6 +1128,106 @@ mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
/// Build a parsed manifest with the given bootloader policy and one image
|
||||
/// per listed role (payload bytes are irrelevant to `flash_plan`).
|
||||
fn plan_manifest(policy: &str, roles: &[&str]) -> AfwManifest {
|
||||
let mut value = manifest(&[0_u8; 4]);
|
||||
value["bootloader_policy"] = json!(policy);
|
||||
value["images"] = json!(roles
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, role)| json!({
|
||||
"name": format!("img{i}"), "file": format!("payload/img{i}"),
|
||||
"role": role, "format": "raw", "size": 4, "sha256": "0".repeat(64),
|
||||
"partition": null, "install": false
|
||||
}))
|
||||
.collect::<Vec<_>>());
|
||||
serde_json::from_value(value).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_plan_tier2_preserve_kernel_and_rootfs() {
|
||||
let plan = plan_manifest("preserve", &["kernel", "dtb", "rootfs"]).flash_plan();
|
||||
assert_eq!(plan.tier, 2);
|
||||
assert!(plan.writes_kernel);
|
||||
assert!(plan.writes_userspace);
|
||||
assert!(!plan.writes_uboot);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_plan_tier3_include_with_bootloader_image() {
|
||||
let plan =
|
||||
plan_manifest("include", &["bootloader", "kernel", "dtb", "rootfs"]).flash_plan();
|
||||
assert_eq!(plan.tier, 3);
|
||||
assert!(plan.writes_uboot);
|
||||
assert!(plan.writes_kernel);
|
||||
assert!(plan.writes_userspace);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_plan_tier3_from_bootloader_image_alone() {
|
||||
// A bootloader image forces tier 3 even if the policy says preserve
|
||||
// (verification rejects that combination, but the plan stays safe).
|
||||
let plan = plan_manifest("preserve", &["bootloader"]).flash_plan();
|
||||
assert_eq!(plan.tier, 3);
|
||||
assert!(plan.writes_uboot);
|
||||
assert!(!plan.writes_kernel);
|
||||
assert!(!plan.writes_userspace);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_plan_tier3_from_include_policy_alone() {
|
||||
let plan = plan_manifest("include", &["rootfs"]).flash_plan();
|
||||
assert_eq!(plan.tier, 3);
|
||||
assert!(plan.writes_uboot);
|
||||
assert!(!plan.writes_kernel);
|
||||
assert!(plan.writes_userspace);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_plan_tier1_rootfs_only() {
|
||||
let plan = plan_manifest("preserve", &["rootfs"]).flash_plan();
|
||||
assert_eq!(plan.tier, 1);
|
||||
assert!(plan.writes_userspace);
|
||||
assert!(!plan.writes_kernel);
|
||||
assert!(!plan.writes_uboot);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_plan_boot_role_counts_as_kernel() {
|
||||
let plan = plan_manifest("preserve", &["boot"]).flash_plan();
|
||||
assert_eq!(plan.tier, 2);
|
||||
assert!(plan.writes_kernel);
|
||||
assert!(!plan.writes_userspace);
|
||||
assert!(!plan.writes_uboot);
|
||||
// The shared cv1835 fixture is a single "boot" FIT under preserve.
|
||||
let fixture: AfwManifest = serde_json::from_value(manifest(&[0_u8; 4])).unwrap();
|
||||
assert_eq!(fixture.flash_plan().tier, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_plan_component_only_is_tier1_with_no_regions() {
|
||||
let plan = plan_manifest("preserve", &["component"]).flash_plan();
|
||||
assert_eq!(plan.tier, 1);
|
||||
assert!(!plan.writes_uboot);
|
||||
assert!(!plan.writes_kernel);
|
||||
assert!(!plan.writes_userspace);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_plan_empty_images_preserve_is_tier1() {
|
||||
let plan = plan_manifest("preserve", &[]).flash_plan();
|
||||
assert_eq!(plan.tier, 1);
|
||||
assert!(!plan.writes_uboot && !plan.writes_kernel && !plan.writes_userspace);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flash_plan_tier3_dominates_kernel() {
|
||||
let plan = plan_manifest("include", &["bootloader", "kernel"]).flash_plan();
|
||||
assert_eq!(plan.tier, 3);
|
||||
assert!(plan.writes_uboot && plan.writes_kernel);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refuses_a_hash_mismatch() {
|
||||
let p1 = p1_image(P1);
|
||||
|
||||
@@ -60,6 +60,14 @@ impl ReleaseSource {
|
||||
/// The alkane-os release source, honoring `ALKANE_RELEASE_BASE` and a token
|
||||
/// from `ALKANE_RELEASE_TOKEN` or `GITEA_TOKEN`.
|
||||
pub fn alkane_os() -> Self {
|
||||
Self::for_repo("blueflare", "alkane-os")
|
||||
}
|
||||
|
||||
/// A release source for an arbitrary Gitea `owner`/`repo`. The base URL
|
||||
/// (`ALKANE_RELEASE_BASE`, else the self-hosted Gitea) and the token
|
||||
/// (`ALKANE_RELEASE_TOKEN`, else `GITEA_TOKEN`, else the build-time embedded
|
||||
/// token) are resolved exactly as for `alkane_os`.
|
||||
pub fn for_repo(owner: &str, repo: &str) -> Self {
|
||||
let base_url = std::env::var("ALKANE_RELEASE_BASE")
|
||||
.ok()
|
||||
.filter(|s| !s.is_empty())
|
||||
@@ -71,8 +79,8 @@ impl ReleaseSource {
|
||||
.or_else(|| EMBEDDED_TOKEN.map(str::to_string).filter(|t| !t.is_empty()));
|
||||
Self {
|
||||
base_url,
|
||||
owner: "blueflare".to_string(),
|
||||
repo: "alkane-os".to_string(),
|
||||
owner: owner.to_string(),
|
||||
repo: repo.to_string(),
|
||||
token,
|
||||
}
|
||||
}
|
||||
@@ -223,6 +231,18 @@ pub fn fetch_latest_afw(
|
||||
Ok(dest)
|
||||
}
|
||||
|
||||
/// Board tokens recognised in `.afw` asset names (the `-<board>-` filename
|
||||
/// segment). Used by `ReleaseInfo::compatible_boards`.
|
||||
pub const KNOWN_BOARDS: &[&str] = &[
|
||||
"zynq-7010",
|
||||
"am335x",
|
||||
"cv1835",
|
||||
"a113d",
|
||||
"allwinner-h3",
|
||||
"allwinner-h6",
|
||||
"allwinner-h616",
|
||||
];
|
||||
|
||||
/// One `.afw` asset in a release.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AfwAsset {
|
||||
@@ -249,6 +269,30 @@ impl ReleaseInfo {
|
||||
let needle = format!("-{board}-");
|
||||
self.afw_assets.iter().find(|a| a.name.contains(&needle))
|
||||
}
|
||||
|
||||
/// The distinct board tokens (from `KNOWN_BOARDS`) this release carries an
|
||||
/// `.afw` for, detected from the asset filenames (`-<board>-` segment, e.g.
|
||||
/// `alkane-os-0.1.2-zynq-7010-armv7.afw` -> `zynq-7010`). Ordered by first
|
||||
/// appearance across the assets; a release with no recognised board yields an
|
||||
/// empty list.
|
||||
pub fn compatible_boards(&self) -> Vec<String> {
|
||||
let mut boards: Vec<String> = Vec::new();
|
||||
for asset in &self.afw_assets {
|
||||
for board in KNOWN_BOARDS {
|
||||
let needle = format!("-{board}-");
|
||||
if asset.name.contains(&needle) && !boards.iter().any(|b| b == board) {
|
||||
boards.push((*board).to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
boards
|
||||
}
|
||||
|
||||
/// Whether this release has an `.afw` for `board` (same match as
|
||||
/// `asset_for_board`).
|
||||
pub fn is_compatible_with(&self, board: &str) -> bool {
|
||||
self.asset_for_board(board).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a Gitea releases array (newest first) into `ReleaseInfo`s, keeping only
|
||||
@@ -401,4 +445,84 @@ mod tests {
|
||||
);
|
||||
assert!(parsed[1].asset_for_board("zynq-7010").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn for_repo_builds_the_api_url_for_a_custom_repo() {
|
||||
std::env::remove_var("ALKANE_RELEASE_BASE");
|
||||
let src = ReleaseSource::for_repo("someorg", "some-firmware");
|
||||
assert_eq!(src.owner, "someorg");
|
||||
assert_eq!(src.repo, "some-firmware");
|
||||
assert_eq!(
|
||||
src.api_list(),
|
||||
"https://gitea.bluefla.re/api/v1/repos/someorg/some-firmware/releases?limit=50"
|
||||
);
|
||||
// alkane_os() is for_repo("blueflare", "alkane-os").
|
||||
let os = ReleaseSource::alkane_os();
|
||||
assert_eq!(
|
||||
(os.owner.as_str(), os.repo.as_str()),
|
||||
("blueflare", "alkane-os")
|
||||
);
|
||||
}
|
||||
|
||||
fn release_with(names: &[&str]) -> ReleaseInfo {
|
||||
ReleaseInfo {
|
||||
tag: "v0.1.2".into(),
|
||||
name: String::new(),
|
||||
prerelease: false,
|
||||
draft: false,
|
||||
published_at: String::new(),
|
||||
afw_assets: names
|
||||
.iter()
|
||||
.map(|n| AfwAsset {
|
||||
name: (*n).to_string(),
|
||||
url: format!("https://example.invalid/{n}"),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compatible_boards_extracts_board_tokens_from_asset_names() {
|
||||
let single = release_with(&["alkane-os-0.1.2-zynq-7010-armv7.afw"]);
|
||||
assert_eq!(single.compatible_boards(), vec!["zynq-7010"]);
|
||||
|
||||
// Multi-board release: distinct boards in first-appearance order,
|
||||
// duplicates (a second arch build of one board) collapse.
|
||||
let multi = release_with(&[
|
||||
"alkane-os-0.1.2-am335x-armv7.afw",
|
||||
"alkane-os-0.1.2-zynq-7010-armv7.afw",
|
||||
"alkane-os-0.1.2-allwinner-h616-aarch64.afw",
|
||||
"alkane-os-0.1.2-am335x-arm.afw",
|
||||
"alkane-os-0.1.2-cv1835-riscv64.afw",
|
||||
]);
|
||||
assert_eq!(
|
||||
multi.compatible_boards(),
|
||||
vec!["am335x", "zynq-7010", "allwinner-h616", "cv1835"]
|
||||
);
|
||||
|
||||
// allwinner-h6 must not match an allwinner-h616 asset (and vice versa).
|
||||
let h616 = release_with(&["alkane-os-0.1.2-allwinner-h616-aarch64.afw"]);
|
||||
assert_eq!(h616.compatible_boards(), vec!["allwinner-h616"]);
|
||||
let h6 = release_with(&["alkane-os-0.1.2-allwinner-h6-aarch64.afw"]);
|
||||
assert_eq!(h6.compatible_boards(), vec!["allwinner-h6"]);
|
||||
|
||||
// No .afw assets, or an unrecognised board, yields nothing.
|
||||
assert!(release_with(&[]).compatible_boards().is_empty());
|
||||
assert!(release_with(&["alkane-os-0.1.2-mystery-board-arm.afw"])
|
||||
.compatible_boards()
|
||||
.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_compatible_with_matches_asset_for_board() {
|
||||
let rel = release_with(&[
|
||||
"alkane-os-0.1.2-zynq-7010-armv7.afw",
|
||||
"alkane-os-0.1.2-a113d-aarch64.afw",
|
||||
]);
|
||||
assert!(rel.is_compatible_with("zynq-7010"));
|
||||
assert!(rel.is_compatible_with("a113d"));
|
||||
assert!(!rel.is_compatible_with("am335x"));
|
||||
assert!(!rel.is_compatible_with("allwinner-h6"));
|
||||
assert!(!release_with(&[]).is_compatible_with("zynq-7010"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user