source: mainline/tools/ew.py@ 089901e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 089901e was 089901e, checked in by Jiri Svoboda <jiri@…>, 11 years ago

Merge Intel High Definition Audio driver.

  • Property mode set to 100755
File size: 7.8 KB
RevLine 
[df64dbc]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
[f5ceb18]36import sys
[df64dbc]37import subprocess
38import autotool
[8a26f82]39import platform
[df64dbc]40
[f5ceb18]41overrides = {}
42
43def is_override(str):
44 if str in overrides.keys():
45 return overrides[str]
46 return False
47
48def cfg_get(platform, machine):
49 if machine == "":
50 return emulators[platform]
51 else:
52 return emulators[platform][machine]
53
[df64dbc]54def run_in_console(cmd, title):
55 cmdline = 'xterm -T ' + '"' + title + '"' + ' -e ' + cmd
[e4a1497]56 print(cmdline)
[f5ceb18]57 if not is_override('dryrun'):
58 subprocess.call(cmdline, shell = True);
[df64dbc]59
[8a26f82]60def get_host_native_width():
61 return int(platform.architecture()[0].strip('bit'))
62
63def pc_options(guest_width):
64 opts = ''
65
66 # Do not enable KVM if running 64 bits HelenOS
67 # on 32 bits host
68 host_width = get_host_native_width()
[f5ceb18]69 if guest_width <= host_width and not is_override('nokvm'):
[8a26f82]70 opts = opts + ' -enable-kvm'
71
72 # Remove the leading space
73 return opts[1:]
[df64dbc]74
75def malta_options():
76 return '-cpu 4Kc'
77
78def platform_to_qemu_options(platform, machine):
79 if platform == 'amd64':
[8a26f82]80 return 'system-x86_64', pc_options(64)
[df64dbc]81 elif platform == 'arm32':
[83b01c2]82 return 'system-arm', '-M integratorcp'
[df64dbc]83 elif platform == 'ia32':
[8a26f82]84 return 'system-i386', pc_options(32)
[df64dbc]85 elif platform == 'mips32':
86 if machine == 'lmalta':
87 return 'system-mipsel', malta_options()
88 elif machine == 'bmalta':
89 return 'system-mips', malta_options()
90 elif platform == 'ppc32':
91 return 'system-ppc', ''
92 elif platform == 'sparc64':
93 return 'system-sparc64', ''
94
95def qemu_bd_options():
[f5ceb18]96 if is_override('nohdd'):
97 return ''
98
[df64dbc]99 if not os.path.exists('hdisk.img'):
100 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
[f5ceb18]101
[df64dbc]102 return ' -hda hdisk.img'
103
104def qemu_nic_ne2k_options():
105 return ' -device ne2k_isa,irq=5,vlan=0'
106
107def qemu_nic_e1k_options():
108 return ' -device e1000,vlan=0'
109
110def qemu_nic_rtl8139_options():
111 return ' -device rtl8139,vlan=0'
112
113def qemu_net_options():
[f5ceb18]114 if is_override('nonet'):
115 return ''
116
117 nic_options = ''
118 if 'net' in overrides.keys():
119 if 'e1k' in overrides['net'].keys():
120 nic_options += qemu_nic_e1k_options()
121 if 'rtl8139' in overrides['net'].keys():
122 nic_options += qemu_nic_rtl8139_options()
123 if 'ne2k' in overrides['net'].keys():
124 nic_options += qemu_nic_ne2k_options()
125 else:
126 # Use the default NIC
127 nic_options += qemu_nic_e1k_options()
128
[e4a1497]129 return nic_options + ' -net user -redir udp:8080::8080 -redir udp:8081::8081 -redir tcp:8080::8080 -redir tcp:8081::8081 -redir tcp:2223::2223'
[df64dbc]130
131def qemu_usb_options():
[f5ceb18]132 if is_override('nousb'):
133 return ''
134 return ' -usb'
[df64dbc]135
[f5ceb18]136def qemu_audio_options():
137 if is_override('nosnd'):
138 return ''
[089901e]139 return ' -device intel-hda -device hda-duplex'
[f5ceb18]140
141def qemu_run(platform, machine):
142 cfg = cfg_get(platform, machine)
[df64dbc]143 suffix, options = platform_to_qemu_options(platform, machine)
144 cmd = 'qemu-' + suffix
145
146 cmdline = cmd
147 if options != '':
148 cmdline += ' ' + options
149
[f5ceb18]150 cmdline += qemu_bd_options()
151
152 if (not 'net' in cfg.keys()) or cfg['net']:
[df64dbc]153 cmdline += qemu_net_options()
[f5ceb18]154 if (not 'usb' in cfg.keys()) or cfg['usb']:
[df64dbc]155 cmdline += qemu_usb_options()
[f5ceb18]156 if (not 'audio' in cfg.keys()) or cfg['audio']:
157 cmdline += qemu_audio_options()
[df64dbc]158
[f5ceb18]159 if cfg['image'] == 'image.iso':
[df64dbc]160 cmdline += ' -boot d -cdrom image.iso'
[f5ceb18]161 elif cfg['image'] == 'image.boot':
[df64dbc]162 cmdline += ' -kernel image.boot'
163
[f5ceb18]164 if ('console' in cfg.keys()) and not cfg['console']:
[df64dbc]165 cmdline += ' -nographic'
166
167 title = 'HelenOS/' + platform
168 if machine != '':
169 title += ' on ' + machine
170 run_in_console(cmdline, title)
171 else:
[e4a1497]172 print(cmdline)
[f5ceb18]173 if not is_override('dryrun'):
174 subprocess.call(cmdline, shell = True)
[df64dbc]175
[f5ceb18]176def ski_run(platform, machine):
[df64dbc]177 run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
178
[f5ceb18]179def msim_run(platform, machine):
[df64dbc]180 run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
181
[f5ceb18]182
183emulators = {
184 'amd64' : {
185 'run' : qemu_run,
186 'image' : 'image.iso'
187 },
188 'arm32' : {
189 'integratorcp' : {
190 'run' : qemu_run,
191 'image' : 'image.boot',
192 'net' : False,
193 'audio' : False
194 }
195 },
196 'ia32' : {
197 'run' : qemu_run,
198 'image' : 'image.iso'
199 },
200 'ia64' : {
201 'ski' : {
202 'run' : ski_run
203 }
204 },
205 'mips32' : {
206 'msim' : {
207 'run' : msim_run
208 },
209 'lmalta' : {
210 'run' : qemu_run,
211 'image' : 'image.boot',
212 'console' : False
213 },
214 'bmalta' : {
215 'run' : qemu_run,
216 'image' : 'image.boot',
217 'console' : False
218 },
219 },
220 'ppc32' : {
221 'run' : qemu_run,
222 'image' : 'image.iso',
223 'audio' : False
224 },
225 'sparc64' : {
226 'generic' : {
227 'run' : qemu_run,
228 'image' : 'image.iso',
229 'audio' : False
230 }
231 },
232}
233
234def usage():
235 print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0]))
236 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb]\n" %
237 os.path.basename(sys.argv[0]))
238 print("-d\tDry run: do not run the emulation, just print the command line.")
239 print("-h\tPrint the usage information and exit.")
240 print("-nohdd\tDisable hard disk, if applicable.")
241 print("-nokvm\tDisable KVM, if applicable.")
242 print("-nonet\tDisable networking support, if applicable.")
243 print("-nosnd\tDisable sound, if applicable.")
244 print("-nousb\tDisable USB support, if applicable.")
[df64dbc]245
246def run():
[f5ceb18]247 expect_nic = False
248
249 for i in range(1, len(sys.argv)):
250
251 if expect_nic:
252 expect_nic = False
253 if not 'net' in overrides.keys():
254 overrides['net'] = {}
255 if sys.argv[i] == 'e1k':
256 overrides['net']['e1k'] = True
257 elif sys.argv[i] == 'rtl8139':
258 overrides['net']['rtl8139'] = True
259 elif sys.argv[i] == 'ne2k':
260 overrides['net']['ne2k'] = True
261 else:
262 usage()
263 exit()
264
265 elif sys.argv[i] == '-h':
266 usage()
267 exit()
268 elif sys.argv[i] == '-d':
269 overrides['dryrun'] = True
270 elif sys.argv[i] == '-net' and i < len(sys.argv) - 1:
271 expect_nic = True
272 elif sys.argv[i] == '-nohdd':
273 overrides['nohdd'] = True
274 elif sys.argv[i] == '-nokvm':
275 overrides['nokvm'] = True
276 elif sys.argv[i] == '-nonet':
277 overrides['nonet'] = True
278 elif sys.argv[i] == '-nosnd':
279 overrides['nosnd'] = True
280 elif sys.argv[i] == '-nousb':
281 overrides['nousb'] = True
282 else:
283 usage()
284 exit()
285
[df64dbc]286 config = {}
287 autotool.read_config(autotool.CONFIG, config)
288
[f5ceb18]289 if 'PLATFORM' in config.keys():
[df64dbc]290 platform = config['PLATFORM']
[f5ceb18]291 else:
[df64dbc]292 platform = ''
293
[f5ceb18]294 if 'MACHINE' in config.keys():
[df64dbc]295 mach = config['MACHINE']
[f5ceb18]296 else:
[df64dbc]297 mach = ''
298
299 try:
[f5ceb18]300 emu_run = cfg_get(platform, mach)['run']
[df64dbc]301 except:
[f5ceb18]302 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, mach))
[df64dbc]303 return
304
[f5ceb18]305 emu_run(platform, mach)
[df64dbc]306
307run()
Note: See TracBrowser for help on using the repository browser.