Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 2 | # Copyright (c) 2015 Stephen Warren |
| 3 | # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 4 | |
Heinrich Schuchardt | d209bab | 2021-11-23 00:01:48 +0100 | [diff] [blame] | 5 | """ |
| 6 | Logic to interact with the sandbox port of U-Boot, running as a sub-process. |
| 7 | """ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 8 | |
| 9 | import time |
| 10 | from u_boot_spawn import Spawn |
| 11 | from u_boot_console_base import ConsoleBase |
| 12 | |
| 13 | class ConsoleSandbox(ConsoleBase): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 14 | """Represents a connection to a sandbox U-Boot console, executed as a sub- |
| 15 | process.""" |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 16 | |
| 17 | def __init__(self, log, config): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 18 | """Initialize a U-Boot console connection. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 19 | |
| 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 Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 26 | """ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 27 | |
| 28 | super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024) |
Simon Glass | 8125f2c | 2018-11-15 18:44:00 -0700 | [diff] [blame] | 29 | self.sandbox_flags = [] |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 30 | |
| 31 | def get_spawn(self): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 32 | """Connect to a fresh U-Boot instance. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 33 | |
| 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 Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 42 | """ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 43 | |
Simon Glass | 8cfa74e | 2016-07-04 11:58:40 -0600 | [diff] [blame] | 44 | 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 Burton | 00f2d20 | 2017-09-14 14:34:43 -0700 | [diff] [blame] | 47 | print(fname) |
Stephen Warren | 33db1ee | 2016-02-04 16:11:50 -0700 | [diff] [blame] | 48 | cmd = [] |
| 49 | if self.config.gdbserver: |
| 50 | cmd += ['gdbserver', self.config.gdbserver] |
| 51 | cmd += [ |
Simon Glass | 8cfa74e | 2016-07-04 11:58:40 -0600 | [diff] [blame] | 52 | self.config.build_dir + fname, |
Stephen Warren | 8422703 | 2016-04-04 11:04:50 -0600 | [diff] [blame] | 53 | '-v', |
Stephen Warren | b8936ae | 2016-01-27 23:57:52 -0700 | [diff] [blame] | 54 | '-d', |
Simon Glass | 3b09787 | 2016-07-03 09:40:36 -0600 | [diff] [blame] | 55 | self.config.dtb |
Stephen Warren | b8936ae | 2016-01-27 23:57:52 -0700 | [diff] [blame] | 56 | ] |
Simon Glass | 8125f2c | 2018-11-15 18:44:00 -0700 | [diff] [blame] | 57 | cmd += self.sandbox_flags |
Stephen Warren | a85fce9 | 2016-01-27 23:57:53 -0700 | [diff] [blame] | 58 | return Spawn(cmd, cwd=self.config.source_dir) |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 59 | |
Simon Glass | 8125f2c | 2018-11-15 18:44:00 -0700 | [diff] [blame] | 60 | 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 Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 76 | def kill(self, sig): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 77 | """Send a specific Unix signal to the sandbox process. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 78 | |
| 79 | Args: |
| 80 | sig: The Unix signal to send to the process. |
| 81 | |
| 82 | Returns: |
| 83 | Nothing. |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 84 | """ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 85 | |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 86 | self.log.action('kill %d' % sig) |
| 87 | self.p.kill(sig) |
| 88 | |
| 89 | def validate_exited(self): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 90 | """Determine whether the sandbox process has exited. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 91 | |
| 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 Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 100 | """ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 101 | |
| 102 | p = self.p |
| 103 | self.p = None |
Paul Burton | d2849ed | 2017-09-14 14:34:44 -0700 | [diff] [blame] | 104 | for i in range(100): |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 105 | ret = not p.isalive() |
| 106 | if ret: |
| 107 | break |
| 108 | time.sleep(0.1) |
| 109 | p.close() |
| 110 | return ret |