nsim.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Copyright (c) 2018 Synopsys Inc.
  2. # Copyright (c) 2017 Open Source Foundries Limited.
  3. #
  4. # SPDX-License-Identifier: Apache-2.0
  5. '''ARC architecture-specific runners.'''
  6. from os import path
  7. from runners.core import ZephyrBinaryRunner
  8. DEFAULT_ARC_GDB_PORT = 3333
  9. DEFAULT_PROPS_FILE = 'nsim_em.props'
  10. class NsimBinaryRunner(ZephyrBinaryRunner):
  11. '''Runner front-end for the ARC nSIM.'''
  12. # This unusual 'flash' implementation matches the original shell script.
  13. #
  14. # It works by starting a GDB server in a separate session, connecting a
  15. # client to it to load the program, and running 'continue' within the
  16. # client to execute the application.
  17. #
  18. def __init__(self, cfg,
  19. tui=False,
  20. gdb_port=DEFAULT_ARC_GDB_PORT,
  21. props=DEFAULT_PROPS_FILE):
  22. super().__init__(cfg)
  23. if cfg.gdb is None:
  24. self.gdb_cmd = None
  25. else:
  26. self.gdb_cmd = [cfg.gdb] + (['-tui'] if tui else [])
  27. self.nsim_cmd = ['nsimdrv']
  28. self.gdb_port = gdb_port
  29. self.props = props
  30. @classmethod
  31. def name(cls):
  32. return 'arc-nsim'
  33. @classmethod
  34. def do_add_parser(cls, parser):
  35. parser.add_argument('--gdb-port', default=DEFAULT_ARC_GDB_PORT,
  36. help='nsim gdb port, defaults to 3333')
  37. parser.add_argument('--props', default=DEFAULT_PROPS_FILE,
  38. help='nsim props file, defaults to nsim.props')
  39. @classmethod
  40. def do_create(cls, cfg, args):
  41. return NsimBinaryRunner(
  42. cfg,
  43. gdb_port=args.gdb_port,
  44. props=args.props)
  45. def do_run(self, command, **kwargs):
  46. self.require(self.nsim_cmd[0])
  47. kwargs['nsim-cfg'] = path.join(self.cfg.board_dir, 'support',
  48. self.props)
  49. if command == 'flash':
  50. self.do_flash(**kwargs)
  51. elif command == 'debug':
  52. self.do_debug(**kwargs)
  53. else:
  54. self.debugserver(**kwargs)
  55. def do_flash(self, **kwargs):
  56. config = kwargs['nsim-cfg']
  57. cmd = (self.nsim_cmd + ['-propsfile', config, self.cfg.elf_file])
  58. self.check_call(cmd)
  59. def do_debug(self, **kwargs):
  60. if self.gdb_cmd is None:
  61. raise ValueError('Cannot debug; gdb is missing')
  62. config = kwargs['nsim-cfg']
  63. server_cmd = (self.nsim_cmd + ['-gdb',
  64. '-port={}'.format(self.gdb_port),
  65. '-propsfile', config])
  66. gdb_cmd = (self.gdb_cmd +
  67. ['-ex', 'target remote :{}'.format(self.gdb_port),
  68. '-ex', 'load', self.cfg.elf_file])
  69. self.require(gdb_cmd[0])
  70. self.run_server_and_client(server_cmd, gdb_cmd)
  71. def debugserver(self, **kwargs):
  72. config = kwargs['nsim-cfg']
  73. cmd = (self.nsim_cmd +
  74. ['-gdb', '-port={}'.format(self.gdb_port),
  75. '-propsfile', config])
  76. self.check_call(cmd)