예제 #1
0
    def get_cr50_device_state(self):
        """Get a dict with the current device cr50 information.

        The state dict will include the platform brand, rlz code, chip board id,
        the running cr50 image version, the running cr50 image board id, and the
        device cr50 image version.
        """
        state = {}
        state['mosys platform brand'] = self.host.run(
            'mosys platform brand', ignore_status=True).stdout.strip()
        state['device_prod_ver'] = cr50_utils.GetBinVersion(
            self.host, cr50_utils.CR50_PROD)
        state['has_prepvt'] = cr50_utils.HasPrepvtImage(self.host)
        if state['has_prepvt']:
            state['device_prepvt_ver'] = cr50_utils.GetBinVersion(
                self.host, cr50_utils.CR50_PREPVT)
        else:
            state['device_prepvt_ver'] = None
        state['rlz'] = cr50_utils.GetRLZ(self.host)
        state['chip_bid'] = cr50_utils.GetChipBoardId(self.host)
        state['chip_bid_str'] = '%08x:%08x:%08x' % state['chip_bid']
        state['running_ver'] = cr50_utils.GetRunningVersion(self.host)
        state['cr50_image_bid'] = self.cr50.get_active_board_id_str()

        logging.debug('Current Cr50 state:\n%s', pprint.pformat(state))
        return state
예제 #2
0
    def replace_image_if_newer(self, universal_rw_ver, path):
        """Replace the image at path if it is newer than the universal image

        Copy the universal image to path, if the universal image is older than
        the image at path.

        Args:
            universal_rw_ver: The rw version string of the universal image
            path: The path of the image that may need to be replaced.
        """
        if self.host.path_exists(path):
            dut_ver = cr50_utils.GetBinVersion(self.host, path)[1]
            # If the universal version is lower than the DUT image, install the
            # universal image. It has the lowest version of any image in the
            # test, so cr50-update won't try to update cr50 at any point during
            # the test.
            install_image = (cr50_utils.GetNewestVersion(dut_ver,
                    universal_rw_ver) == dut_ver)
        else:
            # If the DUT doesn't have a file at path, install the image.
            install_image = True

        if install_image:
            # Disable rootfs verification so we can copy the image to the DUT
            self.rootfs_verification_disable()
            # Copy the universal image onto the DUT.
            dest, ver = cr50_utils.InstallImage(self.host, self.universal_path,
                    path)
            logging.info('Copied %s to %s', ver, dest)
예제 #3
0
    def download_cr50_gs_image(self,
                               filename,
                               image_bid='',
                               bucket=None,
                               image_type=None):
        """Get the image from gs and save it in the autotest dir.

        Args:
            filename: The cr50 image basename
            image_bid: the board id info list or string. It will be added to the
                       filename.
            bucket: The gs bucket name
            image_type: 'debug' or 'release'. This will be used to determine
                        the bucket if the bucket is not given.
        Returns:
            A tuple with the local path and version
        """
        # Add the image bid string to the filename
        if image_bid:
            bid_str = cr50_utils.GetBoardIdInfoString(image_bid, symbolic=True)
            filename += '.' + bid_str.replace(':', '_')

        if not bucket:
            bucket, filename = self.find_cr50_gs_image(filename, image_type)

        remote_temp_dir = '/tmp/'
        src = os.path.join(remote_temp_dir, filename)
        dest = os.path.join(self.resultsdir, filename)

        # Copy the image to the dut
        gsutil_wrapper.copy_private_bucket(host=self.host,
                                           bucket=bucket,
                                           filename=filename,
                                           destination=remote_temp_dir)

        self.host.get_file(src, dest)
        ver = cr50_utils.GetBinVersion(self.host, src)

        # Compare the image board id to the downloaded image to make sure we got
        # the right file
        downloaded_bid = cr50_utils.GetBoardIdInfoString(ver[2], symbolic=True)
        if image_bid and bid_str != downloaded_bid:
            raise error.TestError('Could not download image with matching '
                                  'board id wanted %s got %s' %
                                  (bid_str, downloaded_bid))
        return dest, ver
예제 #4
0
    def save_original_image(self, dut_path):
        """Save the image currently running on the DUT.

        Copy the image from the DUT to the local autotest directory and get
        version information. Store the information in the images dict. Make sure
        the saved version matches the running version.

        Args:
            dut_path: the location of the cr50 prod image on the DUT.

        Raises:
            error.TestError if the saved cr50 image version does not match the
            version cr50 is running.
        """
        name = self.ORIGINAL_NAME
        local_dest = os.path.join(self.resultsdir, name + '.bin')

        running_ver = cr50_utils.GetRunningVersion(self.host)
        running_ver_str = cr50_utils.GetVersionString(running_ver)

        self.host.get_file(dut_path, local_dest)

        saved_ver = cr50_utils.GetBinVersion(self.host, dut_path)
        saved_ver_str = cr50_utils.GetVersionString(saved_ver)

        # If Cr50 is not running the image in the cr50 firmware directory, then
        # raise an error. We can't run this test unless we can restore the
        # original state during cleanup.
        if running_ver[1] != saved_ver[1]:
            raise error.TestError("Can't determine original Cr50 version. "
                                  "Running %s, but saved %s." %
                                  (running_ver_str, saved_ver_str))

        self.images[name] = (saved_ver, saved_ver_str, local_dest)
        logging.info("%s stored at %s with version %s", name, local_dest,
                     saved_ver_str)