xref: /aosp_15_r20/external/autotest/server/site_tests/firmware_DevMode/firmware_DevMode.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Copyright (c) 2011 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
6
7from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
8from autotest_lib.server.cros.servo import chrome_ec
9from autotest_lib.server.cros import vboot_constants as vboot
10
11
12class firmware_DevMode(FirmwareTest):
13    """
14    Servo based developer firmware boot test.
15    """
16    version = 1
17
18    def initialize(self, host, cmdline_args, ec_wp=None):
19        super(firmware_DevMode, self).initialize(
20                host, cmdline_args, ec_wp=ec_wp)
21        self.switcher.setup_mode('normal')
22        self.setup_usbkey(usbkey=False)
23
24    def run_once(self):
25        """Method which actually runs the test."""
26        self.check_state((self.checkers.crossystem_checker, {
27                'devsw_boot': '0',
28                'mainfw_type': 'normal',
29        }))
30
31        logging.info("Enable dev mode.")
32        self.switcher.reboot_to_mode("dev", sync_before_boot=False)
33
34        logging.info("Expected developer mode boot and enable normal mode.")
35        self.check_state((self.checkers.crossystem_checker, {
36                'devsw_boot': '1',
37                'mainfw_type': 'developer',
38        }))
39        self.switcher.reboot_to_mode(to_mode='normal')
40
41        logging.info("Expected normal mode boot, done.")
42        self.check_state((self.checkers.crossystem_checker, {
43                'devsw_boot': '0',
44                'mainfw_type': 'normal',
45        }))
46
47        if self.check_ec_capability():
48            gbb = self.faft_client.bios.get_gbb_flags()
49            if gbb & vboot.GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC:
50                # In order to test that entering dev mode does not work when
51                # EC_IN_RW=1, EC software sync must be enabled.  If EC software
52                # sync is disabled, then we must skip this portion of the test.
53                logging.info("Skipping dev mode transition in EC RW test.")
54                return
55
56            logging.info("Rebooting into fake recovery mode (EC still in RW).")
57            self._client.power_off_via_servo()
58            self.ec.set_hostevent(chrome_ec.HOSTEVENT_KEYBOARD_RECOVERY)
59            self.servo.power_short_press()
60
61            logging.info("Trying to transition to dev mode with EC_IN_RW=1.")
62            self.switcher.trigger_rec_to_dev()
63            self.switcher.bypass_dev_mode()
64            if not self._client.ping_wait_up(
65                    timeout=self.faft_config.delay_reboot_to_ping):
66                logging.info("DUT didn't come back up (expected!), rebooting.")
67                self.switcher.simple_reboot(sync_before_boot=False)
68            self.switcher.wait_for_client()
69
70            logging.info("DUT is back up, should still be in normal mode now.")
71            self.check_state((self.checkers.crossystem_checker, {
72                    'devsw_boot': '0',
73                    'mainfw_type': 'normal',
74            }))
75