Pack file_contexts into target_files zip.
file_contexts (specified by SELINUX_FC) is needed both when building and (re)packaging. We used to use the copy in out/ when building, and looked for the copy in BOOT/RAMDISK/ when packaging from target_files zip. With system_root_image enabled, the file_contexts needed for building and packaging might be different from the one on device. So we explicitly pack the file as META/file_contexts in target_files zip. Also refactor out the overriding of selinux_fc property into common.LoadInfoDict(). Change-Id: I0781a147319148c76d989d8f29d5ef766a502dbd
This commit is contained in:
@@ -1482,6 +1482,7 @@ endif
|
|||||||
$(hide) $(ACP) $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
|
$(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) 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) $(ACP) $(SELINUX_FC) $(zip_root)/META/file_contexts
|
||||||
$(hide) echo "recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/misc_info.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
|
$(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
|
||||||
ifdef BOARD_FLASH_BLOCK_SIZE
|
ifdef BOARD_FLASH_BLOCK_SIZE
|
||||||
|
@@ -130,15 +130,9 @@ def CreateImage(input_dir, info_dict, what, block_list=None):
|
|||||||
if not os.path.exists(fs_config):
|
if not os.path.exists(fs_config):
|
||||||
fs_config = None
|
fs_config = None
|
||||||
|
|
||||||
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.
|
# Override values loaded from info_dict.
|
||||||
if fs_config:
|
if fs_config:
|
||||||
image_props["fs_config"] = fs_config
|
image_props["fs_config"] = fs_config
|
||||||
if fc_config:
|
|
||||||
image_props["selinux_fc"] = fc_config
|
|
||||||
if block_list:
|
if block_list:
|
||||||
image_props["block_list"] = block_list
|
image_props["block_list"] = block_list
|
||||||
if image_props.get("system_root_image") == "true":
|
if image_props.get("system_root_image") == "true":
|
||||||
@@ -167,8 +161,7 @@ def AddUserdata(output_zip, prefix="IMAGES/"):
|
|||||||
print "userdata.img already exists in %s, no need to rebuild..." % (prefix,)
|
print "userdata.img already exists in %s, no need to rebuild..." % (prefix,)
|
||||||
return
|
return
|
||||||
|
|
||||||
image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict,
|
image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, "data")
|
||||||
"data")
|
|
||||||
# We only allow yaffs to have a 0/missing partition_size.
|
# We only allow yaffs to have a 0/missing partition_size.
|
||||||
# Extfs, f2fs must have a size. Skip userdata.img if no size.
|
# Extfs, f2fs must have a size. Skip userdata.img if no size.
|
||||||
if (not image_props.get("fs_type", "").startswith("yaffs") and
|
if (not image_props.get("fs_type", "").startswith("yaffs") and
|
||||||
@@ -214,8 +207,7 @@ def AddCache(output_zip, prefix="IMAGES/"):
|
|||||||
print "cache.img already exists in %s, no need to rebuild..." % (prefix,)
|
print "cache.img already exists in %s, no need to rebuild..." % (prefix,)
|
||||||
return
|
return
|
||||||
|
|
||||||
image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict,
|
image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, "cache")
|
||||||
"cache")
|
|
||||||
# The build system has to explicitly request for cache.img.
|
# The build system has to explicitly request for cache.img.
|
||||||
if "fs_type" not in image_props:
|
if "fs_type" not in image_props:
|
||||||
return
|
return
|
||||||
@@ -258,10 +250,7 @@ def AddImagesToTargetFiles(filename):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
has_vendor = False
|
has_vendor = False
|
||||||
|
|
||||||
OPTIONS.info_dict = common.LoadInfoDict(input_zip)
|
OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.input_tmp)
|
||||||
if "selinux_fc" in OPTIONS.info_dict:
|
|
||||||
OPTIONS.info_dict["selinux_fc"] = os.path.join(
|
|
||||||
OPTIONS.input_tmp, "BOOT", "RAMDISK", "file_contexts")
|
|
||||||
|
|
||||||
common.ZipClose(input_zip)
|
common.ZipClose(input_zip)
|
||||||
output_zip = zipfile.ZipFile(filename, "a",
|
output_zip = zipfile.ZipFile(filename, "a",
|
||||||
|
@@ -97,7 +97,7 @@ def CloseInheritedPipes():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def LoadInfoDict(input_file):
|
def LoadInfoDict(input_file, input_dir=None):
|
||||||
"""Read and parse the META/misc_info.txt key/value pairs from the
|
"""Read and parse the META/misc_info.txt key/value pairs from the
|
||||||
input target files and return a dict."""
|
input target files and return a dict."""
|
||||||
|
|
||||||
@@ -148,6 +148,23 @@ def LoadInfoDict(input_file):
|
|||||||
if "fstab_version" not in d:
|
if "fstab_version" not in d:
|
||||||
d["fstab_version"] = "1"
|
d["fstab_version"] = "1"
|
||||||
|
|
||||||
|
# During building, we use the "file_contexts" in the out/ directory tree.
|
||||||
|
# It is no longer available when (re)generating from target_files zip. So
|
||||||
|
# when generating from target_files zip, we look for a copy under META/
|
||||||
|
# first, if not available search under BOOT/RAMDISK/. Note that we may need
|
||||||
|
# a different file_contexts to build images than the one running on device,
|
||||||
|
# such as when enabling system_root_image. In that case, we must have the
|
||||||
|
# one for building copied to META/.
|
||||||
|
if input_dir is not None:
|
||||||
|
fc_config = os.path.join(input_dir, "META", "file_contexts")
|
||||||
|
if not os.path.exists(fc_config):
|
||||||
|
fc_config = os.path.join(input_dir, "BOOT", "RAMDISK", "file_contexts")
|
||||||
|
if not os.path.exists(fc_config):
|
||||||
|
fc_config = None
|
||||||
|
|
||||||
|
if fc_config:
|
||||||
|
d["selinux_fc"] = fc_config
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = read_helper("META/imagesizes.txt")
|
data = read_helper("META/imagesizes.txt")
|
||||||
for line in data.split("\n"):
|
for line in data.split("\n"):
|
||||||
|
@@ -95,16 +95,7 @@ def main(argv):
|
|||||||
# images, so build them.
|
# images, so build them.
|
||||||
import add_img_to_target_files
|
import add_img_to_target_files
|
||||||
|
|
||||||
OPTIONS.info_dict = common.LoadInfoDict(input_zip)
|
OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.input_tmp)
|
||||||
|
|
||||||
# If this image was originally labelled with SELinux contexts,
|
|
||||||
# make sure we also apply the labels in our new image. During
|
|
||||||
# building, the "file_contexts" is in the out/ directory tree,
|
|
||||||
# but for repacking from target-files.zip it's in the root
|
|
||||||
# directory of the ramdisk.
|
|
||||||
if "selinux_fc" in OPTIONS.info_dict:
|
|
||||||
OPTIONS.info_dict["selinux_fc"] = os.path.join(
|
|
||||||
OPTIONS.input_tmp, "BOOT", "RAMDISK", "file_contexts")
|
|
||||||
|
|
||||||
boot_image = common.GetBootableImage(
|
boot_image = common.GetBootableImage(
|
||||||
"boot.img", "boot.img", OPTIONS.input_tmp, "BOOT")
|
"boot.img", "boot.img", OPTIONS.input_tmp, "BOOT")
|
||||||
|
@@ -582,6 +582,8 @@ else if get_stage("%(bcb_dev)s") == "3/3" then
|
|||||||
if HasVendorPartition(input_zip):
|
if HasVendorPartition(input_zip):
|
||||||
system_progress -= 0.1
|
system_progress -= 0.1
|
||||||
|
|
||||||
|
# Place a copy of file_contexts into the OTA package which will be used by
|
||||||
|
# the recovery program.
|
||||||
if "selinux_fc" in OPTIONS.info_dict:
|
if "selinux_fc" in OPTIONS.info_dict:
|
||||||
WritePolicyConfig(OPTIONS.info_dict["selinux_fc"], output_zip)
|
WritePolicyConfig(OPTIONS.info_dict["selinux_fc"], output_zip)
|
||||||
|
|
||||||
@@ -1538,15 +1540,7 @@ def main(argv):
|
|||||||
OPTIONS.input_tmp, input_zip = common.UnzipTemp(args[0])
|
OPTIONS.input_tmp, input_zip = common.UnzipTemp(args[0])
|
||||||
|
|
||||||
OPTIONS.target_tmp = OPTIONS.input_tmp
|
OPTIONS.target_tmp = OPTIONS.input_tmp
|
||||||
OPTIONS.info_dict = common.LoadInfoDict(input_zip)
|
OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.target_tmp)
|
||||||
|
|
||||||
# If this image was originally labelled with SELinux contexts, make sure we
|
|
||||||
# also apply the labels in our new image. During building, the "file_contexts"
|
|
||||||
# is in the out/ directory tree, but for repacking from target-files.zip it's
|
|
||||||
# in the root directory of the ramdisk.
|
|
||||||
if "selinux_fc" in OPTIONS.info_dict:
|
|
||||||
OPTIONS.info_dict["selinux_fc"] = os.path.join(
|
|
||||||
OPTIONS.input_tmp, "BOOT", "RAMDISK", "file_contexts")
|
|
||||||
|
|
||||||
if OPTIONS.verbose:
|
if OPTIONS.verbose:
|
||||||
print "--- target info ---"
|
print "--- target info ---"
|
||||||
@@ -1596,10 +1590,8 @@ def main(argv):
|
|||||||
OPTIONS.source_tmp, source_zip = common.UnzipTemp(
|
OPTIONS.source_tmp, source_zip = common.UnzipTemp(
|
||||||
OPTIONS.incremental_source)
|
OPTIONS.incremental_source)
|
||||||
OPTIONS.target_info_dict = OPTIONS.info_dict
|
OPTIONS.target_info_dict = OPTIONS.info_dict
|
||||||
OPTIONS.source_info_dict = common.LoadInfoDict(source_zip)
|
OPTIONS.source_info_dict = common.LoadInfoDict(source_zip,
|
||||||
if "selinux_fc" in OPTIONS.source_info_dict:
|
OPTIONS.source_tmp)
|
||||||
OPTIONS.source_info_dict["selinux_fc"] = os.path.join(
|
|
||||||
OPTIONS.source_tmp, "BOOT", "RAMDISK", "file_contexts")
|
|
||||||
if OPTIONS.package_key is None:
|
if OPTIONS.package_key is None:
|
||||||
OPTIONS.package_key = OPTIONS.source_info_dict.get(
|
OPTIONS.package_key = OPTIONS.source_info_dict.get(
|
||||||
"default_system_dev_certificate",
|
"default_system_dev_certificate",
|
||||||
|
Reference in New Issue
Block a user