blob: d4043e46331f675b1440e1ef9fde521c90e6a6c0 [file] [log] [blame]
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +08001# 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
6import logging, os
7
8from autotest_lib.client.common_lib import error, utils
Tom Wai-Hong Tam6ec46e32012-10-05 16:39:21 +08009from autotest_lib.server.cros import vboot_constants as vboot
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080010from autotest_lib.server.cros.faftsequence import FAFTSequence
11
12
13class firmware_UpdateECBin(FAFTSequence):
14 """
15 This test verified the EC software sync. The EC binary is embedded in
16 the BIOS image. On AP startup, AP verifies the EC by comparing the
17 hash of the current EC with the hash of the embedded EC image. So
18 updating EC is simple and we just need to change the EC binary on
19 the BIOS image.
20
Tom Wai-Hong Tam55f51a02012-09-06 15:39:20 +080021 This test requires a new EC image for update. The new EC image should
22 be different with the existing EC image on the current BIOS. In normal
23 cases, we use the ec_autest_image.bin from firmware_from_source.tar.bz2.
24 The ec_autest_image.bin is the same binary as ec.bin but shift'ed and its
25 version string has the "_shift" suffix.
26
27 The new EC image should be specified by the new_ec argument, like:
28 run_remote_tests.sh --args "new_ec=ec_autest_image.bin" ...
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080029
30 The test covers RONORMAL->TWOSTOP, TWOSTOP->TWOSTOP, and
31 TWOSTOP->RONORMAL updates.
32 """
33 version = 1
34
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080035
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080036 def initialize(self, host, cmdline_args, use_pyauto=False, use_faft=True):
37 # Parse arguments from command line
38 dict_args = utils.args_to_dict(cmdline_args)
Tom Wai-Hong Tambcbea792012-09-12 10:29:19 +080039 if 'new_ec' not in dict_args or not os.path.isfile(dict_args['new_ec']):
Tom Wai-Hong Tam55f51a02012-09-06 15:39:20 +080040 raise error.TestError(
Tom Wai-Hong Tambcbea792012-09-12 10:29:19 +080041 'Should specify a valid new_ec image for update, like: '
42 'run_remote_tests.sh --args "new_ec=/path/to/'
43 'ec_autest_image.bin". The ec_autest_image.bin file is '
44 'included in the firmware_from_source.tar.bz2.')
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080045 self.arg_new_ec = dict_args['new_ec']
46 logging.info('The EC image to-be-updated is: %s' % self.arg_new_ec)
47 super(firmware_UpdateECBin, self).initialize(host, cmdline_args,
48 use_pyauto, use_faft)
49
50
51 def setup(self, host, dev_mode=False):
52 super(firmware_UpdateECBin, self).setup()
Chun-ting Changfa474072012-09-07 16:11:36 +080053 self.backup_firmware()
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080054 self.setup_dev_mode(dev_mode)
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080055
56 temp_path = self.faft_client.get_temp_path()
57 self.faft_client.setup_firmwareupdate_temp_dir()
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +080058
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080059 self.new_ec_path = os.path.join(temp_path, 'new_ec.bin')
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080060 host.send_file(self.arg_new_ec, self.new_ec_path)
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080061
62
63 def cleanup(self):
Chun-ting Changfa474072012-09-07 16:11:36 +080064 self.restore_firmware()
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080065 super(firmware_UpdateECBin, self).cleanup()
66
67
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +080068 def do_ronormal_update(self):
69 self.faft_client.setup_EC_image(self.new_ec_path)
70 self.new_ec_sha = self.faft_client.get_EC_image_sha()
71 self.faft_client.update_EC_from_image('a', 0)
72
73
74 def do_twostop_update(self):
75 # We update the original BIOS image back. This BIOS image contains
76 # the original EC binary. But set RW boot. So it is a TWOSTOP ->
77 # TWOSTOP update.
78 self.faft_client.write_firmware(self.old_bios_path)
79 self.faft_client.set_firmware_flags('a', 0)
80
81
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080082 def run_once(self, host=None):
Tom Wai-Hong Tam1f16f122012-09-03 11:20:46 +080083 if not self.check_ec_capability():
84 return
85
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080086 flags = self.faft_client.get_firmware_flags('a')
Tom Wai-Hong Tam6ec46e32012-10-05 16:39:21 +080087 if flags & vboot.PREAMBLE_USE_RO_NORMAL == 0:
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080088 logging.info('The firmware USE_RO_NORMAL flag is disabled.')
89 return
90
91 self.register_faft_sequence((
92 { # Step 1, expected EC RO boot, update EC and disable RO flag
Tom Wai-Hong Tam3e82e362012-09-05 10:17:55 +080093 'state_checker': (self.ro_normal_checker, 'A'),
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +080094 'userspace_action': self.do_ronormal_update,
Tom Wai-Hong Tama9c7de42012-08-31 09:40:04 +080095 'reboot_action': self.sync_and_warm_reboot,
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080096 },
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +080097 { # Step 2, expected new EC and RW boot, restore the original BIOS
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +080098 'state_checker': (
Tom Wai-Hong Tam3e82e362012-09-05 10:17:55 +080099 lambda: self.ro_normal_checker('A', twostop=True) and
100 (self.faft_client.get_EC_firmware_sha() ==
101 self.new_ec_sha)),
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800102 'userspace_action': self.do_twostop_update,
Tom Wai-Hong Tama9c7de42012-08-31 09:40:04 +0800103 # We use warm reboot here to test the following EC behavior:
104 # If EC is already into RW before powering on the AP, the AP
105 # will need to get the EC into RO first. It does this by
106 # telling the EC to wait for the AP to shut down, reboot
107 # into RO, then power on the AP automatically.
108 'reboot_action': self.sync_and_warm_reboot,
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +0800109 },
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800110 { # Step 3, expected different EC and RW boot, enable RO flag
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +0800111 'state_checker': (
Tom Wai-Hong Tam3e82e362012-09-05 10:17:55 +0800112 lambda: self.ro_normal_checker('A', twostop=True) and
113 (self.faft_client.get_EC_firmware_sha() !=
114 self.new_ec_sha)),
Tom Wai-Hong Tamb63bc742012-08-30 20:41:30 +0800115 'userspace_action': (self.faft_client.set_firmware_flags,
Tom Wai-Hong Tamfc700b52012-09-13 21:33:52 +0800116 ('a', flags)),
Tom Wai-Hong Tama9c7de42012-08-31 09:40:04 +0800117 'reboot_action': self.sync_and_warm_reboot,
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +0800118 },
119 { # Step 4, expected EC RO boot, done
Tom Wai-Hong Tam3e82e362012-09-05 10:17:55 +0800120 'state_checker': (self.ro_normal_checker, 'A'),
Tom Wai-Hong Tam9b917b82012-08-24 16:21:10 +0800121 },
122 ))
123 self.run_faft_sequence()