Commit graph

47 commits

Author SHA1 Message Date
Håkan Kvist
b77972402e Detect downgrade by checking build time for all partitions
Checking ro.build.date.utc to detect a downgrade is not enough in the
case where several target files are merged, as timestamps can differ
for each partition.

The solution is to check the build timestamp for each partition and
ro.build.date.utc.

With this change ota generation will be aborted during creation
instead of rejected when installing on device.

This also fixes the --override_timestamp so it is possible to generate
a package where timestamps are reversed, as was added in:
3e6161a3b3.

Issue: 315913966
Test: Manual, confirm that ota generation is aborted when timestamp
  on post vendor partitions is newer than on pre.
  Ota created successfully with --override_timestamp parameter and
  installation successful
Test: atest --host releasetools_test
Change-Id: I275e67a3840f4ef2263381c253231068e72f47d2
2023-12-20 08:45:26 +01:00
Kelvin Zhang
b84d2aa7d1 Sign OTA packages inside target_files during signing
Test: th
Bug: 293313353
Change-Id: Ifd5dd08153c5970dac8166808173f7dfbbb3411d
2023-11-28 10:08:38 -08:00
Kelvin Zhang
68252b801a Move signing related options to a shared place
Move OTA signing flags to payload_signer.py so that we can re-use these
flags in multiple binaries.

Test: th
Bug: 293313353
Change-Id: I44f9910cee37c449397e174a5784f747ec9fb0d6
2023-11-14 12:41:58 -08:00
Kelvin Zhang
d51332c82f Allow OEMs to bypass the on device SPL downgrade check
Certain OEMs bootloader implementation allow SPL downgrade. Allow on
device SPL downgrade check to be bypassed.

Test: th
Bug: 306271739
Change-Id: Iba991e12d36291e2d0547c94ef54c750d87f35fb
2023-10-23 10:10:33 -07:00
Kelvin Zhang
e14f2a59a3 Use symlinks instead of hard links
Test: th
Bug: 283172692
Change-Id: Idb91448677d94370e052755842a396cc0e1eb588
2023-09-25 15:24:20 -07:00
Kelvin Zhang
f6fe0a9c9c Reduce OTA tools's dependency on brillo_update_payload
brillo_update_payload is thin bash wrapper for delta_generator, and
OTA tools are wrappers around brillo_update_payload. This is
inconveinent, as adding a new flag requires changing 3 places. Since
brillo_update_payload is really thin, skip it and invoke delta_generator
directly.

Test: th
Bug: 293313353
Change-Id: I2fd5af95c571ea45aea62f9eec475f0f4e864953
2023-08-25 13:49:09 -07:00
Kelvin Zhang
c7441e5907 Add a tool to generate OTA from images
During build, we will need to generate an OTA for boot partition using a
16K boot image. Typically, OTA is generated from target_files.zip . To
avoid relying on target_files.zip as a dependency for 16K OTA, add a
tool to generate OTA directly from a raw image.

Test: th, ota_from_raw_img --partition_name boot --output ota.zip $OUT/boot_16k.img
Bug: 293313353
Change-Id: I2076332faf2a8dc573450597efd481e285a49545
2023-08-23 12:37:29 -07:00
Kelvin Zhang
8f83000732 Check device's launch API level before using new compresison algo
If a T launch device later changes to LZ4(which is supported since U),
we will fallback to older compression algorithms, because if the full
OTA is applied on an T build, the update_engine on device won't support
lz4.

Bug: 295989519
Test: generate full OTA for T launched devices, make sure lz4 is not
used

Change-Id: I82fdf788e47e2a6daeaa4479bfecf317d8ebb5d5
2023-08-16 13:16:48 -07:00
Kelvin Zhang
b789e84499 Search for partition maps in IMAGES dir as well
Partition images are allowed to be in either IMAGES/ or RADIO/ dir of a
target_files zip, so when searching for .map files we should look in
both dirs.

