source: mainline/tools/ew.py@ a91d719

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a91d719 was a91d719, checked in by Jakub Jermar <jakub@…>, 9 years ago

Pass the loc path to the serial console in boot prom arguments

  • Property mode set to 100755
File size: 9.4 KB
Line 
1#!/usr/bin/env python
2#
3# Copyright (c) 2013 Jakub Jermar
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# - Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# - The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29
30
31"""
32Emulator wrapper for running HelenOS
33"""
34
35import os
36import sys
37import subprocess
38import autotool
39import platform
40import thread
41import time
42
43overrides = {}
44
45def is_override(str):
46 if str in overrides.keys():
47 return overrides[str]
48 return False
49
50def cfg_get(platform, machine, processor):
51 if machine == "" or emulators[platform].has_key("run"):
52 return emulators[platform]
53 elif processor == "" or emulators[platform][machine].has_key("run"):
54 return emulators[platform][machine]
55 else:
56 return emulators[platform][machine][processor]
57
58def run_in_console(cmd, title):
59 cmdline = 'xterm -T ' + '"' + title + '"' + ' -e ' + cmd
60 print(cmdline)
61 if not is_override('dryrun'):
62 subprocess.call(cmdline, shell = True);
63
64def get_host_native_width():
65 return int(platform.architecture()[0].strip('bit'))
66
67def pc_options(guest_width):
68 opts = ''
69
70 # Do not enable KVM if running 64 bits HelenOS
71 # on 32 bits host
72 host_width = get_host_native_width()
73 if guest_width <= host_width and not is_override('nokvm'):
74 opts = opts + ' -enable-kvm'
75
76 # Remove the leading space
77 return opts[1:]
78
79def malta_options():
80 return '-cpu 4Kc'
81
82def platform_to_qemu_options(platform, machine):
83 if platform == 'amd64':
84 return 'system-x86_64', pc_options(64)
85 elif platform == 'arm32':
86 return 'system-arm', '-M integratorcp'
87 elif platform == 'ia32':
88 return 'system-i386', pc_options(32)
89 elif platform == 'mips32':
90 if machine == 'lmalta':
91 return 'system-mipsel', malta_options()
92 elif machine == 'bmalta':
93 return 'system-mips', malta_options()
94 elif platform == 'ppc32':
95 return 'system-ppc', '-m 256'
96 elif platform == 'sparc64':
97 return 'system-sparc64', '--prom-env boot-args="console=devices/\\hw\\pci0\\00:03.0\\com1\\a"'
98
99def hdisk_mk():
100 if not os.path.exists('hdisk.img'):
101 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
102
103def qemu_bd_options():
104 if is_override('nohdd'):
105 return ''
106
107 hdisk_mk()
108
109 return ' -drive file=hdisk.img,index=0,media=disk,format=raw'
110
111def qemu_nic_ne2k_options():
112 return ' -device ne2k_isa,irq=5,vlan=0'
113
114def qemu_nic_e1k_options():
115 return ' -device e1000,vlan=0'
116
117def qemu_nic_rtl8139_options():
118 return ' -device rtl8139,vlan=0'
119
120def qemu_net_options():
121 if is_override('nonet'):
122 return ''
123
124 nic_options = ''
125 if 'net' in overrides.keys():
126 if 'e1k' in overrides['net'].keys():
127 nic_options += qemu_nic_e1k_options()
128 if 'rtl8139' in overrides['net'].keys():
129 nic_options += qemu_nic_rtl8139_options()
130 if 'ne2k' in overrides['net'].keys():
131 nic_options += qemu_nic_ne2k_options()
132 else:
133 # Use the default NIC
134 nic_options += qemu_nic_e1k_options()
135
136 return nic_options + ' -net user,hostfwd=udp::8080-:8080,hostfwd=udp::8081-:8081,hostfwd=tcp::8080-:8080,hostfwd=tcp::8081-:8081,hostfwd=tcp::2223-:2223'
137
138def qemu_usb_options():
139 if is_override('nousb'):
140 return ''
141 return ' -usb'
142
143def qemu_audio_options():
144 if is_override('nosnd'):
145 return ''
146 return ' -device intel-hda -device hda-duplex'
147
148def qemu_run(platform, machine, processor):
149 cfg = cfg_get(platform, machine, processor)
150 suffix, options = platform_to_qemu_options(platform, machine)
151 cmd = 'qemu-' + suffix
152
153 cmdline = cmd
154 if options != '':
155 cmdline += ' ' + options
156
157 cmdline += qemu_bd_options()
158
159 if (not 'net' in cfg.keys()) or cfg['net']:
160 cmdline += qemu_net_options()
161 if (not 'usb' in cfg.keys()) or cfg['usb']:
162 cmdline += qemu_usb_options()
163 if (not 'audio' in cfg.keys()) or cfg['audio']:
164 cmdline += qemu_audio_options()
165
166 if cfg['image'] == 'image.iso':
167 cmdline += ' -boot d -cdrom image.iso'
168 elif cfg['image'] == 'image.boot':
169 cmdline += ' -kernel image.boot'
170
171 if ('console' in cfg.keys()) and not cfg['console']:
172 cmdline += ' -nographic'
173
174 title = 'HelenOS/' + platform
175 if machine != '':
176 title += ' on ' + machine
177 run_in_console(cmdline, title)
178 else:
179 print(cmdline)
180 if not is_override('dryrun'):
181 subprocess.call(cmdline, shell = True)
182
183def ski_run(platform, machine, processor):
184 run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
185
186def msim_run(platform, machine, processor):
187 hdisk_mk()
188 run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
189
190def spike_run(platform, machine, processor):
191 run_in_console('spike image.boot', 'HelenOS/risvc64 on Spike')
192
193def gem5_console_thread():
194 # Wait a little bit so that gem5 can create the port
195 time.sleep(1)
196 term = os.environ['M5_PATH'] + '/gem5/util/term/m5term'
197 port = 3457
198 run_in_console('expect -c \'spawn %s %d; expect "ok " { send "boot\n" } timeout exp_continue; interact\'' % (term, port), 'HelenOS/sun4v on gem5')
199
200def gem5_run(platform, machine, processor):
201 try:
202 gem5 = os.environ['M5_PATH'] + '/gem5/build/SPARC/gem5.fast'
203 if not os.path.exists(gem5):
204 raise Exception
205 except:
206 print("Did you forget to set M5_PATH?")
207 raise
208
209 thread.start_new_thread(gem5_console_thread, ())
210
211 cmdline = gem5 + ' ' + os.environ['M5_PATH'] + '/configs/example/fs.py --disk-image=' + os.path.abspath('image.iso')
212
213 print(cmdline)
214 if not is_override('dry_run'):
215 subprocess.call(cmdline, shell = True)
216
217emulators = {
218 'amd64' : {
219 'run' : qemu_run,
220 'image' : 'image.iso'
221 },
222 'arm32' : {
223 'integratorcp' : {
224 'run' : qemu_run,
225 'image' : 'image.boot',
226 'net' : False,
227 'audio' : False
228 }
229 },
230 'ia32' : {
231 'run' : qemu_run,
232 'image' : 'image.iso'
233 },
234 'ia64' : {
235 'ski' : {
236 'run' : ski_run
237 }
238 },
239 'mips32' : {
240 'msim' : {
241 'run' : msim_run
242 },
243 'lmalta' : {
244 'run' : qemu_run,
245 'image' : 'image.boot',
246 'console' : False
247 },
248 'bmalta' : {
249 'run' : qemu_run,
250 'image' : 'image.boot',
251 'console' : False
252 },
253 },
254 'ppc32' : {
255 'run' : qemu_run,
256 'image' : 'image.iso',
257 'audio' : False
258 },
259 'riscv64' : {
260 'run' : spike_run,
261 'image' : 'image.boot'
262 },
263 'sparc64' : {
264 'generic' : {
265 'us' : {
266 'run' : qemu_run,
267 'image' : 'image.iso',
268 'audio' : False,
269 'console' : False,
270 },
271 'sun4v' : {
272 'run' : gem5_run,
273 }
274 }
275 },
276}
277
278def usage():
279 print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0]))
280 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb]\n" %
281 os.path.basename(sys.argv[0]))
282 print("-d\tDry run: do not run the emulation, just print the command line.")
283 print("-h\tPrint the usage information and exit.")
284 print("-nohdd\tDisable hard disk, if applicable.")
285 print("-nokvm\tDisable KVM, if applicable.")
286 print("-nonet\tDisable networking support, if applicable.")
287 print("-nosnd\tDisable sound, if applicable.")
288 print("-nousb\tDisable USB support, if applicable.")
289
290def fail(platform, machine):
291 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine))
292
293
294def run():
295 expect_nic = False
296
297 for i in range(1, len(sys.argv)):
298
299 if expect_nic:
300 expect_nic = False
301 if not 'net' in overrides.keys():
302 overrides['net'] = {}
303 if sys.argv[i] == 'e1k':
304 overrides['net']['e1k'] = True
305 elif sys.argv[i] == 'rtl8139':
306 overrides['net']['rtl8139'] = True
307 elif sys.argv[i] == 'ne2k':
308 overrides['net']['ne2k'] = True
309 else:
310 usage()
311 exit()
312
313 elif sys.argv[i] == '-h':
314 usage()
315 exit()
316 elif sys.argv[i] == '-d':
317 overrides['dryrun'] = True
318 elif sys.argv[i] == '-net' and i < len(sys.argv) - 1:
319 expect_nic = True
320 elif sys.argv[i] == '-nohdd':
321 overrides['nohdd'] = True
322 elif sys.argv[i] == '-nokvm':
323 overrides['nokvm'] = True
324 elif sys.argv[i] == '-nonet':
325 overrides['nonet'] = True
326 elif sys.argv[i] == '-nosnd':
327 overrides['nosnd'] = True
328 elif sys.argv[i] == '-nousb':
329 overrides['nousb'] = True
330 else:
331 usage()
332 exit()
333
334 config = {}
335 autotool.read_config(autotool.CONFIG, config)
336
337 if 'PLATFORM' in config.keys():
338 platform = config['PLATFORM']
339 else:
340 platform = ''
341
342 if 'MACHINE' in config.keys():
343 mach = config['MACHINE']
344 else:
345 mach = ''
346
347 if 'PROCESSOR' in config.keys():
348 processor = config['PROCESSOR']
349 else:
350 processor = ''
351
352 try:
353 emu_run = cfg_get(platform, mach, processor)['run']
354 emu_run(platform, mach, processor)
355 except:
356 fail(platform, mach)
357 return
358
359run()
Note: See TracBrowser for help on using the repository browser.