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