2015-03-24 03:13:21 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Given a target-files zipfile, produces an OTA package that installs
|
|
|
|
that build. An incremental OTA is produced if -i is given, otherwise
|
|
|
|
a full OTA is produced.
|
|
|
|
|
|
|
|
Usage: ota_from_target_files [flags] input_target_files output_ota_package
|
|
|
|
|
|
|
|
--board_config <file>
|
|
|
|
Deprecated.
|
|
|
|
|
|
|
|
-k (--package_key) <key> Key to use to sign the package (default is
|
|
|
|
the value of default_system_dev_certificate from the input
|
|
|
|
target-files's META/misc_info.txt, or
|
|
|
|
"build/target/product/security/testkey" if that value is not
|
|
|
|
specified).
|
|
|
|
|
|
|
|
For incremental OTAs, the default value is based on the source
|
|
|
|
target-file, not the target build.
|
|
|
|
|
|
|
|
-i (--incremental_from) <file>
|
|
|
|
Generate an incremental OTA using the given target-files zip as
|
|
|
|
the starting build.
|
|
|
|
|
2015-04-21 23:32:35 +02:00
|
|
|
--full_radio
|
|
|
|
When generating an incremental OTA, always include a full copy of
|
|
|
|
radio image. This option is only meaningful when -i is specified,
|
|
|
|
because a full radio is always included in a full OTA if applicable.
|
|
|
|
|
2015-08-14 19:57:58 +02:00
|
|
|
--full_bootloader
|
|
|
|
Similar to --full_radio. When generating an incremental OTA, always
|
|
|
|
include a full copy of bootloader image.
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
-v (--verify)
|
|
|
|
Remount and verify the checksums of the files written to the
|
|
|
|
system and vendor (if used) partitions. Incremental builds only.
|
|
|
|
|
2017-02-16 22:06:55 +01:00
|
|
|
-o (--oem_settings) <main_file[,additional_files...]>
|
|
|
|
Comma seperated list of files used to specify the expected OEM-specific
|
|
|
|
properties on the OEM partition of the intended device.
|
|
|
|
Multiple expected values can be used by providing multiple files.
|
|
|
|
|
2016-02-26 04:49:55 +01:00
|
|
|
--oem_no_mount
|
|
|
|
For devices with OEM-specific properties but without an OEM partition,
|
|
|
|
do not mount the OEM partition in the updater-script. This should be
|
|
|
|
very rarely used, since it's expected to have a dedicated OEM partition
|
|
|
|
for OEM-specific properties. Only meaningful when -o is specified.
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
-w (--wipe_user_data)
|
|
|
|
Generate an OTA package that will wipe the user data partition
|
|
|
|
when installed.
|
|
|
|
|
2016-02-23 20:38:39 +01:00
|
|
|
--downgrade
|
|
|
|
Intentionally generate an incremental OTA that updates from a newer
|
|
|
|
build to an older one (based on timestamp comparison). "post-timestamp"
|
|
|
|
will be replaced by "ota-downgrade=yes" in the metadata file. A data
|
|
|
|
wipe will always be enforced, so "ota-wipe=yes" will also be included in
|
2016-03-09 02:53:39 +01:00
|
|
|
the metadata file. The update-binary in the source build will be used in
|
2017-02-28 20:48:48 +01:00
|
|
|
the OTA package, unless --binary flag is specified. Please also check the
|
|
|
|
doc for --override_timestamp below.
|
|
|
|
|
|
|
|
--override_timestamp
|
|
|
|
Intentionally generate an incremental OTA that updates from a newer
|
|
|
|
build to an older one (based on timestamp comparison), by overriding the
|
|
|
|
timestamp in package metadata. This differs from --downgrade flag: we
|
|
|
|
know for sure this is NOT an actual downgrade case, but two builds are
|
|
|
|
cut in a reverse order. A legit use case is that we cut a new build C
|
|
|
|
(after having A and B), but want to enfore an update path of A -> C -> B.
|
|
|
|
Specifying --downgrade may not help since that would enforce a data wipe
|
|
|
|
for C -> B update. The value of "post-timestamp" will be set to the newer
|
|
|
|
timestamp plus one, so that the package can be pushed and applied.
|
2016-02-23 20:38:39 +01:00
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
-e (--extra_script) <file>
|
|
|
|
Insert the contents of file at the end of the update script.
|
|
|
|
|
|
|
|
-2 (--two_step)
|
|
|
|
Generate a 'two-step' OTA package, where recovery is updated
|
|
|
|
first, so that any changes made to the system partition are done
|
|
|
|
using the new recovery (new kernel, etc.).
|
|
|
|
|
|
|
|
--block
|
2017-03-06 18:56:01 +01:00
|
|
|
Generate a block-based OTA for non-A/B device. We have deprecated the
|
|
|
|
support for file-based OTA since O. Block-based OTA will be used by
|
|
|
|
default for all non-A/B devices. Keeping this flag here to not break
|
|
|
|
existing callers.
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
-b (--binary) <file>
|
|
|
|
Use the given binary as the update-binary in the output package,
|
|
|
|
instead of the binary in the build's target_files. Use for
|
|
|
|
development only.
|
|
|
|
|
|
|
|
-t (--worker_threads) <int>
|
|
|
|
Specifies the number of worker-threads that will be used when
|
|
|
|
generating patches for incremental updates (defaults to 3).
|
|
|
|
|
2015-05-21 23:09:49 +02:00
|
|
|
--stash_threshold <float>
|
|
|
|
Specifies the threshold that will be used to compute the maximum
|
|
|
|
allowed stash size (defaults to 0.8).
|
2015-11-10 01:58:28 +01:00
|
|
|
|
|
|
|
--gen_verify
|
|
|
|
Generate an OTA package that verifies the partitions.
|
2015-11-30 18:40:20 +01:00
|
|
|
|
|
|
|
--log_diff <file>
|
|
|
|
Generate a log file that shows the differences in the source and target
|
|
|
|
builds for an incremental package. This option is only meaningful when
|
|
|
|
-i is specified.
|
2016-06-21 02:55:06 +02:00
|
|
|
|
|
|
|
--payload_signer <signer>
|
|
|
|
Specify the signer when signing the payload and metadata for A/B OTAs.
|
|
|
|
By default (i.e. without this flag), it calls 'openssl pkeyutl' to sign
|
|
|
|
with the package private key. If the private key cannot be accessed
|
|
|
|
directly, a payload signer that knows how to do that should be specified.
|
|
|
|
The signer will be supplied with "-inkey <path_to_key>",
|
|
|
|
"-in <input_file>" and "-out <output_file>" parameters.
|
2016-06-22 21:14:16 +02:00
|
|
|
|
|
|
|
--payload_signer_args <args>
|
|
|
|
Specify the arguments needed for payload signer.
|
2015-03-24 03:13:21 +01:00
|
|
|
"""
|
|
|
|
|
2017-01-10 19:47:58 +01:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
import sys
|
|
|
|
|
|
|
|
if sys.hexversion < 0x02070000:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("Python 2.7 or newer is required.", file=sys.stderr)
|
2015-03-24 03:13:21 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
import copy
|
2015-03-24 03:13:21 +01:00
|
|
|
import multiprocessing
|
2017-02-04 01:49:39 +01:00
|
|
|
import os.path
|
2016-01-07 22:03:56 +01:00
|
|
|
import subprocess
|
2016-06-22 21:14:16 +02:00
|
|
|
import shlex
|
2015-03-24 03:13:21 +01:00
|
|
|
import tempfile
|
|
|
|
import zipfile
|
|
|
|
|
|
|
|
import common
|
|
|
|
import edify_generator
|
|
|
|
import sparse_img
|
|
|
|
|
|
|
|
OPTIONS = common.OPTIONS
|
|
|
|
OPTIONS.package_key = None
|
|
|
|
OPTIONS.incremental_source = None
|
|
|
|
OPTIONS.verify = False
|
|
|
|
OPTIONS.patch_threshold = 0.95
|
|
|
|
OPTIONS.wipe_user_data = False
|
2016-02-23 20:38:39 +01:00
|
|
|
OPTIONS.downgrade = False
|
2017-02-28 20:48:48 +01:00
|
|
|
OPTIONS.timestamp = False
|
2015-03-24 03:13:21 +01:00
|
|
|
OPTIONS.extra_script = None
|
|
|
|
OPTIONS.worker_threads = multiprocessing.cpu_count() // 2
|
|
|
|
if OPTIONS.worker_threads == 0:
|
|
|
|
OPTIONS.worker_threads = 1
|
|
|
|
OPTIONS.two_step = False
|
|
|
|
OPTIONS.no_signing = False
|
2017-03-06 18:56:01 +01:00
|
|
|
OPTIONS.block_based = True
|
2015-03-24 03:13:21 +01:00
|
|
|
OPTIONS.updater_binary = None
|
|
|
|
OPTIONS.oem_source = None
|
2016-02-26 04:49:55 +01:00
|
|
|
OPTIONS.oem_no_mount = False
|
2015-03-24 03:13:21 +01:00
|
|
|
OPTIONS.fallback_to_full = True
|
2015-04-21 23:32:35 +02:00
|
|
|
OPTIONS.full_radio = False
|
2015-08-14 19:57:58 +02:00
|
|
|
OPTIONS.full_bootloader = False
|
2015-05-21 23:09:49 +02:00
|
|
|
# Stash size cannot exceed cache_size * threshold.
|
|
|
|
OPTIONS.cache_size = None
|
|
|
|
OPTIONS.stash_threshold = 0.8
|
2015-11-10 01:58:28 +01:00
|
|
|
OPTIONS.gen_verify = False
|
2015-11-30 18:40:20 +01:00
|
|
|
OPTIONS.log_diff = None
|
2016-06-21 02:55:06 +02:00
|
|
|
OPTIONS.payload_signer = None
|
2016-06-22 21:14:16 +02:00
|
|
|
OPTIONS.payload_signer_args = []
|
2017-03-22 06:35:00 +01:00
|
|
|
OPTIONS.extracted_input = None
|
2017-05-01 22:30:15 +02:00
|
|
|
OPTIONS.key_passwords = []
|
2015-05-21 23:09:49 +02:00
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
METADATA_NAME = 'META-INF/com/android/metadata'
|
2017-03-05 20:38:11 +01:00
|
|
|
UNZIP_PATTERN = ['IMAGES/*', 'META/*']
|
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
def SignOutput(temp_zip_name, output_zip_name):
|
2017-05-01 22:30:15 +02:00
|
|
|
pw = OPTIONS.key_passwords[OPTIONS.package_key]
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
common.SignFile(temp_zip_name, output_zip_name, OPTIONS.package_key, pw,
|
|
|
|
whole_file=True)
|
|
|
|
|
|
|
|
|
2017-02-16 22:06:55 +01:00
|
|
|
def AppendAssertions(script, info_dict, oem_dicts=None):
|
2015-03-24 03:13:21 +01:00
|
|
|
oem_props = info_dict.get("oem_fingerprint_properties")
|
2016-03-15 21:20:19 +01:00
|
|
|
if not oem_props:
|
2015-03-24 03:13:21 +01:00
|
|
|
device = GetBuildProp("ro.product.device", info_dict)
|
|
|
|
script.AssertDevice(device)
|
|
|
|
else:
|
2017-02-16 22:06:55 +01:00
|
|
|
if not oem_dicts:
|
2015-03-24 03:13:21 +01:00
|
|
|
raise common.ExternalError(
|
|
|
|
"No OEM file provided to answer expected assertions")
|
|
|
|
for prop in oem_props.split():
|
2017-02-16 22:06:55 +01:00
|
|
|
values = []
|
|
|
|
for oem_dict in oem_dicts:
|
|
|
|
if oem_dict.get(prop):
|
|
|
|
values.append(oem_dict[prop])
|
|
|
|
if not values:
|
2015-03-24 03:13:21 +01:00
|
|
|
raise common.ExternalError(
|
|
|
|
"The OEM file is missing the property %s" % prop)
|
2017-02-16 22:06:55 +01:00
|
|
|
script.AssertOemProperty(prop, values)
|
|
|
|
|
|
|
|
|
2017-03-06 19:22:20 +01:00
|
|
|
def _LoadOemDicts(script, recovery_mount_options=None):
|
2017-02-16 22:06:55 +01:00
|
|
|
"""Returns the list of loaded OEM properties dict."""
|
|
|
|
oem_dicts = None
|
|
|
|
if OPTIONS.oem_source is None:
|
|
|
|
raise common.ExternalError("OEM source required for this build")
|
2017-03-06 19:22:20 +01:00
|
|
|
if not OPTIONS.oem_no_mount and script:
|
2017-02-16 22:06:55 +01:00
|
|
|
script.Mount("/oem", recovery_mount_options)
|
|
|
|
oem_dicts = []
|
|
|
|
for oem_file in OPTIONS.oem_source:
|
|
|
|
oem_dicts.append(common.LoadDictionaryFromLines(
|
|
|
|
open(oem_file).readlines()))
|
|
|
|
return oem_dicts
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
|
2016-11-30 21:11:57 +01:00
|
|
|
def _WriteRecoveryImageToBoot(script, output_zip):
|
|
|
|
"""Find and write recovery image to /boot in two-step OTA.
|
|
|
|
|
|
|
|
In two-step OTAs, we write recovery image to /boot as the first step so that
|
|
|
|
we can reboot to there and install a new recovery image to /recovery.
|
|
|
|
A special "recovery-two-step.img" will be preferred, which encodes the correct
|
|
|
|
path of "/boot". Otherwise the device may show "device is corrupt" message
|
|
|
|
when booting into /boot.
|
|
|
|
|
|
|
|
Fall back to using the regular recovery.img if the two-step recovery image
|
|
|
|
doesn't exist. Note that rebuilding the special image at this point may be
|
|
|
|
infeasible, because we don't have the desired boot signer and keys when
|
|
|
|
calling ota_from_target_files.py.
|
|
|
|
"""
|
|
|
|
|
|
|
|
recovery_two_step_img_name = "recovery-two-step.img"
|
|
|
|
recovery_two_step_img_path = os.path.join(
|
|
|
|
OPTIONS.input_tmp, "IMAGES", recovery_two_step_img_name)
|
|
|
|
if os.path.exists(recovery_two_step_img_path):
|
|
|
|
recovery_two_step_img = common.GetBootableImage(
|
|
|
|
recovery_two_step_img_name, recovery_two_step_img_name,
|
|
|
|
OPTIONS.input_tmp, "RECOVERY")
|
|
|
|
common.ZipWriteStr(
|
|
|
|
output_zip, recovery_two_step_img_name, recovery_two_step_img.data)
|
2017-01-10 19:47:58 +01:00
|
|
|
print("two-step package: using %s in stage 1/3" % (
|
|
|
|
recovery_two_step_img_name,))
|
2016-11-30 21:11:57 +01:00
|
|
|
script.WriteRawImage("/boot", recovery_two_step_img_name)
|
|
|
|
else:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("two-step package: using recovery.img in stage 1/3")
|
2016-11-30 21:11:57 +01:00
|
|
|
# The "recovery.img" entry has been written into package earlier.
|
|
|
|
script.WriteRawImage("/boot", "recovery.img")
|
|
|
|
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
def HasRecoveryPatch(target_files_zip):
|
2015-07-22 21:33:18 +02:00
|
|
|
namelist = [name for name in target_files_zip.namelist()]
|
|
|
|
return ("SYSTEM/recovery-from-boot.p" in namelist or
|
|
|
|
"SYSTEM/etc/recovery.img" in namelist)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2017-03-06 18:56:01 +01:00
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
def HasVendorPartition(target_files_zip):
|
|
|
|
try:
|
|
|
|
target_files_zip.getinfo("VENDOR/")
|
|
|
|
return True
|
|
|
|
except KeyError:
|
|
|
|
return False
|
|
|
|
|
2017-03-06 18:56:01 +01:00
|
|
|
|
2017-08-26 22:10:26 +02:00
|
|
|
def HasTrebleEnabled(target_files_zip, info_dict):
|
|
|
|
return (HasVendorPartition(target_files_zip) and
|
|
|
|
GetBuildProp("ro.treble.enabled", info_dict) == "true")
|
|
|
|
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
def GetOemProperty(name, oem_props, oem_dict, info_dict):
|
|
|
|
if oem_props is not None and name in oem_props:
|
|
|
|
return oem_dict[name]
|
|
|
|
return GetBuildProp(name, info_dict)
|
|
|
|
|
|
|
|
|
|
|
|
def CalculateFingerprint(oem_props, oem_dict, info_dict):
|
|
|
|
if oem_props is None:
|
|
|
|
return GetBuildProp("ro.build.fingerprint", info_dict)
|
|
|
|
return "%s/%s/%s:%s" % (
|
|
|
|
GetOemProperty("ro.product.brand", oem_props, oem_dict, info_dict),
|
|
|
|
GetOemProperty("ro.product.name", oem_props, oem_dict, info_dict),
|
|
|
|
GetOemProperty("ro.product.device", oem_props, oem_dict, info_dict),
|
|
|
|
GetBuildProp("ro.build.thumbprint", info_dict))
|
|
|
|
|
|
|
|
|
2017-03-07 00:50:08 +01:00
|
|
|
def GetImage(which, tmpdir):
|
|
|
|
"""Returns an image object suitable for passing to BlockImageDiff.
|
|
|
|
|
|
|
|
'which' partition must be "system" or "vendor". A prebuilt image and file
|
|
|
|
map must already exist in tmpdir.
|
|
|
|
"""
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
assert which in ("system", "vendor")
|
|
|
|
|
|
|
|
path = os.path.join(tmpdir, "IMAGES", which + ".img")
|
|
|
|
mappath = os.path.join(tmpdir, "IMAGES", which + ".map")
|
|
|
|
|
2017-03-07 00:50:08 +01:00
|
|
|
# The image and map files must have been created prior to calling
|
|
|
|
# ota_from_target_files.py (since LMP).
|
|
|
|
assert os.path.exists(path) and os.path.exists(mappath)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2015-05-12 20:42:31 +02:00
|
|
|
# Bug: http://b/20939131
|
|
|
|
# In ext4 filesystems, block 0 might be changed even being mounted
|
|
|
|
# R/O. We add it to clobbered_blocks so that it will be written to the
|
|
|
|
# target unconditionally. Note that they are still part of care_map.
|
|
|
|
clobbered_blocks = "0"
|
|
|
|
|
|
|
|
return sparse_img.SparseImage(path, mappath, clobbered_blocks)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
|
2017-08-26 22:10:26 +02:00
|
|
|
def AddCompatibilityArchiveIfTrebleEnabled(target_zip, output_zip,
|
|
|
|
target_info_dict,
|
|
|
|
source_info_dict=None):
|
|
|
|
"""Adds compatibility info into the output zip if it's Treble-enabled target.
|
2017-04-19 19:16:09 +02:00
|
|
|
|
|
|
|
Metadata used for on-device compatibility verification is retrieved from
|
|
|
|
target_zip then added to compatibility.zip which is added to the output_zip
|
|
|
|
archive.
|
|
|
|
|
2017-08-26 22:10:26 +02:00
|
|
|
Compatibility archive should only be included for devices that have enabled
|
|
|
|
Treble support.
|
2017-04-19 19:16:09 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
target_zip: Zip file containing the source files to be included for OTA.
|
|
|
|
output_zip: Zip file that will be sent for OTA.
|
2017-08-26 22:10:26 +02:00
|
|
|
target_info_dict: The dict that holds the target build info.
|
|
|
|
source_info_dict: The dict that holds the source build info, if generating
|
|
|
|
an incremental OTA; None otherwise.
|
2017-04-19 19:16:09 +02:00
|
|
|
"""
|
|
|
|
|
2017-08-26 22:10:26 +02:00
|
|
|
def AddCompatibilityArchive(system_updated, vendor_updated):
|
|
|
|
"""Adds compatibility info based on system/vendor update status.
|
2017-04-19 19:16:09 +02:00
|
|
|
|
2017-08-26 22:10:26 +02:00
|
|
|
Args:
|
|
|
|
system_updated: If True, the system image will be updated and therefore
|
|
|
|
its metadata should be included.
|
|
|
|
vendor_updated: If True, the vendor image will be updated and therefore
|
|
|
|
its metadata should be included.
|
|
|
|
"""
|
|
|
|
# Determine what metadata we need. Files are names relative to META/.
|
|
|
|
compatibility_files = []
|
|
|
|
vendor_metadata = ("vendor_manifest.xml", "vendor_matrix.xml")
|
|
|
|
system_metadata = ("system_manifest.xml", "system_matrix.xml")
|
|
|
|
if vendor_updated:
|
|
|
|
compatibility_files += vendor_metadata
|
|
|
|
if system_updated:
|
|
|
|
compatibility_files += system_metadata
|
|
|
|
|
|
|
|
# Create new archive.
|
|
|
|
compatibility_archive = tempfile.NamedTemporaryFile()
|
|
|
|
compatibility_archive_zip = zipfile.ZipFile(compatibility_archive, "w",
|
|
|
|
compression=zipfile.ZIP_DEFLATED)
|
|
|
|
|
|
|
|
# Add metadata.
|
|
|
|
for file_name in compatibility_files:
|
|
|
|
target_file_name = "META/" + file_name
|
|
|
|
|
|
|
|
if target_file_name in target_zip.namelist():
|
|
|
|
data = target_zip.read(target_file_name)
|
|
|
|
common.ZipWriteStr(compatibility_archive_zip, file_name, data)
|
|
|
|
|
|
|
|
# Ensure files are written before we copy into output_zip.
|
|
|
|
compatibility_archive_zip.close()
|
|
|
|
|
|
|
|
# Only add the archive if we have any compatibility info.
|
|
|
|
if compatibility_archive_zip.namelist():
|
|
|
|
common.ZipWrite(output_zip, compatibility_archive.name,
|
|
|
|
arcname="compatibility.zip",
|
|
|
|
compress_type=zipfile.ZIP_STORED)
|
|
|
|
|
|
|
|
# Will only proceed if the target has enabled the Treble support (as well as
|
|
|
|
# having a /vendor partition).
|
|
|
|
if not HasTrebleEnabled(target_zip, target_info_dict):
|
|
|
|
return
|
|
|
|
|
|
|
|
# We don't support OEM thumbprint in Treble world (which calculates
|
|
|
|
# fingerprints in a different way as shown in CalculateFingerprint()).
|
|
|
|
assert not target_info_dict.get("oem_fingerprint_properties")
|
|
|
|
|
|
|
|
# Full OTA carries the info for system/vendor both.
|
|
|
|
if source_info_dict is None:
|
|
|
|
AddCompatibilityArchive(True, True)
|
|
|
|
return
|
|
|
|
|
|
|
|
assert not source_info_dict.get("oem_fingerprint_properties")
|
|
|
|
|
|
|
|
source_fp = GetBuildProp("ro.build.fingerprint", source_info_dict)
|
|
|
|
target_fp = GetBuildProp("ro.build.fingerprint", target_info_dict)
|
|
|
|
system_updated = source_fp != target_fp
|
|
|
|
|
|
|
|
source_fp_vendor = GetVendorBuildProp("ro.vendor.build.fingerprint",
|
|
|
|
source_info_dict)
|
|
|
|
target_fp_vendor = GetVendorBuildProp("ro.vendor.build.fingerprint",
|
|
|
|
target_info_dict)
|
|
|
|
vendor_updated = source_fp_vendor != target_fp_vendor
|
|
|
|
|
|
|
|
AddCompatibilityArchive(system_updated, vendor_updated)
|
2017-04-19 19:16:09 +02:00
|
|
|
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
def WriteFullOTAPackage(input_zip, output_zip):
|
|
|
|
# TODO: how to determine this? We don't know what version it will
|
2015-06-23 04:17:41 +02:00
|
|
|
# be installed on top of. For now, we expect the API just won't
|
|
|
|
# change very often. Similarly for fstab, it might have changed
|
|
|
|
# in the target build.
|
2015-03-24 03:13:21 +01:00
|
|
|
script = edify_generator.EdifyGenerator(3, OPTIONS.info_dict)
|
|
|
|
|
2016-03-15 20:16:18 +01:00
|
|
|
recovery_mount_options = OPTIONS.info_dict.get("recovery_mount_options")
|
2016-03-15 21:20:19 +01:00
|
|
|
oem_props = OPTIONS.info_dict.get("oem_fingerprint_properties")
|
2017-02-16 22:06:55 +01:00
|
|
|
oem_dicts = None
|
2016-03-15 21:20:19 +01:00
|
|
|
if oem_props:
|
2017-02-16 22:06:55 +01:00
|
|
|
oem_dicts = _LoadOemDicts(script, recovery_mount_options)
|
|
|
|
|
|
|
|
target_fp = CalculateFingerprint(oem_props, oem_dicts and oem_dicts[0],
|
|
|
|
OPTIONS.info_dict)
|
2015-03-24 03:13:21 +01:00
|
|
|
metadata = {
|
2017-03-10 00:01:11 +01:00
|
|
|
"post-build": target_fp,
|
2017-02-16 22:06:55 +01:00
|
|
|
"pre-device": GetOemProperty("ro.product.device", oem_props,
|
|
|
|
oem_dicts and oem_dicts[0],
|
2015-03-24 03:13:21 +01:00
|
|
|
OPTIONS.info_dict),
|
|
|
|
"post-timestamp": GetBuildProp("ro.build.date.utc", OPTIONS.info_dict),
|
|
|
|
}
|
|
|
|
|
|
|
|
device_specific = common.DeviceSpecificParams(
|
|
|
|
input_zip=input_zip,
|
|
|
|
input_version=OPTIONS.info_dict["recovery_api_version"],
|
|
|
|
output_zip=output_zip,
|
|
|
|
script=script,
|
|
|
|
input_tmp=OPTIONS.input_tmp,
|
|
|
|
metadata=metadata,
|
|
|
|
info_dict=OPTIONS.info_dict)
|
|
|
|
|
2017-03-06 18:56:01 +01:00
|
|
|
assert HasRecoveryPatch(input_zip)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2017-03-06 18:56:01 +01:00
|
|
|
metadata["ota-type"] = "BLOCK"
|
2016-02-04 23:26:02 +01:00
|
|
|
|
2016-06-20 23:35:47 +02:00
|
|
|
ts = GetBuildProp("ro.build.date.utc", OPTIONS.info_dict)
|
|
|
|
ts_text = GetBuildProp("ro.build.date", OPTIONS.info_dict)
|
|
|
|
script.AssertOlderBuild(ts, ts_text)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2017-02-16 22:06:55 +01:00
|
|
|
AppendAssertions(script, OPTIONS.info_dict, oem_dicts)
|
2015-03-24 03:13:21 +01:00
|
|
|
device_specific.FullOTA_Assertions()
|
|
|
|
|
|
|
|
# Two-step package strategy (in chronological order, which is *not*
|
|
|
|
# the order in which the generated script has things):
|
|
|
|
#
|
|
|
|
# if stage is not "2/3" or "3/3":
|
|
|
|
# write recovery image to boot partition
|
|
|
|
# set stage to "2/3"
|
|
|
|
# reboot to boot partition and restart recovery
|
|
|
|
# else if stage is "2/3":
|
|
|
|
# write recovery image to recovery partition
|
|
|
|
# set stage to "3/3"
|
|
|
|
# reboot to recovery partition and restart recovery
|
|
|
|
# else:
|
|
|
|
# (stage must be "3/3")
|
|
|
|
# set stage to ""
|
|
|
|
# do normal full package installation:
|
|
|
|
# wipe and install system, boot image, etc.
|
|
|
|
# set up system to update recovery partition on first boot
|
|
|
|
# complete script normally
|
|
|
|
# (allow recovery to mark itself finished and reboot)
|
|
|
|
|
|
|
|
recovery_img = common.GetBootableImage("recovery.img", "recovery.img",
|
|
|
|
OPTIONS.input_tmp, "RECOVERY")
|
|
|
|
if OPTIONS.two_step:
|
|
|
|
if not OPTIONS.info_dict.get("multistage_support", None):
|
|
|
|
assert False, "two-step packages not supported by this build"
|
|
|
|
fs = OPTIONS.info_dict["fstab"]["/misc"]
|
|
|
|
assert fs.fs_type.upper() == "EMMC", \
|
|
|
|
"two-step packages only supported on devices with EMMC /misc partitions"
|
|
|
|
bcb_dev = {"bcb_dev": fs.device}
|
|
|
|
common.ZipWriteStr(output_zip, "recovery.img", recovery_img.data)
|
|
|
|
script.AppendExtra("""
|
|
|
|
if get_stage("%(bcb_dev)s") == "2/3" then
|
|
|
|
""" % bcb_dev)
|
2016-11-30 21:11:57 +01:00
|
|
|
|
|
|
|
# Stage 2/3: Write recovery image to /recovery (currently running /boot).
|
|
|
|
script.Comment("Stage 2/3")
|
2015-03-24 03:13:21 +01:00
|
|
|
script.WriteRawImage("/recovery", "recovery.img")
|
|
|
|
script.AppendExtra("""
|
|
|
|
set_stage("%(bcb_dev)s", "3/3");
|
|
|
|
reboot_now("%(bcb_dev)s", "recovery");
|
|
|
|
else if get_stage("%(bcb_dev)s") == "3/3" then
|
|
|
|
""" % bcb_dev)
|
|
|
|
|
2016-11-30 21:11:57 +01:00
|
|
|
# Stage 3/3: Make changes.
|
|
|
|
script.Comment("Stage 3/3")
|
|
|
|
|
2015-04-09 00:30:27 +02:00
|
|
|
# Dump fingerprints
|
2016-03-15 21:20:19 +01:00
|
|
|
script.Print("Target: %s" % target_fp)
|
2015-04-09 00:30:27 +02:00
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
device_specific.FullOTA_InstallBegin()
|
|
|
|
|
|
|
|
system_progress = 0.75
|
|
|
|
|
|
|
|
if OPTIONS.wipe_user_data:
|
|
|
|
system_progress -= 0.1
|
|
|
|
if HasVendorPartition(input_zip):
|
|
|
|
system_progress -= 0.1
|
|
|
|
|
|
|
|
recovery_mount_options = OPTIONS.info_dict.get("recovery_mount_options")
|
|
|
|
|
|
|
|
script.ShowProgress(system_progress, 0)
|
|
|
|
|
2017-03-06 18:56:01 +01:00
|
|
|
# Full OTA is done as an "incremental" against an empty source image. This
|
|
|
|
# has the effect of writing new data from the package to the entire
|
|
|
|
# partition, but lets us reuse the updater code that writes incrementals to
|
|
|
|
# do it.
|
|
|
|
system_tgt = GetImage("system", OPTIONS.input_tmp)
|
|
|
|
system_tgt.ResetFileMap()
|
|
|
|
system_diff = common.BlockDifference("system", system_tgt, src=None)
|
|
|
|
system_diff.WriteScript(script, output_zip)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2015-07-22 03:01:20 +02:00
|
|
|
boot_img = common.GetBootableImage(
|
|
|
|
"boot.img", "boot.img", OPTIONS.input_tmp, "BOOT")
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
if HasVendorPartition(input_zip):
|
|
|
|
script.ShowProgress(0.1, 0)
|
|
|
|
|
2017-03-06 18:56:01 +01:00
|
|
|
vendor_tgt = GetImage("vendor", OPTIONS.input_tmp)
|
|
|
|
vendor_tgt.ResetFileMap()
|
|
|
|
vendor_diff = common.BlockDifference("vendor", vendor_tgt)
|
|
|
|
vendor_diff.WriteScript(script, output_zip)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2017-08-26 22:10:26 +02:00
|
|
|
AddCompatibilityArchiveIfTrebleEnabled(input_zip, output_zip,
|
|
|
|
OPTIONS.info_dict)
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
common.CheckSize(boot_img.data, "boot.img", OPTIONS.info_dict)
|
|
|
|
common.ZipWriteStr(output_zip, "boot.img", boot_img.data)
|
|
|
|
|
|
|
|
script.ShowProgress(0.05, 5)
|
|
|
|
script.WriteRawImage("/boot", "boot.img")
|
|
|
|
|
|
|
|
script.ShowProgress(0.2, 10)
|
|
|
|
device_specific.FullOTA_InstallEnd()
|
|
|
|
|
|
|
|
if OPTIONS.extra_script is not None:
|
|
|
|
script.AppendExtra(OPTIONS.extra_script)
|
|
|
|
|
|
|
|
script.UnmountAll()
|
|
|
|
|
|
|
|
if OPTIONS.wipe_user_data:
|
|
|
|
script.ShowProgress(0.1, 10)
|
|
|
|
script.FormatPartition("/data")
|
|
|
|
|
|
|
|
if OPTIONS.two_step:
|
|
|
|
script.AppendExtra("""
|
|
|
|
set_stage("%(bcb_dev)s", "");
|
|
|
|
""" % bcb_dev)
|
|
|
|
script.AppendExtra("else\n")
|
2016-11-30 21:11:57 +01:00
|
|
|
|
|
|
|
# Stage 1/3: Nothing to verify for full OTA. Write recovery image to /boot.
|
|
|
|
script.Comment("Stage 1/3")
|
|
|
|
_WriteRecoveryImageToBoot(script, output_zip)
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
script.AppendExtra("""
|
|
|
|
set_stage("%(bcb_dev)s", "2/3");
|
|
|
|
reboot_now("%(bcb_dev)s", "");
|
|
|
|
endif;
|
|
|
|
endif;
|
|
|
|
""" % bcb_dev)
|
2016-02-04 23:26:02 +01:00
|
|
|
|
2016-02-23 20:38:39 +01:00
|
|
|
script.SetProgress(1)
|
|
|
|
script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)
|
2016-02-04 23:26:02 +01:00
|
|
|
metadata["ota-required-cache"] = str(script.required_cache)
|
2015-03-24 03:13:21 +01:00
|
|
|
WriteMetadata(metadata, output_zip)
|
|
|
|
|
|
|
|
|
|
|
|
def WriteMetadata(metadata, output_zip):
|
2017-02-04 01:49:39 +01:00
|
|
|
value = "".join(["%s=%s\n" % kv for kv in sorted(metadata.iteritems())])
|
|
|
|
common.ZipWriteStr(output_zip, METADATA_NAME, value,
|
|
|
|
compress_type=zipfile.ZIP_STORED)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
def GetBuildProp(prop, info_dict):
|
2017-08-26 22:10:26 +02:00
|
|
|
"""Returns the inquired build property from a given info_dict."""
|
2015-03-24 03:13:21 +01:00
|
|
|
try:
|
|
|
|
return info_dict.get("build.prop", {})[prop]
|
|
|
|
except KeyError:
|
|
|
|
raise common.ExternalError("couldn't find %s in build.prop" % (prop,))
|
|
|
|
|
|
|
|
|
2017-08-26 22:10:26 +02:00
|
|
|
def GetVendorBuildProp(prop, info_dict):
|
|
|
|
"""Returns the inquired vendor build property from a given info_dict."""
|
|
|
|
try:
|
|
|
|
return info_dict.get("vendor.build.prop", {})[prop]
|
|
|
|
except KeyError:
|
|
|
|
raise common.ExternalError(
|
|
|
|
"couldn't find %s in vendor.build.prop" % (prop,))
|
|
|
|
|
|
|
|
|
2017-02-07 20:21:17 +01:00
|
|
|
def HandleDowngradeMetadata(metadata):
|
|
|
|
# Only incremental OTAs are allowed to reach here.
|
|
|
|
assert OPTIONS.incremental_source is not None
|
|
|
|
|
|
|
|
post_timestamp = GetBuildProp("ro.build.date.utc", OPTIONS.target_info_dict)
|
|
|
|
pre_timestamp = GetBuildProp("ro.build.date.utc", OPTIONS.source_info_dict)
|
|
|
|
is_downgrade = long(post_timestamp) < long(pre_timestamp)
|
|
|
|
|
|
|
|
if OPTIONS.downgrade:
|
|
|
|
if not is_downgrade:
|
|
|
|
raise RuntimeError("--downgrade specified but no downgrade detected: "
|
|
|
|
"pre: %s, post: %s" % (pre_timestamp, post_timestamp))
|
2017-02-28 20:48:48 +01:00
|
|
|
metadata["ota-downgrade"] = "yes"
|
|
|
|
elif OPTIONS.timestamp:
|
|
|
|
if not is_downgrade:
|
|
|
|
raise RuntimeError("--timestamp specified but no timestamp hack needed: "
|
|
|
|
"pre: %s, post: %s" % (pre_timestamp, post_timestamp))
|
|
|
|
metadata["post-timestamp"] = str(long(pre_timestamp) + 1)
|
2017-02-07 20:21:17 +01:00
|
|
|
else:
|
|
|
|
if is_downgrade:
|
2017-02-28 20:48:48 +01:00
|
|
|
raise RuntimeError("Downgrade detected based on timestamp check: "
|
|
|
|
"pre: %s, post: %s. Need to specify --timestamp OR "
|
|
|
|
"--downgrade to allow building the incremental." % (
|
|
|
|
pre_timestamp, post_timestamp))
|
2017-02-07 20:21:17 +01:00
|
|
|
metadata["post-timestamp"] = post_timestamp
|
|
|
|
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
def WriteBlockIncrementalOTAPackage(target_zip, source_zip, output_zip):
|
|
|
|
source_version = OPTIONS.source_info_dict["recovery_api_version"]
|
|
|
|
target_version = OPTIONS.target_info_dict["recovery_api_version"]
|
|
|
|
|
|
|
|
if source_version == 0:
|
2016-03-15 21:20:19 +01:00
|
|
|
print("WARNING: generating edify script for a source that "
|
|
|
|
"can't install it.")
|
2015-06-23 04:17:41 +02:00
|
|
|
script = edify_generator.EdifyGenerator(
|
|
|
|
source_version, OPTIONS.target_info_dict,
|
|
|
|
fstab=OPTIONS.source_info_dict["fstab"])
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2015-07-06 06:08:33 +02:00
|
|
|
recovery_mount_options = OPTIONS.source_info_dict.get(
|
|
|
|
"recovery_mount_options")
|
2016-03-15 21:20:19 +01:00
|
|
|
source_oem_props = OPTIONS.source_info_dict.get("oem_fingerprint_properties")
|
|
|
|
target_oem_props = OPTIONS.target_info_dict.get("oem_fingerprint_properties")
|
2017-02-16 22:06:55 +01:00
|
|
|
oem_dicts = None
|
|
|
|
if source_oem_props and target_oem_props:
|
|
|
|
oem_dicts = _LoadOemDicts(script, recovery_mount_options)
|
2015-07-06 06:08:33 +02:00
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
metadata = {
|
2016-03-15 21:20:19 +01:00
|
|
|
"pre-device": GetOemProperty("ro.product.device", source_oem_props,
|
2017-02-16 22:06:55 +01:00
|
|
|
oem_dicts and oem_dicts[0],
|
|
|
|
OPTIONS.source_info_dict),
|
2016-02-04 23:26:02 +01:00
|
|
|
"ota-type": "BLOCK",
|
2015-03-24 03:13:21 +01:00
|
|
|
}
|
|
|
|
|
2017-02-07 20:21:17 +01:00
|
|
|
HandleDowngradeMetadata(metadata)
|
2016-02-23 20:38:39 +01:00
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
device_specific = common.DeviceSpecificParams(
|
|
|
|
source_zip=source_zip,
|
|
|
|
source_version=source_version,
|
|
|
|
target_zip=target_zip,
|
|
|
|
target_version=target_version,
|
|
|
|
output_zip=output_zip,
|
|
|
|
script=script,
|
|
|
|
metadata=metadata,
|
2015-10-14 01:37:12 +02:00
|
|
|
info_dict=OPTIONS.source_info_dict)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2017-02-16 22:06:55 +01:00
|
|
|
source_fp = CalculateFingerprint(source_oem_props, oem_dicts and oem_dicts[0],
|
2015-07-06 06:08:33 +02:00
|
|
|
OPTIONS.source_info_dict)
|
2017-02-16 22:06:55 +01:00
|
|
|
target_fp = CalculateFingerprint(target_oem_props, oem_dicts and oem_dicts[0],
|
2015-07-06 06:08:33 +02:00
|
|
|
OPTIONS.target_info_dict)
|
2015-03-24 03:13:21 +01:00
|
|
|
metadata["pre-build"] = source_fp
|
|
|
|
metadata["post-build"] = target_fp
|
2016-06-09 23:18:45 +02:00
|
|
|
metadata["pre-build-incremental"] = GetBuildProp(
|
|
|
|
"ro.build.version.incremental", OPTIONS.source_info_dict)
|
|
|
|
metadata["post-build-incremental"] = GetBuildProp(
|
|
|
|
"ro.build.version.incremental", OPTIONS.target_info_dict)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
source_boot = common.GetBootableImage(
|
|
|
|
"/tmp/boot.img", "boot.img", OPTIONS.source_tmp, "BOOT",
|
|
|
|
OPTIONS.source_info_dict)
|
|
|
|
target_boot = common.GetBootableImage(
|
|
|
|
"/tmp/boot.img", "boot.img", OPTIONS.target_tmp, "BOOT")
|
|
|
|
updating_boot = (not OPTIONS.two_step and
|
|
|
|
(source_boot.data != target_boot.data))
|
|
|
|
|
|
|
|
target_recovery = common.GetBootableImage(
|
|
|
|
"/tmp/recovery.img", "recovery.img", OPTIONS.target_tmp, "RECOVERY")
|
|
|
|
|
2017-03-07 00:50:08 +01:00
|
|
|
system_src = GetImage("system", OPTIONS.source_tmp)
|
|
|
|
system_tgt = GetImage("system", OPTIONS.target_tmp)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
blockimgdiff_version = 1
|
|
|
|
if OPTIONS.info_dict:
|
|
|
|
blockimgdiff_version = max(
|
|
|
|
int(i) for i in
|
|
|
|
OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
|
|
|
|
|
2016-07-07 18:09:58 +02:00
|
|
|
# Check the first block of the source system partition for remount R/W only
|
|
|
|
# if the filesystem is ext4.
|
|
|
|
system_src_partition = OPTIONS.source_info_dict["fstab"]["/system"]
|
|
|
|
check_first_block = system_src_partition.fs_type == "ext4"
|
2016-06-11 21:19:23 +02:00
|
|
|
# Disable using imgdiff for squashfs. 'imgdiff -z' expects input files to be
|
|
|
|
# in zip formats. However with squashfs, a) all files are compressed in LZ4;
|
|
|
|
# b) the blocks listed in block map may not contain all the bytes for a given
|
|
|
|
# file (because they're rounded to be 4K-aligned).
|
2016-07-07 18:09:58 +02:00
|
|
|
system_tgt_partition = OPTIONS.target_info_dict["fstab"]["/system"]
|
|
|
|
disable_imgdiff = (system_src_partition.fs_type == "squashfs" or
|
|
|
|
system_tgt_partition.fs_type == "squashfs")
|
2015-03-24 03:13:21 +01:00
|
|
|
system_diff = common.BlockDifference("system", system_tgt, system_src,
|
2015-12-15 20:53:59 +01:00
|
|
|
check_first_block,
|
2016-06-11 21:19:23 +02:00
|
|
|
version=blockimgdiff_version,
|
|
|
|
disable_imgdiff=disable_imgdiff)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
if HasVendorPartition(target_zip):
|
|
|
|
if not HasVendorPartition(source_zip):
|
|
|
|
raise RuntimeError("can't generate incremental that adds /vendor")
|
2017-03-07 00:50:08 +01:00
|
|
|
vendor_src = GetImage("vendor", OPTIONS.source_tmp)
|
|
|
|
vendor_tgt = GetImage("vendor", OPTIONS.target_tmp)
|
2015-12-15 20:53:59 +01:00
|
|
|
|
|
|
|
# Check first block of vendor partition for remount R/W only if
|
|
|
|
# disk type is ext4
|
|
|
|
vendor_partition = OPTIONS.source_info_dict["fstab"]["/vendor"]
|
2016-02-04 23:26:02 +01:00
|
|
|
check_first_block = vendor_partition.fs_type == "ext4"
|
2016-06-11 21:19:23 +02:00
|
|
|
disable_imgdiff = vendor_partition.fs_type == "squashfs"
|
2015-03-24 03:13:21 +01:00
|
|
|
vendor_diff = common.BlockDifference("vendor", vendor_tgt, vendor_src,
|
2015-12-15 20:53:59 +01:00
|
|
|
check_first_block,
|
2016-06-11 21:19:23 +02:00
|
|
|
version=blockimgdiff_version,
|
|
|
|
disable_imgdiff=disable_imgdiff)
|
2015-03-24 03:13:21 +01:00
|
|
|
else:
|
|
|
|
vendor_diff = None
|
|
|
|
|
2017-08-26 22:10:26 +02:00
|
|
|
AddCompatibilityArchiveIfTrebleEnabled(
|
|
|
|
target_zip, output_zip, OPTIONS.target_info_dict,
|
|
|
|
OPTIONS.source_info_dict)
|
|
|
|
|
2017-02-16 22:06:55 +01:00
|
|
|
AppendAssertions(script, OPTIONS.target_info_dict, oem_dicts)
|
2015-03-24 03:13:21 +01:00
|
|
|
device_specific.IncrementalOTA_Assertions()
|
|
|
|
|
|
|
|
# Two-step incremental package strategy (in chronological order,
|
|
|
|
# which is *not* the order in which the generated script has
|
|
|
|
# things):
|
|
|
|
#
|
|
|
|
# if stage is not "2/3" or "3/3":
|
|
|
|
# do verification on current system
|
|
|
|
# write recovery image to boot partition
|
|
|
|
# set stage to "2/3"
|
|
|
|
# reboot to boot partition and restart recovery
|
|
|
|
# else if stage is "2/3":
|
|
|
|
# write recovery image to recovery partition
|
|
|
|
# set stage to "3/3"
|
|
|
|
# reboot to recovery partition and restart recovery
|
|
|
|
# else:
|
|
|
|
# (stage must be "3/3")
|
|
|
|
# perform update:
|
|
|
|
# patch system files, etc.
|
|
|
|
# force full install of new boot image
|
|
|
|
# set up system to update recovery partition on first boot
|
|
|
|
# complete script normally
|
|
|
|
# (allow recovery to mark itself finished and reboot)
|
|
|
|
|
|
|
|
if OPTIONS.two_step:
|
2015-07-29 23:09:23 +02:00
|
|
|
if not OPTIONS.source_info_dict.get("multistage_support", None):
|
2015-03-24 03:13:21 +01:00
|
|
|
assert False, "two-step packages not supported by this build"
|
2015-07-29 23:09:23 +02:00
|
|
|
fs = OPTIONS.source_info_dict["fstab"]["/misc"]
|
2015-03-24 03:13:21 +01:00
|
|
|
assert fs.fs_type.upper() == "EMMC", \
|
|
|
|
"two-step packages only supported on devices with EMMC /misc partitions"
|
|
|
|
bcb_dev = {"bcb_dev": fs.device}
|
|
|
|
common.ZipWriteStr(output_zip, "recovery.img", target_recovery.data)
|
|
|
|
script.AppendExtra("""
|
|
|
|
if get_stage("%(bcb_dev)s") == "2/3" then
|
|
|
|
""" % bcb_dev)
|
2016-11-30 21:11:57 +01:00
|
|
|
|
|
|
|
# Stage 2/3: Write recovery image to /recovery (currently running /boot).
|
|
|
|
script.Comment("Stage 2/3")
|
2015-03-24 03:13:21 +01:00
|
|
|
script.AppendExtra("sleep(20);\n")
|
|
|
|
script.WriteRawImage("/recovery", "recovery.img")
|
|
|
|
script.AppendExtra("""
|
|
|
|
set_stage("%(bcb_dev)s", "3/3");
|
|
|
|
reboot_now("%(bcb_dev)s", "recovery");
|
|
|
|
else if get_stage("%(bcb_dev)s") != "3/3" then
|
|
|
|
""" % bcb_dev)
|
|
|
|
|
2016-11-30 21:11:57 +01:00
|
|
|
# Stage 1/3: (a) Verify the current system.
|
|
|
|
script.Comment("Stage 1/3")
|
|
|
|
|
2015-04-09 00:30:27 +02:00
|
|
|
# Dump fingerprints
|
2016-12-14 20:53:38 +01:00
|
|
|
script.Print("Source: %s" % (source_fp,))
|
|
|
|
script.Print("Target: %s" % (target_fp,))
|
2015-04-09 00:30:27 +02:00
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
script.Print("Verifying current system...")
|
|
|
|
|
|
|
|
device_specific.IncrementalOTA_VerifyBegin()
|
|
|
|
|
2016-03-15 21:20:19 +01:00
|
|
|
# When blockimgdiff version is less than 3 (non-resumable block-based OTA),
|
|
|
|
# patching on a device that's already on the target build will damage the
|
|
|
|
# system. Because operations like move don't check the block state, they
|
|
|
|
# always apply the changes unconditionally.
|
|
|
|
if blockimgdiff_version <= 2:
|
|
|
|
if source_oem_props is None:
|
2015-03-24 03:13:21 +01:00
|
|
|
script.AssertSomeFingerprint(source_fp)
|
|
|
|
else:
|
|
|
|
script.AssertSomeThumbprint(
|
|
|
|
GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
|
2016-03-15 21:20:19 +01:00
|
|
|
|
|
|
|
else: # blockimgdiff_version > 2
|
|
|
|
if source_oem_props is None and target_oem_props is None:
|
|
|
|
script.AssertSomeFingerprint(source_fp, target_fp)
|
|
|
|
elif source_oem_props is not None and target_oem_props is not None:
|
2016-03-15 20:16:18 +01:00
|
|
|
script.AssertSomeThumbprint(
|
|
|
|
GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict),
|
2016-03-07 22:03:19 +01:00
|
|
|
GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
|
2016-03-15 21:20:19 +01:00
|
|
|
elif source_oem_props is None and target_oem_props is not None:
|
|
|
|
script.AssertFingerprintOrThumbprint(
|
|
|
|
source_fp,
|
|
|
|
GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict))
|
|
|
|
else:
|
|
|
|
script.AssertFingerprintOrThumbprint(
|
|
|
|
target_fp,
|
|
|
|
GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2016-02-04 23:26:02 +01:00
|
|
|
# Check the required cache size (i.e. stashed blocks).
|
|
|
|
size = []
|
|
|
|
if system_diff:
|
|
|
|
size.append(system_diff.required_cache)
|
|
|
|
if vendor_diff:
|
|
|
|
size.append(vendor_diff.required_cache)
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
if updating_boot:
|
2015-07-29 23:09:23 +02:00
|
|
|
boot_type, boot_device = common.GetTypeAndDevice(
|
|
|
|
"/boot", OPTIONS.source_info_dict)
|
2015-03-24 03:13:21 +01:00
|
|
|
d = common.Difference(target_boot, source_boot)
|
|
|
|
_, _, d = d.ComputePatch()
|
|
|
|
if d is None:
|
|
|
|
include_full_boot = True
|
|
|
|
common.ZipWriteStr(output_zip, "boot.img", target_boot.data)
|
|
|
|
else:
|
|
|
|
include_full_boot = False
|
|
|
|
|
2017-01-10 19:47:58 +01:00
|
|
|
print("boot target: %d source: %d diff: %d" % (
|
|
|
|
target_boot.size, source_boot.size, len(d)))
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
common.ZipWriteStr(output_zip, "patch/boot.img.p", d)
|
|
|
|
|
|
|
|
script.PatchCheck("%s:%s:%d:%s:%d:%s" %
|
|
|
|
(boot_type, boot_device,
|
|
|
|
source_boot.size, source_boot.sha1,
|
|
|
|
target_boot.size, target_boot.sha1))
|
2016-02-04 23:26:02 +01:00
|
|
|
size.append(target_boot.size)
|
|
|
|
|
|
|
|
if size:
|
|
|
|
script.CacheFreeSpaceCheck(max(size))
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
device_specific.IncrementalOTA_VerifyEnd()
|
|
|
|
|
|
|
|
if OPTIONS.two_step:
|
2016-11-30 21:11:57 +01:00
|
|
|
# Stage 1/3: (b) Write recovery image to /boot.
|
|
|
|
_WriteRecoveryImageToBoot(script, output_zip)
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
script.AppendExtra("""
|
|
|
|
set_stage("%(bcb_dev)s", "2/3");
|
|
|
|
reboot_now("%(bcb_dev)s", "");
|
|
|
|
else
|
|
|
|
""" % bcb_dev)
|
|
|
|
|
2016-11-30 21:11:57 +01:00
|
|
|
# Stage 3/3: Make changes.
|
|
|
|
script.Comment("Stage 3/3")
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
# Verify the existing partitions.
|
2016-04-13 00:53:16 +02:00
|
|
|
system_diff.WriteVerifyScript(script, touched_blocks_only=True)
|
2015-03-24 03:13:21 +01:00
|
|
|
if vendor_diff:
|
2016-04-13 00:53:16 +02:00
|
|
|
vendor_diff.WriteVerifyScript(script, touched_blocks_only=True)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
script.Comment("---- start making changes here ----")
|
|
|
|
|
|
|
|
device_specific.IncrementalOTA_InstallBegin()
|
|
|
|
|
|
|
|
system_diff.WriteScript(script, output_zip,
|
|
|
|
progress=0.8 if vendor_diff else 0.9)
|
2015-06-01 22:40:49 +02:00
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
if vendor_diff:
|
|
|
|
vendor_diff.WriteScript(script, output_zip, progress=0.1)
|
|
|
|
|
|
|
|
if OPTIONS.two_step:
|
|
|
|
common.ZipWriteStr(output_zip, "boot.img", target_boot.data)
|
|
|
|
script.WriteRawImage("/boot", "boot.img")
|
2017-01-10 19:47:58 +01:00
|
|
|
print("writing full boot image (forced by two-step mode)")
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
if not OPTIONS.two_step:
|
|
|
|
if updating_boot:
|
|
|
|
if include_full_boot:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("boot image changed; including full.")
|
2015-03-24 03:13:21 +01:00
|
|
|
script.Print("Installing boot image...")
|
|
|
|
script.WriteRawImage("/boot", "boot.img")
|
|
|
|
else:
|
|
|
|
# Produce the boot image by applying a patch to the current
|
|
|
|
# contents of the boot partition, and write it back to the
|
|
|
|
# partition.
|
2017-01-10 19:47:58 +01:00
|
|
|
print("boot image changed; including patch.")
|
2015-03-24 03:13:21 +01:00
|
|
|
script.Print("Patching boot image...")
|
|
|
|
script.ShowProgress(0.1, 10)
|
|
|
|
script.ApplyPatch("%s:%s:%d:%s:%d:%s"
|
|
|
|
% (boot_type, boot_device,
|
|
|
|
source_boot.size, source_boot.sha1,
|
|
|
|
target_boot.size, target_boot.sha1),
|
|
|
|
"-",
|
|
|
|
target_boot.size, target_boot.sha1,
|
|
|
|
source_boot.sha1, "patch/boot.img.p")
|
|
|
|
else:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("boot image unchanged; skipping.")
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
# Do device-specific installation (eg, write radio image).
|
|
|
|
device_specific.IncrementalOTA_InstallEnd()
|
|
|
|
|
|
|
|
if OPTIONS.extra_script is not None:
|
|
|
|
script.AppendExtra(OPTIONS.extra_script)
|
|
|
|
|
|
|
|
if OPTIONS.wipe_user_data:
|
|
|
|
script.Print("Erasing user data...")
|
|
|
|
script.FormatPartition("/data")
|
2016-02-23 20:38:39 +01:00
|
|
|
metadata["ota-wipe"] = "yes"
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
if OPTIONS.two_step:
|
|
|
|
script.AppendExtra("""
|
|
|
|
set_stage("%(bcb_dev)s", "");
|
|
|
|
endif;
|
|
|
|
endif;
|
|
|
|
""" % bcb_dev)
|
|
|
|
|
|
|
|
script.SetProgress(1)
|
2016-03-09 02:53:39 +01:00
|
|
|
# For downgrade OTAs, we prefer to use the update-binary in the source
|
|
|
|
# build that is actually newer than the one in the target build.
|
|
|
|
if OPTIONS.downgrade:
|
|
|
|
script.AddToZip(source_zip, output_zip, input_path=OPTIONS.updater_binary)
|
|
|
|
else:
|
|
|
|
script.AddToZip(target_zip, output_zip, input_path=OPTIONS.updater_binary)
|
2016-02-04 23:26:02 +01:00
|
|
|
metadata["ota-required-cache"] = str(script.required_cache)
|
2015-03-24 03:13:21 +01:00
|
|
|
WriteMetadata(metadata, output_zip)
|
|
|
|
|
|
|
|
|
2015-11-10 01:58:28 +01:00
|
|
|
def WriteVerifyPackage(input_zip, output_zip):
|
|
|
|
script = edify_generator.EdifyGenerator(3, OPTIONS.info_dict)
|
|
|
|
|
|
|
|
oem_props = OPTIONS.info_dict.get("oem_fingerprint_properties")
|
|
|
|
recovery_mount_options = OPTIONS.info_dict.get(
|
|
|
|
"recovery_mount_options")
|
2017-02-16 22:06:55 +01:00
|
|
|
oem_dicts = None
|
2016-03-15 21:20:19 +01:00
|
|
|
if oem_props:
|
2017-03-06 19:22:20 +01:00
|
|
|
oem_dicts = _LoadOemDicts(script, recovery_mount_options)
|
2017-02-16 22:06:55 +01:00
|
|
|
|
|
|
|
target_fp = CalculateFingerprint(oem_props, oem_dicts and oem_dicts[0],
|
|
|
|
OPTIONS.info_dict)
|
2015-11-10 01:58:28 +01:00
|
|
|
metadata = {
|
|
|
|
"post-build": target_fp,
|
2017-02-16 22:06:55 +01:00
|
|
|
"pre-device": GetOemProperty("ro.product.device", oem_props,
|
|
|
|
oem_dicts and oem_dicts[0],
|
2015-11-10 01:58:28 +01:00
|
|
|
OPTIONS.info_dict),
|
|
|
|
"post-timestamp": GetBuildProp("ro.build.date.utc", OPTIONS.info_dict),
|
|
|
|
}
|
|
|
|
|
|
|
|
device_specific = common.DeviceSpecificParams(
|
|
|
|
input_zip=input_zip,
|
|
|
|
input_version=OPTIONS.info_dict["recovery_api_version"],
|
|
|
|
output_zip=output_zip,
|
|
|
|
script=script,
|
|
|
|
input_tmp=OPTIONS.input_tmp,
|
|
|
|
metadata=metadata,
|
|
|
|
info_dict=OPTIONS.info_dict)
|
|
|
|
|
2017-02-16 22:06:55 +01:00
|
|
|
AppendAssertions(script, OPTIONS.info_dict, oem_dicts)
|
2015-11-10 01:58:28 +01:00
|
|
|
|
|
|
|
script.Print("Verifying device images against %s..." % target_fp)
|
|
|
|
script.AppendExtra("")
|
|
|
|
|
|
|
|
script.Print("Verifying boot...")
|
|
|
|
boot_img = common.GetBootableImage(
|
|
|
|
"boot.img", "boot.img", OPTIONS.input_tmp, "BOOT")
|
|
|
|
boot_type, boot_device = common.GetTypeAndDevice(
|
|
|
|
"/boot", OPTIONS.info_dict)
|
|
|
|
script.Verify("%s:%s:%d:%s" % (
|
|
|
|
boot_type, boot_device, boot_img.size, boot_img.sha1))
|
|
|
|
script.AppendExtra("")
|
|
|
|
|
|
|
|
script.Print("Verifying recovery...")
|
|
|
|
recovery_img = common.GetBootableImage(
|
|
|
|
"recovery.img", "recovery.img", OPTIONS.input_tmp, "RECOVERY")
|
|
|
|
recovery_type, recovery_device = common.GetTypeAndDevice(
|
|
|
|
"/recovery", OPTIONS.info_dict)
|
|
|
|
script.Verify("%s:%s:%d:%s" % (
|
|
|
|
recovery_type, recovery_device, recovery_img.size, recovery_img.sha1))
|
|
|
|
script.AppendExtra("")
|
|
|
|
|
2017-03-07 00:50:08 +01:00
|
|
|
system_tgt = GetImage("system", OPTIONS.input_tmp)
|
2015-11-10 01:58:28 +01:00
|
|
|
system_tgt.ResetFileMap()
|
|
|
|
system_diff = common.BlockDifference("system", system_tgt, src=None)
|
|
|
|
system_diff.WriteStrictVerifyScript(script)
|
|
|
|
|
|
|
|
if HasVendorPartition(input_zip):
|
2017-03-07 00:50:08 +01:00
|
|
|
vendor_tgt = GetImage("vendor", OPTIONS.input_tmp)
|
2015-11-10 01:58:28 +01:00
|
|
|
vendor_tgt.ResetFileMap()
|
|
|
|
vendor_diff = common.BlockDifference("vendor", vendor_tgt, src=None)
|
|
|
|
vendor_diff.WriteStrictVerifyScript(script)
|
|
|
|
|
|
|
|
# Device specific partitions, such as radio, bootloader and etc.
|
|
|
|
device_specific.VerifyOTA_Assertions()
|
|
|
|
|
|
|
|
script.SetProgress(1.0)
|
|
|
|
script.AddToZip(input_zip, output_zip, input_path=OPTIONS.updater_binary)
|
2016-02-04 23:26:02 +01:00
|
|
|
metadata["ota-required-cache"] = str(script.required_cache)
|
2015-11-10 01:58:28 +01:00
|
|
|
WriteMetadata(metadata, output_zip)
|
|
|
|
|
|
|
|
|
2016-01-07 22:03:56 +01:00
|
|
|
def WriteABOTAPackageWithBrilloScript(target_file, output_file,
|
|
|
|
source_file=None):
|
|
|
|
"""Generate an Android OTA package that has A/B update payload."""
|
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
def ComputeStreamingMetadata(zip_file, reserve_space=False,
|
|
|
|
expected_length=None):
|
|
|
|
"""Compute the streaming metadata for a given zip.
|
|
|
|
|
|
|
|
When 'reserve_space' is True, we reserve extra space for the offset and
|
|
|
|
length of the metadata entry itself, although we don't know the final
|
|
|
|
values until the package gets signed. This function will be called again
|
|
|
|
after signing. We then write the actual values and pad the string to the
|
|
|
|
length we set earlier. Note that we can't use the actual length of the
|
|
|
|
metadata entry in the second run. Otherwise the offsets for other entries
|
|
|
|
will be changing again.
|
|
|
|
"""
|
2017-01-25 07:10:49 +01:00
|
|
|
|
|
|
|
def ComputeEntryOffsetSize(name):
|
|
|
|
"""Compute the zip entry offset and size."""
|
|
|
|
info = zip_file.getinfo(name)
|
|
|
|
offset = info.header_offset + len(info.FileHeader())
|
|
|
|
size = info.file_size
|
2017-02-04 01:49:39 +01:00
|
|
|
return '%s:%d:%d' % (os.path.basename(name), offset, size)
|
2017-01-25 07:10:49 +01:00
|
|
|
|
|
|
|
# payload.bin and payload_properties.txt must exist.
|
|
|
|
offsets = [ComputeEntryOffsetSize('payload.bin'),
|
|
|
|
ComputeEntryOffsetSize('payload_properties.txt')]
|
|
|
|
|
|
|
|
# care_map.txt is available only if dm-verity is enabled.
|
|
|
|
if 'care_map.txt' in zip_file.namelist():
|
|
|
|
offsets.append(ComputeEntryOffsetSize('care_map.txt'))
|
2017-02-04 01:49:39 +01:00
|
|
|
|
2017-04-19 19:16:09 +02:00
|
|
|
if 'compatibility.zip' in zip_file.namelist():
|
|
|
|
offsets.append(ComputeEntryOffsetSize('compatibility.zip'))
|
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
# 'META-INF/com/android/metadata' is required. We don't know its actual
|
|
|
|
# offset and length (as well as the values for other entries). So we
|
|
|
|
# reserve 10-byte as a placeholder, which is to cover the space for metadata
|
|
|
|
# entry ('xx:xxx', since it's ZIP_STORED which should appear at the
|
|
|
|
# beginning of the zip), as well as the possible value changes in other
|
|
|
|
# entries.
|
|
|
|
if reserve_space:
|
|
|
|
offsets.append('metadata:' + ' ' * 10)
|
|
|
|
else:
|
|
|
|
offsets.append(ComputeEntryOffsetSize(METADATA_NAME))
|
|
|
|
|
|
|
|
value = ','.join(offsets)
|
|
|
|
if expected_length is not None:
|
|
|
|
assert len(value) <= expected_length, \
|
|
|
|
'Insufficient reserved space: reserved=%d, actual=%d' % (
|
|
|
|
expected_length, len(value))
|
|
|
|
value += ' ' * (expected_length - len(value))
|
|
|
|
return value
|
2017-01-25 07:10:49 +01:00
|
|
|
|
2016-06-11 01:38:31 +02:00
|
|
|
# The place where the output from the subprocess should go.
|
|
|
|
log_file = sys.stdout if OPTIONS.verbose else subprocess.PIPE
|
|
|
|
|
2016-06-21 02:55:06 +02:00
|
|
|
# A/B updater expects a signing key in RSA format. Gets the key ready for
|
|
|
|
# later use in step 3, unless a payload_signer has been specified.
|
|
|
|
if OPTIONS.payload_signer is None:
|
|
|
|
cmd = ["openssl", "pkcs8",
|
|
|
|
"-in", OPTIONS.package_key + OPTIONS.private_key_suffix,
|
2017-05-01 22:30:15 +02:00
|
|
|
"-inform", "DER"]
|
|
|
|
pw = OPTIONS.key_passwords[OPTIONS.package_key]
|
|
|
|
cmd.extend(["-passin", "pass:" + pw] if pw else ["-nocrypt"])
|
2016-06-21 02:55:06 +02:00
|
|
|
rsa_key = common.MakeTempFile(prefix="key-", suffix=".key")
|
|
|
|
cmd.extend(["-out", rsa_key])
|
2017-05-01 22:30:15 +02:00
|
|
|
p1 = common.Run(cmd, verbose=False, stdout=log_file, stderr=subprocess.STDOUT)
|
2016-06-21 22:35:26 +02:00
|
|
|
p1.communicate()
|
2016-06-21 02:55:06 +02:00
|
|
|
assert p1.returncode == 0, "openssl pkcs8 failed"
|
|
|
|
|
|
|
|
# Stage the output zip package for package signing.
|
2016-01-07 22:03:56 +01:00
|
|
|
temp_zip_file = tempfile.NamedTemporaryFile()
|
|
|
|
output_zip = zipfile.ZipFile(temp_zip_file, "w",
|
|
|
|
compression=zipfile.ZIP_DEFLATED)
|
|
|
|
|
|
|
|
# Metadata to comply with Android OTA package format.
|
|
|
|
oem_props = OPTIONS.info_dict.get("oem_fingerprint_properties", None)
|
2017-02-16 22:06:55 +01:00
|
|
|
oem_dicts = None
|
2016-01-07 22:03:56 +01:00
|
|
|
if oem_props:
|
2017-03-06 19:22:20 +01:00
|
|
|
oem_dicts = _LoadOemDicts(None)
|
2016-01-07 22:03:56 +01:00
|
|
|
|
|
|
|
metadata = {
|
2017-02-16 22:06:55 +01:00
|
|
|
"post-build": CalculateFingerprint(oem_props, oem_dicts and oem_dicts[0],
|
2016-01-07 22:03:56 +01:00
|
|
|
OPTIONS.info_dict),
|
2016-06-09 23:18:45 +02:00
|
|
|
"post-build-incremental" : GetBuildProp("ro.build.version.incremental",
|
|
|
|
OPTIONS.info_dict),
|
2017-02-16 22:06:55 +01:00
|
|
|
"pre-device": GetOemProperty("ro.product.device", oem_props,
|
|
|
|
oem_dicts and oem_dicts[0],
|
2016-01-07 22:03:56 +01:00
|
|
|
OPTIONS.info_dict),
|
2016-02-04 23:26:02 +01:00
|
|
|
"ota-required-cache": "0",
|
|
|
|
"ota-type": "AB",
|
2016-01-07 22:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if source_file is not None:
|
2017-02-16 22:06:55 +01:00
|
|
|
metadata["pre-build"] = CalculateFingerprint(oem_props,
|
|
|
|
oem_dicts and oem_dicts[0],
|
2016-01-07 22:03:56 +01:00
|
|
|
OPTIONS.source_info_dict)
|
2016-06-09 23:18:45 +02:00
|
|
|
metadata["pre-build-incremental"] = GetBuildProp(
|
|
|
|
"ro.build.version.incremental", OPTIONS.source_info_dict)
|
2016-01-07 22:03:56 +01:00
|
|
|
|
2017-02-07 20:21:17 +01:00
|
|
|
HandleDowngradeMetadata(metadata)
|
|
|
|
else:
|
|
|
|
metadata["post-timestamp"] = GetBuildProp(
|
|
|
|
"ro.build.date.utc", OPTIONS.info_dict)
|
|
|
|
|
2016-01-07 22:03:56 +01:00
|
|
|
# 1. Generate payload.
|
|
|
|
payload_file = common.MakeTempFile(prefix="payload-", suffix=".bin")
|
|
|
|
cmd = ["brillo_update_payload", "generate",
|
|
|
|
"--payload", payload_file,
|
|
|
|
"--target_image", target_file]
|
|
|
|
if source_file is not None:
|
|
|
|
cmd.extend(["--source_image", source_file])
|
2016-06-11 01:38:31 +02:00
|
|
|
p1 = common.Run(cmd, stdout=log_file, stderr=subprocess.STDOUT)
|
|
|
|
p1.communicate()
|
2016-01-07 22:03:56 +01:00
|
|
|
assert p1.returncode == 0, "brillo_update_payload generate failed"
|
|
|
|
|
|
|
|
# 2. Generate hashes of the payload and metadata files.
|
|
|
|
payload_sig_file = common.MakeTempFile(prefix="sig-", suffix=".bin")
|
|
|
|
metadata_sig_file = common.MakeTempFile(prefix="sig-", suffix=".bin")
|
|
|
|
cmd = ["brillo_update_payload", "hash",
|
|
|
|
"--unsigned_payload", payload_file,
|
|
|
|
"--signature_size", "256",
|
|
|
|
"--metadata_hash_file", metadata_sig_file,
|
|
|
|
"--payload_hash_file", payload_sig_file]
|
2016-06-11 01:38:31 +02:00
|
|
|
p1 = common.Run(cmd, stdout=log_file, stderr=subprocess.STDOUT)
|
|
|
|
p1.communicate()
|
2016-01-07 22:03:56 +01:00
|
|
|
assert p1.returncode == 0, "brillo_update_payload hash failed"
|
|
|
|
|
|
|
|
# 3. Sign the hashes and insert them back into the payload file.
|
|
|
|
signed_payload_sig_file = common.MakeTempFile(prefix="signed-sig-",
|
|
|
|
suffix=".bin")
|
|
|
|
signed_metadata_sig_file = common.MakeTempFile(prefix="signed-sig-",
|
|
|
|
suffix=".bin")
|
|
|
|
# 3a. Sign the payload hash.
|
2016-06-21 02:55:06 +02:00
|
|
|
if OPTIONS.payload_signer is not None:
|
2016-06-22 21:14:16 +02:00
|
|
|
cmd = [OPTIONS.payload_signer]
|
|
|
|
cmd.extend(OPTIONS.payload_signer_args)
|
2016-06-21 02:55:06 +02:00
|
|
|
else:
|
|
|
|
cmd = ["openssl", "pkeyutl", "-sign",
|
|
|
|
"-inkey", rsa_key,
|
|
|
|
"-pkeyopt", "digest:sha256"]
|
|
|
|
cmd.extend(["-in", payload_sig_file,
|
|
|
|
"-out", signed_payload_sig_file])
|
2016-06-11 01:38:31 +02:00
|
|
|
p1 = common.Run(cmd, stdout=log_file, stderr=subprocess.STDOUT)
|
|
|
|
p1.communicate()
|
2016-01-07 22:03:56 +01:00
|
|
|
assert p1.returncode == 0, "openssl sign payload failed"
|
|
|
|
|
|
|
|
# 3b. Sign the metadata hash.
|
2016-06-21 02:55:06 +02:00
|
|
|
if OPTIONS.payload_signer is not None:
|
2016-06-22 21:14:16 +02:00
|
|
|
cmd = [OPTIONS.payload_signer]
|
|
|
|
cmd.extend(OPTIONS.payload_signer_args)
|
2016-06-21 02:55:06 +02:00
|
|
|
else:
|
|
|
|
cmd = ["openssl", "pkeyutl", "-sign",
|
|
|
|
"-inkey", rsa_key,
|
|
|
|
"-pkeyopt", "digest:sha256"]
|
|
|
|
cmd.extend(["-in", metadata_sig_file,
|
|
|
|
"-out", signed_metadata_sig_file])
|
2016-06-11 01:38:31 +02:00
|
|
|
p1 = common.Run(cmd, stdout=log_file, stderr=subprocess.STDOUT)
|
|
|
|
p1.communicate()
|
2016-01-07 22:03:56 +01:00
|
|
|
assert p1.returncode == 0, "openssl sign metadata failed"
|
|
|
|
|
|
|
|
# 3c. Insert the signatures back into the payload file.
|
|
|
|
signed_payload_file = common.MakeTempFile(prefix="signed-payload-",
|
|
|
|
suffix=".bin")
|
|
|
|
cmd = ["brillo_update_payload", "sign",
|
|
|
|
"--unsigned_payload", payload_file,
|
|
|
|
"--payload", signed_payload_file,
|
|
|
|
"--signature_size", "256",
|
|
|
|
"--metadata_signature_file", signed_metadata_sig_file,
|
|
|
|
"--payload_signature_file", signed_payload_sig_file]
|
2016-06-11 01:38:31 +02:00
|
|
|
p1 = common.Run(cmd, stdout=log_file, stderr=subprocess.STDOUT)
|
|
|
|
p1.communicate()
|
2016-01-07 22:03:56 +01:00
|
|
|
assert p1.returncode == 0, "brillo_update_payload sign failed"
|
|
|
|
|
2016-02-05 07:29:29 +01:00
|
|
|
# 4. Dump the signed payload properties.
|
|
|
|
properties_file = common.MakeTempFile(prefix="payload-properties-",
|
|
|
|
suffix=".txt")
|
|
|
|
cmd = ["brillo_update_payload", "properties",
|
|
|
|
"--payload", signed_payload_file,
|
|
|
|
"--properties_file", properties_file]
|
2016-06-11 01:38:31 +02:00
|
|
|
p1 = common.Run(cmd, stdout=log_file, stderr=subprocess.STDOUT)
|
|
|
|
p1.communicate()
|
2016-02-05 07:29:29 +01:00
|
|
|
assert p1.returncode == 0, "brillo_update_payload properties failed"
|
|
|
|
|
2016-06-15 02:48:11 +02:00
|
|
|
if OPTIONS.wipe_user_data:
|
|
|
|
with open(properties_file, "a") as f:
|
|
|
|
f.write("POWERWASH=1\n")
|
|
|
|
metadata["ota-wipe"] = "yes"
|
|
|
|
|
2017-01-25 07:10:49 +01:00
|
|
|
# Add the signed payload file and properties into the zip. In order to
|
|
|
|
# support streaming, we pack payload.bin, payload_properties.txt and
|
|
|
|
# care_map.txt as ZIP_STORED. So these entries can be read directly with
|
|
|
|
# the offset and length pairs.
|
2016-01-07 22:03:56 +01:00
|
|
|
common.ZipWrite(output_zip, signed_payload_file, arcname="payload.bin",
|
|
|
|
compress_type=zipfile.ZIP_STORED)
|
2017-01-25 07:10:49 +01:00
|
|
|
common.ZipWrite(output_zip, properties_file,
|
|
|
|
arcname="payload_properties.txt",
|
|
|
|
compress_type=zipfile.ZIP_STORED)
|
2016-01-07 22:03:56 +01:00
|
|
|
|
2016-03-08 01:31:19 +01:00
|
|
|
# If dm-verity is supported for the device, copy contents of care_map
|
|
|
|
# into A/B OTA package.
|
2017-04-19 19:16:09 +02:00
|
|
|
target_zip = zipfile.ZipFile(target_file, "r")
|
2017-06-01 20:32:32 +02:00
|
|
|
if (OPTIONS.info_dict.get("verity") == "true" or
|
2017-05-26 12:30:04 +02:00
|
|
|
OPTIONS.info_dict.get("avb_enable") == "true"):
|
2016-03-08 01:31:19 +01:00
|
|
|
care_map_path = "META/care_map.txt"
|
|
|
|
namelist = target_zip.namelist()
|
|
|
|
if care_map_path in namelist:
|
|
|
|
care_map_data = target_zip.read(care_map_path)
|
2017-01-25 07:10:49 +01:00
|
|
|
common.ZipWriteStr(output_zip, "care_map.txt", care_map_data,
|
|
|
|
compress_type=zipfile.ZIP_STORED)
|
2016-03-08 01:31:19 +01:00
|
|
|
else:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("Warning: cannot find care map file in target_file package")
|
2017-04-19 19:16:09 +02:00
|
|
|
|
2017-08-26 22:10:26 +02:00
|
|
|
# OPTIONS.source_info_dict must be None for incrementals.
|
|
|
|
if source_file is None:
|
|
|
|
assert OPTIONS.source_info_dict is None
|
|
|
|
|
|
|
|
AddCompatibilityArchiveIfTrebleEnabled(
|
|
|
|
target_zip, output_zip, OPTIONS.info_dict, OPTIONS.source_info_dict)
|
|
|
|
|
2017-04-19 19:16:09 +02:00
|
|
|
common.ZipClose(target_zip)
|
2016-03-08 01:31:19 +01:00
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
# Write the current metadata entry with placeholders.
|
|
|
|
metadata['ota-streaming-property-files'] = ComputeStreamingMetadata(
|
|
|
|
output_zip, reserve_space=True)
|
|
|
|
WriteMetadata(metadata, output_zip)
|
2016-01-07 22:03:56 +01:00
|
|
|
common.ZipClose(output_zip)
|
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
# SignOutput(), which in turn calls signapk.jar, will possibly reorder the
|
|
|
|
# zip entries, as well as padding the entry headers. We do a preliminary
|
|
|
|
# signing (with an incomplete metadata entry) to allow that to happen. Then
|
|
|
|
# compute the zip entry offsets, write back the final metadata and do the
|
|
|
|
# final signing.
|
|
|
|
prelim_signing = tempfile.NamedTemporaryFile()
|
|
|
|
SignOutput(temp_zip_file.name, prelim_signing.name)
|
|
|
|
common.ZipClose(temp_zip_file)
|
|
|
|
|
|
|
|
# Open the signed zip. Compute the final metadata that's needed for streaming.
|
|
|
|
prelim_zip = zipfile.ZipFile(prelim_signing, "r",
|
2017-01-25 07:10:49 +01:00
|
|
|
compression=zipfile.ZIP_DEFLATED)
|
2017-02-04 01:49:39 +01:00
|
|
|
expected_length = len(metadata['ota-streaming-property-files'])
|
2017-02-01 00:06:05 +01:00
|
|
|
metadata['ota-streaming-property-files'] = ComputeStreamingMetadata(
|
2017-02-04 01:49:39 +01:00
|
|
|
prelim_zip, reserve_space=False, expected_length=expected_length)
|
|
|
|
|
|
|
|
# Copy the zip entries, as we cannot update / delete entries with zipfile.
|
|
|
|
final_signing = tempfile.NamedTemporaryFile()
|
|
|
|
output_zip = zipfile.ZipFile(final_signing, "w",
|
|
|
|
compression=zipfile.ZIP_DEFLATED)
|
|
|
|
for item in prelim_zip.infolist():
|
|
|
|
if item.filename == METADATA_NAME:
|
|
|
|
continue
|
|
|
|
|
|
|
|
data = prelim_zip.read(item.filename)
|
|
|
|
out_info = copy.copy(item)
|
|
|
|
common.ZipWriteStr(output_zip, out_info, data)
|
2017-01-25 07:10:49 +01:00
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
# Now write the final metadata entry.
|
2017-01-25 07:10:49 +01:00
|
|
|
WriteMetadata(metadata, output_zip)
|
2017-02-04 01:49:39 +01:00
|
|
|
common.ZipClose(prelim_zip)
|
2017-01-25 07:10:49 +01:00
|
|
|
common.ZipClose(output_zip)
|
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
# Re-sign the package after updating the metadata entry.
|
|
|
|
SignOutput(final_signing.name, output_file)
|
|
|
|
final_signing.close()
|
2017-01-25 07:10:49 +01:00
|
|
|
|
2017-02-04 01:49:39 +01:00
|
|
|
# Reopen the final signed zip to double check the streaming metadata.
|
2017-01-25 07:10:49 +01:00
|
|
|
output_zip = zipfile.ZipFile(output_file, "r")
|
2017-02-04 01:49:39 +01:00
|
|
|
actual = metadata['ota-streaming-property-files'].strip()
|
|
|
|
expected = ComputeStreamingMetadata(output_zip)
|
|
|
|
assert actual == expected, \
|
|
|
|
"Mismatching streaming metadata: %s vs %s." % (actual, expected)
|
2017-01-25 07:10:49 +01:00
|
|
|
common.ZipClose(output_zip)
|
|
|
|
|
2016-01-07 22:03:56 +01:00
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
def main(argv):
|
|
|
|
|
|
|
|
def option_handler(o, a):
|
|
|
|
if o == "--board_config":
|
|
|
|
pass # deprecated
|
|
|
|
elif o in ("-k", "--package_key"):
|
|
|
|
OPTIONS.package_key = a
|
|
|
|
elif o in ("-i", "--incremental_from"):
|
|
|
|
OPTIONS.incremental_source = a
|
2015-04-21 23:32:35 +02:00
|
|
|
elif o == "--full_radio":
|
|
|
|
OPTIONS.full_radio = True
|
2015-08-14 19:57:58 +02:00
|
|
|
elif o == "--full_bootloader":
|
|
|
|
OPTIONS.full_bootloader = True
|
2015-03-24 03:13:21 +01:00
|
|
|
elif o in ("-w", "--wipe_user_data"):
|
|
|
|
OPTIONS.wipe_user_data = True
|
2016-02-23 20:38:39 +01:00
|
|
|
elif o == "--downgrade":
|
|
|
|
OPTIONS.downgrade = True
|
|
|
|
OPTIONS.wipe_user_data = True
|
2017-02-28 20:48:48 +01:00
|
|
|
elif o == "--override_timestamp":
|
|
|
|
OPTIONS.timestamp = True
|
2015-03-24 03:13:21 +01:00
|
|
|
elif o in ("-o", "--oem_settings"):
|
2017-02-16 22:06:55 +01:00
|
|
|
OPTIONS.oem_source = a.split(',')
|
2016-02-26 04:49:55 +01:00
|
|
|
elif o == "--oem_no_mount":
|
|
|
|
OPTIONS.oem_no_mount = True
|
2015-03-24 03:13:21 +01:00
|
|
|
elif o in ("-e", "--extra_script"):
|
|
|
|
OPTIONS.extra_script = a
|
|
|
|
elif o in ("-t", "--worker_threads"):
|
|
|
|
if a.isdigit():
|
|
|
|
OPTIONS.worker_threads = int(a)
|
|
|
|
else:
|
|
|
|
raise ValueError("Cannot parse value %r for option %r - only "
|
|
|
|
"integers are allowed." % (a, o))
|
|
|
|
elif o in ("-2", "--two_step"):
|
|
|
|
OPTIONS.two_step = True
|
|
|
|
elif o == "--no_signing":
|
|
|
|
OPTIONS.no_signing = True
|
|
|
|
elif o == "--verify":
|
|
|
|
OPTIONS.verify = True
|
|
|
|
elif o == "--block":
|
|
|
|
OPTIONS.block_based = True
|
|
|
|
elif o in ("-b", "--binary"):
|
|
|
|
OPTIONS.updater_binary = a
|
|
|
|
elif o in ("--no_fallback_to_full",):
|
|
|
|
OPTIONS.fallback_to_full = False
|
2015-05-21 23:09:49 +02:00
|
|
|
elif o == "--stash_threshold":
|
|
|
|
try:
|
|
|
|
OPTIONS.stash_threshold = float(a)
|
|
|
|
except ValueError:
|
|
|
|
raise ValueError("Cannot parse value %r for option %r - expecting "
|
|
|
|
"a float" % (a, o))
|
2015-11-10 01:58:28 +01:00
|
|
|
elif o == "--gen_verify":
|
|
|
|
OPTIONS.gen_verify = True
|
2015-11-30 18:40:20 +01:00
|
|
|
elif o == "--log_diff":
|
|
|
|
OPTIONS.log_diff = a
|
2016-06-21 02:55:06 +02:00
|
|
|
elif o == "--payload_signer":
|
|
|
|
OPTIONS.payload_signer = a
|
2016-06-22 21:14:16 +02:00
|
|
|
elif o == "--payload_signer_args":
|
|
|
|
OPTIONS.payload_signer_args = shlex.split(a)
|
2017-03-21 22:44:27 +01:00
|
|
|
elif o == "--extracted_input_target_files":
|
|
|
|
OPTIONS.extracted_input = a
|
2015-03-24 03:13:21 +01:00
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
args = common.ParseOptions(argv, __doc__,
|
2017-01-13 20:56:54 +01:00
|
|
|
extra_opts="b:k:i:d:we:t:2o:",
|
2015-03-24 03:13:21 +01:00
|
|
|
extra_long_opts=[
|
|
|
|
"board_config=",
|
|
|
|
"package_key=",
|
|
|
|
"incremental_from=",
|
2015-04-21 23:32:35 +02:00
|
|
|
"full_radio",
|
2015-08-14 19:57:58 +02:00
|
|
|
"full_bootloader",
|
2015-03-24 03:13:21 +01:00
|
|
|
"wipe_user_data",
|
2016-02-23 20:38:39 +01:00
|
|
|
"downgrade",
|
2017-02-28 20:48:48 +01:00
|
|
|
"override_timestamp",
|
2015-03-24 03:13:21 +01:00
|
|
|
"extra_script=",
|
|
|
|
"worker_threads=",
|
|
|
|
"two_step",
|
|
|
|
"no_signing",
|
|
|
|
"block",
|
|
|
|
"binary=",
|
|
|
|
"oem_settings=",
|
2016-02-26 04:49:55 +01:00
|
|
|
"oem_no_mount",
|
2015-03-24 03:13:21 +01:00
|
|
|
"verify",
|
|
|
|
"no_fallback_to_full",
|
2015-05-21 23:09:49 +02:00
|
|
|
"stash_threshold=",
|
2015-11-30 18:40:20 +01:00
|
|
|
"gen_verify",
|
|
|
|
"log_diff=",
|
2016-06-21 02:55:06 +02:00
|
|
|
"payload_signer=",
|
2016-06-22 21:14:16 +02:00
|
|
|
"payload_signer_args=",
|
2017-03-21 22:44:27 +01:00
|
|
|
"extracted_input_target_files=",
|
2015-03-24 03:13:21 +01:00
|
|
|
], extra_option_handler=option_handler)
|
|
|
|
|
|
|
|
if len(args) != 2:
|
|
|
|
common.Usage(__doc__)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-02-23 20:38:39 +01:00
|
|
|
if OPTIONS.downgrade:
|
|
|
|
# Sanity check to enforce a data wipe.
|
|
|
|
if not OPTIONS.wipe_user_data:
|
|
|
|
raise ValueError("Cannot downgrade without a data wipe")
|
|
|
|
|
|
|
|
# We should only allow downgrading incrementals (as opposed to full).
|
|
|
|
# Otherwise the device may go back from arbitrary build with this full
|
|
|
|
# OTA package.
|
|
|
|
if OPTIONS.incremental_source is None:
|
2016-06-20 23:35:47 +02:00
|
|
|
raise ValueError("Cannot generate downgradable full OTAs")
|
2016-02-23 20:38:39 +01:00
|
|
|
|
2017-02-28 20:48:48 +01:00
|
|
|
assert not (OPTIONS.downgrade and OPTIONS.timestamp), \
|
|
|
|
"Cannot have --downgrade AND --override_timestamp both"
|
|
|
|
|
2016-01-07 22:03:56 +01:00
|
|
|
# Load the dict file from the zip directly to have a peek at the OTA type.
|
|
|
|
# For packages using A/B update, unzipping is not needed.
|
2017-03-21 22:44:27 +01:00
|
|
|
if OPTIONS.extracted_input is not None:
|
|
|
|
OPTIONS.info_dict = common.LoadInfoDict(OPTIONS.extracted_input, OPTIONS.extracted_input)
|
|
|
|
else:
|
|
|
|
input_zip = zipfile.ZipFile(args[0], "r")
|
|
|
|
OPTIONS.info_dict = common.LoadInfoDict(input_zip)
|
|
|
|
common.ZipClose(input_zip)
|
2016-01-07 22:03:56 +01:00
|
|
|
|
|
|
|
ab_update = OPTIONS.info_dict.get("ab_update") == "true"
|
|
|
|
|
2017-05-01 22:30:15 +02:00
|
|
|
# Use the default key to sign the package if not specified with package_key.
|
|
|
|
# package_keys are needed on ab_updates, so always define them if an
|
|
|
|
# ab_update is getting created.
|
|
|
|
if not OPTIONS.no_signing or ab_update:
|
|
|
|
if OPTIONS.package_key is None:
|
|
|
|
OPTIONS.package_key = OPTIONS.info_dict.get(
|
|
|
|
"default_system_dev_certificate",
|
|
|
|
"build/target/product/security/testkey")
|
|
|
|
# Get signing keys
|
|
|
|
OPTIONS.key_passwords = common.GetKeyPasswords([OPTIONS.package_key])
|
|
|
|
|
2016-01-07 22:03:56 +01:00
|
|
|
if ab_update:
|
|
|
|
if OPTIONS.incremental_source is not None:
|
|
|
|
OPTIONS.target_info_dict = OPTIONS.info_dict
|
|
|
|
source_zip = zipfile.ZipFile(OPTIONS.incremental_source, "r")
|
|
|
|
OPTIONS.source_info_dict = common.LoadInfoDict(source_zip)
|
|
|
|
common.ZipClose(source_zip)
|
|
|
|
|
|
|
|
if OPTIONS.verbose:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("--- target info ---")
|
2016-01-07 22:03:56 +01:00
|
|
|
common.DumpInfoDict(OPTIONS.info_dict)
|
|
|
|
|
|
|
|
if OPTIONS.incremental_source is not None:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("--- source info ---")
|
2016-01-07 22:03:56 +01:00
|
|
|
common.DumpInfoDict(OPTIONS.source_info_dict)
|
|
|
|
|
|
|
|
WriteABOTAPackageWithBrilloScript(
|
|
|
|
target_file=args[0],
|
|
|
|
output_file=args[1],
|
|
|
|
source_file=OPTIONS.incremental_source)
|
|
|
|
|
2017-01-10 19:47:58 +01:00
|
|
|
print("done.")
|
2016-01-07 22:03:56 +01:00
|
|
|
return
|
|
|
|
|
2015-03-24 03:13:21 +01:00
|
|
|
if OPTIONS.extra_script is not None:
|
|
|
|
OPTIONS.extra_script = open(OPTIONS.extra_script).read()
|
|
|
|
|
2017-03-21 22:44:27 +01:00
|
|
|
if OPTIONS.extracted_input is not None:
|
|
|
|
OPTIONS.input_tmp = OPTIONS.extracted_input
|
|
|
|
OPTIONS.target_tmp = OPTIONS.input_tmp
|
|
|
|
OPTIONS.info_dict = common.LoadInfoDict(OPTIONS.input_tmp, OPTIONS.input_tmp)
|
|
|
|
input_zip = zipfile.ZipFile(args[0], "r")
|
|
|
|
else:
|
|
|
|
print("unzipping target target-files...")
|
|
|
|
OPTIONS.input_tmp, input_zip = common.UnzipTemp(
|
|
|
|
args[0], UNZIP_PATTERN)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2017-03-21 22:44:27 +01:00
|
|
|
OPTIONS.target_tmp = OPTIONS.input_tmp
|
|
|
|
OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.target_tmp)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
if OPTIONS.verbose:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("--- target info ---")
|
2015-03-24 03:13:21 +01:00
|
|
|
common.DumpInfoDict(OPTIONS.info_dict)
|
|
|
|
|
|
|
|
# If the caller explicitly specified the device-specific extensions
|
|
|
|
# path via -s/--device_specific, use that. Otherwise, use
|
|
|
|
# META/releasetools.py if it is present in the target target_files.
|
|
|
|
# Otherwise, take the path of the file from 'tool_extensions' in the
|
|
|
|
# info dict and look for that in the local filesystem, relative to
|
|
|
|
# the current directory.
|
|
|
|
|
|
|
|
if OPTIONS.device_specific is None:
|
|
|
|
from_input = os.path.join(OPTIONS.input_tmp, "META", "releasetools.py")
|
|
|
|
if os.path.exists(from_input):
|
2017-01-10 19:47:58 +01:00
|
|
|
print("(using device-specific extensions from target_files)")
|
2015-03-24 03:13:21 +01:00
|
|
|
OPTIONS.device_specific = from_input
|
|
|
|
else:
|
|
|
|
OPTIONS.device_specific = OPTIONS.info_dict.get("tool_extensions", None)
|
|
|
|
|
|
|
|
if OPTIONS.device_specific is not None:
|
|
|
|
OPTIONS.device_specific = os.path.abspath(OPTIONS.device_specific)
|
|
|
|
|
2016-01-07 22:03:56 +01:00
|
|
|
if OPTIONS.info_dict.get("no_recovery") == "true":
|
2015-10-28 03:25:18 +01:00
|
|
|
raise common.ExternalError(
|
|
|
|
"--- target build has specified no recovery ---")
|
|
|
|
|
2015-11-10 21:19:19 +01:00
|
|
|
# Set up the output zip. Create a temporary zip file if signing is needed.
|
|
|
|
if OPTIONS.no_signing:
|
|
|
|
if os.path.exists(args[1]):
|
|
|
|
os.unlink(args[1])
|
|
|
|
output_zip = zipfile.ZipFile(args[1], "w",
|
|
|
|
compression=zipfile.ZIP_DEFLATED)
|
|
|
|
else:
|
|
|
|
temp_zip_file = tempfile.NamedTemporaryFile()
|
|
|
|
output_zip = zipfile.ZipFile(temp_zip_file, "w",
|
|
|
|
compression=zipfile.ZIP_DEFLATED)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2015-11-11 04:21:34 +01:00
|
|
|
# Non A/B OTAs rely on /cache partition to store temporary files.
|
2015-11-10 21:19:19 +01:00
|
|
|
cache_size = OPTIONS.info_dict.get("cache_size", None)
|
2016-01-07 22:03:56 +01:00
|
|
|
if cache_size is None:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("--- can't determine the cache partition size ---")
|
2015-11-10 21:19:19 +01:00
|
|
|
OPTIONS.cache_size = cache_size
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2015-11-10 01:58:28 +01:00
|
|
|
# Generate a verify package.
|
|
|
|
if OPTIONS.gen_verify:
|
|
|
|
WriteVerifyPackage(input_zip, output_zip)
|
|
|
|
|
2015-11-10 21:19:19 +01:00
|
|
|
# Generate a full OTA.
|
2015-11-10 01:58:28 +01:00
|
|
|
elif OPTIONS.incremental_source is None:
|
2016-01-07 22:03:56 +01:00
|
|
|
WriteFullOTAPackage(input_zip, output_zip)
|
2015-05-21 23:09:49 +02:00
|
|
|
|
2015-11-10 21:19:19 +01:00
|
|
|
# Generate an incremental OTA. It will fall back to generate a full OTA on
|
|
|
|
# failure unless no_fallback_to_full is specified.
|
|
|
|
else:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("unzipping source target-files...")
|
2015-11-10 21:19:19 +01:00
|
|
|
OPTIONS.source_tmp, source_zip = common.UnzipTemp(
|
2017-03-05 20:38:11 +01:00
|
|
|
OPTIONS.incremental_source,
|
2017-03-06 18:56:01 +01:00
|
|
|
UNZIP_PATTERN)
|
2015-11-10 21:19:19 +01:00
|
|
|
OPTIONS.target_info_dict = OPTIONS.info_dict
|
|
|
|
OPTIONS.source_info_dict = common.LoadInfoDict(source_zip,
|
|
|
|
OPTIONS.source_tmp)
|
|
|
|
if OPTIONS.verbose:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("--- source info ---")
|
2015-11-10 21:19:19 +01:00
|
|
|
common.DumpInfoDict(OPTIONS.source_info_dict)
|
|
|
|
try:
|
2017-03-06 18:56:01 +01:00
|
|
|
WriteBlockIncrementalOTAPackage(input_zip, source_zip, output_zip)
|
2015-11-30 18:40:20 +01:00
|
|
|
if OPTIONS.log_diff:
|
|
|
|
out_file = open(OPTIONS.log_diff, 'w')
|
|
|
|
import target_files_diff
|
|
|
|
target_files_diff.recursiveDiff('',
|
|
|
|
OPTIONS.source_tmp,
|
|
|
|
OPTIONS.input_tmp,
|
|
|
|
out_file)
|
|
|
|
out_file.close()
|
2015-11-10 21:19:19 +01:00
|
|
|
except ValueError:
|
|
|
|
if not OPTIONS.fallback_to_full:
|
|
|
|
raise
|
2017-01-10 19:47:58 +01:00
|
|
|
print("--- failed to build incremental; falling back to full ---")
|
2015-11-10 21:19:19 +01:00
|
|
|
OPTIONS.incremental_source = None
|
2015-03-24 03:13:21 +01:00
|
|
|
WriteFullOTAPackage(input_zip, output_zip)
|
|
|
|
|
2015-11-10 21:19:19 +01:00
|
|
|
common.ZipClose(output_zip)
|
2015-03-24 03:13:21 +01:00
|
|
|
|
2015-11-10 21:19:19 +01:00
|
|
|
# Sign the generated zip package unless no_signing is specified.
|
2015-03-24 03:13:21 +01:00
|
|
|
if not OPTIONS.no_signing:
|
|
|
|
SignOutput(temp_zip_file.name, args[1])
|
|
|
|
temp_zip_file.close()
|
|
|
|
|
2017-01-10 19:47:58 +01:00
|
|
|
print("done.")
|
2015-03-24 03:13:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
|
|
|
common.CloseInheritedPipes()
|
|
|
|
main(sys.argv[1:])
|
|
|
|
except common.ExternalError as e:
|
2017-01-10 19:47:58 +01:00
|
|
|
print("\n ERROR: %s\n" % (e,))
|
2015-03-24 03:13:21 +01:00
|
|
|
sys.exit(1)
|
|
|
|
finally:
|
|
|
|
common.Cleanup()
|