Skip to content

Commit

Permalink
Add option to skip inserting OTA cert into recovery image
Browse files Browse the repository at this point in the history
Issue: #366

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Nov 4, 2024
1 parent 7ffeb5e commit 32674ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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

0 comments on commit 32674ab

Please sign in to comment.