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