Example #1
0
def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
  logger.info("creating " + what + ".img...")

  image_props = build_image.ImagePropFromGlobalDict(info_dict, what)
  fstab = info_dict["fstab"]
  mount_point = "/" + what
  if fstab and mount_point in fstab:
    image_props["fs_type"] = fstab[mount_point].fs_type

  image_props["timestamp"] = FIXED_FILE_TIMESTAMP

  if what == "system":
    fs_config_prefix = ""
  else:
    fs_config_prefix = what + "_"

  fs_config = os.path.join(
      input_dir, "META/" + fs_config_prefix + "filesystem_config.txt")
  if not os.path.exists(fs_config):
    fs_config = None

  # Override values loaded from info_dict.
  if fs_config:
    image_props["fs_config"] = fs_config
  if block_list:
    image_props["block_list"] = block_list.name

  # Use repeatable ext4 FS UUID and hash_seed UUID (based on partition name and
  # build fingerprint).
  uuid_seed = what + "-"
  if "build.prop" in info_dict:
    build_prop = info_dict["build.prop"]
    if "ro.build.fingerprint" in build_prop:
      uuid_seed += build_prop["ro.build.fingerprint"]
    elif "ro.build.thumbprint" in build_prop:
      uuid_seed += build_prop["ro.build.thumbprint"]
  image_props["uuid"] = str(uuid.uuid5(uuid.NAMESPACE_URL, uuid_seed))
  hash_seed = "hash_seed-" + uuid_seed
  image_props["hash_seed"] = str(uuid.uuid5(uuid.NAMESPACE_URL, hash_seed))

  build_image.BuildImage(
      os.path.join(input_dir, what.upper()), image_props, output_file.name)

  output_file.Write()
  if block_list:
    block_list.Write()

  # Set the '_image_size' for given image size.
  is_verity_partition = "verity_block_device" in image_props
  verity_supported = (image_props.get("verity") == "true" or
                      image_props.get("avb_enable") == "true")
  is_avb_enable = image_props.get("avb_hashtree_enable") == "true"
  if verity_supported and (is_verity_partition or is_avb_enable):
    image_size = image_props.get("image_size")
    if image_size:
      image_size_key = what + "_image_size"
      info_dict[image_size_key] = int(image_size)

  use_dynamic_size = (
      info_dict.get("use_dynamic_partition_size") == "true" and
      what in shlex.split(info_dict.get("dynamic_partition_list", "").strip()))
  if use_dynamic_size:
    info_dict.update(build_image.GlobalDictFromImageProp(image_props, what))
Example #2
0
def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
    print("creating " + what + ".img...")

    # The name of the directory it is making an image out of matters to
    # mkyaffs2image.  It wants "system" but we have a directory named
    # "SYSTEM", so create a symlink.
    temp_dir = tempfile.mkdtemp()
    OPTIONS.tempfiles.append(temp_dir)
    try:
        os.symlink(os.path.join(input_dir, what.upper()),
                   os.path.join(temp_dir, what))
    except OSError as e:
        # bogus error on my mac version?
        #   File "./build/tools/releasetools/img_from_target_files"
        #     os.path.join(OPTIONS.input_tmp, "system"))
        # OSError: [Errno 17] File exists
        if e.errno == errno.EEXIST:
            pass

    image_props = build_image.ImagePropFromGlobalDict(info_dict, what)
    fstab = info_dict["fstab"]
    mount_point = "/" + what
    if fstab and mount_point in fstab:
        image_props["fs_type"] = fstab[mount_point].fs_type

    # Use a fixed timestamp (01/01/2009) when packaging the image.
    # Bug: 24377993
    epoch = datetime.datetime.fromtimestamp(0)
    timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
    image_props["timestamp"] = int(timestamp)

    if what == "system":
        fs_config_prefix = ""
    else:
        fs_config_prefix = what + "_"

    fs_config = os.path.join(
        input_dir, "META/" + fs_config_prefix + "filesystem_config.txt")
    if not os.path.exists(fs_config):
        fs_config = None

    # Override values loaded from info_dict.
    if fs_config:
        image_props["fs_config"] = fs_config
    if block_list:
        image_props["block_list"] = block_list.name

    # Use repeatable ext4 FS UUID and hash_seed UUID (based on partition name and
    # build fingerprint).
    uuid_seed = what + "-"
    if "build.prop" in info_dict:
        build_prop = info_dict["build.prop"]
        if "ro.build.fingerprint" in build_prop:
            uuid_seed += build_prop["ro.build.fingerprint"]
        elif "ro.build.thumbprint" in build_prop:
            uuid_seed += build_prop["ro.build.thumbprint"]
    image_props["uuid"] = str(uuid.uuid5(uuid.NAMESPACE_URL, uuid_seed))
    hash_seed = "hash_seed-" + uuid_seed
    image_props["hash_seed"] = str(uuid.uuid5(uuid.NAMESPACE_URL, hash_seed))

    succ = build_image.BuildImage(os.path.join(temp_dir, what), image_props,
                                  output_file.name)
    assert succ, "build " + what + ".img image failed"

    if what == "system":
        img_out = os.path.join(os.environ["OUT"], "system.img")
        print("get system.img from ota")
        shutil.copyfile(output_file.name, img_out)

    if what == "vendor":
        print("get vendor.img from ota")
        img_out = os.path.join(os.environ["OUT"], "vendor.img")
        shutil.copyfile(output_file.name, img_out)

    if what == "oem":
        print("get oem.img from ota")
        img_out = os.path.join(os.environ["OUT"], "oem.img")
        shutil.copyfile(output_file.name, img_out)

    output_file.Write()
    if block_list:
        block_list.Write()

    # Set the 'adjusted_partition_size' that excludes the verity blocks of the
    # given image. When avb is enabled, this size is the max image size returned
    # by the avb tool.
    is_verity_partition = "verity_block_device" in image_props
    verity_supported = (image_props.get("verity") == "true"
                        or image_props.get("avb_enable") == "true")
    is_avb_enable = image_props.get("avb_hashtree_enable") == "true"
    if verity_supported and (is_verity_partition or is_avb_enable):
        adjusted_blocks_value = image_props.get("partition_size")
        if adjusted_blocks_value:
            adjusted_blocks_key = what + "_adjusted_partition_size"
            info_dict[
                adjusted_blocks_key] = int(adjusted_blocks_value) / 4096 - 1
