|
| 1 | +# Copyright (c) 2018 Intel Corporation. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +'''Runner for debugging and flashing Intel_s1000 devices''' |
| 6 | +from os import path |
| 7 | +from .core import ZephyrBinaryRunner |
| 8 | +import time |
| 9 | +import signal |
| 10 | + |
| 11 | +DEFAULT_XT_GDB_PORT = 20000 |
| 12 | + |
| 13 | +class intel_s1000BinaryRunner(ZephyrBinaryRunner): |
| 14 | + '''Runner front-end for Intel_s1000.''' |
| 15 | + |
| 16 | + def __init__(self, |
| 17 | + board_dir, xt_ocd_dir, |
| 18 | + ocd_topology, ocd_jtag_instr, gdb_flash_file, |
| 19 | + elf_name, gdb, |
| 20 | + gdb_port=DEFAULT_XT_GDB_PORT, debug=False): |
| 21 | + super(intel_s1000BinaryRunner, self).__init__(debug=debug) |
| 22 | + self.board_dir = board_dir |
| 23 | + self.xt_ocd_dir = xt_ocd_dir |
| 24 | + self.ocd_topology = ocd_topology |
| 25 | + self.ocd_jtag_instr = ocd_jtag_instr |
| 26 | + self.gdb_flash_file = gdb_flash_file |
| 27 | + self.elf_name = elf_name |
| 28 | + self.gdb_cmd = gdb |
| 29 | + self.gdb_port = gdb_port |
| 30 | + |
| 31 | + @classmethod |
| 32 | + def name(cls): |
| 33 | + return 'intel_s1000' |
| 34 | + |
| 35 | + @classmethod |
| 36 | + def do_add_parser(cls, parser): |
| 37 | + # Required |
| 38 | + |
| 39 | + # Optional |
| 40 | + parser.add_argument('--gdb-port', default=DEFAULT_XT_GDB_PORT, |
| 41 | + help='xt-gdb port, defaults to 20000') |
| 42 | + parser.add_argument('--xt-ocd-dir', default='/opt/Tensilica/xocd-12.0.4/xt-ocd', |
| 43 | + help='ocd-dir, defaults to /opt/Tensilica/xocd-12.0.4/xt-ocd') |
| 44 | + parser.add_argument('--ocd-topology', default='topology_dsp0_flyswatter2.xml', |
| 45 | + help='ocd-topology, defaults to topology_dsp0_flyswatter2.xml') |
| 46 | + parser.add_argument('--ocd-jtag-instr', default='dsp0_gdb.txt', |
| 47 | + help='ocd-jtag-instr, defaults to dsp0_gdb.txt') |
| 48 | + parser.add_argument('--gdb-flash-file', default='load_elf.txt', |
| 49 | + help='gdb-flash-file, defaults to load_elf.txt') |
| 50 | + |
| 51 | + @classmethod |
| 52 | + def create_from_args(command, args): |
| 53 | + return intel_s1000BinaryRunner( |
| 54 | + args.board_dir, args.xt_ocd_dir, |
| 55 | + args.ocd_topology, args.ocd_jtag_instr, args.gdb_flash_file, |
| 56 | + args.kernel_elf, args.gdb, |
| 57 | + gdb_port=args.gdb_port, debug=args.verbose) |
| 58 | + |
| 59 | + def do_run(self, command, **kwargs): |
| 60 | + kwargs['ocd-topology'] = path.join(self.board_dir, 'support', self.ocd_topology) |
| 61 | + kwargs['ocd-jtag-instr'] = path.join(self.board_dir, 'support', self.ocd_jtag_instr) |
| 62 | + kwargs['gdb-flash-file'] = path.join(self.board_dir, 'support', self.gdb_flash_file) |
| 63 | + |
| 64 | + if command == 'flash': |
| 65 | + self.flash(**kwargs) |
| 66 | + elif command == 'debugserver': |
| 67 | + self.debugserver(**kwargs) |
| 68 | + else: |
| 69 | + self.do_debug() |
| 70 | + |
| 71 | + def flash(self, **kwargs): |
| 72 | + topology_file = kwargs['ocd-topology'] |
| 73 | + jtag_instr_file = kwargs['ocd-jtag-instr'] |
| 74 | + gdb_flash_file = kwargs['gdb-flash-file'] |
| 75 | + |
| 76 | + self.print_gdbserver_message(self.gdb_port) |
| 77 | + server_cmd = [self.xt_ocd_dir, |
| 78 | + '-c', topology_file, |
| 79 | + '-I', jtag_instr_file] |
| 80 | + |
| 81 | + # Start the server |
| 82 | + # Note that XTOCD always fails the first time. It has to be |
| 83 | + # relaunched the second time to work. |
| 84 | + self.popen_ignore_int(server_cmd) |
| 85 | + time.sleep(3) |
| 86 | + server_proc = self.popen_ignore_int(server_cmd) |
| 87 | + time.sleep(3) |
| 88 | + |
| 89 | + # Start the client |
| 90 | + gdb_cmd = [self.gdb_cmd, '-x', gdb_flash_file] |
| 91 | + client_proc = self.popen_ignore_int(gdb_cmd) |
| 92 | + |
| 93 | + # Wait for 3 seconds (waiting for XTGDB to finish) |
| 94 | + time.sleep(3) |
| 95 | + |
| 96 | + # At this point, the ELF image is loaded and the program is in |
| 97 | + # execution. Now we can quit the client (xt-gdb) and the server |
| 98 | + # (xt-ocd) as they are not needed anymore. The loaded program |
| 99 | + # (ELF) will continue to run though. |
| 100 | + client_proc.terminate() |
| 101 | + server_proc.terminate() |
| 102 | + |
| 103 | + def do_debug(self): |
| 104 | + if self.elf_name is None: |
| 105 | + raise ValueError('Cannot debug; elf is missing') |
| 106 | + if self.gdb_cmd is None: |
| 107 | + raise ValueError('Cannot debug; no gdb specified') |
| 108 | + |
| 109 | + gdb_cmd = [self.gdb_cmd, |
| 110 | + '-ex', 'target remote :{}'.format(self.gdb_port), |
| 111 | + self.elf_name] |
| 112 | + |
| 113 | + # The below statement will consume the "^C" keypress ensuring |
| 114 | + # the python main application doesn't exit. This is important |
| 115 | + # since ^C in gdb means a "halt" operation. |
| 116 | + previous = signal.signal(signal.SIGINT, signal.SIG_IGN) |
| 117 | + try: |
| 118 | + self.check_call(gdb_cmd) |
| 119 | + finally: |
| 120 | + signal.signal(signal.SIGINT, previous) |
| 121 | + |
| 122 | + def print_gdbserver_message(self, gdb_port): |
| 123 | + print('Intel S1000 GDB server running on port {}'.format(gdb_port)) |
| 124 | + |
| 125 | + def debugserver(self, **kwargs): |
| 126 | + topology_file = kwargs['ocd-topology'] |
| 127 | + jtag_instr_file = kwargs['ocd-jtag-instr'] |
| 128 | + |
| 129 | + self.print_gdbserver_message(self.gdb_port) |
| 130 | + server_cmd = [self.xt_ocd_dir, |
| 131 | + '-c', topology_file, |
| 132 | + '-I', jtag_instr_file] |
| 133 | + |
| 134 | + # Note that XTOCD always fails the first time. It has to be |
| 135 | + # relaunched the second time to work. |
| 136 | + self.popen_ignore_int(server_cmd) |
| 137 | + time.sleep(3) |
| 138 | + self.check_call(server_cmd) |
0 commit comments