Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to skip inserting OTA cert into recovery image #367

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ Note that avbroot will validate that the prepatched image is compatible with the

avbroot can be used for just re-signing an OTA by specifying `--rootless` instead of `--magisk`/`--prepatched`. With this option, the patched OTA will not be rooted. The only modification applied is the replacement of the OTA verification certificate so that the OS can be upgraded with future (patched) OTAs.

### Skipping recovery OTA certificate patches

avbroot can skip modifying `otacerts.zip` in the recovery image with the `--skip-recovery-ota-cert` option. **Do not do this unless you have a good reason to do so.** (For example, if you've already manually inserted the OTA certificate into a boot image specified with `--prepatched` or `--replace`.) When this option is used with `--rootless` (and `--dsu` is not specified), then no modifications are performed on any boot image besides ensuring they are properly signed.

When manually adding the OTA certificate to a boot image, [verifying the patched OTA](#verifying-otas) afterwards is recommended to ensure that it was properly done.

### Replacing partitions

avbroot supports replacing entire partitions in the OTA, even partitions that are not boot images (eg. `vendor_dlkm`). A partition can be replaced by passing in `--replace <partition name> /path/to/partition.img`.
Expand Down
19 changes: 17 additions & 2 deletions avbroot/src/cli/ota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn patch_boot_images<'a, 'b: 'a>(
let boot_partitions = required_images.iter_boot().collect::<Vec<_>>();

info!(
"Patching boot images: {}",
"Candidate boot images: {}",
joined(sorted(boot_partitions.iter())),
);

Expand Down Expand Up @@ -1304,7 +1304,11 @@ pub fn patch_subcommand(cli: &PatchCli, cancel_signal: &AtomicBool) -> Result<()
assert!(cli.root.rootless);
};

boot_patchers.push(Box::new(OtaCertPatcher::new(cert_ota.clone())));
if cli.skip_recovery_ota_cert {
warn!("Not inserting OTA cert into recovery image; sideloading further updates may fail");
} else {
boot_patchers.push(Box::new(OtaCertPatcher::new(cert_ota.clone())));
}

if cli.dsu {
boot_patchers.push(Box::new(DsuPubKeyPatcher::new(key_avb.to_public_key())));
Expand Down Expand Up @@ -1922,6 +1926,17 @@ pub struct PatchCli {
)]
pub ignore_prepatched_compat: u8,

/// Skip adding OTA certificate to recovery image.
///
/// DO NOT USE THIS unless you've manually added the certificate to the
/// recovery image already. Otherwise, sideloading further updates will not
/// be possible.
///
/// When this option is used with --rootless, the boot images in the OTA
/// will not be modified.
#[arg(long, help_heading = HEADING_OTHER)]
pub skip_recovery_ota_cert: bool,

/// Add AVB public key to trusted keys for DSU.
#[arg(long, help_heading = HEADING_OTHER)]
pub dsu: bool,
Expand Down
5 changes: 5 additions & 0 deletions avbroot/src/patch/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,11 @@ pub fn patch_boot_images<'a>(
) -> Result<HashSet<&'a str>> {
let parent_span = Span::current();

if patchers.is_empty() {
debug!("Skip loading boot images; nothing to patch");
return Ok(HashSet::new());
}

// Preparse all images. Some patchers need to inspect every candidate.
let mut images = load_boot_images(names, open_input)?;

Expand Down