J. Richard Barnette | 384056b | 2012-04-16 11:04:46 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | # |
| 5 | # Expects to be run in an environment with sudo and no interactive password |
| 6 | # prompt, such as within the Chromium OS development chroot. |
| 7 | |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 8 | import os |
| 9 | |
Vic Yang | 3a7cf60 | 2012-11-07 17:28:39 +0800 | [diff] [blame] | 10 | import logging, re, time, xmlrpclib |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 11 | |
Simran Basi | 741b5d4 | 2012-05-18 11:27:15 -0700 | [diff] [blame] | 12 | from autotest_lib.client.common_lib import error |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 13 | from autotest_lib.server import utils |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 14 | from autotest_lib.server.cros.servo import power_state_controller |
J. Richard Barnette | 7548757 | 2013-03-08 12:47:50 -0800 | [diff] [blame] | 15 | from autotest_lib.server.cros.servo import programmer |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 16 | |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 17 | |
J. Richard Barnette | 384056b | 2012-04-16 11:04:46 -0700 | [diff] [blame] | 18 | class Servo(object): |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 19 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 20 | """Manages control of a Servo board. |
| 21 | |
| 22 | Servo is a board developed by hardware group to aide in the debug and |
| 23 | control of various partner devices. Servo's features include the simulation |
| 24 | of pressing the power button, closing the lid, and pressing Ctrl-d. This |
| 25 | class manages setting up and communicating with a servo demon (servod) |
| 26 | process. It provides both high-level functions for common servo tasks and |
| 27 | low-level functions for directly setting and reading gpios. |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 28 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 29 | """ |
| 30 | |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 31 | # Power button press delays in seconds. |
J. Richard Barnette | d2e4cbd | 2012-06-29 12:18:40 -0700 | [diff] [blame] | 32 | # |
J. Richard Barnette | 5383f07 | 2012-07-26 17:35:40 -0700 | [diff] [blame] | 33 | # The EC specification says that 8.0 seconds should be enough |
| 34 | # for the long power press. However, some platforms need a bit |
| 35 | # more time. Empirical testing has found these requirements: |
| 36 | # Alex: 8.2 seconds |
| 37 | # ZGB: 8.5 seconds |
| 38 | # The actual value is set to the largest known necessary value. |
| 39 | # |
| 40 | # TODO(jrbarnette) Being generous is the right thing to do for |
| 41 | # existing platforms, but if this code is to be used for |
| 42 | # qualification of new hardware, we should be less generous. |
| 43 | LONG_DELAY = 8.5 |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 44 | SHORT_DELAY = 0.1 |
| 45 | NORMAL_TRANSITION_DELAY = 1.2 |
J. Richard Barnette | 5383f07 | 2012-07-26 17:35:40 -0700 | [diff] [blame] | 46 | |
Todd Broch | 31c8250 | 2011-08-29 08:14:39 -0700 | [diff] [blame] | 47 | # Maximum number of times to re-read power button on release. |
| 48 | RELEASE_RETRY_MAX = 5 |
Todd Broch | cf7c665 | 2012-02-24 13:03:59 -0800 | [diff] [blame] | 49 | GET_RETRY_MAX = 10 |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 50 | |
J. Richard Barnette | 5383f07 | 2012-07-26 17:35:40 -0700 | [diff] [blame] | 51 | # Delays to deal with DUT state transitions. |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 52 | SLEEP_DELAY = 6 |
| 53 | BOOT_DELAY = 10 |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 54 | |
| 55 | # Time in seconds to allow the firmware to initialize itself and |
| 56 | # present the "INSERT" screen in recovery mode before actually |
| 57 | # inserting a USB stick to boot from. |
| 58 | _RECOVERY_INSERT_DELAY = 10.0 |
| 59 | |
| 60 | # Minimum time in seconds to hold the "cold_reset" or |
| 61 | # "warm_reset" signals asserted. |
| 62 | _DUT_RESET_DELAY = 0.5 |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 63 | |
J. Richard Barnette | b613397 | 2012-07-19 17:13:55 -0700 | [diff] [blame] | 64 | # Time required for the EC to be working after cold reset. |
| 65 | # Five seconds is at least twice as big as necessary for Alex, |
| 66 | # and is presumably good enough for all future systems. |
| 67 | _EC_RESET_DELAY = 5.0 |
| 68 | |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 69 | # Default minimum time interval between 'press' and 'release' |
| 70 | # keyboard events. |
Vic Yang | 0aca1c2 | 2012-11-19 18:33:56 -0800 | [diff] [blame] | 71 | SERVO_KEY_PRESS_DELAY = 0.1 |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 72 | |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 73 | # Time between an usb disk plugged-in and detected in the system. |
| 74 | USB_DETECTION_DELAY = 10 |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 75 | # Time to keep USB power off before and after USB mux direction is changed |
| 76 | USB_POWEROFF_DELAY = 2 |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 77 | |
Gediminas Ramanauskas | 3297d4f | 2012-09-10 15:30:10 -0700 | [diff] [blame] | 78 | KEY_MATRIX_ALT_0 = { |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 79 | 'ctrl_refresh': ['0', '0', '0', '1'], |
| 80 | 'ctrl_d': ['0', '1', '0', '0'], |
| 81 | 'd': ['0', '1', '1', '1'], |
| 82 | 'ctrl_enter': ['1', '0', '0', '0'], |
| 83 | 'enter': ['1', '0', '1', '1'], |
| 84 | 'ctrl': ['1', '1', '0', '0'], |
| 85 | 'refresh': ['1', '1', '0', '1'], |
| 86 | 'unused': ['1', '1', '1', '0'], |
| 87 | 'none': ['1', '1', '1', '1']} |
Chris Masone | 6a0680f | 2012-03-02 08:40:00 -0800 | [diff] [blame] | 88 | |
Gediminas Ramanauskas | 3297d4f | 2012-09-10 15:30:10 -0700 | [diff] [blame] | 89 | KEY_MATRIX_ALT_1 = { |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 90 | 'ctrl_d': ['0', '0', '1', '0'], |
| 91 | 'd': ['0', '0', '1', '1'], |
| 92 | 'ctrl_enter': ['0', '1', '1', '0'], |
| 93 | 'enter': ['0', '1', '1', '1'], |
| 94 | 'ctrl_refresh': ['1', '0', '0', '1'], |
| 95 | 'unused': ['1', '1', '0', '0'], |
| 96 | 'refresh': ['1', '1', '0', '1'], |
| 97 | 'ctrl': ['1', '1', '1', '0'], |
| 98 | 'none': ['1', '1', '1', '1']} |
Gediminas Ramanauskas | 3297d4f | 2012-09-10 15:30:10 -0700 | [diff] [blame] | 99 | |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 100 | KEY_MATRIX_ALT_2 = { |
| 101 | 'ctrl_d': ['0', '0', '0', '1'], |
| 102 | 'd': ['0', '0', '1', '1'], |
| 103 | 'unused': ['0', '1', '1', '1'], |
| 104 | 'rec_mode': ['1', '0', '0', '0'], |
| 105 | 'ctrl_enter': ['1', '0', '0', '1'], |
| 106 | 'enter': ['1', '0', '1', '1'], |
| 107 | 'ctrl': ['1', '1', '0', '1'], |
| 108 | 'refresh': ['1', '1', '1', '0'], |
| 109 | 'ctrl_refresh': ['1', '1', '1', '1'], |
| 110 | 'none': ['1', '1', '1', '1']} |
| 111 | |
| 112 | KEY_MATRIX = [KEY_MATRIX_ALT_0, KEY_MATRIX_ALT_1, KEY_MATRIX_ALT_2] |
J. Richard Barnette | 67ccb87 | 2012-04-19 16:34:56 -0700 | [diff] [blame] | 113 | |
J. Richard Barnette | d5f807a | 2013-02-11 16:51:00 -0800 | [diff] [blame] | 114 | def __init__(self, servo_host='localhost', servo_port=9999): |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 115 | """Sets up the servo communication infrastructure. |
| 116 | |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 117 | @param servo_host Name of the host where the servod process |
| 118 | is running. |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 119 | @param servo_port Port the servod process is listening on. |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 120 | """ |
Gediminas Ramanauskas | 3297d4f | 2012-09-10 15:30:10 -0700 | [diff] [blame] | 121 | self._key_matrix = 0 |
J. Richard Barnette | 384056b | 2012-04-16 11:04:46 -0700 | [diff] [blame] | 122 | self._server = None |
Todd Broch | f24d278 | 2011-08-19 10:55:41 -0700 | [diff] [blame] | 123 | self._connect_servod(servo_host, servo_port) |
Tom Wai-Hong Tam | 1c86c7a | 2012-10-22 10:08:24 +0800 | [diff] [blame] | 124 | self._is_localhost = (servo_host == 'localhost') |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 125 | self._power_state = power_state_controller.PowerStateController(self) |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 126 | |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 127 | # a string, showing what interface (host or dut) the USB device is |
| 128 | # connected to. |
| 129 | self._usb_position = None |
| 130 | self.set('dut_hub_pwren', 'on') |
| 131 | self.set('usb_mux_oe1', 'on') |
| 132 | self.switch_usbkey('host') |
| 133 | |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 134 | # Commands on the servo host must be run by the superuser. Our account |
| 135 | # on Beaglebone is root, but locally we might be running as a |
| 136 | # different user. If so - `sudo ' will have to be added to the |
| 137 | # commands. |
| 138 | if self._is_localhost: |
| 139 | self._sudo_required = utils.system_output('id -u') != '0' |
| 140 | self._ssh_prefix = '' |
| 141 | else: |
| 142 | common_options = '-o PasswordAuthentication=no' |
| 143 | self._sudo_required = False |
| 144 | self._ssh_prefix = 'ssh %s root@%s ' % (common_options, servo_host) |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 145 | self._scp_cmd_template = 'scp -r %s ' % common_options |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 146 | self._scp_cmd_template += '%s ' + 'root@' + servo_host + ':%s' |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 147 | |
J. Richard Barnette | b613397 | 2012-07-19 17:13:55 -0700 | [diff] [blame] | 148 | def initialize_dut(self, cold_reset=False): |
| 149 | """Initializes a dut for testing purposes. |
| 150 | |
| 151 | This sets various servo signals back to default values |
| 152 | appropriate for the target board. By default, if the DUT |
| 153 | is already on, it stays on. If the DUT is powered off |
| 154 | before initialization, its state afterward is unspecified. |
| 155 | |
| 156 | If cold reset is requested, the DUT is guaranteed to be off |
| 157 | at the end of initialization, regardless of its initial |
| 158 | state. |
| 159 | |
| 160 | Rationale: Basic initialization of servo sets the lid open, |
| 161 | when there is a lid. This operation won't affect powered on |
| 162 | units; however, setting the lid open may power on a unit |
| 163 | that's off, depending on factors outside the scope of this |
| 164 | function. |
| 165 | |
| 166 | @param cold_reset If True, cold reset the device after |
| 167 | initialization. |
| 168 | """ |
| 169 | self._server.hwinit() |
| 170 | if cold_reset: |
| 171 | self.cold_reset() |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 172 | |
| 173 | |
Tom Wai-Hong Tam | 1c86c7a | 2012-10-22 10:08:24 +0800 | [diff] [blame] | 174 | def is_localhost(self): |
| 175 | """Is the servod hosted locally? |
| 176 | |
| 177 | Returns: |
| 178 | True if local hosted; otherwise, False. |
| 179 | """ |
| 180 | return self._is_localhost |
| 181 | |
| 182 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 183 | def power_long_press(self): |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 184 | """Simulate a long power button press.""" |
J. Richard Barnette | f12bff2 | 2012-07-18 14:41:06 -0700 | [diff] [blame] | 185 | # After a long power press, the EC may ignore the next power |
| 186 | # button press (at least on Alex). To guarantee that this |
| 187 | # won't happen, we need to allow the EC one second to |
| 188 | # collect itself. |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 189 | self.power_key(Servo.LONG_DELAY) |
J. Richard Barnette | f12bff2 | 2012-07-18 14:41:06 -0700 | [diff] [blame] | 190 | time.sleep(1.0) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 191 | |
| 192 | |
| 193 | def power_normal_press(self): |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 194 | """Simulate a normal power button press.""" |
| 195 | self.power_key() |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 196 | |
| 197 | |
| 198 | def power_short_press(self): |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 199 | """Simulate a short power button press.""" |
| 200 | self.power_key(Servo.SHORT_DELAY) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 201 | |
| 202 | |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 203 | def power_key(self, secs=NORMAL_TRANSITION_DELAY): |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 204 | """Simulate a power button press. |
| 205 | |
| 206 | Args: |
| 207 | secs: Time in seconds to simulate the keypress. |
| 208 | """ |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 209 | self.set_nocheck('pwr_button', 'press') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 210 | time.sleep(secs) |
Todd Broch | 31c8250 | 2011-08-29 08:14:39 -0700 | [diff] [blame] | 211 | self.set_nocheck('pwr_button', 'release') |
| 212 | # TODO(tbroch) Different systems have different release times on the |
| 213 | # power button that this loop addresses. Longer term we may want to |
| 214 | # make this delay platform specific. |
| 215 | retry = 1 |
| 216 | while True: |
| 217 | value = self.get('pwr_button') |
| 218 | if value == 'release' or retry > Servo.RELEASE_RETRY_MAX: |
| 219 | break |
Todd Broch | 9753bd4 | 2012-03-21 10:15:08 -0700 | [diff] [blame] | 220 | logging.info('Waiting for pwr_button to release, retry %d.', retry) |
Todd Broch | 31c8250 | 2011-08-29 08:14:39 -0700 | [diff] [blame] | 221 | retry += 1 |
| 222 | time.sleep(Servo.SHORT_DELAY) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 223 | |
| 224 | |
| 225 | def lid_open(self): |
| 226 | """Simulate opening the lid.""" |
Craig Harrison | 4899726 | 2011-06-27 14:31:10 -0700 | [diff] [blame] | 227 | self.set_nocheck('lid_open', 'yes') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 228 | |
| 229 | |
| 230 | def lid_close(self): |
Craig Harrison | 4899726 | 2011-06-27 14:31:10 -0700 | [diff] [blame] | 231 | """Simulate closing the lid. |
| 232 | |
| 233 | Waits 6 seconds to ensure the device is fully asleep before returning. |
| 234 | """ |
| 235 | self.set_nocheck('lid_open', 'no') |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 236 | time.sleep(Servo.SLEEP_DELAY) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 237 | |
| 238 | |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 239 | def _press_keys(self, key): |
| 240 | """Simulate button presses. |
| 241 | |
| 242 | Note, key presses will remain on indefinitely. See |
| 243 | _press_and_release_keys for release procedure. |
| 244 | """ |
Gediminas Ramanauskas | 9da80f2 | 2012-11-14 12:59:43 -0800 | [diff] [blame] | 245 | (m1_a1, m1_a0, m2_a1, m2_a0) = self.KEY_MATRIX[self._key_matrix]['none'] |
Todd Broch | 9753bd4 | 2012-03-21 10:15:08 -0700 | [diff] [blame] | 246 | self.set_nocheck('kbd_m2_a0', m2_a0) |
| 247 | self.set_nocheck('kbd_m2_a1', m2_a1) |
| 248 | self.set_nocheck('kbd_m1_a0', m1_a0) |
| 249 | self.set_nocheck('kbd_m1_a1', m1_a1) |
Vic Yang | e262a3e | 2012-11-02 18:48:37 +0800 | [diff] [blame] | 250 | self.set_nocheck('kbd_en', 'on') |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 251 | |
Gediminas Ramanauskas | 9da80f2 | 2012-11-14 12:59:43 -0800 | [diff] [blame] | 252 | (m1_a1, m1_a0, m2_a1, m2_a0) = self.KEY_MATRIX[self._key_matrix][key] |
| 253 | self.set_nocheck('kbd_m2_a0', m2_a0) |
| 254 | self.set_nocheck('kbd_m2_a1', m2_a1) |
| 255 | self.set_nocheck('kbd_m1_a0', m1_a0) |
| 256 | self.set_nocheck('kbd_m1_a1', m1_a1) |
| 257 | |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 258 | |
| 259 | def _press_and_release_keys(self, key, |
| 260 | press_secs=SERVO_KEY_PRESS_DELAY): |
| 261 | """Simulate button presses and release.""" |
| 262 | self._press_keys(key) |
Todd Broch | 9dfc3a8 | 2011-11-01 08:09:28 -0700 | [diff] [blame] | 263 | time.sleep(press_secs) |
| 264 | self.set_nocheck('kbd_en', 'off') |
| 265 | |
| 266 | |
Gediminas Ramanauskas | 3297d4f | 2012-09-10 15:30:10 -0700 | [diff] [blame] | 267 | def set_key_matrix(self, matrix=0): |
| 268 | """Set keyboard mapping""" |
| 269 | self._key_matrix = matrix |
| 270 | |
| 271 | |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 272 | def ctrl_d(self): |
| 273 | """Simulate Ctrl-d simultaneous button presses.""" |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 274 | self._press_and_release_keys('ctrl_d') |
Todd Broch | 9dfc3a8 | 2011-11-01 08:09:28 -0700 | [diff] [blame] | 275 | |
| 276 | |
Todd Broch | 9753bd4 | 2012-03-21 10:15:08 -0700 | [diff] [blame] | 277 | def ctrl_enter(self): |
| 278 | """Simulate Ctrl-enter simultaneous button presses.""" |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 279 | self._press_and_release_keys('ctrl_enter') |
Todd Broch | 9753bd4 | 2012-03-21 10:15:08 -0700 | [diff] [blame] | 280 | |
| 281 | |
Todd Broch | 9dfc3a8 | 2011-11-01 08:09:28 -0700 | [diff] [blame] | 282 | def d_key(self): |
| 283 | """Simulate Enter key button press.""" |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 284 | self._press_and_release_keys('d') |
Todd Broch | 9dfc3a8 | 2011-11-01 08:09:28 -0700 | [diff] [blame] | 285 | |
| 286 | |
| 287 | def ctrl_key(self): |
| 288 | """Simulate Enter key button press.""" |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 289 | self._press_and_release_keys('ctrl') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 290 | |
| 291 | |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 292 | def enter_key(self): |
| 293 | """Simulate Enter key button press.""" |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 294 | self._press_and_release_keys('enter') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 295 | |
| 296 | |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 297 | def refresh_key(self): |
| 298 | """Simulate Refresh key (F3) button press.""" |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 299 | self._press_and_release_keys('refresh') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 300 | |
| 301 | |
Tom Wai-Hong Tam | 9e61e66 | 2012-08-01 15:10:07 +0800 | [diff] [blame] | 302 | def ctrl_refresh_key(self): |
| 303 | """Simulate Ctrl and Refresh (F3) simultaneous press. |
| 304 | |
| 305 | This key combination is an alternative of Space key. |
| 306 | """ |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 307 | self._press_and_release_keys('ctrl_refresh') |
Tom Wai-Hong Tam | 9e61e66 | 2012-08-01 15:10:07 +0800 | [diff] [blame] | 308 | |
| 309 | |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 310 | def imaginary_key(self): |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 311 | """Simulate imaginary key button press. |
| 312 | |
| 313 | Maps to a key that doesn't physically exist. |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 314 | """ |
Gediminas Ramanauskas | 515e701 | 2012-09-18 17:01:10 -0700 | [diff] [blame] | 315 | self._press_and_release_keys('unused') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 316 | |
| 317 | |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 318 | def enable_recovery_mode(self): |
| 319 | """Enable recovery mode on device.""" |
| 320 | self.set('rec_mode', 'on') |
| 321 | |
| 322 | |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 323 | def custom_recovery_mode(self): |
| 324 | """Custom key combination to enter recovery mode.""" |
| 325 | self._press_keys('rec_mode') |
| 326 | self.power_normal_press() |
| 327 | time.sleep(self.SERVO_KEY_PRESS_DELAY) |
| 328 | self.set_nocheck('kbd_en', 'off') |
| 329 | |
| 330 | |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 331 | def disable_recovery_mode(self): |
| 332 | """Disable recovery mode on device.""" |
| 333 | self.set('rec_mode', 'off') |
| 334 | |
| 335 | |
| 336 | def enable_development_mode(self): |
| 337 | """Enable development mode on device.""" |
| 338 | self.set('dev_mode', 'on') |
| 339 | |
| 340 | |
| 341 | def disable_development_mode(self): |
| 342 | """Disable development mode on device.""" |
| 343 | self.set('dev_mode', 'off') |
| 344 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 345 | def boot_devmode(self): |
| 346 | """Boot a dev-mode device that is powered off.""" |
Tom Wai-Hong Tam | 2386910 | 2012-01-17 15:41:30 +0800 | [diff] [blame] | 347 | self.power_short_press() |
Craig Harrison | 4899726 | 2011-06-27 14:31:10 -0700 | [diff] [blame] | 348 | self.pass_devmode() |
| 349 | |
| 350 | |
| 351 | def pass_devmode(self): |
| 352 | """Pass through boot screens in dev-mode.""" |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 353 | time.sleep(Servo.BOOT_DELAY) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 354 | self.ctrl_d() |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 355 | time.sleep(Servo.BOOT_DELAY) |
Craig Harrison | 4899726 | 2011-06-27 14:31:10 -0700 | [diff] [blame] | 356 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 357 | |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 358 | def cold_reset(self): |
| 359 | """Perform a cold reset of the EC. |
| 360 | |
J. Richard Barnette | b613397 | 2012-07-19 17:13:55 -0700 | [diff] [blame] | 361 | This has the side effect of shutting off the device. The |
| 362 | device is guaranteed to be off at the end of this call. |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 363 | """ |
J. Richard Barnette | b613397 | 2012-07-19 17:13:55 -0700 | [diff] [blame] | 364 | # After the reset, give the EC the time it needs to |
| 365 | # re-initialize. |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 366 | self.set('cold_reset', 'on') |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 367 | time.sleep(self._DUT_RESET_DELAY) |
J. Richard Barnette | b613397 | 2012-07-19 17:13:55 -0700 | [diff] [blame] | 368 | self.set('cold_reset', 'off') |
| 369 | time.sleep(self._EC_RESET_DELAY) |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 370 | |
| 371 | |
| 372 | def warm_reset(self): |
| 373 | """Perform a warm reset of the device. |
| 374 | |
| 375 | Has the side effect of restarting the device. |
| 376 | """ |
| 377 | self.set('warm_reset', 'on') |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 378 | time.sleep(self._DUT_RESET_DELAY) |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 379 | self.set('warm_reset', 'off') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 380 | |
| 381 | |
Todd Broch | efe72cb | 2012-07-11 19:58:53 -0700 | [diff] [blame] | 382 | def _get_xmlrpclib_exception(self, xmlexc): |
| 383 | """Get meaningful exception string from xmlrpc. |
| 384 | |
| 385 | Args: |
| 386 | xmlexc: xmlrpclib.Fault object |
| 387 | |
| 388 | xmlrpclib.Fault.faultString has the following format: |
| 389 | |
| 390 | <type 'exception type'>:'actual error message' |
| 391 | |
| 392 | Parse and return the real exception from the servod side instead of the |
| 393 | less meaningful one like, |
| 394 | <Fault 1: "<type 'exceptions.AttributeError'>:'tca6416' object has no |
| 395 | attribute 'hw_driver'"> |
| 396 | |
| 397 | Returns: |
| 398 | string of underlying exception raised in servod. |
| 399 | """ |
| 400 | return re.sub('^.*>:', '', xmlexc.faultString) |
| 401 | |
| 402 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 403 | def get(self, gpio_name): |
| 404 | """Get the value of a gpio from Servod.""" |
| 405 | assert gpio_name |
Todd Broch | efe72cb | 2012-07-11 19:58:53 -0700 | [diff] [blame] | 406 | try: |
| 407 | return self._server.get(gpio_name) |
| 408 | except xmlrpclib.Fault as e: |
| 409 | err_msg = "Getting '%s' :: %s" % \ |
| 410 | (gpio_name, self._get_xmlrpclib_exception(e)) |
| 411 | raise error.TestFail(err_msg) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 412 | |
| 413 | |
| 414 | def set(self, gpio_name, gpio_value): |
| 415 | """Set and check the value of a gpio using Servod.""" |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 416 | self.set_nocheck(gpio_name, gpio_value) |
Todd Broch | cf7c665 | 2012-02-24 13:03:59 -0800 | [diff] [blame] | 417 | retry_count = Servo.GET_RETRY_MAX |
| 418 | while gpio_value != self.get(gpio_name) and retry_count: |
| 419 | logging.warn("%s != %s, retry %d", gpio_name, gpio_value, |
| 420 | retry_count) |
| 421 | retry_count -= 1 |
| 422 | time.sleep(Servo.SHORT_DELAY) |
| 423 | if not retry_count: |
| 424 | assert gpio_value == self.get(gpio_name), \ |
| 425 | 'Servo failed to set %s to %s' % (gpio_name, gpio_value) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 426 | |
| 427 | |
| 428 | def set_nocheck(self, gpio_name, gpio_value): |
| 429 | """Set the value of a gpio using Servod.""" |
| 430 | assert gpio_name and gpio_value |
Todd Broch | 9753bd4 | 2012-03-21 10:15:08 -0700 | [diff] [blame] | 431 | logging.info('Setting %s to %s', gpio_name, gpio_value) |
Todd Broch | efe72cb | 2012-07-11 19:58:53 -0700 | [diff] [blame] | 432 | try: |
| 433 | self._server.set(gpio_name, gpio_value) |
| 434 | except xmlrpclib.Fault as e: |
| 435 | err_msg = "Setting '%s' to '%s' :: %s" % \ |
| 436 | (gpio_name, gpio_value, self._get_xmlrpclib_exception(e)) |
| 437 | raise error.TestFail(err_msg) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 438 | |
| 439 | |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 440 | # TODO(waihong) It may fail if multiple servo's are connected to the same |
| 441 | # host. Should look for a better way, like the USB serial name, to identify |
| 442 | # the USB device. |
Simran Basi | 741b5d4 | 2012-05-18 11:27:15 -0700 | [diff] [blame] | 443 | # TODO(sbasi) Remove this code from autoserv once firmware tests have been |
| 444 | # updated. |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 445 | def probe_host_usb_dev(self): |
| 446 | """Probe the USB disk device plugged-in the servo from the host side. |
| 447 | |
| 448 | It tries to switch the USB mux to make the host unable to see the |
| 449 | USB disk and compares the result difference. |
| 450 | |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 451 | Returns: |
| 452 | A string of USB disk path, like '/dev/sdb', or None if not existed. |
| 453 | """ |
| 454 | cmd = 'ls /dev/sd[a-z]' |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 455 | original_value = self.get_usbkey_direction() |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 456 | |
| 457 | # Make the host unable to see the USB disk. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 458 | if original_value != 'dut': |
| 459 | self.switch_usbkey('dut') |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 460 | time.sleep(self.USB_DETECTION_DELAY) |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 461 | no_usb_set = set(self.system_output(cmd, ignore_status=True).split()) |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 462 | |
| 463 | # Make the host able to see the USB disk. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 464 | self.switch_usbkey('host') |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 465 | time.sleep(self.USB_DETECTION_DELAY) |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 466 | has_usb_set = set(self.system_output(cmd, ignore_status=True).split()) |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 467 | |
| 468 | # Back to its original value. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 469 | if original_value != self.get_usbkey_direction(): |
| 470 | self.switch_usbkey(original_value) |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 471 | time.sleep(self.USB_DETECTION_DELAY) |
| 472 | |
| 473 | diff_set = has_usb_set - no_usb_set |
| 474 | if len(diff_set) == 1: |
| 475 | return diff_set.pop() |
| 476 | else: |
| 477 | return None |
| 478 | |
| 479 | |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 480 | def image_to_servo_usb(self, image_path=None, |
| 481 | make_image_noninteractive=False): |
| 482 | """Install an image to the USB key plugged into the servo. |
| 483 | |
| 484 | This method may copy any image to the servo USB key including a |
| 485 | recovery image or a test image. These images are frequently used |
| 486 | for test purposes such as restoring a corrupted image or conducting |
| 487 | an upgrade of ec/fw/kernel as part of a test of a specific image part. |
| 488 | |
| 489 | Args: |
| 490 | image_path: Path on the host to the recovery image. |
| 491 | make_image_noninteractive: Make the recovery image noninteractive, |
| 492 | therefore the DUT will reboot |
| 493 | automatically after installation. |
| 494 | """ |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 495 | # We're about to start plugging/unplugging the USB key. We |
| 496 | # don't know the state of the DUT, or what it might choose |
| 497 | # to do to the device after hotplug. To avoid surprises, |
| 498 | # force the DUT to be off. |
| 499 | self._server.hwinit() |
| 500 | self._power_state.power_off() |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 501 | |
| 502 | # Set up Servo's usb mux. |
| 503 | self.set('prtctl4_pwren', 'on') |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 504 | self.switch_usbkey('host') |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 505 | if image_path: |
Tom Wai-Hong Tam | 42f136d | 2012-10-26 11:11:23 +0800 | [diff] [blame] | 506 | logging.info('Searching for usb device and copying image to it. ' |
| 507 | 'Please wait a few minutes...') |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 508 | if not self._server.download_image_to_usb(image_path): |
| 509 | logging.error('Failed to transfer requested image to USB. ' |
| 510 | 'Please take a look at Servo Logs.') |
| 511 | raise error.AutotestError('Download image to usb failed.') |
| 512 | if make_image_noninteractive: |
| 513 | logging.info('Making image noninteractive') |
| 514 | if not self._server.make_image_noninteractive(): |
| 515 | logging.error('Failed to make image noninteractive. ' |
| 516 | 'Please take a look at Servo Logs.') |
| 517 | |
| 518 | |
Simran Basi | 741b5d4 | 2012-05-18 11:27:15 -0700 | [diff] [blame] | 519 | def install_recovery_image(self, image_path=None, |
J. Richard Barnette | b6de7e3 | 2013-02-14 13:28:04 -0800 | [diff] [blame] | 520 | make_image_noninteractive=False): |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 521 | """Install the recovery image specied by the path onto the DUT. |
| 522 | |
| 523 | This method uses google recovery mode to install a recovery image |
| 524 | onto a DUT through the use of a USB stick that is mounted on a servo |
Tom Wai-Hong Tam | a07115e | 2012-01-09 12:27:01 +0800 | [diff] [blame] | 525 | board specified by the usb_dev. If no image path is specified |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 526 | we use the recovery image already on the usb image. |
| 527 | |
| 528 | Args: |
| 529 | image_path: Path on the host to the recovery image. |
Simran Basi | 741b5d4 | 2012-05-18 11:27:15 -0700 | [diff] [blame] | 530 | make_image_noninteractive: Make the recovery image noninteractive, |
| 531 | therefore the DUT will reboot |
| 532 | automatically after installation. |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 533 | """ |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 534 | self.image_to_servo_usb(image_path, make_image_noninteractive) |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame^] | 535 | self._power_state.power_on(dev_mode=self._power_state.DEV_OFF, |
| 536 | rec_mode=self._power_state.REC_ON) |
| 537 | time.sleep(self._RECOVERY_INSERT_DELAY) |
| 538 | self.switch_usbkey('dut') |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 539 | |
| 540 | |
Todd Broch | f24d278 | 2011-08-19 10:55:41 -0700 | [diff] [blame] | 541 | def _connect_servod(self, servo_host, servo_port): |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 542 | """Connect to the Servod process with XMLRPC. |
| 543 | |
| 544 | Args: |
| 545 | servo_port: Port the Servod process is listening on. |
| 546 | """ |
Todd Broch | f24d278 | 2011-08-19 10:55:41 -0700 | [diff] [blame] | 547 | remote = 'http://%s:%s' % (servo_host, servo_port) |
Todd Broch | 96d83aa | 2011-08-29 14:37:38 -0700 | [diff] [blame] | 548 | self._server = xmlrpclib.ServerProxy(remote) |
Todd Broch | f24d278 | 2011-08-19 10:55:41 -0700 | [diff] [blame] | 549 | try: |
| 550 | self._server.echo("ping-test") |
Todd Broch | 96d83aa | 2011-08-29 14:37:38 -0700 | [diff] [blame] | 551 | except: |
| 552 | logging.error('Connection to servod failed') |
Todd Broch | f24d278 | 2011-08-19 10:55:41 -0700 | [diff] [blame] | 553 | raise |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 554 | |
| 555 | |
| 556 | def _scp_image(self, image_path): |
| 557 | """Copy image to the servo host. |
| 558 | |
| 559 | When programming a firmware image on the DUT, the image must be |
| 560 | located on the host to which the servo device is connected. Sometimes |
| 561 | servo is controlled by a remote host, in this case the image needs to |
| 562 | be transferred to the remote host. |
| 563 | |
| 564 | @param image_path: a string, name of the firmware image file to be |
| 565 | transferred. |
| 566 | @return: a string, full path name of the copied file on the remote. |
| 567 | """ |
| 568 | |
| 569 | dest_path = os.path.join('/tmp', os.path.basename(image_path)) |
| 570 | scp_cmd = self._scp_cmd_template % (image_path, dest_path) |
| 571 | utils.system(scp_cmd) |
| 572 | return dest_path |
| 573 | |
| 574 | |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 575 | def system(self, command, timeout=None): |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 576 | """Execute the passed in command on the servod host.""" |
| 577 | if self._sudo_required: |
| 578 | command = 'sudo -n %s' % command |
| 579 | if self._ssh_prefix: |
| 580 | command = "%s '%s'" % (self._ssh_prefix, command) |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 581 | logging.info('Will execute on servo host: %s', command) |
| 582 | utils.system(command, timeout=timeout) |
| 583 | |
| 584 | |
| 585 | def system_output(self, command, timeout=None, |
| 586 | ignore_status=False, args=()): |
| 587 | """Execute the passed in command on the servod host, return stdout. |
| 588 | |
| 589 | @param command, a string, the command to execute |
| 590 | @param timeout, an int, max number of seconds to wait til command |
| 591 | execution completes |
| 592 | @ignore_status, a Boolean, if true - ignore command's nonzero exit |
| 593 | status, otherwise an exception will be thrown |
| 594 | @param args, a tuple of strings, each becoming a separate command line |
| 595 | parameter for the command |
| 596 | @return: command's stdout as a string. |
| 597 | """ |
| 598 | if self._sudo_required: |
| 599 | command = 'sudo -n %s' % command |
| 600 | if self._ssh_prefix: |
| 601 | command = "%s '%s'" % (self._ssh_prefix, command) |
| 602 | logging.info('Will execute and collect output on servo host: %s %s', |
| 603 | command, ' '.join("'%s'" % x for x in args)) |
| 604 | return utils.system_output(command, timeout=timeout, |
| 605 | ignore_status=ignore_status, args=args) |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 606 | |
| 607 | |
| 608 | def program_ec(self, board, image): |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 609 | """Program EC on a given board using given image. |
| 610 | |
| 611 | @param board: a string, type of the DUT board |
| 612 | @param image: a string, file name of the EC image to program on the |
| 613 | DUT |
| 614 | """ |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 615 | if not self.is_localhost(): |
| 616 | image = self._scp_image(image) |
| 617 | programmer.program_ec(board, self, image) |
| 618 | |
| 619 | |
| 620 | def program_bootprom(self, board, image): |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 621 | """Program bootprom on a given board using given image. |
| 622 | |
| 623 | In case servo is controlled by a remote host, the image needs to be |
| 624 | transferred to the host. |
| 625 | |
| 626 | If the device tree subdirectory is present along with the image, the |
| 627 | subdirectory is also copied to the remote host. |
| 628 | |
| 629 | @param board: a string, type of the DUT board |
| 630 | @param image: a string, file name of the firmware image to program on |
| 631 | the DUT. The device tree subdirectory, if present, is on |
| 632 | the same level with the image file. |
| 633 | """ |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 634 | if not self.is_localhost(): |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 635 | dts_path = os.path.join(os.path.dirname(image), 'dts') |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 636 | image = self._scp_image(image) |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 637 | if os.path.isdir(dts_path): |
| 638 | self._scp_image(dts_path) |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 639 | programmer.program_bootprom(board, self, image) |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 640 | |
| 641 | def switch_usbkey(self, side): |
| 642 | """Connect USB flash stick to either host or DUT. |
| 643 | |
| 644 | This function switches the servo multiplexer to provide electrical |
| 645 | connection between the USB port J3 and either host or DUT side. |
| 646 | |
| 647 | Switching is accompanied by powercycling of the USB stick, because it |
| 648 | sometimes gets wedged if the mux is switched while the stick power is |
| 649 | on. |
| 650 | |
| 651 | @param side: a string, either 'dut' or 'host' - indicates which side |
| 652 | the USB flash device is required to be connected to. |
| 653 | |
| 654 | @raise: error.TestError in case the parameter is neither 'dut' not |
| 655 | 'host' |
| 656 | """ |
| 657 | |
| 658 | if self._usb_position == side: |
| 659 | return |
| 660 | |
| 661 | if side == 'host': |
| 662 | mux_direction = 'servo_sees_usbkey' |
| 663 | elif side == 'dut': |
| 664 | mux_direction = 'dut_sees_usbkey' |
| 665 | else: |
| 666 | raise error.TestError('unknown USB mux setting: %s' % side) |
| 667 | |
| 668 | self.set('prtctl4_pwren', 'off') |
| 669 | time.sleep(self.USB_POWEROFF_DELAY) |
| 670 | self.set('usb_mux_sel1', mux_direction) |
| 671 | time.sleep(self.USB_POWEROFF_DELAY) |
| 672 | self.set('prtctl4_pwren', 'on') |
| 673 | |
| 674 | self._usb_position = side |
| 675 | |
| 676 | |
| 677 | def get_usbkey_direction(self): |
| 678 | """Get name of the side the USB device is connected to. |
| 679 | |
| 680 | @return a string, either 'dut' or 'host' |
| 681 | """ |
| 682 | if not self._usb_position: |
| 683 | if self.get('usb_mux_sel1').starstwith('dut'): |
| 684 | self._usb_position = 'dut' |
| 685 | else: |
| 686 | self._usb_position = 'host' |
| 687 | return self._usb_position |