xref: /aosp_15_r20/external/autotest/server/cros/servo/chrome_ti50.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2# Copyright 2021 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6from autotest_lib.server.cros.servo import chrome_cr50
7from autotest_lib.client.common_lib import error
8
9
10class ChromeTi50(chrome_cr50.ChromeCr50):
11    """Manages control of a Chrome Ti50.
12
13    We control the Chrome Ti50 via the console of a Servo board. Chrome Ti50
14    provides many interfaces to set and get its behavior via console commands.
15    This class is to abstract these interfaces.
16    """
17
18    WAKE_RESPONSE = ['(>|ti50_common)']
19    START_STR = ['ti50_common']
20
21    # List of all ti50 ccd capabilities. Same order of 'ccd' output.
22    # This is not the same as cr50 list.
23    CAP_NAMES = [
24            'UartGscRxAPTx', 'UartGscTxAPRx', 'UartGscRxECTx', 'UartGscTxECRx',
25            'UartGscRxFpmcuTx', 'UartGscTxFpmcuRx', 'FlashAP', 'FlashEC',
26            'OverrideWP', 'RebootECAP', 'GscFullConsole', 'UnlockNoReboot',
27            'UnlockNoShortPP', 'OpenNoTPMWipe', 'OpenNoLongPP',
28            'BatteryBypassPP', 'I2C', 'FlashRead', 'OpenNoDevMode',
29            'OpenFromUSB', 'OverrideBatt'
30    ]
31    # Ti50 only supports v2
32    AP_RO_VERSIONS = [2]
33
34    def __init__(self, servo, faft_config):
35        """Initializes a ChromeCr50 object.
36
37        @param servo: A servo object.
38        @param faft_config: A faft config object.
39        """
40        super(ChromeTi50, self).__init__(servo, 'cr50_uart')
41        self.faft_config = faft_config
42        # Update CCD_FORMAT to use ti50 version of CAP_NAMES.
43        self.CCD_FORMAT['Capabilities'] = \
44            '(Capabilities:.*(?P<Capabilities>%s))' % \
45            (self.CAP_FORMAT.join(self.CAP_NAMES) + self.CAP_FORMAT)
46
47    def set_ccd_level(self, level, password=''):
48        if level == 'unlock':
49            raise error.TestError(
50                "Ti50 does not support privilege level unlock")
51        super(ChromeTi50, self).set_ccd_level(level, password)
52
53    def unlock_is_supported(self):
54        return False
55
56    def check_boot_mode(self, mode_exp='NORMAL'):
57        """Query the Ti50 boot mode, and compare it against mode_exp.
58
59        Args:
60            mode_exp: expected boot mode. It should be either 'NORMAL'
61                      or 'NO_BOOT'.
62        Returns:
63            True if the boot mode matches mode_exp.
64            False, otherwise.
65        Raises:
66            TestError: Input parameter is not valid.
67        """
68
69        # Ti50 implements EFS 2.1, Cr50 implements EFS 2.0. This means
70        # 'NORMAL' is renamed to 'VERIFIED'. Ti50 also changes the case.
71        rv = self.send_command_retry_get_output('ec_comm',
72                [r'boot_mode\s*:\s*(Verified|NoBoot)'], safe=True)
73        if mode_exp == 'NORMAL':
74            return rv[0][1] == 'Verified'
75        elif mode_exp == 'NO_BOOT':
76            return rv[0][1] == 'NoBoot'
77        else:
78            raise error.TestError('parameter, mode_exp is not valid: %s' %
79                                  mode_exp)
80