chenxiaolong / avbroot-inc-ota

Proof-of-concept tool to generate an Android incremental OTA from two full OTAs
GNU General Public License v3.0
8 stars 2 forks source link

avbroot-inc-ota

avbroot-inc-ota is a tool for generating a signed incremental Android A/B OTA zip from two full OTA zips.

This is a proof of concept, but has been tested on real devices and should work with any valid full OTA zip. This will likely not be integrated in avbroot, nor will it receive further development because the delta payload.bin generation depends on AOSP's delta_generator and it is too complicated to reimplement.

Usage

  1. Download the AOSP source code (or the source code for any AOSP-based OS). This will likely require 100-200 GiB of disk space.

  2. Inside the AOSP source directory, build delta_generator.

    source build/envsetup.sh
    m delta_generator

    The output will be in out/host/linux-x86/bin/delta_generator.

  3. Ensure the Rust toolchain is installed.

  4. Clone this git repo and build avbroot-inc-ota.

    cargo build --release

    The output will be in target/release/avbroot-inc-ota.

  5. Generate an incremental OTA from two full OTAs:

    avbroot-inc-ota \
        --input-old /path/to/old/full/ota.zip \
        --input-new /path/to/new/full/ota.zip \
        --output /path/to/output/incremental/ota.zip \
        --delta-generator /path/to/aosp/out/host/linux-x86/bin/delta_generator \
        --key /path/to/ota.key \
        --cert /path/to/ota.crt

    For testing, it is perfectly valid to use the same file as both the old and new full OTAs. The resulting incremental OTA will just "upgrade" to the same Android build.

  6. That's it! The output OTA can be sideloaded with adb sideload if the currently installed Android build matches the old full OTA.

How it works

The delta payload.bin is generated by AOSP's delta_generator. It computes the binary diff between old and new raw partition images and stores the resulting bsdiff diffs in an unsigned payload. Since bsdiff computation is slow, CPU/memory intensive, and produces large diffs when an unmodified block is moved to a different offset in the new image, delta_generator includes ext4 and erofs filesystem parsers to compare the data of individual files. This allows diff computation for blocks containing identical files to be avoided entirely and instead, stores SOURCE_COPY operations in the payload. (The necessity of these filesystem parsers is why this project won't be integrated into avbroot.)

delta_generator also requires a few additional input files:

The META-INF/com/android/metadata{,.pb} files are generated from the new full OTA, but with the build and build-incremental precondition fields set to the appropriate values from the old full OTA. This prevents the incremental OTA from being installed on top of an Android build that it wasn't built for.

The payload and OTA signing is provided by avbroot's library functions.

License

avbroot-inc-ota is licensed under GPLv3. Please see LICENSE for the full license text.