blob: cef416d738ff2c04c2e99b5ad5141f7319d3fbba [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
Heinrich Schuchardtd209bab2021-11-23 00:01:48 +01005"""
6Logic to interact with the sandbox port of U-Boot, running as a sub-process.
7"""
Stephen Warren10e50632016-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 Warren75e731e2016-01-26 13:41:30 -070014 """Represents a connection to a sandbox U-Boot console, executed as a sub-
15 process."""
Stephen Warren10e50632016-01-15 11:15:24 -070016
17 def __init__(self, log, config):
Stephen Warren75e731e2016-01-26 13:41:30 -070018 """Initialize a U-Boot console connection.
Stephen Warren10e50632016-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 Warren75e731e2016-01-26 13:41:30 -070026 """
Stephen Warren10e50632016-01-15 11:15:24 -070027
28 super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024)
Simon Glass8125f2c2018-11-15 18:44:00 -070029 self.sandbox_flags = []
Stephen Warren10e50632016-01-15 11:15:24 -070030
31 def get_spawn(self):
Stephen Warren75e731e2016-01-26 13:41:30 -070032 """Connect to a fresh U-Boot instance.
Stephen Warren10e50632016-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 Warren75e731e2016-01-26 13:41:30 -070042 """
Stephen Warren10e50632016-01-15 11:15:24 -070043
Simon Glass8cfa74e2016-07-04 11:58:40 -060044 bcfg = self.config.buildconfig
45 config_spl = bcfg.get('config_spl', 'n') == 'y'
Simon Glassb6c665f2022-04-30 00:56:55 -060046 config_vpl = bcfg.get('config_vpl', 'n') == 'y'
47 if config_vpl:
48 # Run TPL first, which runs VPL
49 fname = '/tpl/u-boot-tpl'
50 else:
51 fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
Paul Burton00f2d202017-09-14 14:34:43 -070052 print(fname)
Stephen Warren33db1ee2016-02-04 16:11:50 -070053 cmd = []
54 if self.config.gdbserver:
55 cmd += ['gdbserver', self.config.gdbserver]
56 cmd += [
Simon Glass8cfa74e2016-07-04 11:58:40 -060057 self.config.build_dir + fname,
Stephen Warren84227032016-04-04 11:04:50 -060058 '-v',
Stephen Warrenb8936ae2016-01-27 23:57:52 -070059 '-d',
Simon Glass3b097872016-07-03 09:40:36 -060060 self.config.dtb
Stephen Warrenb8936ae2016-01-27 23:57:52 -070061 ]
Simon Glass8125f2c2018-11-15 18:44:00 -070062 cmd += self.sandbox_flags
Stephen Warrena85fce92016-01-27 23:57:53 -070063 return Spawn(cmd, cwd=self.config.source_dir)
Stephen Warren10e50632016-01-15 11:15:24 -070064
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +090065 def restart_uboot_with_flags(self, flags, expect_reset=False):
Simon Glass8125f2c2018-11-15 18:44:00 -070066 """Run U-Boot with the given command-line flags
67
68 Args:
69 flags: List of flags to pass, each a string
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +090070 expect_reset: Boolean indication whether this boot is expected
71 to be reset while the 1st boot process after main boot before
72 prompt. False by default.
Simon Glass8125f2c2018-11-15 18:44:00 -070073
74 Returns:
75 A u_boot_spawn.Spawn object that is attached to U-Boot.
76 """
77
78 try:
79 self.sandbox_flags = flags
Masami Hiramatsu4d3b9962022-02-16 15:16:02 +090080 return self.restart_uboot(expect_reset)
Simon Glass8125f2c2018-11-15 18:44:00 -070081 finally:
82 self.sandbox_flags = []
83
Stephen Warren10e50632016-01-15 11:15:24 -070084 def kill(self, sig):
Stephen Warren75e731e2016-01-26 13:41:30 -070085 """Send a specific Unix signal to the sandbox process.
Stephen Warren10e50632016-01-15 11:15:24 -070086
87 Args:
88 sig: The Unix signal to send to the process.
89
90 Returns:
91 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070092 """
Stephen Warren10e50632016-01-15 11:15:24 -070093
Stephen Warren10e50632016-01-15 11:15:24 -070094 self.log.action('kill %d' % sig)
95 self.p.kill(sig)
96
97 def validate_exited(self):
Stephen Warren75e731e2016-01-26 13:41:30 -070098 """Determine whether the sandbox process has exited.
Stephen Warren10e50632016-01-15 11:15:24 -070099
100 If required, this function waits a reasonable time for the process to
101 exit.
102
103 Args:
104 None.
105
106 Returns:
107 Boolean indicating whether the process has exited.
Stephen Warren75e731e2016-01-26 13:41:30 -0700108 """
Stephen Warren10e50632016-01-15 11:15:24 -0700109
110 p = self.p
111 self.p = None
Paul Burtond2849ed2017-09-14 14:34:44 -0700112 for i in range(100):
Stephen Warren10e50632016-01-15 11:15:24 -0700113 ret = not p.isalive()
114 if ret:
115 break
116 time.sleep(0.1)
117 p.close()
118 return ret