From cc46eae994d919d444edd8bb504ef476a7ec3541 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 2 Jan 2019 11:51:19 -0800 Subject: [PATCH] Put system_other in super.img ... for launch A/B devices. Test: build super image and lpdump Bug: 113182233 Change-Id: I79ad9da2f6852b39b23e862ff00f320b6565db2f --- tools/releasetools/build_super_image.py | 52 ++++++++++++++++--------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/tools/releasetools/build_super_image.py b/tools/releasetools/build_super_image.py index e8730ae19a..bb0e6413af 100755 --- a/tools/releasetools/build_super_image.py +++ b/tools/releasetools/build_super_image.py @@ -67,6 +67,17 @@ def GetPartitionSizeFromImage(img): return os.path.getsize(img) +def GetArgumentsForImage(partition, group, image=None): + image_size = GetPartitionSizeFromImage(image) if image else 0 + + cmd = ["--partition", + "{}:readonly:{}:{}".format(partition, image_size, group)] + if image: + cmd += ["--image", "{}={}".format(partition, image)] + + return cmd + + def BuildSuperImageFromDict(info_dict, output): cmd = [info_dict["lpmake"], @@ -105,26 +116,25 @@ def BuildSuperImageFromDict(info_dict, output): for partition in partition_list: image = info_dict.get("{}_image".format(partition)) - image_size = 0 if image: - image_size = GetPartitionSizeFromImage(image) has_image = True - if append_suffix: - cmd += ["--partition", - "{}_a:readonly:{}:{}_a".format(partition, image_size, group), - "--partition", - "{}_b:readonly:0:{}_b".format(partition, group)] - if image: - # For A/B devices, super partition always contains sub-partitions in - # the _a slot, because this image should only be used for - # bootstrapping / initializing the device. When flashing the image, - # bootloader fastboot should always mark _a slot as bootable. - cmd += ["--image", "{}_a={}".format(partition, image)] - else: - cmd += ["--partition", - "{}:readonly:{}:{}".format(partition, image_size, group)] - if image: - cmd += ["--image", "{}={}".format(partition, image)] + + if not append_suffix: + cmd += GetArgumentsForImage(partition, group, image) + continue + + # For A/B devices, super partition always contains sub-partitions in + # the _a slot, because this image should only be used for + # bootstrapping / initializing the device. When flashing the image, + # bootloader fastboot should always mark _a slot as bootable. + cmd += GetArgumentsForImage(partition + "_a", group + "_a", image) + + other_image = None + if partition == "system" and "system_other_image" in info_dict: + other_image = info_dict["system_other_image"] + has_image = True + + cmd += GetArgumentsForImage(partition + "_b", group + "_b", other_image) if has_image: cmd.append("--sparse") @@ -145,6 +155,12 @@ def BuildSuperImageFromExtractedTargetFiles(inp, out): info_dict = common.LoadInfoDict(inp) partition_list = shlex.split( info_dict.get("dynamic_partition_list", "").strip()) + + if "system" in partition_list: + image_path = os.path.join(inp, "IMAGES", "system_other.img") + if os.path.isfile(image_path): + info_dict["system_other_image"] = image_path + missing_images = [] for partition in partition_list: image_path = os.path.join(inp, "IMAGES", "{}.img".format(partition))