diff options
Diffstat (limited to 'tools/releasetools/add_img_to_target_files.py')
-rwxr-xr-x | tools/releasetools/add_img_to_target_files.py | 85 |
1 files changed, 68 insertions, 17 deletions
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py index f2bf1e1..b132963 100755 --- a/tools/releasetools/add_img_to_target_files.py +++ b/tools/releasetools/add_img_to_target_files.py @@ -22,10 +22,12 @@ add them to the zipfile. Usage: add_img_to_target_files target_files """ +from __future__ import print_function + import sys if sys.hexversion < 0x02070000: - print >> sys.stderr, "Python 2.7 or newer is required." + print("Python 2.7 or newer is required.", file=sys.stderr) sys.exit(1) import datetime @@ -51,7 +53,7 @@ def AddSystem(output_zip, prefix="IMAGES/", recovery_img=None, boot_img=None): prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "system.img") if os.path.exists(prebuilt_path): - print "system.img already exists in %s, no need to rebuild..." % (prefix,) + print("system.img already exists in %s, no need to rebuild..." % prefix) return def output_sink(fn, data): @@ -60,7 +62,7 @@ def AddSystem(output_zip, prefix="IMAGES/", recovery_img=None, boot_img=None): ofile.close() if OPTIONS.rebuild_recovery: - print "Building new recovery patch" + print("Building new recovery patch") common.MakeRecoveryPatch(OPTIONS.input_tmp, output_sink, recovery_img, boot_img, info_dict=OPTIONS.info_dict) @@ -83,7 +85,7 @@ def AddVendor(output_zip, prefix="IMAGES/"): prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "vendor.img") if os.path.exists(prebuilt_path): - print "vendor.img already exists in %s, no need to rebuild..." % (prefix,) + print("vendor.img already exists in %s, no need to rebuild..." % prefix) return block_list = common.MakeTempFile(prefix="vendor-blocklist-", suffix=".map") @@ -100,7 +102,7 @@ def BuildVendor(input_dir, info_dict, block_list=None): def CreateImage(input_dir, info_dict, what, block_list=None): - print "creating " + what + ".img..." + print("creating " + what + ".img...") img = common.MakeTempFile(prefix=what + "-", suffix=".img") @@ -167,7 +169,7 @@ def AddUserdata(output_zip, prefix="IMAGES/"): prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "userdata.img") if os.path.exists(prebuilt_path): - 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 image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, @@ -178,7 +180,7 @@ def AddUserdata(output_zip, prefix="IMAGES/"): not image_props.get("partition_size")): return - print "creating userdata.img..." + print("creating userdata.img...") # Use a fixed timestamp (01/01/2009) when packaging the image. # Bug: 24377993 @@ -207,12 +209,59 @@ def AddUserdata(output_zip, prefix="IMAGES/"): os.rmdir(temp_dir) +def AddUserdataExtra(output_zip, prefix="IMAGES/"): + """Create extra userdata image and store it in output_zip.""" + + image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, + "data_extra") + + # The build system has to explicitly request extra userdata. + if "fs_type" not in image_props: + return + + extra_name = image_props.get("partition_name", "extra") + + prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "userdata_%s.img" % extra_name) + if os.path.exists(prebuilt_path): + print("userdata_%s.img already exists in %s, no need to rebuild..." % (extra_name, prefix,)) + return + + # We only allow yaffs to have a 0/missing partition_size. + # Extfs, f2fs must have a size. Skip userdata_extra.img if no size. + if (not image_props.get("fs_type", "").startswith("yaffs") and + not image_props.get("partition_size")): + return + + print("creating userdata_%s.img..." % extra_name) + + # 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. + temp_dir = tempfile.mkdtemp() + user_dir = os.path.join(temp_dir, "data") + os.mkdir(user_dir) + img = tempfile.NamedTemporaryFile() + + fstab = OPTIONS.info_dict["fstab"] + if fstab: + image_props["fs_type" ] = fstab["/data"].fs_type + succ = build_image.BuildImage(user_dir, image_props, img.name) + assert succ, "build userdata_%s.img image failed" % extra_name + + # Disable size check since this fetches original data partition size + #common.CheckSize(img.name, "userdata_extra.img", OPTIONS.info_dict) + output_zip.write(img.name, prefix + "userdata_%s.img" % extra_name) + img.close() + os.rmdir(user_dir) + os.rmdir(temp_dir) + + def AddCache(output_zip, prefix="IMAGES/"): """Create an empty cache image and store it in output_zip.""" prebuilt_path = os.path.join(OPTIONS.input_tmp, prefix, "cache.img") if os.path.exists(prebuilt_path): - 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 image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict, @@ -221,7 +270,7 @@ def AddCache(output_zip, prefix="IMAGES/"): if "fs_type" not in image_props: return - print "creating cache.img..." + print("creating cache.img...") # Use a fixed timestamp (01/01/2009) when packaging the image. # Bug: 24377993 @@ -256,7 +305,7 @@ def AddImagesToTargetFiles(filename): if not OPTIONS.add_missing: for n in input_zip.namelist(): if n.startswith("IMAGES/"): - print "target_files appears to already contain images." + print("target_files appears to already contain images.") sys.exit(1) try: @@ -275,13 +324,13 @@ def AddImagesToTargetFiles(filename): compression=zipfile.ZIP_DEFLATED) def banner(s): - print "\n\n++++ " + s + " ++++\n\n" + print("\n\n++++ " + s + " ++++\n\n") banner("boot") prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", "boot.img") boot_image = None if os.path.exists(prebuilt_path): - print "boot.img already exists in IMAGES/, no need to rebuild..." + print("boot.img already exists in IMAGES/, no need to rebuild...") if OPTIONS.rebuild_recovery: boot_image = common.GetBootableImage( "IMAGES/boot.img", "boot.img", OPTIONS.input_tmp, "BOOT") @@ -295,7 +344,7 @@ def AddImagesToTargetFiles(filename): recovery_image = None prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", "recovery.img") if os.path.exists(prebuilt_path): - print "recovery.img already exists in IMAGES/, no need to rebuild..." + print("recovery.img already exists in IMAGES/, no need to rebuild...") if OPTIONS.rebuild_recovery: recovery_image = common.GetBootableImage( "IMAGES/recovery.img", "recovery.img", OPTIONS.input_tmp, "RECOVERY") @@ -312,6 +361,8 @@ def AddImagesToTargetFiles(filename): AddVendor(output_zip) banner("userdata") AddUserdata(output_zip) + banner("extrauserdata") + AddUserdataExtra(output_zip) banner("cache") AddCache(output_zip) @@ -347,16 +398,16 @@ def main(argv): sys.exit(1) AddImagesToTargetFiles(args[0]) - print "done." + print("done.") if __name__ == '__main__': try: common.CloseInheritedPipes() main(sys.argv[1:]) except common.ExternalError as e: - print - print " ERROR: %s" % (e,) - print + print() + print(" ERROR: %s" % e) + print() sys.exit(1) finally: common.Cleanup() |