Example #3
0
  if what == "system":
    fs_config_prefix = ""
  else:
    fs_config_prefix = what + "_"

  fs_config = os.path.join(
      input_dir, "META/" + fs_config_prefix + "filesystem_config.txt")
  if not os.path.exists(fs_config): fs_config = None

  fc_config = os.path.join(input_dir, "BOOT/RAMDISK/file_contexts")
  if not os.path.exists(fc_config): fc_config = None

  succ = build_image.BuildImage(os.path.join(input_dir, what),
                                image_props, img,
                                fs_config=fs_config,
                                fc_config=fc_config,
                                block_list=block_list)
  assert succ, "build " + what + ".img image failed"

  return img


def AddUserdata(output_zip, prefix="IMAGES/"):
  """Create an empty userdata image and store it in output_zip."""

  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,)
    return
def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
    print("creating " + what + ".img...")

    # The name of the directory it is making an image out of matters to
    # mkyaffs2image.  It wants "system" but we have a directory named
    # "SYSTEM", so create a symlink.
    temp_dir = tempfile.mkdtemp()
    OPTIONS.tempfiles.append(temp_dir)
    try:
        os.symlink(os.path.join(input_dir, what.upper()),
                   os.path.join(temp_dir, what))
    except OSError as e:
        # bogus error on my mac version?
        #   File "./build/tools/releasetools/img_from_target_files"
        #     os.path.join(OPTIONS.input_tmp, "system"))
        # OSError: [Errno 17] File exists
        if e.errno == errno.EEXIST:
            pass

    image_props = build_image.ImagePropFromGlobalDict(info_dict, what)
    fstab = info_dict["fstab"]
    mount_point = "/" + what
    if fstab and mount_point in fstab:
        image_props["fs_type"] = fstab[mount_point].fs_type

    # Use a fixed timestamp (01/01/2009) when packaging the image.
    # Bug: 24377993
    epoch = datetime.datetime.fromtimestamp(0)
    timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
    image_props["timestamp"] = int(timestamp)

    if what == "system":
        fs_config_prefix = ""
    else:
        fs_config_prefix = what + "_"

    fs_config = os.path.join(
        input_dir, "META/" + fs_config_prefix + "filesystem_config.txt")
    if not os.path.exists(fs_config):
        fs_config = None

    # Override values loaded from info_dict.
    if fs_config:
        image_props["fs_config"] = fs_config
    if block_list:
        image_props["block_list"] = block_list.name

    succ = build_image.BuildImage(os.path.join(temp_dir, what), image_props,
                                  output_file.name)
    assert succ, "build " + what + ".img image failed"

    output_file.Write()
    if block_list:
        block_list.Write()

    is_verity_partition = "verity_block_device" in image_props
    verity_supported = image_props.get("verity") == "true"
    if is_verity_partition and verity_supported:
        adjusted_blocks_value = image_props.get("partition_size")
        if adjusted_blocks_value:
            adjusted_blocks_key = what + "_adjusted_partition_size"
            info_dict[
                adjusted_blocks_key] = int(adjusted_blocks_value) / 4096 - 1
