Exemplo n.º 1
0
def BuildSuperEmpty():
    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"))
    # Regenerate super_empty.img if both partial builds enable DAP. If only the
    # the vendor build enables DAP, the vendor build's existing super_empty.img
    # will be reused. If only the framework build should enable DAP, super_empty
    # should be included in the --framework_images flag to copy the existing
    # super_empty.img from the framework build.
    if (framework_dict.get("use_dynamic_partitions")
            == "true") and (vendor_dict.get("use_dynamic_partitions")
                            == "true"):
        logger.info("Building super_empty.img.")
        merged_dict = dict(vendor_dict)
        merged_dict.update(
            common.MergeDynamicPartitionInfoDicts(
                framework_dict=framework_dict,
                vendor_dict=vendor_dict,
                size_prefix="super_",
                size_suffix="_group_size",
                list_prefix="super_",
                list_suffix="_partition_list"))
        output_super_empty_path = os.path.join(OPTIONS.product_out_vendor,
                                               "super_empty.img")
        build_super_image.BuildSuperImage(merged_dict, output_super_empty_path)
def generate_super_empty_image(target_dir, output_super_empty):
    """Generates super_empty image from target package.

  Args:
    target_dir: Path to the target file package which contains misc_info.txt for
      detailed information for super image.
    output_super_empty: If provided, copies a super_empty.img file from the
      target files package to this path.
  """
    # Create super_empty.img using the merged misc_info.txt.

    misc_info_txt = os.path.join(target_dir, 'META', 'misc_info.txt')

    use_dynamic_partitions = common.LoadDictionaryFromFile(misc_info_txt).get(
        'use_dynamic_partitions')

    if use_dynamic_partitions != 'true' and output_super_empty:
        raise ValueError(
            'Building super_empty.img requires use_dynamic_partitions=true.')
    elif use_dynamic_partitions == 'true':
        super_empty_img = os.path.join(target_dir, 'IMAGES', 'super_empty.img')
        build_super_image_args = [
            misc_info_txt,
            super_empty_img,
        ]
        build_super_image.main(build_super_image_args)

        # Copy super_empty.img to the user-provided output_super_empty location.
        if output_super_empty:
            shutil.copyfile(super_empty_img, output_super_empty)
Exemplo n.º 3
0
def CheckPartitionSizes(inp):
    if isinstance(inp, str):
        info_dict = common.LoadDictionaryFromFile(inp)
        return DynamicPartitionSizeChecker(info_dict).Run()
    if isinstance(inp, dict):
        return DynamicPartitionSizeChecker(inp).Run()
    raise ValueError("{} is not a dictionary or a valid path".format(inp))
def process_dynamic_partitions_info_txt(framework_target_files_dir,
                                        vendor_target_files_dir,
                                        output_target_files_dir):
    """Performs special processing for META/dynamic_partitions_info.txt.

  This function merges the contents of the META/dynamic_partitions_info.txt
  files from the framework directory and the vendor directory, placing the
  merged result in the output directory.

  This function does nothing if META/dynamic_partitions_info.txt from the vendor
  directory does not exist.

  Args:
    framework_target_files_dir: The name of a directory containing the special
      items extracted from the framework target files package.
    vendor_target_files_dir: The name of a directory containing the special
      items extracted from the vendor target files package.
    output_target_files_dir: The name of a directory that will be used to create
      the output target files package after all the special cases are processed.
  """

    if not os.path.exists(
            os.path.join(vendor_target_files_dir, 'META',
                         'dynamic_partitions_info.txt')):
        return

    dynamic_partitions_info_path = ['META', 'dynamic_partitions_info.txt']

    framework_dynamic_partitions_dict = common.LoadDictionaryFromFile(
        os.path.join(framework_target_files_dir,
                     *dynamic_partitions_info_path))
    vendor_dynamic_partitions_dict = common.LoadDictionaryFromFile(
        os.path.join(vendor_target_files_dir, *dynamic_partitions_info_path))

    merged_dynamic_partitions_dict = common.MergeDynamicPartitionInfoDicts(
        framework_dict=framework_dynamic_partitions_dict,
        vendor_dict=vendor_dynamic_partitions_dict,
        # META/dynamic_partitions_info.txt does not use dynamic_partition_list.
        include_dynamic_partition_list=False,
        size_suffix='_size',
        list_suffix='_partition_list')

    output_dynamic_partitions_info_txt = os.path.join(
        output_target_files_dir, 'META', 'dynamic_partitions_info.txt')
    write_sorted_data(data=merged_dynamic_partitions_dict,
                      path=output_dynamic_partitions_info_txt)
Exemplo n.º 5
0
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)
def process_misc_info_txt(framework_target_files_temp_dir,
                          vendor_target_files_temp_dir,
                          output_target_files_temp_dir,
                          framework_misc_info_keys):
    """Performs special processing for META/misc_info.txt.

  This function merges the contents of the META/misc_info.txt files from the
  framework directory and the vendor directory, placing the merged result in the
  output directory. The precondition in that the files are already extracted.
  The post condition is that the output META/misc_info.txt contains the merged
  content.

  Args:
    framework_target_files_temp_dir: The name of a directory containing the
      special items extracted from the framework target files package.
    vendor_target_files_temp_dir: The name of a directory containing the special
      items extracted from the vendor target files package.
    output_target_files_temp_dir: The name of a directory that will be used to
      create the output target files package after all the special cases are
      processed.
    framework_misc_info_keys: A list of keys to obtain from the framework
      instance of META/misc_info.txt. The remaining keys from the vendor
      instance.
  """

    misc_info_path = ['META', 'misc_info.txt']
    framework_dict = common.LoadDictionaryFromFile(
        os.path.join(framework_target_files_temp_dir, *misc_info_path))

    # We take most of the misc info from the vendor target files.

    merged_dict = common.LoadDictionaryFromFile(
        os.path.join(vendor_target_files_temp_dir, *misc_info_path))

    # Replace certain values in merged_dict with values from
    # framework_dict.

    for key in framework_misc_info_keys:
        merged_dict[key] = framework_dict[key]

    # Merge misc info keys used for Dynamic Partitions.
    if (merged_dict.get('use_dynamic_partitions')
            == 'true') and (framework_dict.get('use_dynamic_partitions')
                            == 'true'):
        merged_dynamic_partitions_dict = common.MergeDynamicPartitionInfoDicts(
            framework_dict=framework_dict,
            vendor_dict=merged_dict,
            size_prefix='super_',
            size_suffix='_group_size',
            list_prefix='super_',
            list_suffix='_partition_list')
        merged_dict.update(merged_dynamic_partitions_dict)
        # Ensure that add_img_to_target_files rebuilds super split images for
        # devices that retrofit dynamic partitions. This flag may have been set to
        # false in the partial builds to prevent duplicate building of super.img.
        merged_dict['build_super_partition'] = 'true'

    # Replace <image>_selinux_fc values with framework or vendor file_contexts.bin
    # depending on which dictionary the key came from.
    # Only the file basename is required because all selinux_fc properties are
    # replaced with the full path to the file under META/ when misc_info.txt is
    # loaded from target files for repacking. See common.py LoadInfoDict().
    for key in merged_dict:
        if key.endswith('_selinux_fc'):
            merged_dict[key] = 'vendor_file_contexts.bin'
    for key in framework_dict:
        if key.endswith('_selinux_fc'):
            merged_dict[key] = 'framework_file_contexts.bin'

    output_misc_info_txt = os.path.join(output_target_files_temp_dir, 'META',
                                        'misc_info.txt')
    write_sorted_data(data=merged_dict, path=output_misc_info_txt)