source: mainline/tools/ew.py@ 3ef901d0

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

Add virtio-blk driver

  • Property mode set to 100755
File size: 12.5 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 termemu_detect():
59 for termemu in ['xfce4-terminal', 'xterm']:
60 try:
61 subprocess.check_output('which ' + termemu, shell = True)
62 return termemu
63 except:
64 pass
65
66def run_in_console(cmd, title):
67 ecmd = cmd.replace('"', '\\"')
68 cmdline = termemu_detect() + ' -T ' + '"' + title + '"' + ' -e "' + ecmd + '"'
69 print(cmdline)
70 if not is_override('dryrun'):
71 subprocess.call(cmdline, shell = True)
72
73def get_host_native_width():
74 return int(platform.architecture()[0].strip('bit'))
75
76def pc_options(guest_width):
77 opts = ''
78
79 # Do not enable KVM if running 64 bits HelenOS
80 # on 32 bits host
81 host_width = get_host_native_width()
82 if guest_width <= host_width and not is_override('nokvm'):
83 opts = opts + ' -enable-kvm'
84
85 # Remove the leading space
86 return opts[1:]
87
88def malta_options():
89 return '-cpu 4Kc'
90
91def platform_to_qemu_options(platform, machine, processor):
92 if platform == 'amd64':
93 return 'system-x86_64', pc_options(64)
94 elif platform == 'arm32':
95 return 'system-arm', '-M integratorcp'
96 elif platform == 'ia32':
97 return 'system-i386', pc_options(32)
98 elif platform == 'mips32':
99 if machine == 'lmalta':
100 return 'system-mipsel', malta_options()
101 elif machine == 'bmalta':
102 return 'system-mips', malta_options()
103 elif platform == 'ppc32':
104 return 'system-ppc', '-m 256'
105 elif platform == 'sparc64':
106 if machine != 'generic':
107 raise Exception
108 if processor == 'us':
109 return 'system-sparc64', '-M sun4u --prom-env boot-args="console=devices/\\hw\\pci0\\01:01.0\\com1\\a"'
110 elif processor == 'sun4v':
111 default_path = '/usr/local/opensparc/image/'
112 try:
113 if os.path.exists(default_path):
114 opensparc_bins = default_path
115 elif os.path.exists(os.environ['OPENSPARC_BINARIES']):
116 opensparc_bins = os.environ['OPENSPARC_BINARIES']
117 else:
118 raise Exception
119 except:
120 print("Cannot find OpenSPARC binary images!")
121 print("Either set OPENSPARC_BINARIES environment variable accordingly or place the images in %s." % (default_path))
122 raise Exception
123
124 return 'system-sparc64', '-M niagara -m 256 -L %s' % (opensparc_bins)
125
126
127def hdisk_mk():
128 if not os.path.exists('hdisk.img'):
129 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
130
131def qemu_bd_options():
132 if is_override('nohdd'):
133 return ''
134
135 hdisk_mk()
136
137 hdd_options = ''
138 if 'hdd' in overrides.keys():
139 if 'ata' in overrides['hdd'].keys():
140 hdd_options += ''
141 elif 'virtio-blk' in overrides['hdd'].keys():
142 hdd_options += ',if=virtio'
143
144 return ' -drive file=hdisk.img,index=0,media=disk,format=raw' + hdd_options
145
146def qemu_nic_ne2k_options():
147 return ' -device ne2k_isa,irq=5,netdev=n1'
148
149def qemu_nic_e1k_options():
150 return ' -device e1000,netdev=n1'
151
152def qemu_nic_rtl8139_options():
153 return ' -device rtl8139,netdev=n1'
154
155def qemu_nic_virtio_options():
156 return ' -device virtio-net,netdev=n1'
157
158def qemu_net_options():
159 if is_override('nonet'):
160 return ''
161
162 nic_options = ''
163 if 'net' in overrides.keys():
164 if 'e1k' in overrides['net'].keys():
165 nic_options += qemu_nic_e1k_options()
166 if 'rtl8139' in overrides['net'].keys():
167 nic_options += qemu_nic_rtl8139_options()
168 if 'ne2k' in overrides['net'].keys():
169 nic_options += qemu_nic_ne2k_options()
170 if 'virtio-net' in overrides['net'].keys():
171 nic_options += qemu_nic_virtio_options()
172 else:
173 # Use the default NIC
174 nic_options += qemu_nic_e1k_options()
175
176 return nic_options + ' -netdev user,id=n1,hostfwd=udp::8080-:8080,hostfwd=udp::8081-:8081,hostfwd=tcp::8080-:8080,hostfwd=tcp::8081-:8081,hostfwd=tcp::2223-:2223'
177
178def qemu_usb_options():
179 if is_override('nousb'):
180 return ''
181 return ' -usb'
182
183def qemu_xhci_options():
184 if is_override('noxhci'):
185 return ''
186 return ' -device nec-usb-xhci,id=xhci'
187
188def qemu_tablet_options():
189 if is_override('notablet') or (is_override('nousb') and is_override('noxhci')):
190 return ''
191 return ' -device usb-tablet'
192
193def qemu_audio_options():
194 if is_override('nosnd'):
195 return ''
196 return ' -device intel-hda -device hda-duplex'
197
198def qemu_run(platform, machine, processor):
199 cfg = cfg_get(platform, machine, processor)
200 suffix, options = platform_to_qemu_options(platform, machine, processor)
201 cmd = 'qemu-' + suffix
202
203 cmdline = cmd
204 if 'qemu_path' in overrides.keys():
205 cmdline = overrides['qemu_path'] + cmd
206
207 if options != '':
208 cmdline += ' ' + options
209
210 cmdline += qemu_bd_options()
211
212 if (not 'net' in cfg.keys()) or cfg['net']:
213 cmdline += qemu_net_options()
214 if (not 'usb' in cfg.keys()) or cfg['usb']:
215 cmdline += qemu_usb_options()
216 if (not 'xhci' in cfg.keys()) or cfg['xhci']:
217 cmdline += qemu_xhci_options()
218 if (not 'tablet' in cfg.keys()) or cfg['tablet']:
219 cmdline += qemu_tablet_options()
220 if (not 'audio' in cfg.keys()) or cfg['audio']:
221 cmdline += qemu_audio_options()
222
223 console = ('console' in cfg.keys() and cfg['console'])
224
225 if (is_override('nographic')):
226 cmdline += ' -nographic'
227
228 if (not console and (not is_override('nographic')) and not is_override('noserial')):
229 cmdline += ' -serial stdio'
230
231 if (is_override('bigmem')):
232 cmdline += ' -m 4G'
233
234 if cfg['image'] == 'image.iso':
235 cmdline += ' -boot d -cdrom image.iso'
236 elif cfg['image'] == 'image.boot':
237 cmdline += ' -kernel image.boot'
238 else:
239 cmdline += ' ' + cfg['image']
240
241 if console:
242 cmdline += ' -nographic'
243
244 title = 'HelenOS/' + platform
245 if machine != '':
246 title += ' on ' + machine
247 if 'expect' in cfg.keys():
248 cmdline = 'expect -c \'spawn %s; expect "%s" { send "%s" } timeout exp_continue; interact\'' % (cmdline, cfg['expect']['src'], cfg['expect']['dst'])
249 run_in_console(cmdline, title)
250 else:
251 print(cmdline)
252 if not is_override('dryrun'):
253 subprocess.call(cmdline, shell = True)
254
255def ski_run(platform, machine, processor):
256 run_in_console('ski -i tools/conf/ski.conf', 'HelenOS/ia64 on ski')
257
258def msim_run(platform, machine, processor):
259 hdisk_mk()
260 run_in_console('msim -c tools/conf/msim.conf', 'HelenOS/mips32 on msim')
261
262def spike_run(platform, machine, processor):
263 run_in_console('spike -m1073741824:1073741824 image.boot', 'HelenOS/risvc64 on Spike')
264
265emulators = {
266 'amd64' : {
267 'run' : qemu_run,
268 'image' : 'image.iso'
269 },
270 'arm32' : {
271 'integratorcp' : {
272 'run' : qemu_run,
273 'image' : 'image.boot',
274 'net' : False,
275 'audio' : False,
276 'xhci' : False,
277 'tablet' : False
278 }
279 },
280 'ia32' : {
281 'run' : qemu_run,
282 'image' : 'image.iso'
283 },
284 'ia64' : {
285 'ski' : {
286 'run' : ski_run
287 }
288 },
289 'mips32' : {
290 'msim' : {
291 'run' : msim_run
292 },
293 'lmalta' : {
294 'run' : qemu_run,
295 'image' : 'image.boot',
296 'console' : True
297 },
298 'bmalta' : {
299 'run' : qemu_run,
300 'image' : 'image.boot',
301 'console' : True
302 },
303 },
304 'ppc32' : {
305 'run' : qemu_run,
306 'image' : 'image.iso',
307 'audio' : False
308 },
309 'riscv64' : {
310 'run' : spike_run,
311 'image' : 'image.boot'
312 },
313 'sparc64' : {
314 'generic' : {
315 'us' : {
316 'run' : qemu_run,
317 'image' : 'image.iso',
318 'audio' : False,
319 'console' : True,
320 'net' : False,
321 'usb' : False,
322 'xhci' : False,
323 'tablet' : False
324 },
325 'sun4v' : {
326 'run' : qemu_run,
327 'image' : '-drive if=pflash,readonly=on,file=image.iso',
328 'audio' : False,
329 'console' : True,
330 'net' : False,
331 'usb' : False,
332 'xhci' : False,
333 'tablet' : False,
334 'expect' : {
335 'src' : 'ok ',
336 'dst' : 'boot\n'
337 },
338 }
339 }
340 },
341}
342
343def usage():
344 print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0]))
345 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k|virtio-net] [-hdd ata|virtio-blk] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci] [-notablet]\n" %
346 os.path.basename(sys.argv[0]))
347 print("-d\tDry run: do not run the emulation, just print the command line.")
348 print("-h\tPrint the usage information and exit.")
349 print("-nohdd\tDisable hard disk, if applicable.")
350 print("-nokvm\tDisable KVM, if applicable.")
351 print("-nonet\tDisable networking support, if applicable.")
352 print("-nosnd\tDisable sound, if applicable.")
353 print("-nousb\tDisable USB support, if applicable.")
354 print("-noxhci\tDisable XHCI support, if applicable.")
355 print("-notablet\tDisable USB tablet (use only relative-position PS/2 mouse instead), if applicable.")
356 print("-nographic\tDisable graphical output. Serial port output must be enabled for this to be useful.")
357 print("-noserial\tDisable serial port output in the terminal.")
358 print("-bigmem\tSets maximum RAM size to 4GB.")
359
360def fail(platform, machine):
361 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine))
362
363
364def run():
365 expect_nic = False
366 expect_hdd = False
367 expect_qemu = False
368
369 for i in range(1, len(sys.argv)):
370
371 if expect_nic:
372 expect_nic = False
373 if not 'net' in overrides.keys():
374 overrides['net'] = {}
375 if sys.argv[i] == 'e1k':
376 overrides['net']['e1k'] = True
377 elif sys.argv[i] == 'rtl8139':
378 overrides['net']['rtl8139'] = True
379 elif sys.argv[i] == 'ne2k':
380 overrides['net']['ne2k'] = True
381 elif sys.argv[i] == 'virtio-net':
382 overrides['net']['virtio-net'] = True
383 else:
384 usage()
385 exit()
386 continue
387
388 if expect_hdd:
389 expect_hdd = False
390 if not 'hdd' in overrides.keys():
391 overrides['hdd'] = {}
392 if sys.argv[i] == 'ata':
393 overrides['hdd']['ata'] = True
394 elif sys.argv[i] == 'virtio-blk':
395 overrides['hdd']['virtio-blk'] = True
396 else:
397 usage()
398 exit()
399 continue
400
401 if expect_qemu:
402 expect_qemu = False
403 overrides['qemu_path'] = sys.argv[i]
404
405 elif sys.argv[i] == '-h':
406 usage()
407 exit()
408 elif sys.argv[i] == '-d':
409 overrides['dryrun'] = True
410 elif sys.argv[i] == '-net' and i < len(sys.argv) - 1:
411 expect_nic = True
412 elif sys.argv[i] == '-hdd' and i < len(sys.argv) - 1:
413 expect_hdd = True
414 elif sys.argv[i] == '-nohdd':
415 overrides['nohdd'] = True
416 elif sys.argv[i] == '-nokvm':
417 overrides['nokvm'] = True
418 elif sys.argv[i] == '-nonet':
419 overrides['nonet'] = True
420 elif sys.argv[i] == '-nosnd':
421 overrides['nosnd'] = True
422 elif sys.argv[i] == '-nousb':
423 overrides['nousb'] = True
424 elif sys.argv[i] == '-noxhci':
425 overrides['noxhci'] = True
426 elif sys.argv[i] == '-notablet':
427 overrides['notablet'] = True
428 elif sys.argv[i] == '-nographic':
429 overrides['nographic'] = True
430 elif sys.argv[i] == '-bigmem':
431 overrides['bigmem'] = True
432 elif sys.argv[i] == '-noserial':
433 overrides['noserial'] = True
434 elif sys.argv[i] == '-qemu_path' and i < len(sys.argv) - 1:
435 expect_qemu = True
436 else:
437 usage()
438 exit()
439
440 config = {}
441 autotool.read_config(autotool.CONFIG, config)
442
443 if 'PLATFORM' in config.keys():
444 platform = config['PLATFORM']
445 else:
446 platform = ''
447
448 if 'MACHINE' in config.keys():
449 mach = config['MACHINE']
450 else:
451 mach = ''
452
453 if 'PROCESSOR' in config.keys():
454 processor = config['PROCESSOR']
455 else:
456 processor = ''
457
458 try:
459 emu_run = cfg_get(platform, mach, processor)['run']
460 emu_run(platform, mach, processor)
461 except:
462 fail(platform, mach)
463 return
464
465run()
Note: See TracBrowser for help on using the repository browser.