misc.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (c) 2019, Nordic Semiconductor ASA
  2. #
  3. # SPDX-License-Identifier: Apache-2.0
  4. '''Catch-all module for miscellaneous devices which can't use a
  5. generic or widely used tool like J-Link, OpenOCD, etc.
  6. Please use this sparingly and only when your setup is exotic and
  7. you're willing to handle requests for help. E.g. if your "board" is a
  8. core on a special-purpose SoC which requires a complicated script to
  9. network boot.'''
  10. from runners.core import ZephyrBinaryRunner, RunnerCaps
  11. import argparse
  12. class MiscFlasher(ZephyrBinaryRunner):
  13. '''Runner for handling special purpose flashing commands.'''
  14. def __init__(self, cfg, cmd, args):
  15. super().__init__(cfg)
  16. if not cmd:
  17. # This is a board definition error, not a user error,
  18. # so we can do it now and not in do_run().
  19. raise ValueError('no command was given')
  20. self.cmd = cmd
  21. self.args = args
  22. @classmethod
  23. def name(cls):
  24. return 'misc-flasher'
  25. @classmethod
  26. def capabilities(cls):
  27. return RunnerCaps(commands={'flash'})
  28. @classmethod
  29. def do_add_parser(cls, parser):
  30. parser.add_argument('cmd',
  31. help='''command to run; it will be passed the
  32. build directory as its first argument''')
  33. parser.add_argument('args', nargs=argparse.REMAINDER,
  34. help='''additional arguments to pass after the build
  35. directory''')
  36. @classmethod
  37. def do_create(cls, cfg, args):
  38. return MiscFlasher(cfg, args.cmd, args.args)
  39. def do_run(self, *args, **kwargs):
  40. self.require(self.cmd)
  41. self.check_call([self.cmd, self.cfg.build_dir] + self.args)