]> git.ipfire.org Git - people/ms/u-boot.git/blame - test/py/u_boot_console_sandbox.py
engicam: Add fdt_addr env value based on cpu_type
[people/ms/u-boot.git] / test / py / u_boot_console_sandbox.py
CommitLineData
d201506c
SW
1# 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):
e8debf39
SW
13 """Represents a connection to a sandbox U-Boot console, executed as a sub-
14 process."""
d201506c
SW
15
16 def __init__(self, log, config):
e8debf39 17 """Initialize a U-Boot console connection.
d201506c
SW
18
19 Args:
20 log: A multiplexed_log.Logfile instance.
21 config: A "configuration" object as defined in conftest.py.
22
23 Returns:
24 Nothing.
e8debf39 25 """
d201506c
SW
26
27 super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024)
28
29 def get_spawn(self):
e8debf39 30 """Connect to a fresh U-Boot instance.
d201506c
SW
31
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.
e8debf39 40 """
d201506c 41
a811779b
SG
42 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
89ab8410
SW
46 cmd = []
47 if self.config.gdbserver:
48 cmd += ['gdbserver', self.config.gdbserver]
49 cmd += [
a811779b 50 self.config.build_dir + fname,
eed095da 51 '-v',
77bcb22d 52 '-d',
0671960b 53 self.config.dtb
77bcb22d 54 ]
d27f2fc1 55 return Spawn(cmd, cwd=self.config.source_dir)
d201506c
SW
56
57 def kill(self, sig):
e8debf39 58 """Send a specific Unix signal to the sandbox process.
d201506c
SW
59
60 Args:
61 sig: The Unix signal to send to the process.
62
63 Returns:
64 Nothing.
e8debf39 65 """
d201506c 66
d201506c
SW
67 self.log.action('kill %d' % sig)
68 self.p.kill(sig)
69
70 def validate_exited(self):
e8debf39 71 """Determine whether the sandbox process has exited.
d201506c
SW
72
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.
e8debf39 81 """
d201506c
SW
82
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