Commit Graph

208 Commits

Author SHA1 Message Date
Andrew Gunnerson bf53859bcd Ensure output files are zip64-compliant (again)
PR #110 fixed this incorrectly. I misinterpreted "set to zero in the
local header" from §4.4.4 in the spec as referring to the two 32-bit
size fields in the local header. However, the spec considers the zip64
extra record as part of the local header. The correct behavior for
writing zip64 entries to unseekable files is 0xffffffff in the 32-bit
local header size fields (to enable zip64), 0 in the zip64 extra record
(due to streaming writes), and the actual sizes in the data descriptor.

Fixes: #109

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-07-03 16:30:09 -04:00
Andrew Gunnerson 056359c853 Merge pull request #103 from chenxiaolong/replace
Add support for replacing any partition image
2023-06-28 21:24:50 -04:00
Andrew Gunnerson 93dcd63829 Add support for replacing any partition image
This commit adds support for replacing any partition image within
the payload with a custom image. This is useful, for example, to add a
custom kernel to an OTA, which may involve partitions that wouldn't
normally be touched (eg. `vendor_dlkm`).

Any image specified via `--replace` will have its corresponding
descriptor in the vbmeta image updated. This is handled recursively. For
example, replacing `vendor_dlkm` would update both `vbmeta_vendor` and
`vbmeta`. This requires all vbmeta images to be extracted during the
patching process so that a complete dependency graph can be computed.
The performance hit in doing so is negligible, but does require the
checksums of the stripped images to be updated for the tests.

Fixes: #102

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-06-28 21:04:49 -04:00
Andrew Gunnerson be177d0111 Merge pull request #112 from chenxiaolong/ignore_prepatched
Add support for ignoring boot image checks for --prepatched
2023-06-28 20:28:24 -04:00
Andrew Gunnerson 48318f333a Add support for ignoring boot image checks for --prepatched
There are 3 levels of warnings:

* Level 0: Warnings that don't affect booting
    * Mismatched `id` or `os_version` fields
* Level 1: Warnings that may affect booting
    * Mismatched `cmdline` or `extra_cmdline` fields
    * Unexpected addition of `kernel`, `second`, `recovery_dtbo`, `dtb`,
      or `bootconfig`
* Level 2: Warnings that are very likely to affect booting
    * All other mismatched, added, or removed fields

By default, any warning of level 1 or higher is treated as a fatal
error. Each time `--ignore-prepatched-compat` is passed in, the
permitted warning level is increased.

Fixes: #108

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-06-28 19:40:50 -04:00
Andrew Gunnerson 1b5bc24821 Merge pull request #111 from chenxiaolong/arch
tests: Containerfile.arch: Allow system-wide pip installation
2023-06-28 19:21:22 -04:00
Andrew Gunnerson a0421d3eb4 tests: Containerfile.arch: Allow system-wide pip installation
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-06-28 18:59:21 -04:00
Andrew Gunnerson fec788c438 Merge pull request #110 from chenxiaolong/zip64
Ensure output files are zip64-compliant
2023-06-28 18:58:14 -04:00
Andrew Gunnerson f25ac50b0a Ensure output files are zip64-compliant
This commit fixes two issues:

* Python 3.11.4 has a regression where it sets the local file header's
  compressed and uncompressed size fields to 0xffffffff when data
  descriptors are used. These should be set to 0 (along with the CRC)
  according to §4.4.4 of the spec. We work around this by monkey
  patching zipfile's local file header serialization function to correct
  the fields.
* avbroot tries to preserve as much metadata from the original zip as
  possible, including the `extra` records. This caused zip64 records
  (0x0001) to be duplicated. The first instance was from the original
  zip (containing invalid size fields) and the second instance was newly
  created by zipfile. We fix this by stripping out all 0x0001 records,
  similar to what we already do for 0xd935.

