blob: a616cfb49fc7a06a97af6e6b19fd93b804f3cf0e [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)
27
28 def get_spawn(self):
Stephen Warren75e731e2016-01-26 13:41:30 -070029 """Connect to a fresh U-Boot instance.
Stephen Warren10e50632016-01-15 11:15:24 -070030
31 A new sandbox process is created, so that U-Boot begins running from
32 scratch.
33
34 Args:
35 None.
36
37 Returns:
38 A u_boot_spawn.Spawn object that is attached to U-Boot.
Stephen Warren75e731e2016-01-26 13:41:30 -070039 """
Stephen Warren10e50632016-01-15 11:15:24 -070040
Simon Glass8cfa74e2016-07-04 11:58:40 -060041 bcfg = self.config.buildconfig
42 config_spl = bcfg.get('config_spl', 'n') == 'y'
43 fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
44 print fname
Stephen Warren33db1ee2016-02-04 16:11:50 -070045 cmd = []
46 if self.config.gdbserver:
47 cmd += ['gdbserver', self.config.gdbserver]
48 cmd += [
Simon Glass8cfa74e2016-07-04 11:58:40 -060049 self.config.build_dir + fname,
Stephen Warren84227032016-04-04 11:04:50 -060050 '-v',
Stephen Warrenb8936ae2016-01-27 23:57:52 -070051 '-d',
Simon Glass3b097872016-07-03 09:40:36 -060052 self.config.dtb
Stephen Warrenb8936ae2016-01-27 23:57:52 -070053 ]
Stephen Warrena85fce92016-01-27 23:57:53 -070054 return Spawn(cmd, cwd=self.config.source_dir)
Stephen Warren10e50632016-01-15 11:15:24 -070055
56 def kill(self, sig):
Stephen Warren75e731e2016-01-26 13:41:30 -070057 """Send a specific Unix signal to the sandbox process.
Stephen Warren10e50632016-01-15 11:15:24 -070058
59 Args:
60 sig: The Unix signal to send to the process.
61
62 Returns:
63 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070064 """
Stephen Warren10e50632016-01-15 11:15:24 -070065
Stephen Warren10e50632016-01-15 11:15:24 -070066 self.log.action('kill %d' % sig)
67 self.p.kill(sig)
68
69 def validate_exited(self):
Stephen Warren75e731e2016-01-26 13:41:30 -070070 """Determine whether the sandbox process has exited.
Stephen Warren10e50632016-01-15 11:15:24 -070071
72 If required, this function waits a reasonable time for the process to
73 exit.
74
75 Args:
76 None.
77
78 Returns:
79 Boolean indicating whether the process has exited.
Stephen Warren75e731e2016-01-26 13:41:30 -070080 """
Stephen Warren10e50632016-01-15 11:15:24 -070081
82 p = self.p
83 self.p = None
84 for i in xrange(100):
85 ret = not p.isalive()
86 if ret:
87 break
88 time.sleep(0.1)
89 p.close()
90 return ret