Skip to content

Commit

Permalink
cli/ota: Improve error reporting when descriptor types are mismatched
Browse files Browse the repository at this point in the history
Issue: #201

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Nov 12, 2023
1 parent cb62996 commit 2f1ee1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions avbroot/src/cli/ota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)) => {
Expand All @@ -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 {
Expand All @@ -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");
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions avbroot/src/format/avb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 2f1ee1a

Please sign in to comment.