def AddVBMeta(output_zip, partitions, name, needed_partitions): """Creates a VBMeta image and stores it in output_zip. It generates the requested VBMeta image. The requested image could be for top-level or chained VBMeta image, which is determined based on the name. Args: output_zip: The output zip file, which needs to be already open. partitions: A dict that's keyed by partition names with image paths as values. Only valid partition names are accepted, as partitions listed in common.AVB_PARTITIONS and custom partitions listed in OPTIONS.info_dict.get("avb_custom_images_partition_list") name: Name of the VBMeta partition, e.g. 'vbmeta', 'vbmeta_system'. needed_partitions: Partitions whose descriptors should be included into the generated VBMeta image. Returns: Path to the created image. Raises: AssertionError: On invalid input args. """ assert needed_partitions, "Needed partitions must be specified" img = OutputFile(output_zip, OPTIONS.input_tmp, "IMAGES", "{}.img".format(name)) if os.path.exists(img.name): logger.info("%s.img already exists; not rebuilding...", name) return img.name common.BuildVBMeta(img.name, partitions, name, needed_partitions) img.Write() return img.name
def BuildVBMeta(): logger.info("Building vbmeta.img.") framework_dict = common.LoadDictionaryFromFile( os.path.join(OPTIONS.product_out_framework, "misc_info.txt")) vendor_dict = common.LoadDictionaryFromFile( os.path.join(OPTIONS.product_out_vendor, "misc_info.txt")) merged_dict = dict(vendor_dict) if OPTIONS.framework_misc_info_keys: for key in common.LoadListFromFile(OPTIONS.framework_misc_info_keys): merged_dict[key] = framework_dict[key] # Build vbmeta.img using partitions in product_out_vendor. partitions = {} for partition in common.AVB_PARTITIONS: partition_path = os.path.join(OPTIONS.product_out_vendor, "%s.img" % partition) if os.path.exists(partition_path): partitions[partition] = partition_path # vbmeta_partitions includes the partitions that should be included into # top-level vbmeta.img, which are the ones that are not included in any # chained VBMeta image plus the chained VBMeta images themselves. vbmeta_partitions = common.AVB_PARTITIONS[:] for partition in common.AVB_VBMETA_PARTITIONS: chained_partitions = merged_dict.get("avb_%s" % partition, "").strip() if chained_partitions: partitions[partition] = os.path.join(OPTIONS.product_out_vendor, "%s.img" % partition) vbmeta_partitions = [ item for item in vbmeta_partitions if item not in chained_partitions.split() ] vbmeta_partitions.append(partition) output_vbmeta_path = os.path.join(OPTIONS.product_out_vendor, "vbmeta.img") OPTIONS.info_dict = merged_dict common.BuildVBMeta(output_vbmeta_path, partitions, "vbmeta", vbmeta_partitions)