blob: 7e1eb0e0b45c4af5ed522d28e1602fe35547ae46 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0
Stephen Warrend2015062016-01-15 11:15:24 -07002# Copyright (c) 2015 Stephen Warren
3# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
Stephen Warrend2015062016-01-15 11:15:24 -07004
Heinrich Schuchardt6e6d37f2021-11-23 00:01:48 +01005"""
6Logic to interact with the sandbox port of U-Boot, running as a sub-process.
7"""
Stephen Warrend2015062016-01-15 11:15:24 -07008
9import time
10from u_boot_spawn import Spawn
11from u_boot_console_base import ConsoleBase
12
13class ConsoleSandbox(ConsoleBase):
Stephen Warrene8debf32016-01-26 13:41:30 -070014 """Represents a connection to a sandbox U-Boot console, executed as a sub-
15 process."""
Stephen Warrend2015062016-01-15 11:15:24 -070016
17 def __init__(self, log, config):
Stephen Warrene8debf32016-01-26 13:41:30 -070018 """Initialize a U-Boot console connection.
Stephen Warrend2015062016-01-15 11:15:24 -070019
20 Args:
21 log: A multiplexed_log.Logfile instance.
22 config: A "configuration" object as defined in conftest.py.
23
24 Returns:
25 Nothing.
Stephen Warrene8debf32016-01-26 13:41:30 -070026 """
Stephen Warrend2015062016-01-15 11:15:24 -070027
28 super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024)
Simon Glass20d44402018-11-15 18:44:00 -070029 self.sandbox_flags = []
Stephen Warrend2015062016-01-15 11:15:24 -070030
31 def get_spawn(self):
Stephen Warrene8debf32016-01-26 13:41:30 -070032 """Connect to a fresh U-Boot instance.
Stephen Warrend2015062016-01-15 11:15:24 -070033
34 A new sandbox process is created, so that U-Boot begins running from
35 scratch.
36
37 Args:
38 None.
39
40 Returns:
41 A u_boot_spawn.Spawn object that is attached to U-Boot.
Stephen Warrene8debf32016-01-26 13:41:30 -070042 """
Stephen Warrend2015062016-01-15 11:15:24 -070043
Simon Glassa8117792016-07-04 11:58:40 -060044 bcfg = self.config.buildconfig
45 config_spl = bcfg.get('config_spl', 'n') == 'y'
46 fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
Paul Burtondffd56d2017-09-14 14:34:43 -070047 print(fname)
Stephen Warren89ab8412016-02-04 16:11:50 -070048 cmd = []
49 if self.config.gdbserver:
50 cmd += ['gdbserver', self.config.gdbserver]
51 cmd += [
Simon Glassa8117792016-07-04 11:58:40 -060052 self.config.build_dir + fname,
Stephen Warreneed095d2016-04-04 11:04:50 -060053 '-v',
Stephen Warren77bcb222016-01-27 23:57:52 -070054 '-d',
Simon Glass06719602016-07-03 09:40:36 -060055 self.config.dtb
Stephen Warren77bcb222016-01-27 23:57:52 -070056 ]
Simon Glass20d44402018-11-15 18:44:00 -070057 cmd += self.sandbox_flags
Stephen Warrend27f2fc2016-01-27 23:57:53 -070058 return Spawn(cmd, cwd=self.config.source_dir)
Stephen Warrend2015062016-01-15 11:15:24 -070059
Simon Glass20d44402018-11-15 18:44:00 -070060 def restart_uboot_with_flags(self, flags):
61 """Run U-Boot with the given command-line flags
62
63 Args:
64 flags: List of flags to pass, each a string
65
66 Returns:
67 A u_boot_spawn.Spawn object that is attached to U-Boot.
68 """
69
70 try:
71 self.sandbox_flags = flags
72 return self.restart_uboot()
73 finally:
74 self.sandbox_flags = []
75
Stephen Warrend2015062016-01-15 11:15:24 -070076 def kill(self, sig):
Stephen Warrene8debf32016-01-26 13:41:30 -070077 """Send a specific Unix signal to the sandbox process.
Stephen Warrend2015062016-01-15 11:15:24 -070078
79 Args:
80 sig: The Unix signal to send to the process.
81
82 Returns:
83 Nothing.
Stephen Warrene8debf32016-01-26 13:41:30 -070084 """
Stephen Warrend2015062016-01-15 11:15:24 -070085
Stephen Warrend2015062016-01-15 11:15:24 -070086 self.log.action('kill %d' % sig)
87 self.p.kill(sig)
88
89 def validate_exited(self):
Stephen Warrene8debf32016-01-26 13:41:30 -070090 """Determine whether the sandbox process has exited.
Stephen Warrend2015062016-01-15 11:15:24 -070091
92 If required, this function waits a reasonable time for the process to
93 exit.
94
95 Args:
96 None.
97
98 Returns:
99 Boolean indicating whether the process has exited.
Stephen Warrene8debf32016-01-26 13:41:30 -0700100 """
Stephen Warrend2015062016-01-15 11:15:24 -0700101
102 p = self.p
103 self.p = None
Paul Burtonb8c45552017-09-14 14:34:44 -0700104 for i in range(100):
Stephen Warrend2015062016-01-15 11:15:24 -0700105 ret = not p.isalive()
106 if ret:
107 break
108 time.sleep(0.1)
109 p.close()
110 return ret