def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
    print("creating " + what + ".img...")

    image_props = build_image.ImagePropFromGlobalDict(info_dict, what)
    fstab = info_dict["fstab"]
    mount_point = "/" + what
    if fstab and mount_point in fstab:
        image_props["fs_type"] = fstab[mount_point].fs_type

    # Use a fixed timestamp (01/01/2009) when packaging the image.
    # Bug: 24377993
    epoch = datetime.datetime.fromtimestamp(0)
    timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
    image_props["timestamp"] = int(timestamp)

    if what == "system":
        fs_config_prefix = ""
    else:
        fs_config_prefix = what + "_"

    fs_config = os.path.join(
        input_dir, "META/" + fs_config_prefix + "filesystem_config.txt")
    if not os.path.exists(fs_config):
        fs_config = None

    # Override values loaded from info_dict.
    if fs_config:
        image_props["fs_config"] = fs_config
    if block_list:
        image_props["block_list"] = block_list.name

    # Use repeatable ext4 FS UUID and hash_seed UUID (based on partition name and
    # build fingerprint).
    uuid_seed = what + "-"
    if "build.prop" in info_dict:
        build_prop = info_dict["build.prop"]
        if "ro.build.fingerprint" in build_prop:
            uuid_seed += build_prop["ro.build.fingerprint"]
        elif "ro.build.thumbprint" in build_prop:
            uuid_seed += build_prop["ro.build.thumbprint"]
    image_props["uuid"] = str(uuid.uuid5(uuid.NAMESPACE_URL, uuid_seed))
    hash_seed = "hash_seed-" + uuid_seed
    image_props["hash_seed"] = str(uuid.uuid5(uuid.NAMESPACE_URL, hash_seed))

    succ = build_image.BuildImage(os.path.join(input_dir, what.upper()),
                                  image_props, output_file.name)
    assert succ, "build " + what + ".img image failed"

    output_file.Write()
    if block_list:
        block_list.Write()

    # Set the 'adjusted_partition_size' that excludes the verity blocks of the
    # given image. When avb is enabled, this size is the max image size returned
    # by the avb tool.
    is_verity_partition = "verity_block_device" in image_props
    verity_supported = (image_props.get("verity") == "true"
                        or image_props.get("avb_enable") == "true")
    is_avb_enable = image_props.get("avb_hashtree_enable") == "true"
    if verity_supported and (is_verity_partition or is_avb_enable):
        adjusted_blocks_value = image_props.get("partition_size")
        if adjusted_blocks_value:
            adjusted_blocks_key = what + "_adjusted_partition_size"
            info_dict[
                adjusted_blocks_key] = int(adjusted_blocks_value) / 4096 - 1
def CreateImage(input_dir, info_dict, what, block_list=None):
    print("creating " + what + ".img...")

    img = common.MakeTempFile(prefix=what + "-", suffix=".img")

    # The name of the directory it is making an image out of matters to
    # mkyaffs2image.  It wants "system" but we have a directory named
    # "SYSTEM", so create a symlink.
    try:
        os.symlink(os.path.join(input_dir, what.upper()),
                   os.path.join(input_dir, what))
    except OSError as e:
        # bogus error on my mac version?
        #   File "./build/tools/releasetools/img_from_target_files"
        #     os.path.join(OPTIONS.input_tmp, "system"))
        # OSError: [Errno 17] File exists
        if e.errno == errno.EEXIST:
            pass

    image_props = build_image.ImagePropFromGlobalDict(info_dict, what)
    fstab = info_dict["fstab"]
    if fstab:
        image_props["fs_type"] = fstab["/" + what].fs_type

    # Use a fixed timestamp (01/01/2009) when packaging the image.
    # Bug: 24377993
    epoch = datetime.datetime.fromtimestamp(0)
    timestamp = (datetime.datetime(2009, 1, 1) - epoch).total_seconds()
    image_props["timestamp"] = int(timestamp)

    if what == "system":
        fs_config_prefix = ""
    else:
        fs_config_prefix = what + "_"

    fs_config = os.path.join(
        input_dir, "META/" + fs_config_prefix + "filesystem_config.txt")
    if not os.path.exists(fs_config):
        fs_config = None

    fc_config = os.path.join(input_dir, "BOOT/RAMDISK/file_contexts")
    if not os.path.exists(fc_config):
        fc_config = None

    # Override values loaded from info_dict.
    if fs_config:
        image_props["fs_config"] = fs_config
    if fc_config:
        image_props["selinux_fc"] = fc_config
    if block_list:
        image_props["block_list"] = block_list
    if image_props.get("system_root_image") == "true":
        image_props["ramdisk_dir"] = os.path.join(input_dir, "BOOT/RAMDISK")
        image_props["ramdisk_fs_config"] = os.path.join(
            input_dir, "META/boot_filesystem_config.txt")

    succ = build_image.BuildImage(os.path.join(input_dir, what), image_props,
                                  img)
    assert succ, "build " + what + ".img image failed"

    return img