summaryrefslogtreecommitdiffstats
path: root/tools/releasetools/img_from_target_files
diff options
context:
space:
mode:
Diffstat (limited to 'tools/releasetools/img_from_target_files')
-rwxr-xr-xtools/releasetools/img_from_target_files110
1 files changed, 49 insertions, 61 deletions
diff --git a/tools/releasetools/img_from_target_files b/tools/releasetools/img_from_target_files
index ad03398..002e6e6 100755
--- a/tools/releasetools/img_from_target_files
+++ b/tools/releasetools/img_from_target_files
@@ -27,10 +27,6 @@ Usage: img_from_target_files [flags] input_target_files output_image_zip
Include only the bootable images (eg 'boot' and 'recovery') in
the output.
- -S (--file_context) <file>
- the file contexts configuration used to assign SELinux file
- context attributes.
-
"""
import sys
@@ -51,10 +47,10 @@ import zipfile
if not hasattr(os, "SEEK_SET"):
os.SEEK_SET = 0
+import build_image
import common
OPTIONS = common.OPTIONS
-OPTIONS.selinux_fc = None
def AddUserdata(output_zip):
"""Create an empty userdata image and store it in output_zip."""
@@ -69,32 +65,13 @@ def AddUserdata(output_zip):
os.mkdir(user_dir)
img = tempfile.NamedTemporaryFile()
- build_command = []
+ image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict,
+ "data")
fstab = OPTIONS.info_dict["fstab"]
- if fstab and fstab["/data"].fs_type.startswith("ext"):
- build_command = ["mkuserimg.sh"]
- if "extfs_sparse_flag" in OPTIONS.info_dict:
- build_command.append(OPTIONS.info_dict["extfs_sparse_flag"])
- build_command.extend([user_dir, img.name,
- fstab["/data"].fs_type, "data"])
- if "userdata_size" in OPTIONS.info_dict:
- build_command.append(str(OPTIONS.info_dict["userdata_size"]))
- if OPTIONS.selinux_fc is not None:
- build_command.append(OPTIONS.selinux_fc)
- else:
- build_command = ["mkyaffs2image", "-f"]
- extra = OPTIONS.info_dict.get("mkyaffs2_extra_flags", None)
- if extra:
- build_command.extend(extra.split())
- build_command.append(user_dir)
- build_command.append(img.name)
- if OPTIONS.selinux_fc is not None:
- build_command.append(OPTIONS.selinux_fc)
- build_command.append("/data")
-
- p = common.Run(build_command);
- p.communicate()
- assert p.returncode == 0, "build userdata.img image failed"
+ if fstab:
+ image_props["fs_type" ] = fstab["/data"].fs_type
+ succ = build_image.BuildImage(user_dir, image_props, img.name)
+ assert succ, "build userdata.img image failed"
common.CheckSize(img.name, "userdata.img", OPTIONS.info_dict)
output_zip.write(img.name, "userdata.img")
@@ -103,6 +80,38 @@ def AddUserdata(output_zip):
os.rmdir(temp_dir)
+def AddCache(output_zip):
+ """Create an empty cache image and store it in output_zip."""
+
+ image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict,
+ "cache")
+ # The build system has to explicitly request for cache.img.
+ if "fs_type" not in image_props:
+ return
+
+ print "creating cache.img..."
+
+ # 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 "cache", and build the image from that.
+ temp_dir = tempfile.mkdtemp()
+ user_dir = os.path.join(temp_dir, "cache")
+ os.mkdir(user_dir)
+ img = tempfile.NamedTemporaryFile()
+
+ fstab = OPTIONS.info_dict["fstab"]
+ if fstab:
+ image_props["fs_type" ] = fstab["/cache"].fs_type
+ succ = build_image.BuildImage(user_dir, image_props, img.name)
+ assert succ, "build cache.img image failed"
+
+ common.CheckSize(img.name, "cache.img", OPTIONS.info_dict)
+ output_zip.write(img.name, "cache.img")
+ img.close()
+ os.rmdir(user_dir)
+ os.rmdir(temp_dir)
+
+
def AddSystem(output_zip):
"""Turn the contents of SYSTEM into a system image and store it in
output_zip."""
@@ -125,33 +134,14 @@ def AddSystem(output_zip):
if (e.errno == errno.EEXIST):
pass
- build_command = []
+ image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict,
+ "system")
fstab = OPTIONS.info_dict["fstab"]
- if fstab and fstab["/system"].fs_type.startswith("ext"):
-
- build_command = ["mkuserimg.sh"]
- if "extfs_sparse_flag" in OPTIONS.info_dict:
- build_command.append(OPTIONS.info_dict["extfs_sparse_flag"])
- build_command.extend([os.path.join(OPTIONS.input_tmp, "system"), img.name,
- fstab["/system"].fs_type, "system"])
- if "system_size" in OPTIONS.info_dict:
- build_command.append(str(OPTIONS.info_dict["system_size"]))
- if OPTIONS.selinux_fc is not None:
- build_command.append(OPTIONS.selinux_fc)
- else:
- build_command = ["mkyaffs2image", "-f"]
- extra = OPTIONS.info_dict.get("mkyaffs2_extra_flags", None)
- if extra:
- build_command.extend(extra.split())
- build_command.append(os.path.join(OPTIONS.input_tmp, "system"))
- build_command.append(img.name)
- if OPTIONS.selinux_fc is not None:
- build_command.append(OPTIONS.selinux_fc)
- build_command.append("/system")
-
- p = common.Run(build_command)
- p.communicate()
- assert p.returncode == 0, "build system.img image failed"
+ if fstab:
+ image_props["fs_type" ] = fstab["/system"].fs_type
+ succ = build_image.BuildImage(os.path.join(OPTIONS.input_tmp, "system"),
+ image_props, img.name)
+ assert succ, "build system.img image failed"
img.seek(os.SEEK_SET, 0)
data = img.read()
@@ -175,17 +165,14 @@ def main(argv):
pass # deprecated
if o in ("-z", "--bootable_zip"):
bootable_only[0] = True
- if o in ("-S", "--file_context"):
- OPTIONS.selinux_fc = a
else:
return False
return True
args = common.ParseOptions(argv, __doc__,
- extra_opts="b:zS:",
+ extra_opts="b:z",
extra_long_opts=["board_config=",
- "bootable_zip",
- "file_context="],
+ "bootable_zip"],
extra_option_handler=option_handler)
bootable_only = bootable_only[0]
@@ -208,6 +195,7 @@ def main(argv):
if not bootable_only:
AddSystem(output_zip)
AddUserdata(output_zip)
+ AddCache(output_zip)
CopyInfo(output_zip)
print "cleaning up..."