Test: th
Bug: 227848550
Change-Id: I0a9d2c582d8f5d570237434902fac012513c9aad
2023-06-14 10:01:21 -07:00
Håkan Kvist
ddb968dce0 Supply apex_info.pb as parameter to delta_generator if file exists
Supply generator with parameter --apex_info_file=META/apex_info.pb
if the file exists.

This ensures that apex_info is included in payload header.

This is identical to the behaviour of brillo_update_payload
which is not being used since:
Invoke delta_generator directly
fcd731e3d6

Issue: 286253576
Test: Manual, confirm that apex_info is included in payload header
Change-Id: Ic096c5f8966beec8686f918aba462c955290a6c5
2023-06-09 12:46:58 +02:00
Kelvin Zhang
89b87f6aa9 Open ab_partitions.txt with just read access
We don't actually need write permission, so going with least privilege
principle. We have observed some mysterious permission denied errors on server environments. Without detailed logs or access to the server it's hard to pinpoint what the root cause is. This is an attempt/hypothesis to fix the permission denied error.

Test: th
Bug: 283033491
Change-Id: I52dc360d593aab57c749109994bf3e1e3625d0ce
2023-06-01 17:28:25 +00:00
Kelvin Zhang
2268091521 Unsparse images before generating OTA
Test: th
Bug: 283172692
Change-Id: Ie6d3dc704fd9a8c107e2888222e4c2bf804dad3e
2023-05-22 10:22:59 -07:00
Kelvin Zhang
6b10e15acc Support generating partial OTAs from extracted target_files
This allows the build system to potentially paralleize generation of OTA
package and zipping of target files

Bug: 262185376
Bug: 227848550
Change-Id: I90b6c25761683ebe3803b22fc8e23540a5282c66
2023-05-02 20:48:14 -07:00
Kelvin Zhang
ca45d7a85d Fix incremental OTA generation failures
source_file might be a directory, use the _ReadApexInfo() helper
function to read it instead of go straight to zipfiles.

Test: build incremental OTA for pixel
Bug: 279142680
Bug: 227848550
Bug: 277028723

Change-Id: Ia0041e2c72c1a57123519c970f6e734194a81cd2
2023-04-21 17:30:50 +00:00
Kelvin Zhang
9dbe2ce40f Allow ota_from_target_file to work entirely on directories
When building android, build system will first zip target_file directory
into a .zip file, and then invoke ota_from_target_files. We
ota_from_target_files can work directly on top of directories, we can
parallelize OTA generation and target_file zipping, making builds
faster.

Bug: 227848550
Bug: 277028723
Test: th
Change-Id: Id72bd7cca708af0e1bae2db754f39b27777cd601
2023-04-18 17:47:29 -07:00
Treehugger Robot
7b640806da Merge "Revert "Remove all ZIP64LIMIT hack"" 2023-04-15 01:48:58 +00:00
Kelvin Zhang
f92f7f046a Revert "Remove all ZIP64LIMIT hack"
This reverts commit 37a4290909.

Reason for revert: b/278156419

Change-Id: I67ea667619a9623be849d911993010ef0f0bfd88
2023-04-14 21:32:54 +00:00
Kelvin Zhang
629bc8dc1c Fix s to t OTA
Android S update_engine has a smaller minor version, we should use
update_engine version number from source build when generating an
incremental OTA.

Test: th
Bug: 277837157
Change-Id: Ic1ccdccd26c19bf9fb13d146a9151e699e481201
2023-04-11 21:30:42 -07:00
Kelvin Zhang
fcd731e3d6 Invoke delta_generator directly
Currently, ota_from_target_files(a python script) calls
brillo_update_payload(a bash script), which then calls delta_generator(a
C++ binary) to do the actual diffing. Having brillo_update_payload in
the middle does not offer any additional flexibility, but it makes
maintaince more difficult. Bash code is less readable and harder to
debug. Further more, everytime we want to add a new flag to
delta_generator, we have to add the flag in three places:
ota_from_target_files, brillo_update_payload, delta_generator.

