u_boot_console_sandbox.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Copyright (c) 2015 Stephen Warren
  2. # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
  3. #
  4. # SPDX-License-Identifier: GPL-2.0
  5. # Logic to interact with the sandbox port of U-Boot, running as a sub-process.
  6. import time
  7. from u_boot_spawn import Spawn
  8. from u_boot_console_base import ConsoleBase
  9. class ConsoleSandbox(ConsoleBase):
  10. """Represents a connection to a sandbox U-Boot console, executed as a sub-
  11. process."""
  12. def __init__(self, log, config):
  13. """Initialize a U-Boot console connection.
  14. Args:
  15. log: A multiplexed_log.Logfile instance.
  16. config: A "configuration" object as defined in conftest.py.
  17. Returns:
  18. Nothing.
  19. """
  20. super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024)
  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. return Spawn(cmd, cwd=self.config.source_dir)
  44. def kill(self, sig):
  45. """Send a specific Unix signal to the sandbox process.
  46. Args:
  47. sig: The Unix signal to send to the process.
  48. Returns:
  49. Nothing.
  50. """
  51. self.log.action('kill %d' % sig)
  52. self.p.kill(sig)
  53. def validate_exited(self):
  54. """Determine whether the sandbox process has exited.
  55. If required, this function waits a reasonable time for the process to
  56. exit.
  57. Args:
  58. None.
  59. Returns:
  60. Boolean indicating whether the process has exited.
  61. """
  62. p = self.p
  63. self.p = None
  64. for i in xrange(100):
  65. ret = not p.isalive()
  66. if ret:
  67. break
  68. time.sleep(0.1)
  69. p.close()
  70. return ret