Fixes: #109

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-06-28 18:38:06 -04:00
Andrew Gunnerson 2bc69f5bc6 Merge pull request #107 from chenxiaolong/readme
README.md: Improve project description and remove suggestion for compiling AOSP from source
2023-06-22 19:57:28 -04:00
Andrew Gunnerson 1b5d98d718 README.md: Improve project description and remove suggestion for compiling AOSP from source
Issue: #106

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-06-22 19:56:23 -04:00
Andrew Gunnerson 5b1622c382 Merge pull request #105 from chenxiaolong/windows
modules/build.py: Windows requires `.bat` extension to be specified explicitly
2023-06-14 18:05:38 -04:00
Andrew Gunnerson 6c7165cfb7 modules/build.py: Windows requires .bat extension to be specified explicitly
Fixes: #104

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-06-14 18:04:47 -04:00
Andrew Gunnerson 5dda181e90 Merge pull request #101 from chenxiaolong/readme
README.md: Add note about using unencrypted private keys
2023-05-31 00:05:27 -04:00
Andrew Gunnerson 0ff1bb2b2f README.md: Add note about using unencrypted private keys
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-31 00:04:48 -04:00
Andrew Gunnerson 19bfc0bd8e Merge pull request #100 from chenxiaolong/env_var
Add support for supplying the private key passphrases non-interactively
2023-05-31 00:04:04 -04:00
Andrew Gunnerson 6be4665557 Update tests for non-interactive patching with encrypted keys
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-30 23:54:16 -04:00
Andrew Gunnerson 601c24222f Add support for supplying the private key passphrases non-interactively
Fixes: #99

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-30 22:35:49 -04:00
Andrew Gunnerson 669ea9c471 Merge pull request #98 from chenxiaolong/rootless
Add option to skip applying the root patch entirely
2023-05-27 16:42:58 -04:00
Andrew Gunnerson da3c9da2bf Add option to skip applying the root patch entirely
This allows users to use avbroot for just resigning an OTA with their
own signing keys.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-27 16:35:46 -04:00
Andrew Gunnerson 883a5da7a8 Merge pull request #96 from chenxiaolong/deps
Update AOSP submodules and test container image versions
2023-05-23 15:38:05 -04:00
Andrew Gunnerson e51c3661dd tests: Update container image distros to the latest versions
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-23 15:27:20 -04:00
Andrew Gunnerson 6e6805cdb5 Update AOSP submodules dependencies to the latest master commits
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-23 15:11:47 -04:00
Andrew Gunnerson 6e7c516736 Merge pull request #95 from chenxiaolong/readme-calyxos
README.md: Add reference to `oemunlockonboot` in the CalyxOS warning message
2023-05-23 13:44:58 -04:00
Andrew Gunnerson 2982f00ef3 README.md: Add reference to oemunlockonboot in the CalyxOS warning message
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-23 13:43:55 -04:00
Andrew Gunnerson 59a3947ae3 Merge pull request #92 from chenxiaolong/oemunlock
Add Magisk module to enable OEM unlocking on every boot
2023-05-23 13:36:49 -04:00
Andrew Gunnerson f507e5a32f modules/build.py: Allow building individual modules
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-23 00:06:24 -04:00
Andrew Gunnerson 53e0e30c86 Add Magisk module to enable OEM unlocking on every boot
The module helps reduce the chance of OEM unlocking being disabled,
whether by the user or by some OS's initial setup wizard. It works by
running some Java code at boot, which connects to the `OemLockService`
binder service and calls `setOemUnlockAllowedByUser(true)`, the same as
what the Settings app does.

Fixes: #8
Issue: #84

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-23 00:06:24 -04:00
Andrew Gunnerson ad0f640890 Merge pull request #94 from chenxiaolong/zip_extra
Strip out 0xd935 extra field record in zip entries
2023-05-23 00:05:39 -04:00
Andrew Gunnerson dc81e8571f Strip out 0xd935 extra field record in zip entries
The extra field record was previously stripped out due to a bug in
Python's zipfile implementation. That was fixed by [1], which was
backported to 3.10 and 3.11, but not 3.9.

This commit explicitly strips out the 0xd935 record to ensure that the
checksums of the patched files are the same across all Python versions.
This is probably the correct thing to do anyway, since the record is
related to zip entry alignment [2], which we don't do.

Note that the Python bug can affect other extra field records too, but
we don't see that in practice.

[1] https://github.com/python/cpython/commit/62c0327487ce39ec6504919b7712e0f197075ef9
[2] https://android.googlesource.com/platform/build/+/android-13.0.0_r1/tools/signapk/src/com/android/signapk/SignApk.java#133