Historically, brillo_update_payload was there because we inherited from
ChromeOS side. This bash scripts extracts target_files.zip and invoke
delta_generator to generate the actual OTA. Any customizations we want
on OTA must be implemented by modifying the input target_files.zip ,
Manipuating big zip files is slow and inefficient.

To make thing simpler/faster, remove the intermdiary call to
brill_update_payload. ota_from_target_files will now extract target
files and call delta_generator directly.

Test: th
Bug: 227848550
Change-Id: I44b296e43bf7921bcf48ef6a1e4021a12669739c
2023-04-11 13:53:05 -07:00
Kelvin Zhang
f80e886273 Fix non-AB OTA signing issue
After aosp/2201756 , caller must explicitly pass signing key as a
parameter to FinalizeMetadata . We forgot to update non_ab.py ,
therefore causing non-AB OTAs to be unsigned.

Test: th
Bug: 265895599
Change-Id: Ia54b1105f37b6574742b9b55d715fc9c61c223eb
2023-01-20 10:18:11 -08:00
Kelvin Zhang
37a4290909 Remove all ZIP64LIMIT hack
In the old days, we hacked values of ZIP64LIMIT to get around size
limitations of non-zip64 supported zip files. Now that we switched to
python3 + zip64, there's no point in keeping those hacks.

Test: th
Bug: 255683436
Change-Id: I913db33dad5503736c68a7a1f1321aa952019f60
2022-10-26 13:22:52 -07:00
Kelvin Zhang
2e1ff6e262 Remove unnecesasry use of ZipClose()
ZipClose() was introduced to work with large zip without switching to
ZIP64. It is a hacky patch. Now we have moved to python3 and zip64
completely, no need to keep using it.

Test: th
Bug: 246504616
Change-Id: I1ff15171bb26887b819f655e32817627ecad1132
2022-10-17 10:04:45 -07:00
Zhou Xuezan
d0d49f5b42 Fix incorrect input for path and entry
Change-Id: Idff184d8fb8b328f42fc4f96cdde2663f6581864
2022-09-14 16:26:55 +08:00
Kelvin Zhang
bf01f8b3f0 Refactor ota_utils to reduce dependency on global OPTIONS
Move some depency on global OPTIONS to parameters. This makes it easier
for other modules to re-use these functions w/o having to modify OPTIONS
variables before/after calling.

Test: th
Bug: 227536004
Change-Id: I3bab292f65a4222f0c9502bcf04fa7a85f8124c6
2022-09-06 23:51:20 +00:00
Kelvin Zhang
fa9286943c Rename ota_utils.Payload to PayloadGenerator
There's also a Payload class in system/update_engine/scripts. To avoid
name collision, rename the one in releasetools to PayloadGenerator.
No functional changes in this CL.

Bug: 227848550
Test: th

Change-Id: Ib7d4c7ad9839d99416d965e3a3661b8cee7b7693
2022-08-30 19:46:49 +00:00
Kelvin Zhang
62a7f6e08e Move Payload/StreamProperty class to ota_utils.py
This allows other modules to import these classes w/o bring in tons of
depedency. No functional changes.

Test: th
Bug: 227848550
Change-Id: I98139b45c02eddefa8a26d032e759fa11cc4c694
2022-08-30 18:29:41 +00:00
Kelvin Zhang
b9fdf2dc08 Fix a bug in unsigned OTA generation
Caller expects output_file to contain the final OTA, so we must copy
data into that location. Modifying loca variables isn't enough.

Test: make ota with --no_signing
Change-Id: Id4aaefbc53b4250b7308701493d151f9408f47f1
2022-08-12 14:07:31 -07:00
Treehugger Robot
7b53ae67f1 Merge "Only enable zucchini if configuration file exists" 2022-05-04 02:39:39 +00:00
Håkan Kvist
3db1ef61de Only enable zucchini if configuration file exists
Only enable zucchini if configuration file zucchini_config.txt exits
in target files and version in source and target is the same.

