source: mainline/tools/ew.py@ 129b92c6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 129b92c6 was 129b92c6, checked in by Martin Decky <martin@…>, 9 years ago

refactor disk image creation, use it for MSIM, too

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