xref: /rk3399_rockchip-uboot/test/py/u_boot_console_exec_attach.py (revision d201506cca782c54309b488170623094f252aab5)
1*d201506cSStephen Warren# Copyright (c) 2015 Stephen Warren
2*d201506cSStephen Warren# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
3*d201506cSStephen Warren#
4*d201506cSStephen Warren# SPDX-License-Identifier: GPL-2.0
5*d201506cSStephen Warren
6*d201506cSStephen Warren# Logic to interact with U-Boot running on real hardware, typically via a
7*d201506cSStephen Warren# physical serial port.
8*d201506cSStephen Warren
9*d201506cSStephen Warrenimport sys
10*d201506cSStephen Warrenfrom u_boot_spawn import Spawn
11*d201506cSStephen Warrenfrom u_boot_console_base import ConsoleBase
12*d201506cSStephen Warren
13*d201506cSStephen Warrenclass ConsoleExecAttach(ConsoleBase):
14*d201506cSStephen Warren    '''Represents a physical connection to a U-Boot console, typically via a
15*d201506cSStephen Warren    serial port. This implementation executes a sub-process to attach to the
16*d201506cSStephen Warren    console, expecting that the stdin/out of the sub-process will be forwarded
17*d201506cSStephen Warren    to/from the physical hardware. This approach isolates the test infra-
18*d201506cSStephen Warren    structure from the user-/installation-specific details of how to
19*d201506cSStephen Warren    communicate with, and the identity of, serial ports etc.'''
20*d201506cSStephen Warren
21*d201506cSStephen Warren    def __init__(self, log, config):
22*d201506cSStephen Warren        '''Initialize a U-Boot console connection.
23*d201506cSStephen Warren
24*d201506cSStephen Warren        Args:
25*d201506cSStephen Warren            log: A multiplexed_log.Logfile instance.
26*d201506cSStephen Warren            config: A "configuration" object as defined in conftest.py.
27*d201506cSStephen Warren
28*d201506cSStephen Warren        Returns:
29*d201506cSStephen Warren            Nothing.
30*d201506cSStephen Warren        '''
31*d201506cSStephen Warren
32*d201506cSStephen Warren        # The max_fifo_fill value might need tweaking per-board/-SoC?
33*d201506cSStephen Warren        # 1 would be safe anywhere, but is very slow (a pexpect issue?).
34*d201506cSStephen Warren        # 16 is a common FIFO size.
35*d201506cSStephen Warren        # HW flow control would mean this could be infinite.
36*d201506cSStephen Warren        super(ConsoleExecAttach, self).__init__(log, config, max_fifo_fill=16)
37*d201506cSStephen Warren
38*d201506cSStephen Warren        self.log.action('Flashing U-Boot')
39*d201506cSStephen Warren        cmd = ['u-boot-test-flash', config.board_type, config.board_identity]
40*d201506cSStephen Warren        runner = self.log.get_runner(cmd[0], sys.stdout)
41*d201506cSStephen Warren        runner.run(cmd)
42*d201506cSStephen Warren        runner.close()
43*d201506cSStephen Warren
44*d201506cSStephen Warren    def get_spawn(self):
45*d201506cSStephen Warren        '''Connect to a fresh U-Boot instance.
46*d201506cSStephen Warren
47*d201506cSStephen Warren        The target board is reset, so that U-Boot begins running from scratch.
48*d201506cSStephen Warren
49*d201506cSStephen Warren        Args:
50*d201506cSStephen Warren            None.
51*d201506cSStephen Warren
52*d201506cSStephen Warren        Returns:
53*d201506cSStephen Warren            A u_boot_spawn.Spawn object that is attached to U-Boot.
54*d201506cSStephen Warren        '''
55*d201506cSStephen Warren
56*d201506cSStephen Warren        args = [self.config.board_type, self.config.board_identity]
57*d201506cSStephen Warren        s = Spawn(['u-boot-test-console'] + args)
58*d201506cSStephen Warren
59*d201506cSStephen Warren        self.log.action('Resetting board')
60*d201506cSStephen Warren        cmd = ['u-boot-test-reset'] + args
61*d201506cSStephen Warren        runner = self.log.get_runner(cmd[0], sys.stdout)
62*d201506cSStephen Warren        runner.run(cmd)
63*d201506cSStephen Warren        runner.close()
64*d201506cSStephen Warren
65*d201506cSStephen Warren        return s
66