Without this patch zucchini would be enabled if configuration file
was missing from both target files.

Bug: 231204699
Test: Run ota package generation with zucchini_config.txt missing from
      both source and target zips. Confirm that zucchini is disabled.
Change-Id: Ia34998fd911d5860b38fe49fa5a88056a22d661e
2022-05-03 13:00:32 +02:00
TJ Rhoades
6f488e9e33 Expose GetRamdiskFormat and use in ota_utils.py
Some OTA files may have additional OTA props; when this is being computed within
ota_utils.py -> ComputeRuntimeBuildInfos, the ramdisk type needs to be passed into
PartitionBuildProps.FromInputFile as not all ramdisk may still use gzip. This check
is already defined in common.py, so this change also exposes the function GetRamdiskFormat.

Bug: 231075507

Signed-off-by: TJ Rhoades <tjr@microsoft.com>
Change-Id: If1b93b887990f0d90df2c6003122821c1e66a1ac
2022-05-02 13:19:49 -07:00
Treehugger Robot
07491322c3 Merge "ota_utils: Don't fail if metadata proto doesn't exist" 2022-02-18 21:20:07 +00:00
Luca Stefani
b6075c581b ota_utils: Don't fail if metadata proto doesn't exist
The protobuf addition is present only in S+
while the legacy metadata is always present

Test: tools/gen_update_config.py with ota from R
Change-Id: I482c75b6b3b2b1ade139e59dc9dc57dbf9731d45
2022-02-18 11:37:43 +00:00
Kelvin Zhang
f2728d615e Add option to enable lz4diff
When lz4diff is enabled, we inject the host copy of liblz4.so in
target_file to delta_generator. This is to ensure that host tooling can
produce same compressed output as the device.

Test: th
Bug: 206729162

Change-Id: I2d8206f7ec54fadedea16bf3d811b8353bc9414d
2022-01-12 17:21:00 -08:00
Kelvin Zhang
410bb389d8 Add option to enable zucchini
Change-Id: Id952826c9c5af912fba679af61f2a2e1645641dd
2022-01-07 14:59:01 -08:00
Cole Faust
b820bcd829 Prepare release tools for python 3
- Sort dictionaries before looping over them
- Don't call sorted() on lists with Nones
- Open file in binary format when serializing protobufs

Change-Id: If5dbc908f7125f6184014b3c1c7891f833d1d8bf
Bug: 203436762
Test: Presubmits
2021-11-04 17:58:44 -07:00
Kelvin Zhang
25ab998d82 Fix a bug in computing streaming property of payload.bin
When computing the data offset of an entry in zip file, we used length
of extra field from central directory. That is correct most of the time
but wrong if the extra field in central directory has different length
than the one in local file directory. Since python's zipfile doesn't
provide an API to access local file header, we need to parse local file
header ourselves and extract length of extra field.

An incorrect offset will cause magic mismatch error from update_engine,
as update_engine expects to find uncompressed payload at the recorded
offset.

Test: th, partner verification
Bug: 191443484

Change-Id: Id670cd79b0bd65adffaaa5224ae4f8065d66b358
2021-07-28 11:40:18 -04:00
Tianjie
a5fca03e0a Amend the apex info for ota package
We have already logged the compressed apexes in the target-files.
Because we want to support the apex metrics during OTA update, also
include the uncompressed apexes in the META/apex_info.pb.

For incremental OTA packages, include the source apex version for
each apex package as well.

Bug: 190244686
Test: unit test
Change-Id: I5cf2647c56c4feb5517f9a81aa1e9abc52515bf1
2021-06-07 20:33:46 -07:00
Kelvin Zhang
05ff7055b6 Add spl-downgrade field to ota metadata
In aosp/1581143 , we banned generation of SPL downgrade OTAs. However,
caller of OTA script can still force an SPL downgrade OTA by passing
--spl_downgrade flag. If this flag is specified, we propagate it to OTA
metadata so that GOTA server can properly honor this flag.

