u_boot_console_sandbox.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Copyright (c) 2015 Stephen Warren
  3. # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
  4. # Logic to interact with the sandbox port of U-Boot, running as a sub-process.
  5. import time
  6. from u_boot_spawn import Spawn
  7. from u_boot_console_base import ConsoleBase
  8. class ConsoleSandbox(ConsoleBase):
  9. """Represents a connection to a sandbox U-Boot console, executed as a sub-
  10. process."""
  11. def __init__(self, log, config):
  12. """Initialize a U-Boot console connection.
  13. Args:
  14. log: A multiplexed_log.Logfile instance.
  15. config: A "configuration" object as defined in conftest.py.
  16. Returns:
  17. Nothing.
  18. """
  19. super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024)
  20. self.sandbox_flags = []
  21. def get_spawn(self):
  22. """Connect to a fresh U-Boot instance.
  23. A new sandbox process is created, so that U-Boot begins running from
  24. scratch.
  25. Args:
  26. None.
  27. Returns:
  28. A u_boot_spawn.Spawn object that is attached to U-Boot.
  29. """
  30. bcfg = self.config.buildconfig
  31. config_spl = bcfg.get('config_spl', 'n') == 'y'
  32. fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
  33. print(fname)
  34. cmd = []
  35. if self.config.gdbserver:
  36. cmd += ['gdbserver', self.config.gdbserver]
  37. cmd += [
  38. self.config.build_dir + fname,
  39. '-v',
  40. '-d',
  41. self.config.dtb
  42. ]
  43. cmd += self.sandbox_flags
  44. return Spawn(cmd, cwd=self.config.source_dir)
  45. def restart_uboot_with_flags(self, flags):
  46. """Run U-Boot with the given command-line flags
  47. Args:
  48. flags: List of flags to pass, each a string
  49. Returns:
  50. A u_boot_spawn.Spawn object that is attached to U-Boot.
  51. """
  52. try:
  53. self.sandbox_flags = flags
  54. return self.restart_uboot()
  55. finally:
  56. self.sandbox_flags = []
  57. def kill(self, sig):
  58. """Send a specific Unix signal to the sandbox process.
  59. Args:
  60. sig: The Unix signal to send to the process.
  61. Returns:
  62. Nothing.
  63. """
  64. self.log.action('kill %d' % sig)
  65. self.p.kill(sig)
  66. def validate_exited(self):
  67. """Determine whether the sandbox process has exited.
  68. If required, this function waits a reasonable time for the process to
  69. exit.
  70. Args:
  71. None.
  72. Returns:
  73. Boolean indicating whether the process has exited.
  74. """
  75. p = self.p
  76. self.p = None
  77. for i in range(100):
  78. ret = not p.isalive()
  79. if ret:
  80. break
  81. time.sleep(0.1)
  82. p.close()
  83. return ret