u_boot_console_exec_attach.py 2.4 KB

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