Merge "releasetools: img_from_target_files uses zip2zip."
This commit is contained in:
@@ -3708,13 +3708,13 @@ $(BUILT_OTATOOLS_PACKAGE): PRIVATE_ZIP_ROOT := $(call intermediates-dir-for,PACK
|
|||||||
$(BUILT_OTATOOLS_PACKAGE): PRIVATE_OTATOOLS_PACKAGE_FILES := $(INTERNAL_OTATOOLS_PACKAGE_FILES)
|
$(BUILT_OTATOOLS_PACKAGE): PRIVATE_OTATOOLS_PACKAGE_FILES := $(INTERNAL_OTATOOLS_PACKAGE_FILES)
|
||||||
$(BUILT_OTATOOLS_PACKAGE): PRIVATE_OTATOOLS_RELEASETOOLS := $(INTERNAL_OTATOOLS_RELEASETOOLS)
|
$(BUILT_OTATOOLS_PACKAGE): PRIVATE_OTATOOLS_RELEASETOOLS := $(INTERNAL_OTATOOLS_RELEASETOOLS)
|
||||||
$(BUILT_OTATOOLS_PACKAGE): $(INTERNAL_OTATOOLS_PACKAGE_FILES) $(INTERNAL_OTATOOLS_RELEASETOOLS)
|
$(BUILT_OTATOOLS_PACKAGE): $(INTERNAL_OTATOOLS_PACKAGE_FILES) $(INTERNAL_OTATOOLS_RELEASETOOLS)
|
||||||
$(BUILT_OTATOOLS_PACKAGE): $(SOONG_ZIP)
|
$(BUILT_OTATOOLS_PACKAGE): $(SOONG_ZIP) $(ZIP2ZIP)
|
||||||
@echo "Package OTA tools: $@"
|
@echo "Package OTA tools: $@"
|
||||||
rm -rf $@ $(PRIVATE_ZIP_ROOT)
|
rm -rf $@ $(PRIVATE_ZIP_ROOT)
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(call copy-files-with-structure,$(PRIVATE_OTATOOLS_PACKAGE_FILES),$(HOST_OUT)/,$(PRIVATE_ZIP_ROOT))
|
$(call copy-files-with-structure,$(PRIVATE_OTATOOLS_PACKAGE_FILES),$(HOST_OUT)/,$(PRIVATE_ZIP_ROOT))
|
||||||
$(call copy-files-with-structure,$(PRIVATE_OTATOOLS_RELEASETOOLS),build/make/tools/,$(PRIVATE_ZIP_ROOT))
|
$(call copy-files-with-structure,$(PRIVATE_OTATOOLS_RELEASETOOLS),build/make/tools/,$(PRIVATE_ZIP_ROOT))
|
||||||
cp $(SOONG_ZIP) $(PRIVATE_ZIP_ROOT)/bin/
|
cp $(SOONG_ZIP) $(ZIP2ZIP) $(PRIVATE_ZIP_ROOT)/bin/
|
||||||
$(SOONG_ZIP) -o $@ -C $(PRIVATE_ZIP_ROOT) -D $(PRIVATE_ZIP_ROOT)
|
$(SOONG_ZIP) -o $@ -C $(PRIVATE_ZIP_ROOT) -D $(PRIVATE_ZIP_ROOT)
|
||||||
|
|
||||||
.PHONY: otatools-package
|
.PHONY: otatools-package
|
||||||
@@ -4631,35 +4631,12 @@ name := $(name)-img-$(FILE_NAME_TAG)
|
|||||||
|
|
||||||
INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
|
INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
|
||||||
|
|
||||||
$(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(ZIP2ZIP)
|
$(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(IMG_FROM_TARGET_FILES)
|
||||||
|
$(call pretty,"Package: $@")
|
||||||
ifeq (true,$(BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE))
|
PATH=$(INTERNAL_USERIMAGES_BINARY_PATHS):$(dir $(ZIP2ZIP)):$$PATH \
|
||||||
$(INTERNAL_UPDATE_PACKAGE_TARGET): $(INTERNAL_SUPERIMAGE_DIST_TARGET)
|
$(IMG_FROM_TARGET_FILES) \
|
||||||
@echo "Package: $@"
|
--additional IMAGES/VerifiedBootParams.textproto:VerifiedBootParams.textproto \
|
||||||
# Filter out super_empty and images in BOARD_SUPER_PARTITION_PARTITION_LIST.
|
$(BUILT_TARGET_FILES_PACKAGE) $@
|
||||||
# Filter out system_other for launch DAP devices because it is in super image.
|
|
||||||
# Include OTA/super_*.img for retrofit devices and super.img for non-retrofit
|
|
||||||
# devices.
|
|
||||||
$(hide) $(ZIP2ZIP) -i $(BUILT_TARGET_FILES_PACKAGE) -o $@ \
|
|
||||||
-x IMAGES/super_empty.img \
|
|
||||||
$(foreach partition,$(BOARD_SUPER_PARTITION_PARTITION_LIST), \
|
|
||||||
-x IMAGES/$(partition).img) \
|
|
||||||
$(if $(filter system, $(BOARD_SUPER_PARTITION_PARTITION_LIST)), \
|
|
||||||
$(if $(filter true, $(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)),, \
|
|
||||||
-x IMAGES/system_other.img)) \
|
|
||||||
$(if $(filter true,$(PRODUCT_RETROFIT_DYNAMIC_PARTITIONS)), \
|
|
||||||
$(foreach device,$(BOARD_SUPER_PARTITION_BLOCK_DEVICES), \
|
|
||||||
OTA/super_$(device).img:super_$(device).img)) \
|
|
||||||
IMAGES/VerifiedBootParams.textproto:VerifiedBootParams.textproto \
|
|
||||||
OTA/android-info.txt:android-info.txt "IMAGES/*.img:."
|
|
||||||
$(if $(INTERNAL_SUPERIMAGE_DIST_TARGET), zip -q -j -u $@ $(INTERNAL_SUPERIMAGE_DIST_TARGET))
|
|
||||||
else
|
|
||||||
$(INTERNAL_UPDATE_PACKAGE_TARGET):
|
|
||||||
@echo "Package: $@"
|
|
||||||
$(hide) $(ZIP2ZIP) -i $(BUILT_TARGET_FILES_PACKAGE) -o $@ \
|
|
||||||
IMAGES/VerifiedBootParams.textproto:VerifiedBootParams.textproto \
|
|
||||||
OTA/android-info.txt:android-info.txt "IMAGES/*.img:."
|
|
||||||
endif # BOARD_SUPER_IMAGE_IN_UPDATE_PACKAGE
|
|
||||||
|
|
||||||
.PHONY: updatepackage
|
.PHONY: updatepackage
|
||||||
updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
|
updatepackage: $(INTERNAL_UPDATE_PACKAGE_TARGET)
|
||||||
|
@@ -608,6 +608,7 @@ LPMAKE := $(HOST_OUT_EXECUTABLES)/lpmake$(HOST_EXECUTABLE_SUFFIX)
|
|||||||
ADD_IMG_TO_TARGET_FILES := $(HOST_OUT_EXECUTABLES)/add_img_to_target_files$(HOST_EXECUTABLE_SUFFIX)
|
ADD_IMG_TO_TARGET_FILES := $(HOST_OUT_EXECUTABLES)/add_img_to_target_files$(HOST_EXECUTABLE_SUFFIX)
|
||||||
BUILD_IMAGE := $(HOST_OUT_EXECUTABLES)/build_image$(HOST_EXECUTABLE_SUFFIX)
|
BUILD_IMAGE := $(HOST_OUT_EXECUTABLES)/build_image$(HOST_EXECUTABLE_SUFFIX)
|
||||||
BUILD_SUPER_IMAGE := $(HOST_OUT_EXECUTABLES)/build_super_image$(HOST_EXECUTABLE_SUFFIX)
|
BUILD_SUPER_IMAGE := $(HOST_OUT_EXECUTABLES)/build_super_image$(HOST_EXECUTABLE_SUFFIX)
|
||||||
|
IMG_FROM_TARGET_FILES := $(HOST_OUT_EXECUTABLES)/img_from_target_files$(HOST_EXECUTABLE_SUFFIX)
|
||||||
MAKE_RECOVERY_PATCH := $(HOST_OUT_EXECUTABLES)/make_recovery_patch$(HOST_EXECUTABLE_SUFFIX)
|
MAKE_RECOVERY_PATCH := $(HOST_OUT_EXECUTABLES)/make_recovery_patch$(HOST_EXECUTABLE_SUFFIX)
|
||||||
OTA_FROM_TARGET_FILES := $(HOST_OUT_EXECUTABLES)/ota_from_target_files$(HOST_EXECUTABLE_SUFFIX)
|
OTA_FROM_TARGET_FILES := $(HOST_OUT_EXECUTABLES)/ota_from_target_files$(HOST_EXECUTABLE_SUFFIX)
|
||||||
SPARSE_IMG := $(HOST_OUT_EXECUTABLES)/sparse_img$(HOST_EXECUTABLE_SUFFIX)
|
SPARSE_IMG := $(HOST_OUT_EXECUTABLES)/sparse_img$(HOST_EXECUTABLE_SUFFIX)
|
||||||
|
@@ -73,6 +73,9 @@ python_defaults {
|
|||||||
"releasetools_build_super_image",
|
"releasetools_build_super_image",
|
||||||
"releasetools_common",
|
"releasetools_common",
|
||||||
],
|
],
|
||||||
|
required: [
|
||||||
|
"zip2zip",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
python_defaults {
|
python_defaults {
|
||||||
|
@@ -27,6 +27,14 @@ Flags:
|
|||||||
Include only the bootable images (eg 'boot' and 'recovery') in
|
Include only the bootable images (eg 'boot' and 'recovery') in
|
||||||
the output.
|
the output.
|
||||||
|
|
||||||
|
--additional <filespec>
|
||||||
|
Include an additional entry into the generated zip file. The filespec is
|
||||||
|
in a format that's accepted by zip2zip (e.g.
|
||||||
|
'OTA/android-info.txt:android-info.txt', to copy `OTA/android-info.txt`
|
||||||
|
from input_file into output_file as `android-info.txt`. Refer to the
|
||||||
|
`filespec` arg in zip2zip's help message). The option can be repeated to
|
||||||
|
include multiple entries.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
@@ -47,6 +55,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
OPTIONS = common.OPTIONS
|
OPTIONS = common.OPTIONS
|
||||||
|
|
||||||
|
OPTIONS.additional_entries = []
|
||||||
OPTIONS.bootable_only = False
|
OPTIONS.bootable_only = False
|
||||||
OPTIONS.put_super = None
|
OPTIONS.put_super = None
|
||||||
OPTIONS.dynamic_partition_list = None
|
OPTIONS.dynamic_partition_list = None
|
||||||
@@ -60,9 +69,10 @@ def LoadOptions(input_file):
|
|||||||
"""Loads information from input_file to OPTIONS.
|
"""Loads information from input_file to OPTIONS.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
input_file: Path to the root dir of an extracted target_files zip.
|
input_file: Path to the input target_files zip file.
|
||||||
"""
|
"""
|
||||||
info = OPTIONS.info_dict = common.LoadInfoDict(input_file)
|
with zipfile.ZipFile(input_file) as input_zip:
|
||||||
|
info = OPTIONS.info_dict = common.LoadInfoDict(input_zip)
|
||||||
|
|
||||||
OPTIONS.put_super = info.get('super_image_in_update_package') == 'true'
|
OPTIONS.put_super = info.get('super_image_in_update_package') == 'true'
|
||||||
OPTIONS.dynamic_partition_list = info.get('dynamic_partition_list',
|
OPTIONS.dynamic_partition_list = info.get('dynamic_partition_list',
|
||||||
@@ -74,19 +84,29 @@ def LoadOptions(input_file):
|
|||||||
OPTIONS.sparse_userimages = bool(info.get('extfs_sparse_flag'))
|
OPTIONS.sparse_userimages = bool(info.get('extfs_sparse_flag'))
|
||||||
|
|
||||||
|
|
||||||
def CopyInfo(input_tmp, output_zip):
|
def CopyZipEntries(input_file, output_file, entries):
|
||||||
"""Copies the android-info.txt file from the input to the output."""
|
"""Copies ZIP entries between input and output files.
|
||||||
common.ZipWrite(
|
|
||||||
output_zip, os.path.join(input_tmp, 'OTA', 'android-info.txt'),
|
|
||||||
'android-info.txt')
|
|
||||||
|
|
||||||
|
|
||||||
def CopyUserImages(input_tmp, output_zip):
|
|
||||||
"""Copies user images from the unzipped input and write to output_zip.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
input_tmp: path to the unzipped input.
|
input_file: Path to the input target_files zip.
|
||||||
output_zip: a ZipFile instance to write images to.
|
output_file: Output filename.
|
||||||
|
entries: A list of entries to copy, in a format that's accepted by zip2zip
|
||||||
|
(e.g. 'OTA/android-info.txt:android-info.txt', which copies
|
||||||
|
`OTA/android-info.txt` from input_file into output_file as
|
||||||
|
`android-info.txt`. Refer to the `filespec` arg in zip2zip's help
|
||||||
|
message).
|
||||||
|
"""
|
||||||
|
logger.info('Writing %d entries to archive...', len(entries))
|
||||||
|
cmd = ['zip2zip', '-i', input_file, '-o', output_file]
|
||||||
|
cmd.extend(entries)
|
||||||
|
common.RunAndCheckOutput(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def EntriesForUserImages(input_file):
|
||||||
|
"""Returns the user images entries to be copied.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_file: Path to the input target_files zip file.
|
||||||
"""
|
"""
|
||||||
dynamic_images = [p + '.img' for p in OPTIONS.dynamic_partition_list]
|
dynamic_images = [p + '.img' for p in OPTIONS.dynamic_partition_list]
|
||||||
|
|
||||||
@@ -94,56 +114,62 @@ def CopyUserImages(input_tmp, output_zip):
|
|||||||
if not OPTIONS.retrofit_dap and 'system' in OPTIONS.dynamic_partition_list:
|
if not OPTIONS.retrofit_dap and 'system' in OPTIONS.dynamic_partition_list:
|
||||||
dynamic_images.append('system_other.img')
|
dynamic_images.append('system_other.img')
|
||||||
|
|
||||||
images_path = os.path.join(input_tmp, 'IMAGES')
|
entries = [
|
||||||
# A target-files zip must contain the images since Lollipop.
|
'OTA/android-info.txt:android-info.txt',
|
||||||
assert os.path.exists(images_path)
|
]
|
||||||
for image in sorted(os.listdir(images_path)):
|
with zipfile.ZipFile(input_file) as input_zip:
|
||||||
|
namelist = input_zip.namelist()
|
||||||
|
|
||||||
|
for image_path in [name for name in namelist if name.startswith('IMAGES/')]:
|
||||||
|
image = os.path.basename(image_path)
|
||||||
if OPTIONS.bootable_only and image not in ('boot.img', 'recovery.img'):
|
if OPTIONS.bootable_only and image not in ('boot.img', 'recovery.img'):
|
||||||
continue
|
continue
|
||||||
if not image.endswith('.img'):
|
if not image.endswith('.img'):
|
||||||
continue
|
continue
|
||||||
|
# Filter out super_empty and the images that are already in super partition.
|
||||||
if OPTIONS.put_super:
|
if OPTIONS.put_super:
|
||||||
if image == 'super_empty.img':
|
if image == 'super_empty.img':
|
||||||
continue
|
continue
|
||||||
if image in dynamic_images:
|
if image in dynamic_images:
|
||||||
continue
|
continue
|
||||||
logger.info('writing %s to archive...', os.path.join('IMAGES', image))
|
entries.append('{}:{}'.format(image_path, image))
|
||||||
common.ZipWrite(output_zip, os.path.join(images_path, image), image)
|
return entries
|
||||||
|
|
||||||
|
|
||||||
def WriteSuperImages(input_tmp, output_zip):
|
def EntriesForSplitSuperImages(input_file):
|
||||||
"""Writes super images from the unzipped input into output_zip.
|
"""Returns the entries for split super images.
|
||||||
|
|
||||||
This is only done if super_image_in_update_package is set to 'true'.
|
This is only done for retrofit dynamic partition devices.
|
||||||
|
|
||||||
- For retrofit dynamic partition devices, copy split super images from target
|
|
||||||
files package.
|
|
||||||
- For devices launched with dynamic partitions, build super image from target
|
|
||||||
files package.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
input_tmp: path to the unzipped input.
|
input_file: Path to the input target_files zip file.
|
||||||
output_zip: a ZipFile instance to write images to.
|
|
||||||
"""
|
"""
|
||||||
if not OPTIONS.build_super or not OPTIONS.put_super:
|
with zipfile.ZipFile(input_file) as input_zip:
|
||||||
return
|
namelist = input_zip.namelist()
|
||||||
|
entries = []
|
||||||
if OPTIONS.retrofit_dap:
|
|
||||||
# retrofit devices already have split super images under OTA/
|
|
||||||
images_path = os.path.join(input_tmp, 'OTA')
|
|
||||||
for device in OPTIONS.super_device_list:
|
for device in OPTIONS.super_device_list:
|
||||||
image = 'super_%s.img' % device
|
image = 'OTA/super_{}.img'.format(device)
|
||||||
image_path = os.path.join(images_path, image)
|
assert image in namelist, 'Failed to find {}'.format(image)
|
||||||
assert os.path.exists(image_path)
|
entries.append('{}:{}'.format(image, os.path.basename(image)))
|
||||||
logger.info('writing %s to archive...', os.path.join('OTA', image))
|
return entries
|
||||||
common.ZipWrite(output_zip, image_path, image)
|
|
||||||
else:
|
|
||||||
# super image for non-retrofit devices aren't in target files package,
|
def RebuildAndWriteSuperImages(input_file, output_file):
|
||||||
# so build it.
|
"""Builds and writes super images to the output file."""
|
||||||
|
logger.info('Building super image...')
|
||||||
|
|
||||||
|
# We need files under IMAGES/, OTA/, META/ for img_from_target_files.py.
|
||||||
|
# However, common.LoadInfoDict() may read additional files under BOOT/,
|
||||||
|
# RECOVERY/ and ROOT/. So unzip everything from the target_files.zip.
|
||||||
|
input_tmp = common.UnzipTemp(input_file)
|
||||||
|
|
||||||
super_file = common.MakeTempFile('super_', '.img')
|
super_file = common.MakeTempFile('super_', '.img')
|
||||||
logger.info('building super image %s...', super_file)
|
|
||||||
BuildSuperImage(input_tmp, super_file)
|
BuildSuperImage(input_tmp, super_file)
|
||||||
logger.info('writing super.img to archive...')
|
|
||||||
|
logger.info('Writing super.img to archive...')
|
||||||
|
with zipfile.ZipFile(
|
||||||
|
output_file, 'a', compression=zipfile.ZIP_DEFLATED,
|
||||||
|
allowZip64=not OPTIONS.sparse_userimages) as output_zip:
|
||||||
common.ZipWrite(output_zip, super_file, 'super.img')
|
common.ZipWrite(output_zip, super_file, 'super.img')
|
||||||
|
|
||||||
|
|
||||||
@@ -162,38 +188,47 @@ def ImgFromTargetFiles(input_file, output_file):
|
|||||||
|
|
||||||
logger.info('Building image zip from target files zip.')
|
logger.info('Building image zip from target files zip.')
|
||||||
|
|
||||||
# We need files under IMAGES/, OTA/, META/ for img_from_target_files.py.
|
LoadOptions(input_file)
|
||||||
# However, common.LoadInfoDict() may read additional files under BOOT/,
|
|
||||||
# RECOVERY/ and ROOT/. So unzip everything from the target_files.zip.
|
|
||||||
input_tmp = common.UnzipTemp(input_file)
|
|
||||||
|
|
||||||
LoadOptions(input_tmp)
|
# Entries to be copied into the output file.
|
||||||
output_zip = zipfile.ZipFile(
|
entries = EntriesForUserImages(input_file)
|
||||||
output_file, 'w', compression=zipfile.ZIP_DEFLATED,
|
|
||||||
allowZip64=not OPTIONS.sparse_userimages)
|
|
||||||
|
|
||||||
try:
|
# Only for devices that retrofit dynamic partitions there're split super
|
||||||
CopyInfo(input_tmp, output_zip)
|
# images available in the target_files.zip.
|
||||||
CopyUserImages(input_tmp, output_zip)
|
rebuild_super = False
|
||||||
WriteSuperImages(input_tmp, output_zip)
|
if OPTIONS.build_super and OPTIONS.put_super:
|
||||||
finally:
|
if OPTIONS.retrofit_dap:
|
||||||
common.ZipClose(output_zip)
|
entries += EntriesForSplitSuperImages(input_file)
|
||||||
|
else:
|
||||||
|
rebuild_super = True
|
||||||
|
|
||||||
|
# Any additional entries provided by caller.
|
||||||
|
entries += OPTIONS.additional_entries
|
||||||
|
|
||||||
|
CopyZipEntries(input_file, output_file, entries)
|
||||||
|
|
||||||
|
if rebuild_super:
|
||||||
|
RebuildAndWriteSuperImages(input_file, output_file)
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
|
||||||
def option_handler(o, _):
|
def option_handler(o, a):
|
||||||
if o in ('-z', '--bootable_zip'):
|
if o in ('-z', '--bootable_zip'):
|
||||||
OPTIONS.bootable_only = True
|
OPTIONS.bootable_only = True
|
||||||
|
elif o == '--additional':
|
||||||
|
OPTIONS.additional_entries.append(a)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
args = common.ParseOptions(argv, __doc__,
|
args = common.ParseOptions(argv, __doc__,
|
||||||
extra_opts='z',
|
extra_opts='z',
|
||||||
extra_long_opts=['bootable_zip'],
|
extra_long_opts=[
|
||||||
|
'additional=',
|
||||||
|
'bootable_zip',
|
||||||
|
],
|
||||||
extra_option_handler=option_handler)
|
extra_option_handler=option_handler)
|
||||||
|
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
common.Usage(__doc__)
|
common.Usage(__doc__)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Reference in New Issue
Block a user