Esempio n. 1
0
def GenerateTestPayloads(target_image_path,
                         archive_dir,
                         full=False,
                         delta=False,
                         stateful=False):
    """Generates the payloads for hw testing.

  Args:
    target_image_path (str): The path to the image to generate payloads to.
    archive_dir (str): Where to store payloads we generated.
    full (bool): Generate full payloads.
    delta (bool): Generate delta payloads.
    stateful (bool): Generate stateful payload.

  Returns:
    list[str] - The list of payloads that were generated.
  """
    real_target = os.path.realpath(target_image_path)
    # The path to the target should look something like this:
    # .../link/R37-5952.0.2014_06_12_2302-a1/chromiumos_test_image.bin
    board, os_version = real_target.split('/')[-3:-1]
    prefix = 'chromeos'
    suffix = 'dev.bin'
    generated = []

    if full:
        # Names for full payloads look something like this:
        # chromeos_R37-5952.0.2014_06_12_2302-a1_link_full_dev.bin
        name = '_'.join([prefix, os_version, board, 'full', suffix])
        payload_path = os.path.join(archive_dir, name)
        paygen_payload_lib.GenerateUpdatePayload(target_image_path,
                                                 payload_path)
        generated.append(payload_path)

    if delta:
        # Names for delta payloads look something like this:
        # chromeos_R37-5952.0.2014_06_12_2302-a1_R37-
        # 5952.0.2014_06_12_2302-a1_link_delta_dev.bin
        name = '_'.join(
            [prefix, os_version, os_version, board, 'delta', suffix])
        payload_path = os.path.join(archive_dir, name)
        paygen_payload_lib.GenerateUpdatePayload(target_image_path,
                                                 payload_path,
                                                 src_image=target_image_path)
        generated.append(payload_path)

    if stateful:
        generated.append(
            paygen_stateful_payload_lib.GenerateStatefulPayload(
                target_image_path, archive_dir))

    return generated
Esempio n. 2
0
def main(argv):
  opts = ParseArguments(argv)

  if opts.kern_path:
    partition_lib.ExtractKernel(opts.image, opts.kern_path)
  if opts.root_path:
    partition_lib.ExtractRoot(opts.image, opts.root_path)
  if opts.root_pretruncate_path:
    partition_lib.ExtractRoot(opts.image, opts.root_pretruncate_path,
                              truncate=False)

  if opts.src_image:
    if opts.src_kern_path:
      partition_lib.ExtractKernel(opts.src_image, opts.src_kern_path)
    if opts.src_root_path:
      partition_lib.ExtractRoot(opts.src_image, opts.src_root_path)

  if opts.extract:
    # If we just wanted extraction, we did it, just return.
    logging.info('Done extracting kernel/root.')
    return

  if opts.payload:
    # We only want the payload's metadata. Create it and exit.
    logging.info('Generating payload properties file.')
    paygen_payload_lib.GenerateUpdatePayloadPropertiesFile(opts.payload,
                                                           opts.output)
    return

  return paygen_payload_lib.GenerateUpdatePayload(
      opts.image, opts.output, src_image=opts.src_image, work_dir=opts.work_dir,
      private_key=opts.private_key, check=opts.check,
      out_metadata_hash_file=opts.out_metadata_hash_file)
Esempio n. 3
0
    def _GeneratePayloads(self, tempdir):
        """Generate the update payloads we require.

    Args:
      tempdir: Temporary Directory to store the generated payloads.
    """
        # Devservers will look for a file named *_full_*.
        payload = os.path.join(tempdir, 'update_full_dev.bin')
        paygen_payload_lib.GenerateUpdatePayload(self.options.image, payload)
        paygen_stateful_payload_lib.GenerateStatefulPayload(
            self.options.image, tempdir)
Esempio n. 4
0
def main(argv):
  opts = ParseArguments(argv)

  if opts.payload:
    # We only want the payload's metadata. Create it and exit.
    logging.info('Generating payload properties file.')
    paygen_payload_lib.GenerateUpdatePayloadPropertiesFile(opts.payload,
                                                           opts.output)
    return

  return paygen_payload_lib.GenerateUpdatePayload(
      opts.tgt_image, opts.output, src_image=opts.src_image,
      work_dir=opts.work_dir, private_key=opts.private_key, check=opts.check)
