Merge "Add fingerprint HAL to emulator system images"
diff --git a/CleanSpec.mk b/CleanSpec.mk
index c0fe216..74e7c43 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -339,6 +339,21 @@
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/root/default.prop)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/recovery/root/default.prop)
+# Rename dalvik.vm.usejit to debug.dalvik.vm.usejit
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/build.prop)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/root/default.prop)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/recovery/root/default.prop)
+
+# Revert rename dalvik.vm.usejit to debug.dalvik.vm.usejit
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/build.prop)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/root/default.prop)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/recovery/root/default.prop)
+
+# Change from interpret-only to verify-at-runtime.
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/build.prop)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/root/default.prop)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/recovery/root/default.prop)
+
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
diff --git a/core/Makefile b/core/Makefile
index 478c966..353b49c 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -717,6 +717,9 @@
$(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),$(hide) echo "verity_signer_cmd=$(VERITY_SIGNER)" >> $(1))
$(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION),$(hide) echo "system_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SYSTEM_VERITY_PARTITION)" >> $(1))
$(if $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION),$(hide) echo "vendor_verity_block_device=$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VENDOR_VERITY_PARTITION)" >> $(1))
+$(if $(filter true,$(BOARD_BUILD_SYSTEM_ROOT_IMAGE)),\
+ $(hide) echo "system_root_image=true" >> $(1);\
+ echo "ramdisk_dir=$(TARGET_ROOT_OUT)" >> $(1))
$(if $(2),$(hide) $(foreach kv,$(2),echo "$(kv)" >> $(1);))
endef
@@ -1417,7 +1420,7 @@
$(hide) mkdir -p $(zip_root)/META
$(hide) $(ACP) $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
$(hide) if test -e $(tool_extensions)/releasetools.py; then $(ACP) $(tool_extensions)/releasetools.py $(zip_root)/META/; fi
- $(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
+ $(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
$(hide) echo "recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/misc_info.txt
$(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
ifdef BOARD_FLASH_BLOCK_SIZE
diff --git a/core/clang/config.mk b/core/clang/config.mk
index 72a880f..a39095e 100644
--- a/core/clang/config.mk
+++ b/core/clang/config.mk
@@ -60,8 +60,12 @@
-fno-tree-sra \
-fprefetch-loop-arrays \
-funswitch-loops \
+ -Werror=unused-but-set-variable \
+ -Werror=unused-but-set-parameter \
-Wmaybe-uninitialized \
-Wno-error=maybe-uninitialized \
+ -Wno-error=unused-but-set-variable \
+ -Wno-error=unused-but-set-parameter \
-Wno-free-nonheap-object \
-Wno-literal-suffix \
-Wno-maybe-uninitialized \
diff --git a/core/config.mk b/core/config.mk
index 3811190..41f9524 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -436,7 +436,7 @@
# $(1): vm arguments
# $(2): jack perf arguments
define call-jack
-$(JACK_VM) $(1) $(JAVA_TMPDIR_ARG) -cp $(JACK_JAR) com.android.jack.Main $(2)
+$(JACK_VM) $(1) $(JAVA_TMPDIR_ARG) -jar $(JACK_JAR) $(2)
endef
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_VM_ARGS := $(DEFAULT_JACK_VM_ARGS)
ifneq ($(ANDROID_JACK_VM_ARGS),)
@@ -447,10 +447,12 @@
ifneq ($(ANDROID_JACK_EXTRA_ARGS),)
DEFAULT_JACK_EXTRA_ARGS := $(ANDROID_JACK_EXTRA_ARGS)
else
-DEFAULT_JACK_EXTRA_ARGS := --sanity-checks off -D jack.reporter.level.file=error=--,warning=-
+DEFAULT_JACK_EXTRA_ARGS := --sanity-checks off
endif
+# Turn off jack warnings by default.
+DEFAULT_JACK_EXTRA_ARGS += --verbose error
-JILL := java -Xmx3500m -cp $(JILL_JAR) com.android.jill.Main
+JILL := java -Xmx3500m -jar $(JILL_JAR)
PROGUARD := external/proguard/bin/proguard.sh
JAVATAGS := build/tools/java-event-log-tags.py
LLVM_RS_CC := $(HOST_OUT_EXECUTABLES)/llvm-rs-cc$(HOST_EXECUTABLE_SUFFIX)
diff --git a/core/cxx_stl_setup.mk b/core/cxx_stl_setup.mk
index 265d8cb..63e2069 100644
--- a/core/cxx_stl_setup.mk
+++ b/core/cxx_stl_setup.mk
@@ -53,6 +53,11 @@
my_shared_libraries += libc++
else
my_static_libraries += libc++_static
+ ifndef LOCAL_IS_HOST_MODULE
+ ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
+ my_static_libraries += libm libc libdl
+ endif
+ endif
endif
ifdef LOCAL_IS_HOST_MODULE
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 3dfcfd6..ee04557 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -72,6 +72,10 @@
HOST_ARCH := x86_64
HOST_2ND_ARCH := x86
HOST_IS_64_BIT := true
+else
+ifneq (,$(findstring x86,$(UNAME)))
+$(error Building on a 32-bit x86 host is not supported: $(UNAME)!)
+endif
endif
BUILD_ARCH := $(HOST_ARCH)
diff --git a/core/main.mk b/core/main.mk
index a360d6c..7350f99 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -388,10 +388,10 @@
ro.setupwizard.mode=OPTIONAL
endif
ifndef is_sdk_build
- # Don't even verify the image on eng builds to speed startup
- ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.image-dex2oat-filter=verify-none
- # Don't compile apps on eng builds to speed startup
- ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dex2oat-filter=interpret-only
+ # Don't verify or compile the image on eng builds to speed startup.
+ ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.image-dex2oat-filter=verify-at-runtime
+ # Don't verify or compile apps on eng builds to speed startup.
+ ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dex2oat-filter=verify-at-runtime
endif
ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.usejit=true
endif
diff --git a/core/tasks/build_custom_images.mk b/core/tasks/build_custom_images.mk
index 263b81a..8ebf89b 100644
--- a/core/tasks/build_custom_images.mk
+++ b/core/tasks/build_custom_images.mk
@@ -34,6 +34,9 @@
# module's LOCAL_PICKUP_FILES.
# - CUSTOM_IMAGE_COPY_FILES, a list of "<src>:<dest>" to be copied to the
# image. <dest> is relativ to the root of the image.
+# - CUSTOM_IMAGE_SELINUX, set to "true" if the image supports selinux.
+# - CUSTOM_IMAGE_SUPPORT_VERITY, set to "true" if the product supports verity.
+# - CUSTOM_IMAGE_VERITY_BLOCK_DEVICE
#
# To build all those images, run "make custom_images".
@@ -48,6 +51,9 @@
CUSTOM_IMAGE_DICT_FILE \
CUSTOM_IMAGE_MODULES \
CUSTOM_IMAGE_COPY_FILES \
+ CUSTOM_IMAGE_SELINUX \
+ CUSTOM_IMAGE_SUPPORT_VERITY \
+ CUSTOM_IMAGE_VERITY_BLOCK_DEVICE \
# We don't expect product makefile to inherit/override PRODUCT_CUSTOM_IMAGE_MAKEFILES,
# so we don't put it in the _product_var_list.
diff --git a/core/tasks/tools/build_custom_image.mk b/core/tasks/tools/build_custom_image.mk
index fa9cda2..e59ed42 100644
--- a/core/tasks/tools/build_custom_image.mk
+++ b/core/tasks/tools/build_custom_image.mk
@@ -26,7 +26,7 @@
intermediates := $(call intermediates-dir-for,PACKAGING,$(my_custom_image_name))
my_built_custom_image := $(intermediates)/$(my_custom_image_name).img
-my_staging_dir := $(intermediates)/$(my_custom_image_name)
+my_staging_dir := $(intermediates)/$(CUSTOM_IMAGE_MOUNT_POINT)
# Collect CUSTOM_IMAGE_MODULES's installd files and their PICKUP_FILES.
my_built_modules :=
@@ -69,6 +69,10 @@
$(my_built_custom_image): PRIVATE_STAGING_DIR := $(my_staging_dir)
$(my_built_custom_image): PRIVATE_COPY_PAIRS := $(my_copy_pairs)
$(my_built_custom_image): PRIVATE_PICKUP_FILES := $(my_pickup_files)
+$(my_built_custom_image): PRIVATE_SELINUX := $(CUSTOM_IMAGE_SELINUX)
+$(my_built_custom_image): PRIVATE_SUPPORT_VERITY := $(CUSTOM_IMAGE_SUPPORT_VERITY)
+$(my_built_custom_image): PRIVATE_VERITY_KEY := $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_VERITY_SIGNING_KEY)
+$(my_built_custom_image): PRIVATE_VERITY_BLOCK_DEVICE := $(CUSTOM_IMAGE_VERITY_BLOCK_DEVICE)
$(my_built_custom_image): PRIVATE_DICT_FILE := $(CUSTOM_IMAGE_DICT_FILE)
$(my_built_custom_image): $(INTERNAL_USERIMAGES_DEPS) $(my_built_modules) $(my_image_copy_files) \
$(CUSTOM_IMAGE_DICT_FILE)
@@ -86,9 +90,15 @@
$(hide) echo "mount_point=$(PRIVATE_MOUNT_POINT)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
$(hide) echo "fs_type=$(PRIVATE_FILE_SYSTEM_TYPE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
$(hide) echo "partition_size=$(PRIVATE_PARTITION_SIZE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt
+ $(if $(PRIVATE_SELINUX),$(hide) echo "selinux_fc=$(SELINUX_FC)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
+ $(if $(PRIVATE_SUPPORT_VERITY),\
+ $(hide) echo "verity=$(PRIVATE_SUPPORT_VERITY)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
+ echo "verity_key=$(PRIVATE_VERITY_KEY)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
+ echo "verity_signer_cmd=$(VERITY_SIGNER)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
+ echo "verity_block_device=$(PRIVATE_VERITY_BLOCK_DEVICE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
$(if $(PRIVATE_DICT_FILE),\
$(hide) echo "# Properties from $(PRIVATE_DICT_FILE)" >> $(PRIVATE_INTERMEDIATES)/image_info.txt;\
- cat $(PRIVATE_DICT_FILE) >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
+ cat $(PRIVATE_DICT_FILE) >> $(PRIVATE_INTERMEDIATES)/image_info.txt)
# Generate the image.
$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH \
./build/tools/releasetools/build_image.py \
diff --git a/target/board/generic_arm64/BoardConfig.mk b/target/board/generic_arm64/BoardConfig.mk
index 8afd5a8..c98624d 100644
--- a/target/board/generic_arm64/BoardConfig.mk
+++ b/target/board/generic_arm64/BoardConfig.mk
@@ -76,7 +76,7 @@
USE_OPENGL_RENDERER := true
TARGET_USERIMAGES_USE_EXT4 := true
-BOARD_SYSTEMIMAGE_PARTITION_SIZE := 943718400
+BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1073741824
BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
diff --git a/target/board/generic_mips/BoardConfig.mk b/target/board/generic_mips/BoardConfig.mk
index ff5a4e4..b40f9ba 100644
--- a/target/board/generic_mips/BoardConfig.mk
+++ b/target/board/generic_mips/BoardConfig.mk
@@ -53,7 +53,7 @@
USE_OPENGL_RENDERER := true
TARGET_USERIMAGES_USE_EXT4 := true
-BOARD_SYSTEMIMAGE_PARTITION_SIZE := 838860800
+BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1073741824
BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
diff --git a/target/board/generic_x86_64/BoardConfig.mk b/target/board/generic_x86_64/BoardConfig.mk
index 295ee2b..192bbb2 100755
--- a/target/board/generic_x86_64/BoardConfig.mk
+++ b/target/board/generic_x86_64/BoardConfig.mk
@@ -41,7 +41,7 @@
USE_OPENGL_RENDERER := true
TARGET_USERIMAGES_USE_EXT4 := true
-BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1073741824 # 1GB
+BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1073741824 # 1GB
BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800
BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016
BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
diff --git a/target/product/base.mk b/target/product/base.mk
index 8c1beeb..2d72961 100644
--- a/target/product/base.mk
+++ b/target/product/base.mk
@@ -99,7 +99,6 @@
monkey \
mtpd \
ndc \
- netcfg \
netd \
ping \
ping6 \
diff --git a/target/product/full_base_telephony.mk b/target/product/full_base_telephony.mk
index 2fd2ce8..9a2c63a 100644
--- a/target/product/full_base_telephony.mk
+++ b/target/product/full_base_telephony.mk
@@ -19,9 +19,6 @@
# build quite specifically for the emulator, and might not be
# entirely appropriate to inherit from for on-device configurations.
-PRODUCT_PACKAGES := \
- VoiceDialer
-
PRODUCT_PROPERTY_OVERRIDES := \
keyguard.no_require_sim=true \
ro.com.android.dataroaming=true
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index e98e4b6..b3d2ede 100755
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -30,9 +30,6 @@
import errno
import os
-import re
-import shutil
-import subprocess
import tempfile
import zipfile
@@ -70,10 +67,8 @@
block_list = common.MakeTempFile(prefix="system-blocklist-", suffix=".map")
imgname = BuildSystem(OPTIONS.input_tmp, OPTIONS.info_dict,
block_list=block_list)
- with open(imgname, "rb") as f:
- common.ZipWriteStr(output_zip, prefix + "system.img", f.read())
- with open(block_list, "rb") as f:
- common.ZipWriteStr(output_zip, prefix + "system.map", f.read())
+ common.ZipWrite(output_zip, imgname, prefix + "system.img")
+ common.ZipWrite(output_zip, block_list, prefix + "system.map")
def BuildSystem(input_dir, info_dict, block_list=None):
@@ -94,10 +89,8 @@
block_list = common.MakeTempFile(prefix="vendor-blocklist-", suffix=".map")
imgname = BuildVendor(OPTIONS.input_tmp, OPTIONS.info_dict,
block_list=block_list)
- with open(imgname, "rb") as f:
- common.ZipWriteStr(output_zip, prefix + "vendor.img", f.read())
- with open(block_list, "rb") as f:
- common.ZipWriteStr(output_zip, prefix + "vendor.map", f.read())
+ common.ZipWrite(output_zip, imgname, prefix + "vendor.img")
+ common.ZipWrite(output_zip, block_list, prefix + "vendor.map")
def BuildVendor(input_dir, info_dict, block_list=None):
@@ -142,11 +135,20 @@
fc_config = os.path.join(input_dir, "BOOT/RAMDISK/file_contexts")
if not os.path.exists(fc_config): fc_config = None
+ # Override values loaded from info_dict.
+ if fs_config:
+ image_props["fs_config"] = fs_config
+ if fc_config:
+ image_props["selinux_fc"] = fc_config
+ if block_list:
+ image_props["block_list"] = block_list
+ if image_props.get("system_root_image") == "true":
+ image_props["ramdisk_dir"] = os.path.join(input_dir, "BOOT/RAMDISK")
+ image_props["ramdisk_fs_config"] = os.path.join(
+ input_dir, "META/boot_filesystem_config.txt")
+
succ = build_image.BuildImage(os.path.join(input_dir, what),
- image_props, img,
- fs_config=fs_config,
- fc_config=fc_config,
- block_list=block_list)
+ image_props, img)
assert succ, "build " + what + ".img image failed"
return img
@@ -296,7 +298,6 @@
output_zip.close()
def main(argv):
-
def option_handler(o, a):
if o in ("-a", "--add_missing"):
OPTIONS.add_missing = True
diff --git a/tools/releasetools/blockimgdiff.py b/tools/releasetools/blockimgdiff.py
index 5cf0f2d..5b5c4cc 100644
--- a/tools/releasetools/blockimgdiff.py
+++ b/tools/releasetools/blockimgdiff.py
@@ -140,8 +140,11 @@
self.style = style
self.intact = (getattr(tgt_ranges, "monotonic", False) and
getattr(src_ranges, "monotonic", False))
- self.goes_before = {}
- self.goes_after = {}
+
+ # We use OrderedDict rather than dict so that the output is repeatable;
+ # otherwise it would depend on the hash values of the Transfer objects.
+ self.goes_before = OrderedDict()
+ self.goes_after = OrderedDict()
self.stash_before = []
self.use_stash = []
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index 692ec93..97353df 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -198,25 +198,39 @@
shutil.rmtree(tempdir_name, ignore_errors=True)
return True
-def BuildImage(in_dir, prop_dict, out_file,
- fs_config=None,
- fc_config=None,
- block_list=None):
+def BuildImage(in_dir, prop_dict, out_file):
"""Build an image to out_file from in_dir with property prop_dict.
Args:
in_dir: path of input directory.
prop_dict: property dictionary.
out_file: path of the output image file.
- fs_config: path to the fs_config file (typically
- META/filesystem_config.txt). If None then the configuration in
- the local client will be used.
- fc_config: path to the SELinux file_contexts file. If None then
- the value from prop_dict['selinux_fc'] will be used.
Returns:
True iff the image is built successfully.
"""
+ # system_root_image=true: build a system.img that combines the contents of /system
+ # and the ramdisk, and can be mounted at the root of the file system.
+ origin_in = in_dir
+ fs_config = prop_dict.get("fs_config")
+ if (prop_dict.get("system_root_image") == "true"
+ and prop_dict["mount_point"] == "system"):
+ in_dir = tempfile.mkdtemp()
+ # Change the mount point to "/"
+ prop_dict["mount_point"] = "/"
+ if fs_config:
+ # We need to merge the fs_config files of system and ramdisk.
+ fd, merged_fs_config = tempfile.mkstemp(prefix="root_fs_config",
+ suffix=".txt")
+ os.close(fd)
+ with open(merged_fs_config, "w") as fw:
+ if "ramdisk_fs_config" in prop_dict:
+ with open(prop_dict["ramdisk_fs_config"]) as fr:
+ fw.writelines(fr.readlines())
+ with open(fs_config) as fr:
+ fw.writelines(fr.readlines())
+ fs_config = merged_fs_config
+
build_command = []
fs_type = prop_dict.get("fs_type", "")
run_fsck = False
@@ -244,22 +258,18 @@
build_command.extend(["-j", prop_dict["journal_size"]])
if "timestamp" in prop_dict:
build_command.extend(["-T", str(prop_dict["timestamp"])])
- if fs_config is not None:
+ if fs_config:
build_command.extend(["-C", fs_config])
- if block_list is not None:
- build_command.extend(["-B", block_list])
+ if "block_list" in prop_dict:
+ build_command.extend(["-B", prop_dict["block_list"]])
build_command.extend(["-L", prop_dict["mount_point"]])
- if fc_config is not None:
- build_command.append(fc_config)
- elif "selinux_fc" in prop_dict:
+ if "selinux_fc" in prop_dict:
build_command.append(prop_dict["selinux_fc"])
elif fs_type.startswith("squash"):
build_command = ["mksquashfsimage.sh"]
build_command.extend([in_dir, out_file])
build_command.extend(["-m", prop_dict["mount_point"]])
- if fc_config is not None:
- build_command.extend(["-c", fc_config])
- elif "selinux_fc" in prop_dict:
+ if "selinux_fc" in prop_dict:
build_command.extend(["-c", prop_dict["selinux_fc"]])
elif fs_type.startswith("f2fs"):
build_command = ["mkf2fsuserimg.sh"]
@@ -274,7 +284,23 @@
build_command.append(prop_dict["selinux_fc"])
build_command.append(prop_dict["mount_point"])
- exit_code = RunCommand(build_command)
+ if in_dir != origin_in:
+ # Construct a staging directory of the root file system.
+ ramdisk_dir = prop_dict.get("ramdisk_dir")
+ if ramdisk_dir:
+ shutil.rmtree(in_dir)
+ shutil.copytree(ramdisk_dir, in_dir, symlinks=True)
+ staging_system = os.path.join(in_dir, "system")
+ shutil.rmtree(staging_system, ignore_errors=True)
+ shutil.copytree(origin_in, staging_system, symlinks=True)
+ try:
+ exit_code = RunCommand(build_command)
+ finally:
+ if in_dir != origin_in:
+ # Clean up temporary directories and files.
+ shutil.rmtree(in_dir, ignore_errors=True)
+ if fs_config:
+ os.remove(fs_config)
if exit_code != 0:
return False
@@ -334,6 +360,8 @@
copy_prop("system_size", "partition_size")
copy_prop("system_journal_size", "journal_size")
copy_prop("system_verity_block_device", "verity_block_device")
+ copy_prop("system_root_image","system_root_image")
+ copy_prop("ramdisk_dir","ramdisk_dir")
elif mount_point == "data":
# Copy the generic fs type first, override with specific one if available.
copy_prop("fs_type", "fs_type")
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index a3dd780..6903dc66 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -781,6 +781,46 @@
return result
+def ZipWrite(zip_file, filename, arcname=None, perms=0o644,
+ compress_type=None):
+ import datetime
+
+ # http://b/18015246
+ # Python 2.7's zipfile implementation wrongly thinks that zip64 is required
+ # for files larger than 2GiB. We can work around this by adjusting their
+ # limit. Note that `zipfile.writestr()` will not work for strings larger than
+ # 2GiB. The Python interpreter sometimes rejects strings that large (though
+ # it isn't clear to me exactly what circumstances cause this).
+ # `zipfile.write()` must be used directly to work around this.
+ #
+ # This mess can be avoided if we port to python3.
+ saved_zip64_limit = zipfile.ZIP64_LIMIT
+ zipfile.ZIP64_LIMIT = (1 << 32) - 1
+
+ if compress_type is None:
+ compress_type = zip_file.compression
+ if arcname is None:
+ arcname = filename
+
+ saved_stat = os.stat(filename)
+
+ try:
+ # `zipfile.write()` doesn't allow us to pass ZipInfo, so just modify the
+ # file to be zipped and reset it when we're done.
+ os.chmod(filename, perms)
+
+ # Use a fixed timestamp so the output is repeatable.
+ epoch = datetime.datetime.fromtimestamp(0)
+ timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
+ os.utime(filename, (timestamp, timestamp))
+
+ zip_file.write(filename, arcname=arcname, compress_type=compress_type)
+ finally:
+ os.chmod(filename, saved_stat.st_mode)
+ os.utime(filename, (saved_stat.st_atime, saved_stat.st_mtime))
+ zipfile.ZIP64_LIMIT = saved_zip64_limit
+
+
def ZipWriteStr(zip, filename, data, perms=0644, compression=None):
# use a fixed timestamp so the output is repeatable.
zinfo = zipfile.ZipInfo(filename=filename,
@@ -1024,17 +1064,19 @@
class BlockDifference:
- def __init__(self, partition, tgt, src=None, check_first_block=False):
+ def __init__(self, partition, tgt, src=None, check_first_block=False, version=None):
self.tgt = tgt
self.src = src
self.partition = partition
self.check_first_block = check_first_block
- self.version = 1
- if OPTIONS.info_dict:
- self.version = max(
- int(i) for i in
- OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
+ if version is None:
+ version = 1
+ if OPTIONS.info_dict:
+ version = max(
+ int(i) for i in
+ OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
+ self.version = version
b = blockimgdiff.BlockImageDiff(tgt, src, threads=OPTIONS.worker_threads,
version=self.version)
@@ -1090,19 +1132,21 @@
'endif;') % (partition,))
def _WriteUpdate(self, script, output_zip):
- partition = self.partition
- with open(self.path + ".transfer.list", "rb") as f:
- ZipWriteStr(output_zip, partition + ".transfer.list", f.read())
- with open(self.path + ".new.dat", "rb") as f:
- ZipWriteStr(output_zip, partition + ".new.dat", f.read())
- with open(self.path + ".patch.dat", "rb") as f:
- ZipWriteStr(output_zip, partition + ".patch.dat", f.read(),
- compression=zipfile.ZIP_STORED)
+ ZipWrite(output_zip,
+ '{}.transfer.list'.format(self.path),
+ '{}.transfer.list'.format(self.partition))
+ ZipWrite(output_zip,
+ '{}.new.dat'.format(self.path),
+ '{}.new.dat'.format(self.partition))
+ ZipWrite(output_zip,
+ '{}.patch.dat'.format(self.path),
+ '{}.patch.dat'.format(self.partition),
+ compress_type=zipfile.ZIP_STORED)
- call = (('block_image_update("%s", '
- 'package_extract_file("%s.transfer.list"), '
- '"%s.new.dat", "%s.patch.dat");\n') %
- (self.device, partition, partition, partition))
+ call = ('block_image_update("{device}", '
+ 'package_extract_file("{partition}.transfer.list"), '
+ '"{partition}.new.dat", "{partition}.patch.dat");\n'.format(
+ device=self.device, partition=self.partition))
script.AppendExtra(script._WordWrap(call))
def _HashBlocks(self, source, ranges):
diff --git a/tools/releasetools/edify_generator.py b/tools/releasetools/edify_generator.py
index e52c264..934d751 100644
--- a/tools/releasetools/edify_generator.py
+++ b/tools/releasetools/edify_generator.py
@@ -74,11 +74,11 @@
raise ValueError("must specify an OEM property")
if not value:
raise ValueError("must specify the OEM value")
- cmd = ('file_getprop("/oem/oem.prop", "%s") == "%s" || '
- 'abort("This package expects the value \\"%s\\" for '
- '\\"%s\\" on the OEM partition; '
- 'this has value \\"" + file_getprop("/oem/oem.prop") + "\\".");'
- ) % (name, value, name, value)
+ cmd = ('file_getprop("/oem/oem.prop", "{name}") == "{value}" || '
+ 'abort("This package expects the value \\"{value}\\" for '
+ '\\"{name}\\" on the OEM partition; this has value \\"" + '
+ 'file_getprop("/oem/oem.prop", "{name}") + "\\".");'
+ ).format(name=name, value=value)
self.script.append(cmd)
def AssertSomeFingerprint(self, *fp):
diff --git a/tools/releasetools/img_from_target_files.py b/tools/releasetools/img_from_target_files.py
index 4b88e73..4dda0b7 100755
--- a/tools/releasetools/img_from_target_files.py
+++ b/tools/releasetools/img_from_target_files.py
@@ -88,11 +88,13 @@
# and all we have to do is copy them to the output zip.
images = os.listdir(images_path)
if images:
- for i in images:
- if bootable_only and i not in ("boot.img", "recovery.img"): continue
- if not i.endswith(".img"): continue
- with open(os.path.join(images_path, i), "r") as f:
- common.ZipWriteStr(output_zip, i, f.read())
+ for image in images:
+ if bootable_only and image not in ("boot.img", "recovery.img"):
+ continue
+ if not image.endswith(".img"):
+ continue
+ common.ZipWrite(
+ output_zip, os.path.join(images_path, image), image)
done = True
if not done:
@@ -139,7 +141,13 @@
finally:
print "cleaning up..."
+ # http://b/18015246
+ # See common.py for context. zipfile also refers to ZIP64_LIMIT during
+ # close() when it writes out the central directory.
+ saved_zip64_limit = zipfile.ZIP64_LIMIT
+ zipfile.ZIP64_LIMIT = (1 << 32) - 1
output_zip.close()
+ zipfile.ZIP64_LIMIT = saved_zip64_limit
shutil.rmtree(OPTIONS.input_tmp)
print "done."
diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files
index 945f11a..b71baf9 100755
--- a/tools/releasetools/ota_from_target_files
+++ b/tools/releasetools/ota_from_target_files
@@ -349,8 +349,9 @@
partition = itemset.partition
for info in input_zip.infolist():
- if info.filename.startswith(partition.upper() + "/"):
- basefilename = info.filename[7:]
+ prefix = partition.upper() + "/"
+ if info.filename.startswith(prefix):
+ basefilename = info.filename[len(prefix):]
if IsSymlink(info):
symlinks.append((input_zip.read(info.filename),
"/" + partition + "/" + basefilename))
@@ -646,10 +647,8 @@
WriteMetadata(metadata, output_zip)
-def WritePolicyConfig(file_context, output_zip):
- f = open(file_context, 'r');
- basename = os.path.basename(file_context)
- common.ZipWriteStr(output_zip, basename, f.read())
+def WritePolicyConfig(file_name, output_zip):
+ common.ZipWrite(output_zip, file_name, os.path.basename(file_name))
def WriteMetadata(metadata, output_zip):
@@ -665,7 +664,7 @@
prefix = partition.upper() + "/"
for info in z.infolist():
if info.filename.startswith(prefix) and not IsSymlink(info):
- basefilename = info.filename[7:]
+ basefilename = info.filename[len(prefix):]
fn = partition + "/" + basefilename
data = z.read(info.filename)
out[fn] = common.File(fn, data)
@@ -740,8 +739,16 @@
system_src = GetImage("system", OPTIONS.source_tmp, OPTIONS.source_info_dict)
system_tgt = GetImage("system", OPTIONS.target_tmp, OPTIONS.target_info_dict)
+
+ blockimgdiff_version = 1
+ if OPTIONS.info_dict:
+ blockimgdiff_version = max(
+ int(i) for i in
+ OPTIONS.info_dict.get("blockimgdiff_versions", "1").split(","))
+
system_diff = common.BlockDifference("system", system_tgt, system_src,
- check_first_block=True)
+ check_first_block=True,
+ version=blockimgdiff_version)
if HasVendorPartition(target_zip):
if not HasVendorPartition(source_zip):
@@ -749,7 +756,8 @@
vendor_src = GetImage("vendor", OPTIONS.source_tmp, OPTIONS.source_info_dict)
vendor_tgt = GetImage("vendor", OPTIONS.target_tmp, OPTIONS.target_info_dict)
vendor_diff = common.BlockDifference("vendor", vendor_tgt, vendor_src,
- check_first_block=True)
+ check_first_block=True,
+ version=blockimgdiff_version)
else:
vendor_diff = None
@@ -810,11 +818,22 @@
device_specific.IncrementalOTA_VerifyBegin()
if oem_props is None:
- script.AssertSomeFingerprint(source_fp, target_fp)
+ # 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:
+ script.AssertSomeFingerprint(source_fp)
+ else:
+ script.AssertSomeFingerprint(source_fp, target_fp)
else:
- script.AssertSomeThumbprint(
- GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict),
- GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
+ if blockimgdiff_version <= 2:
+ script.AssertSomeThumbprint(
+ GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
+ else:
+ script.AssertSomeThumbprint(
+ GetBuildProp("ro.build.thumbprint", OPTIONS.target_info_dict),
+ GetBuildProp("ro.build.thumbprint", OPTIONS.source_info_dict))
if updating_boot:
boot_type, boot_device = common.GetTypeAndDevice("/boot", OPTIONS.info_dict)
diff --git a/tools/releasetools/test_common.py b/tools/releasetools/test_common.py
new file mode 100644
index 0000000..5fdc132
--- /dev/null
+++ b/tools/releasetools/test_common.py
@@ -0,0 +1,110 @@
+#
+# Copyright (C) 2015 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.
+#
+import os
+import tempfile
+import time
+import unittest
+import zipfile
+
+import common
+
+
+def random_string_with_holes(size, block_size, step_size):
+ data = ["\0"] * size
+ for begin in range(0, size, step_size):
+ end = begin + block_size
+ data[begin:end] = os.urandom(block_size)
+ return "".join(data)
+
+
+class CommonZipTest(unittest.TestCase):
+ def _test_ZipWrite(self, contents, extra_zipwrite_args=None):
+ extra_zipwrite_args = dict(extra_zipwrite_args or {})
+
+ test_file = tempfile.NamedTemporaryFile(delete=False)
+ zip_file = tempfile.NamedTemporaryFile(delete=False)
+
+ test_file_name = test_file.name
+ zip_file_name = zip_file.name
+
+ # File names within an archive strip the leading slash.
+ arcname = extra_zipwrite_args.get("arcname", test_file_name)
+ if arcname[0] == "/":
+ arcname = arcname[1:]
+
+ zip_file.close()
+ zip_file = zipfile.ZipFile(zip_file_name, "w")
+
+ try:
+ test_file.write(contents)
+ test_file.close()
+
+ old_stat = os.stat(test_file_name)
+ expected_mode = extra_zipwrite_args.get("perms", 0o644)
+
+ time.sleep(5) # Make sure the atime/mtime will change measurably.
+
+ common.ZipWrite(zip_file, test_file_name, **extra_zipwrite_args)
+
+ new_stat = os.stat(test_file_name)
+ self.assertEqual(int(old_stat.st_mode), int(new_stat.st_mode))
+ self.assertEqual(int(old_stat.st_mtime), int(new_stat.st_mtime))
+ self.assertIsNone(zip_file.testzip())
+
+ zip_file.close()
+ zip_file = zipfile.ZipFile(zip_file_name, "r")
+ info = zip_file.getinfo(arcname)
+
+ self.assertEqual(info.date_time, (2009, 1, 1, 0, 0, 0))
+ mode = (info.external_attr >> 16) & 0o777
+ self.assertEqual(mode, expected_mode)
+ self.assertEqual(zip_file.read(arcname), contents)
+ self.assertIsNone(zip_file.testzip())
+ finally:
+ os.remove(test_file_name)
+ os.remove(zip_file_name)
+
+ def test_ZipWrite(self):
+ file_contents = os.urandom(1024)
+ self._test_ZipWrite(file_contents)
+
+ def test_ZipWrite_with_opts(self):
+ file_contents = os.urandom(1024)
+ self._test_ZipWrite(file_contents, {
+ "arcname": "foobar",
+ "perms": 0o777,
+ "compress_type": zipfile.ZIP_DEFLATED,
+ })
+
+ def test_ZipWrite_large_file(self):
+ kilobytes = 1024
+ megabytes = 1024 * kilobytes
+ gigabytes = 1024 * megabytes
+
+ size = int(2 * gigabytes + 1)
+ block_size = 4 * kilobytes
+ step_size = 4 * megabytes
+ file_contents = random_string_with_holes(
+ size, block_size, step_size)
+ self._test_ZipWrite(file_contents, {
+ "compress_type": zipfile.ZIP_DEFLATED,
+ })
+
+ def test_ZipWrite_resets_ZIP64_LIMIT(self):
+ default_limit = (1 << 31) - 1
+ self.assertEqual(default_limit, zipfile.ZIP64_LIMIT)
+ self._test_ZipWrite('')
+ self.assertEqual(default_limit, zipfile.ZIP64_LIMIT)