blob: 836f5a9e2b822c2d2d606be156189c094c257ea7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0
Stephen Warren10e50632016-01-15 11:15:24 -07002# Copyright (c) 2015 Stephen Warren
3# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
Stephen Warren10e50632016-01-15 11:15:24 -07004
5# Logic to interact with the sandbox port of U-Boot, running as a sub-process.
6
7import time
8from u_boot_spawn import Spawn
9from u_boot_console_base import ConsoleBase
10
11class ConsoleSandbox(ConsoleBase):
Stephen Warren75e731e2016-01-26 13:41:30 -070012 """Represents a connection to a sandbox U-Boot console, executed as a sub-
13 process."""
Stephen Warren10e50632016-01-15 11:15:24 -070014
15 def __init__(self, log, config):
Stephen Warren75e731e2016-01-26 13:41:30 -070016 """Initialize a U-Boot console connection.
Stephen Warren10e50632016-01-15 11:15:24 -070017
18 Args:
19 log: A multiplexed_log.Logfile instance.
20 config: A "configuration" object as defined in conftest.py.
21
22 Returns:
23 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070024 """
Stephen Warren10e50632016-01-15 11:15:24 -070025
26 super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024)
Simon Glass8125f2c2018-11-15 18:44:00 -070027 self.sandbox_flags = []
Stephen Warren10e50632016-01-15 11:15:24 -070028
29 def get_spawn(self):
Stephen Warren75e731e2016-01-26 13:41:30 -070030 """Connect to a fresh U-Boot instance.
Stephen Warren10e50632016-01-15 11:15:24 -070031
32 A new sandbox process is created, so that U-Boot begins running from
33 scratch.
34
35 Args:
36 None.
37
38 Returns:
39 A u_boot_spawn.Spawn object that is attached to U-Boot.
Stephen Warren75e731e2016-01-26 13:41:30 -070040 """
Stephen Warren10e50632016-01-15 11:15:24 -070041
Simon Glass8cfa74e2016-07-04 11:58:40 -060042 bcfg = self.config.buildconfig
43 config_spl = bcfg.get('config_spl', 'n') == 'y'
44 fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
Paul Burton00f2d202017-09-14 14:34:43 -070045 print(fname)
Stephen Warren33db1ee2016-02-04 16:11:50 -070046 cmd = []
47 if self.config.gdbserver:
48 cmd += ['gdbserver', self.config.gdbserver]
49 cmd += [
Simon Glass8cfa74e2016-07-04 11:58:40 -060050 self.config.build_dir + fname,
Stephen Warren84227032016-04-04 11:04:50 -060051 '-v',
Stephen Warrenb8936ae2016-01-27 23:57:52 -070052 '-d',
Simon Glass3b097872016-07-03 09:40:36 -060053 self.config.dtb
Stephen Warrenb8936ae2016-01-27 23:57:52 -070054 ]
Simon Glass8125f2c2018-11-15 18:44:00 -070055 cmd += self.sandbox_flags
Stephen Warrena85fce92016-01-27 23:57:53 -070056 return Spawn(cmd, cwd=self.config.source_dir)
Stephen Warren10e50632016-01-15 11:15:24 -070057
Simon Glass8125f2c2018-11-15 18:44:00 -070058 def restart_uboot_with_flags(self, flags):
59 """Run U-Boot with the given command-line flags
60
61 Args:
62 flags: List of flags to pass, each a string
63
64 Returns:
65 A u_boot_spawn.Spawn object that is attached to U-Boot.
66 """
67
68 try:
69 self.sandbox_flags = flags
70 return self.restart_uboot()
71 finally:
72 self.sandbox_flags = []
73
Stephen Warren10e50632016-01-15 11:15:24 -070074 def kill(self, sig):
Stephen Warren75e731e2016-01-26 13:41:30 -070075 """Send a specific Unix signal to the sandbox process.
Stephen Warren10e50632016-01-15 11:15:24 -070076
77 Args:
78 sig: The Unix signal to send to the process.
79
80 Returns:
81 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070082 """
Stephen Warren10e50632016-01-15 11:15:24 -070083
Stephen Warren10e50632016-01-15 11:15:24 -070084 self.log.action('kill %d' % sig)
85 self.p.kill(sig)
86
87 def validate_exited(self):
Stephen Warren75e731e2016-01-26 13:41:30 -070088 """Determine whether the sandbox process has exited.
Stephen Warren10e50632016-01-15 11:15:24 -070089
90 If required, this function waits a reasonable time for the process to
91 exit.
92
93 Args:
94 None.
95
96 Returns:
97 Boolean indicating whether the process has exited.
Stephen Warren75e731e2016-01-26 13:41:30 -070098 """
Stephen Warren10e50632016-01-15 11:15:24 -070099
100 p = self.p
101 self.p = None
Paul Burtond2849ed2017-09-14 14:34:44 -0700102 for i in range(100):
Stephen Warren10e50632016-01-15 11:15:24 -0700103 ret = not p.isalive()
104 if ret:
105 break
106 time.sleep(0.1)
107 p.close()
108 return ret