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 = [] |
Simon Glass | 18c5bfb | 2022-04-27 13:47:56 -0600 | [diff] [blame] | 30 | self.use_dtb = True |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 31 | |
| 32 | def get_spawn(self): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 33 | """Connect to a fresh U-Boot instance. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 34 | |
| 35 | A new sandbox process is created, so that U-Boot begins running from |
| 36 | scratch. |
| 37 | |
| 38 | Args: |
| 39 | None. |
| 40 | |
| 41 | Returns: |
| 42 | A u_boot_spawn.Spawn object that is attached to U-Boot. |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 43 | """ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 44 | |
Simon Glass | 8cfa74e | 2016-07-04 11:58:40 -0600 | [diff] [blame] | 45 | bcfg = self.config.buildconfig |
| 46 | config_spl = bcfg.get('config_spl', 'n') == 'y' |
Simon Glass | b6c665f | 2022-04-30 00:56:55 -0600 | [diff] [blame] | 47 | config_vpl = bcfg.get('config_vpl', 'n') == 'y' |
| 48 | if config_vpl: |
| 49 | # Run TPL first, which runs VPL |
| 50 | fname = '/tpl/u-boot-tpl' |
| 51 | else: |
| 52 | fname = '/spl/u-boot-spl' if config_spl else '/u-boot' |
Paul Burton | 00f2d20 | 2017-09-14 14:34:43 -0700 | [diff] [blame] | 53 | print(fname) |
Stephen Warren | 33db1ee | 2016-02-04 16:11:50 -0700 | [diff] [blame] | 54 | cmd = [] |
| 55 | if self.config.gdbserver: |
| 56 | cmd += ['gdbserver', self.config.gdbserver] |
Simon Glass | 18c5bfb | 2022-04-27 13:47:56 -0600 | [diff] [blame] | 57 | cmd += [self.config.build_dir + fname, '-v'] |
| 58 | if self.use_dtb: |
| 59 | cmd += ['-d', self.config.dtb] |
Simon Glass | 8125f2c | 2018-11-15 18:44:00 -0700 | [diff] [blame] | 60 | cmd += self.sandbox_flags |
Stephen Warren | a85fce9 | 2016-01-27 23:57:53 -0700 | [diff] [blame] | 61 | return Spawn(cmd, cwd=self.config.source_dir) |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 62 | |
Simon Glass | 18c5bfb | 2022-04-27 13:47:56 -0600 | [diff] [blame] | 63 | def restart_uboot_with_flags(self, flags, expect_reset=False, use_dtb=True): |
Simon Glass | 8125f2c | 2018-11-15 18:44:00 -0700 | [diff] [blame] | 64 | """Run U-Boot with the given command-line flags |
| 65 | |
| 66 | Args: |
| 67 | flags: List of flags to pass, each a string |
Masami Hiramatsu | 4d3b996 | 2022-02-16 15:16:02 +0900 | [diff] [blame] | 68 | expect_reset: Boolean indication whether this boot is expected |
| 69 | to be reset while the 1st boot process after main boot before |
| 70 | prompt. False by default. |
Simon Glass | 18c5bfb | 2022-04-27 13:47:56 -0600 | [diff] [blame] | 71 | use_dtb: True to use a device tree file, False to run without one |
Simon Glass | 8125f2c | 2018-11-15 18:44:00 -0700 | [diff] [blame] | 72 | |
| 73 | Returns: |
| 74 | A u_boot_spawn.Spawn object that is attached to U-Boot. |
| 75 | """ |
| 76 | |
| 77 | try: |
| 78 | self.sandbox_flags = flags |
Simon Glass | 18c5bfb | 2022-04-27 13:47:56 -0600 | [diff] [blame] | 79 | self.use_dtb = use_dtb |
Masami Hiramatsu | 4d3b996 | 2022-02-16 15:16:02 +0900 | [diff] [blame] | 80 | return self.restart_uboot(expect_reset) |
Simon Glass | 8125f2c | 2018-11-15 18:44:00 -0700 | [diff] [blame] | 81 | finally: |
| 82 | self.sandbox_flags = [] |
Simon Glass | 18c5bfb | 2022-04-27 13:47:56 -0600 | [diff] [blame] | 83 | self.use_dtb = True |
Simon Glass | 8125f2c | 2018-11-15 18:44:00 -0700 | [diff] [blame] | 84 | |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 85 | def kill(self, sig): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 86 | """Send a specific Unix signal to the sandbox process. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 87 | |
| 88 | Args: |
| 89 | sig: The Unix signal to send to the process. |
| 90 | |
| 91 | Returns: |
| 92 | Nothing. |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 93 | """ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 94 | |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 95 | self.log.action('kill %d' % sig) |
| 96 | self.p.kill(sig) |
| 97 | |
| 98 | def validate_exited(self): |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 99 | """Determine whether the sandbox process has exited. |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 100 | |
| 101 | If required, this function waits a reasonable time for the process to |
| 102 | exit. |
| 103 | |
| 104 | Args: |
| 105 | None. |
| 106 | |
| 107 | Returns: |
| 108 | Boolean indicating whether the process has exited. |
Stephen Warren | 75e731e | 2016-01-26 13:41:30 -0700 | [diff] [blame] | 109 | """ |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 110 | |
| 111 | p = self.p |
| 112 | self.p = None |
Paul Burton | d2849ed | 2017-09-14 14:34:44 -0700 | [diff] [blame] | 113 | for i in range(100): |
Stephen Warren | 10e5063 | 2016-01-15 11:15:24 -0700 | [diff] [blame] | 114 | ret = not p.isalive() |
| 115 | if ret: |
| 116 | break |
| 117 | time.sleep(0.1) |
| 118 | p.close() |
| 119 | return ret |