Create userdata.img with real data when SANITIZE_TARGET=address.

Bug: 21785137
Change-Id: Ie0c36988759fe07419ad29bab5a71cdd0d992d2a
This commit is contained in:
Ying Wang 2015-06-25 13:56:53 -07:00
parent c9fcdae29d
commit 2a04839aec
3 changed files with 25 additions and 6 deletions

View File

@ -1474,6 +1474,10 @@ endif
ifneq ($(OEM_THUMBPRINT_PROPERTIES),)
# OTA scripts are only interested in fingerprint related properties
$(hide) echo "oem_fingerprint_properties=$(OEM_THUMBPRINT_PROPERTIES)" >> $(zip_root)/META/misc_info.txt
endif
ifeq ($(SANITIZE_TARGET),address)
# We need to create userdata.img with real data because the instrumented libraries are in userdata.img.
$(hide) echo "userdata_img_with_data=true" >> $(zip_root)/META/misc_info.txt
endif
$(call generate-userimage-prop-dictionary, $(zip_root)/META/misc_info.txt)
$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \

View File

@ -30,6 +30,7 @@ if sys.hexversion < 0x02070000:
import errno
import os
import shutil
import tempfile
import zipfile
@ -153,7 +154,13 @@ def CreateImage(input_dir, info_dict, what, block_list=None):
def AddUserdata(output_zip, prefix="IMAGES/"):
"""Create an empty userdata image and store it in output_zip."""
"""Create a userdata image and store it in output_zip.
In most case we just create and store an empty userdata.img;
But the invoker can also request to create userdata.img with real
data from the target files, by setting "userdata_img_with_data=true"
in OPTIONS.info_dict.
"""
prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "userdata.img")
if os.path.exists(prebuilt_path):
@ -172,10 +179,19 @@ def AddUserdata(output_zip, prefix="IMAGES/"):
# The name of the directory it is making an image out of matters to
# mkyaffs2image. So we create a temp dir, and within it we create an
# empty dir named "data", and build the image from that.
# empty dir named "data", or a symlink to the DATA dir,
# and build the image from that.
temp_dir = tempfile.mkdtemp()
user_dir = os.path.join(temp_dir, "data")
os.mkdir(user_dir)
empty = (OPTIONS.info_dict.get("userdata_img_with_data") != "true")
if empty:
# Create an empty dir.
os.mkdir(user_dir)
else:
# Symlink to the DATA dir.
os.symlink(os.path.join(OPTIONS.input_tmp, "DATA"),
user_dir)
img = tempfile.NamedTemporaryFile()
fstab = OPTIONS.info_dict["fstab"]
@ -187,8 +203,7 @@ def AddUserdata(output_zip, prefix="IMAGES/"):
common.CheckSize(img.name, "userdata.img", OPTIONS.info_dict)
common.ZipWrite(output_zip, img.name, prefix + "userdata.img")
img.close()
os.rmdir(user_dir)
os.rmdir(temp_dir)
shutil.rmtree(temp_dir)
def AddCache(output_zip, prefix="IMAGES/"):

View File

@ -31,7 +31,7 @@ import tempfile
FIXED_SALT = "aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7"
def RunCommand(cmd):
""" Echo and run the given command
""" Echo and run the given command.
Args:
cmd: the command represented as a list of strings.