u_boot_console_exec_attach.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 U-Boot running on real hardware, typically via a
  5. # physical serial port.
  6. import sys
  7. from u_boot_spawn import Spawn
  8. from u_boot_console_base import ConsoleBase
  9. class ConsoleExecAttach(ConsoleBase):
  10. """Represents a physical connection to a U-Boot console, typically via a
  11. serial port. This implementation executes a sub-process to attach to the
  12. console, expecting that the stdin/out of the sub-process will be forwarded
  13. to/from the physical hardware. This approach isolates the test infra-
  14. structure from the user-/installation-specific details of how to
  15. communicate with, and the identity of, serial ports etc."""
  16. def __init__(self, log, config):
  17. """Initialize a U-Boot console connection.
  18. Args:
  19. log: A multiplexed_log.Logfile instance.
  20. config: A "configuration" object as defined in conftest.py.
  21. Returns:
  22. Nothing.
  23. """
  24. # The max_fifo_fill value might need tweaking per-board/-SoC?
  25. # 1 would be safe anywhere, but is very slow (a pexpect issue?).
  26. # 16 is a common FIFO size.
  27. # HW flow control would mean this could be infinite.
  28. super(ConsoleExecAttach, self).__init__(log, config, max_fifo_fill=16)
  29. with self.log.section('flash'):
  30. self.log.action('Flashing U-Boot')
  31. cmd = ['u-boot-test-flash', config.board_type, config.board_identity]
  32. runner = self.log.get_runner(cmd[0], sys.stdout)
  33. runner.run(cmd)
  34. runner.close()
  35. self.log.status_pass('OK')
  36. def get_spawn(self):
  37. """Connect to a fresh U-Boot instance.
  38. The target board is reset, so that U-Boot begins running from scratch.
  39. Args:
  40. None.
  41. Returns:
  42. A u_boot_spawn.Spawn object that is attached to U-Boot.
  43. """
  44. args = [self.config.board_type, self.config.board_identity]
  45. s = Spawn(['u-boot-test-console'] + args)
  46. try:
  47. self.log.action('Resetting board')
  48. cmd = ['u-boot-test-reset'] + args
  49. runner = self.log.get_runner(cmd[0], sys.stdout)
  50. runner.run(cmd)
  51. runner.close()
  52. except:
  53. s.close()
  54. raise
  55. return s