]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | # SPDX-License-Identifier: GPL-2.0 |
d201506c SW |
2 | # Copyright (c) 2015 Stephen Warren |
3 | # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved. | |
d201506c SW |
4 | |
5 | # Logic to interact with the sandbox port of U-Boot, running as a sub-process. | |
6 | ||
7 | import time | |
8 | from u_boot_spawn import Spawn | |
9 | from u_boot_console_base import ConsoleBase | |
10 | ||
11 | class ConsoleSandbox(ConsoleBase): | |
e8debf39 SW |
12 | """Represents a connection to a sandbox U-Boot console, executed as a sub- |
13 | process.""" | |
d201506c SW |
14 | |
15 | def __init__(self, log, config): | |
e8debf39 | 16 | """Initialize a U-Boot console connection. |
d201506c SW |
17 | |
18 | Args: | |
19 | log: A multiplexed_log.Logfile instance. | |
20 | config: A "configuration" object as defined in conftest.py. | |
21 | ||
22 | Returns: | |
23 | Nothing. | |
e8debf39 | 24 | """ |
d201506c SW |
25 | |
26 | super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024) | |
27 | ||
28 | def get_spawn(self): | |
e8debf39 | 29 | """Connect to a fresh U-Boot instance. |
d201506c SW |
30 | |
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. | |
e8debf39 | 39 | """ |
d201506c | 40 | |
a811779b SG |
41 | 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 | |
89ab8410 SW |
45 | cmd = [] |
46 | if self.config.gdbserver: | |
47 | cmd += ['gdbserver', self.config.gdbserver] | |
48 | cmd += [ | |
a811779b | 49 | self.config.build_dir + fname, |
eed095da | 50 | '-v', |
77bcb22d | 51 | '-d', |
0671960b | 52 | self.config.dtb |
77bcb22d | 53 | ] |
d27f2fc1 | 54 | return Spawn(cmd, cwd=self.config.source_dir) |
d201506c SW |
55 | |
56 | def kill(self, sig): | |
e8debf39 | 57 | """Send a specific Unix signal to the sandbox process. |
d201506c SW |
58 | |
59 | Args: | |
60 | sig: The Unix signal to send to the process. | |
61 | ||
62 | Returns: | |
63 | Nothing. | |
e8debf39 | 64 | """ |
d201506c | 65 | |
d201506c SW |
66 | self.log.action('kill %d' % sig) |
67 | self.p.kill(sig) | |
68 | ||
69 | def validate_exited(self): | |
e8debf39 | 70 | """Determine whether the sandbox process has exited. |
d201506c SW |
71 | |
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. | |
e8debf39 | 80 | """ |
d201506c SW |
81 | |
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 |