blob: 647e1f879fcadcbaf1487e6ad728597959e6f577 [file] [log] [blame]
Stephen Warrend2015062016-01-15 11:15:24 -07001# Copyright (c) 2015 Stephen Warren
2# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
3#
4# SPDX-License-Identifier: GPL-2.0
5
6# Logic to interact with the sandbox port of U-Boot, running as a sub-process.
7
8import time
9from u_boot_spawn import Spawn
10from u_boot_console_base import ConsoleBase
11
12class ConsoleSandbox(ConsoleBase):
Stephen Warrene8debf32016-01-26 13:41:30 -070013 """Represents a connection to a sandbox U-Boot console, executed as a sub-
14 process."""
Stephen Warrend2015062016-01-15 11:15:24 -070015
16 def __init__(self, log, config):
Stephen Warrene8debf32016-01-26 13:41:30 -070017 """Initialize a U-Boot console connection.
Stephen Warrend2015062016-01-15 11:15:24 -070018
19 Args:
20 log: A multiplexed_log.Logfile instance.
21 config: A "configuration" object as defined in conftest.py.
22
23 Returns:
24 Nothing.
Stephen Warrene8debf32016-01-26 13:41:30 -070025 """
Stephen Warrend2015062016-01-15 11:15:24 -070026
27 super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024)
28
29 def get_spawn(self):
Stephen Warrene8debf32016-01-26 13:41:30 -070030 """Connect to a fresh U-Boot instance.
Stephen Warrend2015062016-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 Warrene8debf32016-01-26 13:41:30 -070040 """
Stephen Warrend2015062016-01-15 11:15:24 -070041
Simon Glassa8117792016-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'
45 print fname
Stephen Warren89ab8412016-02-04 16:11:50 -070046 cmd = []
47 if self.config.gdbserver:
48 cmd += ['gdbserver', self.config.gdbserver]
49 cmd += [
Simon Glassa8117792016-07-04 11:58:40 -060050 self.config.build_dir + fname,
Stephen Warreneed095d2016-04-04 11:04:50 -060051 '-v',
Stephen Warren77bcb222016-01-27 23:57:52 -070052 '-d',
Simon Glass06719602016-07-03 09:40:36 -060053 self.config.dtb
Stephen Warren77bcb222016-01-27 23:57:52 -070054 ]
Stephen Warrend27f2fc2016-01-27 23:57:53 -070055 return Spawn(cmd, cwd=self.config.source_dir)
Stephen Warrend2015062016-01-15 11:15:24 -070056
57 def kill(self, sig):
Stephen Warrene8debf32016-01-26 13:41:30 -070058 """Send a specific Unix signal to the sandbox process.
Stephen Warrend2015062016-01-15 11:15:24 -070059
60 Args:
61 sig: The Unix signal to send to the process.
62
63 Returns:
64 Nothing.
Stephen Warrene8debf32016-01-26 13:41:30 -070065 """
Stephen Warrend2015062016-01-15 11:15:24 -070066
Stephen Warrend2015062016-01-15 11:15:24 -070067 self.log.action('kill %d' % sig)
68 self.p.kill(sig)
69
70 def validate_exited(self):
Stephen Warrene8debf32016-01-26 13:41:30 -070071 """Determine whether the sandbox process has exited.
Stephen Warrend2015062016-01-15 11:15:24 -070072
73 If required, this function waits a reasonable time for the process to
74 exit.
75
76 Args:
77 None.
78
79 Returns:
80 Boolean indicating whether the process has exited.
Stephen Warrene8debf32016-01-26 13:41:30 -070081 """
Stephen Warrend2015062016-01-15 11:15:24 -070082
83 p = self.p
84 self.p = None
85 for i in xrange(100):
86 ret = not p.isalive()
87 if ret:
88 break
89 time.sleep(0.1)
90 p.close()
91 return ret