u_boot_console_sandbox.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. def get_spawn(self):
  21. """Connect to a fresh U-Boot instance.
  22. A new sandbox process is created, so that U-Boot begins running from
  23. scratch.
  24. Args:
  25. None.
  26. Returns:
  27. A u_boot_spawn.Spawn object that is attached to U-Boot.
  28. """
  29. bcfg = self.config.buildconfig
  30. config_spl = bcfg.get('config_spl', 'n') == 'y'
  31. fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
  32. print(fname)
  33. cmd = []
  34. if self.config.gdbserver:
  35. cmd += ['gdbserver', self.config.gdbserver]
  36. cmd += [
  37. self.config.build_dir + fname,
  38. '-v',
  39. '-d',
  40. self.config.dtb
  41. ]
  42. return Spawn(cmd, cwd=self.config.source_dir)
  43. def kill(self, sig):
  44. """Send a specific Unix signal to the sandbox process.
  45. Args:
  46. sig: The Unix signal to send to the process.
  47. Returns:
  48. Nothing.
  49. """
  50. self.log.action('kill %d' % sig)
  51. self.p.kill(sig)
  52. def validate_exited(self):
  53. """Determine whether the sandbox process has exited.
  54. If required, this function waits a reasonable time for the process to
  55. exit.
  56. Args:
  57. None.
  58. Returns:
  59. Boolean indicating whether the process has exited.
  60. """
  61. p = self.p
  62. self.p = None
  63. for i in xrange(100):
  64. ret = not p.isalive()
  65. if ret:
  66. break
  67. time.sleep(0.1)
  68. p.close()
  69. return ret