• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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
5import logging
6import os
7import time
8
9from autotest_lib.client.common_lib import error
10from autotest_lib.server import test
11
12class firmware_FlashServoKeyboardMap(test.test):
13    """A test to flash the keyboard map on servo v3."""
14    version = 1
15
16    _ATMEGA_RESET_DELAY = 0.2
17    _USB_PRESENT_DELAY = 1
18
19    def run_once(self, host=None):
20        servo = host.servo
21        if host.run('hash dfu-programmer', ignore_status=True).exit_status:
22            raise error.TestError(
23                    'The image is too old that does not have dfu-programmer.')
24
25        try:
26            # Reset the chip and switch mux to let DUT to see the chip.
27            servo.set_get_all(['at_hwb:off',
28                               'atmega_rst:on',
29                               'sleep:%f' % self._ATMEGA_RESET_DELAY,
30                               'atmega_rst:off',
31                               'usb_mux_sel4:on'])
32
33            # Check the result of lsusb.
34            time.sleep(self._USB_PRESENT_DELAY)
35            result = host.run('lsusb -d 03eb:').stdout.strip()
36            if 'LUFA Keyboard Demo' in result:
37                logging.info('Already use the new keyboard map.')
38                return
39
40            if not 'Atmel Corp. atmega32u4 DFU bootloader' in result:
41                message = 'Not an expected chip: %s' % result
42                logging.error(message)
43                raise error.TestFail(message)
44
45            # Update the keyboard map.
46            local_path = os.path.join(self.bindir, 'test_data', 'keyboard.hex')
47            host.send_file(local_path, '/tmp')
48            logging.info('Updating the keyboard map...')
49            host.run('dfu-programmer atmega32u4 erase --force')
50            host.run('dfu-programmer atmega32u4 flash /tmp/keyboard.hex')
51
52            # Reset the chip.
53            servo.set_get_all(['atmega_rst:on',
54                               'sleep:%f' % self._ATMEGA_RESET_DELAY,
55                               'atmega_rst:off'])
56
57            # Check the result of lsusb.
58            time.sleep(self._USB_PRESENT_DELAY)
59            result = host.run('lsusb -d 03eb:').stdout.strip()
60            if 'LUFA Keyboard Demo' in result:
61                logging.info('Update successfully!')
62            else:
63                message = 'Update failed; got the result: %s' % result
64                logging.error(message)
65                raise error.TestFail(message)
66
67        finally:
68            # Restore the default settings.
69            servo.set('usb_mux_sel4', 'off')
70