Esempio n. 5
0
    def GetPayloadDir(self, device):
        """Get directory of payload for update.

    This method is used to obtain the directory of payload for cros-flash. The
    given path 'self.image' is passed in when initializing RemoteDeviceUpdater.

    If self.image is a directory, we directly use the provided update payload(s)
    in this directory.

    If self.image is an image, we will generate payloads for it and put them in
    our temporary directory. The reason is that people may modify a local image
    or override it (on the same path) with a different image, so in order to be
    safe each time we need to generate the payloads and not cache them.

    If non of the above cases, we use the xbuddy to first obtain the image path
    (and possibly download it). Then we will generate the payloads in the same
    directory the image is located. The reason is that this is what devserver
    used to do. The path to the image generated by the devserver (or xbuddy) is
    unique and normally nobody override its image with a different one. That is
    why I think it is safe to put the payloads next to the image. This is a poor
    man's version of caching but it makes cros flash faster for users who flash
    the same image multiple times (without doing any change to the image).

    Args:
      device: A ChromiumOSDevice object.

    Returns:
      A string payload_dir, that represents the payload directory.
    """
        if os.path.isdir(self.image):
            # The given path is a directory.
            logging.info('Using provided payloads in %s', self.image)
            return self.image

        image_path = None
        if os.path.isfile(self.image):
            # The given path is an image.
            image_path = self.image
            payload_dir = self.tempdir
        else:
            # Assuming it is an xbuddy path.
            self.board = cros_build_lib.GetBoard(device_board=device.board
                                                 or GetDefaultBoard(),
                                                 override_board=self.board,
                                                 force=self.yes,
                                                 strict=True)
            if not self.force and self.board != device.board:
                # If a board was specified, it must be compatible with the device.
                raise FlashError('Device (%s) is incompatible with board %s' %
                                 (device.board, self.board))
            logging.info('Board is %s', self.board)

            # TODO(crbug.com/872441): Once devserver code has been moved to chromite,
            # use xbuddy library directly instead of the devserver_wrapper.
            # Fetch the full payload and properties, and stateful files. If this
            # fails, fallback to downloading the image.
            try:
                translated_path, _ = ds_wrapper.GetImagePathWithXbuddy(
                    os.path.join(self.image, artifact_info.FULL_PAYLOAD),
                    self.board,
                    self.version,
                    silent=True)
                payload_dir = os.path.dirname(
                    ds_wrapper.TranslatedPathToLocalPath(translated_path))
                ds_wrapper.GetImagePathWithXbuddy(os.path.join(
                    self.image, artifact_info.STATEFUL_PAYLOAD),
                                                  self.board,
                                                  self.version,
                                                  silent=True)
                fetch_image = False
            except (ds_wrapper.ImagePathError,
                    ds_wrapper.ArtifactDownloadError):
                logging.info(
                    'Could not find full_payload or stateful for "%s"',
                    self.image)
                fetch_image = True

            # We didn't find the full_payload, attempt to download the image.
            if fetch_image:
                translated_path, _ = ds_wrapper.GetImagePathWithXbuddy(
                    self.image, self.board, self.version)
                image_path = ds_wrapper.TranslatedPathToLocalPath(
                    translated_path)
                payload_dir = os.path.join(os.path.dirname(image_path),
                                           'payloads')
                logging.notice('Using image path %s and payload directory %s',
                               image_path, payload_dir)

        # Generate rootfs and stateful update payloads if they do not exist.
        payload_path = os.path.join(payload_dir,
                                    auto_updater_transfer.ROOTFS_FILENAME)
        if not os.path.exists(payload_path):
            paygen_payload_lib.GenerateUpdatePayload(
                image_path, payload_path, src_image=self.src_image_to_delta)
        if not os.path.exists(
                os.path.join(payload_dir,
                             auto_updater_transfer.STATEFUL_FILENAME)):
            paygen_stateful_payload_lib.GenerateStatefulPayload(
                image_path, payload_dir)
        return payload_dir