Skip to content

Commit

Permalink
Merge pull request #135 from chenxiaolong/full
Browse files Browse the repository at this point in the history
Move full OTA check to patch/extract subcommand function
  • Loading branch information
chenxiaolong authored Sep 7, 2023
2 parents 4337170 + 3f86a67 commit 393e65f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
8 changes: 8 additions & 0 deletions avbroot/src/cli/ota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ fn patch_ota_payload(
) -> Result<(String, u64)> {
let header = PayloadHeader::from_reader(open_payload()?)
.with_context(|| anyhow!("Failed to load OTA payload header"))?;
if !header.is_full_ota() {
bail!("Payload is a delta OTA, not a full OTA");
}

let header = Mutex::new(header);
let header_locked = header.lock().unwrap();
let all_partitions = header_locked
Expand Down Expand Up @@ -1027,6 +1031,10 @@ pub fn extract_subcommand(cli: &ExtractCli, cancel_signal: &Arc<AtomicBool>) ->

let header = PayloadHeader::from_reader(&mut payload_reader)
.with_context(|| anyhow!("Failed to load OTA payload header"))?;
if !header.is_full_ota() {
bail!("Payload is a delta OTA, not a full OTA");
}

let mut unique_images = BTreeSet::new();

if cli.all {
Expand Down
20 changes: 9 additions & 11 deletions avbroot/src/format/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ pub enum Error {
UnknownMagic([u8; 4]),
#[error("Unsupported payload version: {0}")]
UnsupportedVersion(u64),
#[error("File is a delta OTA, not a full OTA")]
NotFullOta,
#[error("Payload contains no signatures")]
NoSignatures,
#[error("Blob offset should be {0}, but is {1}")]
Expand Down Expand Up @@ -99,6 +97,15 @@ pub struct PayloadHeader {
pub blob_offset: u64,
}

impl PayloadHeader {
pub fn is_full_ota(&self) -> bool {
self.manifest
.partitions
.iter()
.all(|p| p.old_partition_info.is_none())
}
}

impl<R: Read> FromReader<R> for PayloadHeader {
type Error = Error;

Expand Down Expand Up @@ -128,15 +135,6 @@ impl<R: Read> FromReader<R> for PayloadHeader {
reader.read_exact(&mut manifest_raw)?;
let manifest: DeltaArchiveManifest = util::read_protobuf(&manifest_raw)?;

// Fail as soon as possible since it's impossible to support delta OTAs.
if manifest
.partitions
.iter()
.any(|p| p.old_partition_info.is_some())
{
return Err(Error::NotFullOta);
}

// Skip manifest signatures.
reader.read_discard_exact(metadata_signature_size.into())?;

Expand Down

0 comments on commit 393e65f

Please sign in to comment.