Test: th
Change-Id: Ic8cdc850d2210f4149ad9121fa4ed2e5a4f59bcc
2021-02-25 10:15:45 -05:00
Yifan Hong
5057b95572 Split PARTITIONS_WITH_BUILD_PROP from *_WITH_CARE_MAP
Right now they are the same content. In the future, boot will be added
to PARTITIONS_WITH_BUILD_PROP, but it is not added to
PARTITIONS_WITH_CARE_MAP. Boot partition has a cpio filesystem in the
ramdisk, so it contains a build.prop file, but it doesn't make sense to
create care map from it.

Test: TH
Bug: 162623577

Change-Id: I9b5a20fe2d774b52cf7d5eae9deecbc75122a3dd
2021-01-07 17:20:22 -08:00
Yifan Hong
c65a0545dd Move GetBootImageTimestamp to common.
Test: TH
Bug: 162623577

Change-Id: Icbd8b07dce91006a1abca1f0dc40726de8a10219
2021-01-07 17:20:22 -08:00
Yifan Hong
125d0b63b9 Add function to extract timestamp from boot image
Also add toybox to otatools list.

Bug: 169169031
Test: build OTA
Change-Id: Ib14dbf46a8385ccf2a9c5a9c6f4e7fa9399cf0ba
2020-10-15 19:32:39 +00:00
Kelvin Zhang
928c2341a6 Allow zip64 support when opening zip files
When opening an zip file through zipfile.ZipFile(), python2 by default
disables zip64 support. To support update files >4GB, we manually add
allowZip64 to override the setting.

Test: generate && serve an OTA

Change-Id: I9645e963ced830cc2d3a4b72bc63b9369a1cefe8
2020-09-22 16:53:39 -04:00
Kelvin Zhang
39aea44a96 Generate partition timestamps in ota_from_target_files
Test: make an OTA package
Bug: 162553432
Change-Id: I17b9f1b24307255b1e5115de12fa516126b32365
2020-09-03 14:04:21 -04:00
Tianjie
2bb14864e0 Add per-partition build info into ota metadata
As part of the ota metadata work to support partial update, we should
add the per-partition device name, fingerprint, and version to the ota
metadata.

Bug: 151088567
Bug: 166154730
Test: unit tests pass, generate a package
Change-Id: I7a71a4860aad651daf9e62df39c60d72727c14ff
2020-08-31 14:17:10 -07:00
Tianjie
a2076137a1 Define the protobuf for OTA metadata
Background in http://go/android-partial-updates. For partial update
(e.g. system-only) or devices with mixed build, the current
fingerprint & device name no longer suffice as the precondition to
install the package.

Therefore, we need to additionally include the per-partition build
props into the ota metadata. We also define a protobuf for the metadata
so it can be extended later. The metadata of the legacy format is also
kept for backward compatibility.

Bug: 151088567
Test: unittest pass, generate an OTA and check the result
Change-Id: I716f7da54a393cd340280dbddc3c92b3460f8ef8
2020-08-26 16:17:35 -07:00
Kelvin Zhang
2e41738566 Fix lint errors on ota_utils.py
Pylint reports lot of error on ota_utils.py, because some members of
OPTIONS object aren't defined. This CL moves some definition from
ota_from_target_files.py to ota_utils.py to fix these lint errors.

Test: Make an OTA package
Change-Id: I1e9f255d5919712b13329046c72650dfac184701
2020-08-25 15:58:24 -04:00
Kelvin Zhang
cff4d7606d Move non-AB OTA generation code to a separate file
Test: Generate a non-AB OTA, apply it
Change-Id: I2f1afbe70d17356fcbf4d59901d201a76a3d6c4f
2020-08-10 16:22:22 -04:00