forked from cahirwpz/mimiker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch
executable file
·183 lines (148 loc) · 5.54 KB
/
launch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/python3
import argparse
import os
import os.path
import signal
import subprocess
import shlex
import shutil
from pexpect import popen_spawn
PORT = 8000
DEBUGGERS = {
'gdb': '%(triplet)s-gdb %(kernel)s',
'cgdb': 'cgdb -d %(triplet)s-gdb %(kernel)s',
'ddd': 'ddd --debugger %(triplet)s-gdb %(kernel)s',
'gdbtui': '%(triplet)s-gdb -tui',
'emacs': 'emacsclient -c -e \'(gdb "%(triplet)s-gdb -i=mi %(kernel)s")\''
}
DEFAULT_DEBUGGER = 'cgdb'
assert(DEFAULT_DEBUGGER in DEBUGGERS)
def find_triplet():
for triplet in ['mipsel-unknown-elf', 'mips-mti-elf']:
if shutil.which(triplet + '-gcc'):
return triplet
raise SystemExit('No cross compiler found!')
def configure_ovpsim(args):
OVPSIM_OVERRIDES = {
'mipsle1/vectoredinterrupt': 1,
'mipsle1/srsctlHSS': 1,
'rtc/timefromhost': 1,
'uartCBUS/console': 1,
'uartCBUS/portnum': PORT
}
try:
os.remove('uartCBUS.log')
os.remove('uartTTY0.log')
os.remove('uartTTY1.log')
except OSError:
pass
options = ['--root', '/dev/null',
'--nographics',
'--wallclock',
'--kernel', args.kernel]
if args.test:
OVPSIM_OVERRIDES['uartCBUS/console'] = 0
for item in OVPSIM_OVERRIDES.items():
options += ['--override', '%s=%s' % item]
if args.debug:
options += ['--port', '1234']
return options
def configure_qemu(args):
options = ['-nographic',
'-nodefaults',
'-machine', 'malta',
'-cpu', '24Kf',
'-kernel', args.kernel]
if args.test:
options += ['-serial', 'null',
'-serial', 'null',
'-monitor', 'stdio',
'-serial', 'tcp:127.0.0.1:%d,server,nowait' % PORT]
else:
options += ['-serial', 'none',
'-serial', 'null',
'-serial', 'null',
'-serial', 'stdio']
if args.debug:
options += ['-s', '-S']
return options
def find_simulator():
sim_choices = {}
sim_default = None
if shutil.which('qemu-system-mipsel'):
sim_choices['qemu'] = ['qemu-system-mipsel', configure_qemu]
sim_default = 'qemu'
try:
OVPSIM_VENDOR = 'mips.ovpworld.org'
OVPSIM_PLATFORM = 'MipsMalta/1.0'
IMPERAS_VLNV = os.environ['IMPERAS_VLNV']
IMPERAS_ARCH = os.environ['IMPERAS_ARCH']
ovpsim_path = os.path.join(
IMPERAS_VLNV, OVPSIM_VENDOR, 'platform', OVPSIM_PLATFORM,
'platform.%s.exe' % IMPERAS_ARCH)
sim_choices['ovpsim'] = [ovpsim_path, configure_ovpsim]
sim_default = 'ovpsim'
except KeyError:
pass
if not sim_default:
raise SystemExit('No simulator found!')
return sim_default, sim_choices
if __name__ == '__main__':
triplet = find_triplet()
sim_default, sim_choices = find_simulator()
parser = argparse.ArgumentParser(
description='Launch kernel in Malta board simulator.')
parser.add_argument('kernel', metavar='KERNEL', type=str,
help='Kernel file in ELF format.')
parser.add_argument('-d', '--debug', action='store_true',
help='Start simulation under gdb.')
parser.add_argument('-D', '--debugger', metavar='DEBUGGER', type=str,
choices=DEBUGGERS.keys(), default=DEFAULT_DEBUGGER,
help=('Debugger to use. Implies -d. ' +
'Available options: %s. Default: %s.' %
(', '.join(DEBUGGERS.keys()), DEFAULT_DEBUGGER)))
parser.add_argument('-S', '--simulator', metavar='SIMULATOR', type=str,
choices=sim_choices.keys(), default=sim_default,
help=('Simulator to use. ' +
'Available options: %s. Default: %s.' %
(', '.join(sim_choices.keys()), sim_default)))
parser.add_argument('-t', '--test', action='store_true',
help='Use current stdin & stdout for simulated UART.')
args = parser.parse_args()
if not os.path.isfile(args.kernel):
raise SystemExit('%s: file does not exist!' % args.kernel)
if args.debugger != DEFAULT_DEBUGGER:
args.debug = True
sim_cmd, sim_opts = sim_choices[args.simulator]
sim_cmd = [sim_cmd] + sim_opts(args)
if args.debug:
dbg_cmd = shlex.split(DEBUGGERS[args.debugger] %
{'kernel': args.kernel, 'triplet': triplet})
sim = subprocess.Popen(sim_cmd, start_new_session=True)
gdb = subprocess.Popen(dbg_cmd, start_new_session=True)
while True:
try:
gdb.wait()
sim.send_signal(signal.SIGINT)
break
except KeyboardInterrupt:
gdb.send_signal(signal.SIGINT)
elif args.test:
sim = popen_spawn.PopenSpawn(sim_cmd)
if args.simulator == 'ovpsim':
sim.expect('Waiting for connection on port %d' % PORT, timeout=5)
elif args.simulator == 'qemu':
sim.expect('QEMU .* monitor', timeout=5)
nc = subprocess.Popen(['nc', 'localhost', str(PORT)])
while True:
try:
sim.wait()
break
except KeyboardInterrupt:
sim.kill(signal.SIGINT)
else:
sim = subprocess.Popen(sim_cmd)
try:
sim.wait()
except KeyboardInterrupt:
sim.send_signal(signal.SIGINT)