• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6""" The autotest performing FW update, both EC and AP."""
7
8
9import logging
10import sys
11
12from autotest_lib.client.common_lib import error
13from autotest_lib.server import test
14
15
16class provision_FirmwareUpdate(test.test):
17    """A test that can provision a machine to the correct firmware version."""
18
19    version = 1
20
21
22    def stage_image_to_usb(self, host):
23        """Stage the current ChromeOS image on the USB stick connected to the
24        servo.
25
26        @param host:  a CrosHost object of the machine to update.
27        """
28        info = host.host_info_store.get()
29        if not info.build:
30            logging.warning('Failed to get build label from the DUT, skip '
31                            'staging ChromeOS image on the servo USB stick.')
32        else:
33            host.servo.image_to_servo_usb(
34                    host.stage_image_for_servo(info.build))
35            logging.debug('ChromeOS image %s is staged on the USB stick.',
36                          info.build)
37
38    def get_ro_firmware_ver(self, host):
39        """Get the RO firmware version from the host."""
40        result = host.run('crossystem ro_fwid', ignore_status=True)
41        if result.exit_status == 0:
42            # The firmware ID is something like "Google_Board.1234.56.0".
43            # Remove the prefix "Google_Board".
44            return result.stdout.split('.', 1)[1]
45        else:
46            return None
47
48    def get_rw_firmware_ver(self, host):
49        """Get the RW firmware version from the host."""
50        result = host.run('crossystem fwid', ignore_status=True)
51        if result.exit_status == 0:
52            # The firmware ID is something like "Google_Board.1234.56.0".
53            # Remove the prefix "Google_Board".
54            return result.stdout.split('.', 1)[1]
55        else:
56            return None
57
58    def run_once(self, host, value, rw_only=False, stage_image_to_usb=False):
59        """The method called by the control file to start the test.
60
61        @param host:  a CrosHost object of the machine to update.
62        @param value: the provisioning value, which is the build version
63                      to which we want to provision the machine,
64                      e.g. 'link-firmware/R22-2695.1.144'.
65        @param rw_only: True to only update the RW firmware.
66        @param stage_image_to_usb: True to stage the current ChromeOS image on
67                the USB stick connected to the servo. Default is False.
68        """
69        try:
70            host.repair_servo()
71
72            # Stage the current CrOS image to servo USB stick.
73            if stage_image_to_usb:
74                self.stage_image_to_usb(host)
75
76            host.firmware_install(build=value, rw_only=rw_only)
77        except Exception as e:
78            logging.error(e)
79            raise error.TestFail, str(e), sys.exc_info()[2]
80
81        # DUT reboots after the above firmware_install(). Wait it to boot.
82        host.test_wait_for_boot()
83
84        # Only care about the version number.
85        firmware_ver = value.rsplit('-', 1)[1]
86        if not rw_only:
87            current_ro_ver = self.get_ro_firmware_ver(host)
88            if current_ro_ver != firmware_ver:
89                raise error.TestFail('Failed to update RO, still version %s' %
90                                     current_ro_ver)
91        current_rw_ver = self.get_rw_firmware_ver(host)
92        if current_rw_ver != firmware_ver:
93            raise error.TestFail('Failed to update RW, still version %s' %
94                                 current_rw_ver)
95