hifive1.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) 2019, Timon Baetz
  2. #
  3. # SPDX-License-Identifier: Apache-2.0
  4. '''HiFive1-specific (flash only) runner.'''
  5. from os import path
  6. from runners.core import ZephyrBinaryRunner, RunnerCaps
  7. class HiFive1BinaryRunner(ZephyrBinaryRunner):
  8. '''Runner front-end for the HiFive1 board, using openocd.'''
  9. def __init__(self, cfg):
  10. super().__init__(cfg)
  11. self.openocd_config = path.join(cfg.board_dir, 'support', 'openocd.cfg')
  12. @classmethod
  13. def name(cls):
  14. return 'hifive1'
  15. @classmethod
  16. def capabilities(cls):
  17. return RunnerCaps(commands={'flash'})
  18. @classmethod
  19. def do_add_parser(cls, parser):
  20. pass
  21. @classmethod
  22. def do_create(cls, cfg, args):
  23. if cfg.gdb is None:
  24. raise ValueError('--gdb not provided at command line')
  25. return HiFive1BinaryRunner(cfg)
  26. def do_run(self, command, **kwargs):
  27. self.require(self.cfg.openocd)
  28. self.require(self.cfg.gdb)
  29. openocd_cmd = ([self.cfg.openocd, '-f', self.openocd_config])
  30. gdb_cmd = ([self.cfg.gdb, self.cfg.elf_file, '--batch',
  31. '-ex', 'set remotetimeout 240',
  32. '-ex', 'target extended-remote localhost:3333',
  33. '-ex', 'load',
  34. '-ex', 'quit'])
  35. self.run_server_and_client(openocd_cmd, gdb_cmd)