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