Fixes: #93

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-05-22 23:52:03 -04:00
Andrew Gunnerson 7d5977b410 Merge pull request #89 from chenxiaolong/magisk-26.1
avbroot/boot.py: Allow Magisk 261xx versions
2023-04-12 02:31:45 -04:00
Andrew Gunnerson 7c2e322a37 avbroot/boot.py: Allow Magisk 261xx versions
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-04-12 02:31:23 -04:00
Andrew Gunnerson f1eb67b906 Merge pull request #88 from chenxiaolong/old_magisk
Drop support for Magisk versions <25102
2023-04-05 18:43:48 -04:00
Andrew Gunnerson fbfaae090c Drop support for Magisk versions <25102
These versions are missing Magisk commit
1f8c063dc64806c4f7320ed66c785ff7bc116383, which fixes booting into
recovery on devices that use Android 13 GKIs. Trying to use these
versions with avbroot would prevent the user from installing future OTAs
without manually flashing a boot image patched with a newer Magisk
version while booted into Android first.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-04-05 18:32:38 -04:00
Andrew Gunnerson 00fad4effc Merge pull request #87 from chenxiaolong/magisk_26000
Add support for Magisk >=25211
2023-04-05 18:31:17 -04:00
Andrew Gunnerson 50483b4ffa tests: Update Magisk to 26000 and OTAs to their latest versions
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-04-05 18:14:32 -04:00
Andrew Gunnerson 9c01d3b7e6 Add support for Magisk >=25211
In addition to the preinit device, Magisk now requires a random seed to
be added to the Magisk config in the boot image. Magisk's boot_patch.sh
generates a new seed every time an image is patched, but avbroot will
use the hardcoded seed 0xfedcba9876543210 to guarantee byte-for-byte
reproducibility of the output file. This can be overridden with
--magisk-random-seed <uint64>.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-04-05 17:27:08 -04:00
Andrew Gunnerson f5b886df84 Merge pull request #86 from chenxiaolong/magisk-preinit
Switch to Magisk 25211's PREINITDEVICE
2023-04-05 15:54:42 -04:00
Andrew Gunnerson 27c2bed773 Switch to Magisk 25211's PREINITDEVICE
Unlike the prior RULESDEVICE, PREINITDEVICE uses a block device name
since the rdev major/minor is not guaranteed to remain the same across
reboots. This commit completely drops support for RULESDEVICE (25207
through 25210) since it never made it to a stable Magisk release.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-03-25 19:51:22 -04:00
Andrew Gunnerson 0fff7b77dd Merge pull request #85 from chenxiaolong/calyxos
README.md: Add warning about CalyxOS automatically turning off OEM unlocking
2023-03-24 18:41:12 -04:00
Andrew Gunnerson 543d2eafc6 README.md: Add warning about CalyxOS automatically turning off OEM unlocking
Issue: #84

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-03-24 18:32:34 -04:00
Andrew Gunnerson 5c1a4d19b0 Merge pull request #82 from chenxiaolong/magisk-25207
Magisk >=25207 require a rules device ID
2023-03-11 20:38:23 -05:00
Andrew Gunnerson 0a1888ad94 Magisk >=25207 require a rules device ID
Newer Magisk versions no longer try to autodetect a writable ext4
partition for storing SELinux rules during boot. Instead, the block
device is detected during boot image patching and is stored in the
ramdisk's `.backup/.magisk` as `makedev(rdev_maj, rdev_min)`.

This unfortunately complicates the patching process for avbroot. Even if
we replicate Magisk's algorithm for finding a suitable partition,
there's no way to find the block device's rdev for it with the
information contained in the OTA package. This is the first change that
adds a hard dependency on information only attainable from a running
device.

For these newer Magisk versions, the user will have to patch the boot
image once in the Magisk app (must be on the target device) and then run
`avbroot magisk-info` to show the computed device ID. Then, avbroot can
use this during patching via `--magisk-rules-device`. If the user's
device is unable to run the Magisk app prior to patching (eg.
unbootable), they'll have to go through the patching process twice, once
with `--ignore-magisk-warnings` and a second time with the proper device
ID specified.

When using `--ignore-magisk-warnings`, root still works, but there will
be subtle issues, like certain modules failing to load.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-03-09 17:01:39 -05:00
Andrew Gunnerson 90b1964b55 Merge pull request #81 from pascallj/lookup_only
Use `lookup-only` action to check if cache exists
2023-03-09 16:50:43 -05:00
Pascal Roeleven 9d50d41f6b Give names to reusable workflows 2023-03-09 19:57:02 +01:00
Pascal Roeleven d53896f952 Use actions/cache lookup-only instead of custom action
Now that the lookup-only option is available, we should use this instead
2023-03-09 19:57:00 +01:00
Andrew Gunnerson 1bde511aba Merge pull request #79 from pascallj/cache_keys
Make cache pre-checks more robust
2023-03-06 12:43:55 -05:00
Pascal Roeleven df9a6c2970 Make cache pre-checks more robust
Also fix preload Magisk cache workflow
2023-03-06 12:18:57 +01:00
Andrew Gunnerson 6cb035870e Merge pull request #78 from chenxiaolong/external
Move sys.path modification to __init__.py
2023-03-05 15:00:52 -05:00
Andrew Gunnerson 1bdac19c44 Move sys.path modification to __init__.py
This way, the module path is automatically updated when avbroot is
imported. This also fixes the lint warning about `external` being
imported, but not used.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-03-05 14:44:54 -05:00