From 2f1ee1ae4fda2d3f6c125076a6c176945bce4a3a Mon Sep 17 00:00:00 2001 From: Andrew Gunnerson Date: Sun, 12 Nov 2023 18:29:55 -0500 Subject: [PATCH] cli/ota: Improve error reporting when descriptor types are mismatched Issue: #201 Signed-off-by: Andrew Gunnerson --- avbroot/src/cli/ota.rs | 6 ++++-- avbroot/src/format/avb.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/avbroot/src/cli/ota.rs b/avbroot/src/cli/ota.rs index da65d8c..a55c638 100644 --- a/avbroot/src/cli/ota.rs +++ b/avbroot/src/cli/ota.rs @@ -449,6 +449,7 @@ fn update_vbmeta_headers( let reader = images.get_mut(dep).unwrap(); let (header, _, _) = avb::load_image(reader) .with_context(|| format!("Failed to load vbmeta footer from image: {dep}"))?; + let pd_type = parent_descriptor.type_name(); if header.public_key.is_empty() { // vbmeta is unsigned. Use the existing descriptor. @@ -459,6 +460,7 @@ fn update_vbmeta_headers( else { bail!("{name} has no descriptor for itself"); }; + let d_type = descriptor.type_name(); match (parent_descriptor, descriptor) { (Descriptor::Hash(pd), Descriptor::Hash(d)) => { @@ -468,7 +470,7 @@ fn update_vbmeta_headers( *pd = d.clone(); } _ => { - bail!("{name}'s descriptor for {dep} must match {dep}'s self descriptor"); + bail!("{dep} descriptor ({d_type}) does not match entry in {name} ({pd_type})"); } } } else { @@ -478,7 +480,7 @@ fn update_vbmeta_headers( d.public_key = header.public_key; } _ => { - bail!("{name}'s descriptor for {dep} must be a chain descriptor"); + bail!("{dep} descriptor ({pd_type}) in {name} must be a chain descriptor"); } } } diff --git a/avbroot/src/format/avb.rs b/avbroot/src/format/avb.rs index 7c55b46..be588ac 100644 --- a/avbroot/src/format/avb.rs +++ b/avbroot/src/format/avb.rs @@ -1193,6 +1193,17 @@ pub enum Descriptor { } impl Descriptor { + pub fn type_name(&self) -> &'static str { + match self { + Self::Property(_) => "Property", + Self::HashTree(_) => "HashTree", + Self::Hash(_) => "Hash", + Self::KernelCmdline(_) => "KernelCmdline", + Self::ChainPartition(_) => "ChainPartition", + Self::Unknown { .. } => "Unknown", + } + } + pub fn partition_name(&self) -> Option<&str> { match self { Self::HashTree(d) => Some(&d.partition_name),