source: mainline/tools/ew.py@ 7259317

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7259317 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
RevLine 
[df64dbc]1#!/usr/bin/env python
2#
[3f4c537a]3# Copyright (c) 2013 Jakub Jermar
[df64dbc]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
[1c24c7c]35import os
[f5ceb18]36import sys
[1c24c7c]37import subprocess
[df64dbc]38import autotool
[8a26f82]39import platform
[df425da]40import thread
41import time
[df64dbc]42
[f5ceb18]43overrides = {}
44
45def is_override(str):
46 if str in overrides.keys():
47 return overrides[str]
48 return False
49
[df425da]50def cfg_get(platform, machine, processor):
51 if machine == "" or emulators[platform].has_key("run"):
[f5ceb18]52 return emulators[platform]
[df425da]53 elif processor == "" or emulators[platform][machine].has_key("run"):
[f5ceb18]54 return emulators[platform][machine]
[df425da]55 else:
56 return emulators[platform][machine][processor]
[f5ceb18]57
[df64dbc]58def run_in_console(cmd, title):
59 cmdline = 'xterm -T ' + '"' + title + '"' + ' -e ' + cmd
[e4a1497]60 print(cmdline)
[f5ceb18]61 if not is_override('dryrun'):
62 subprocess.call(cmdline, shell = True);
[df64dbc]63
[8a26f82]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()
[f5ceb18]73 if guest_width <= host_width and not is_override('nokvm'):
[8a26f82]74 opts = opts + ' -enable-kvm'
75
76 # Remove the leading space
77 return opts[1:]
[df64dbc]78
79def malta_options():
80 return '-cpu 4Kc'
81
82def platform_to_qemu_options(platform, machine):
83 if platform == 'amd64':
[8a26f82]84 return 'system-x86_64', pc_options(64)
[df64dbc]85 elif platform == 'arm32':
[83b01c2]86 return 'system-arm', '-M integratorcp'
[df64dbc]87 elif platform == 'ia32':
[8a26f82]88 return 'system-i386', pc_options(32)
[df64dbc]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':
[644352c]95 return 'system-ppc', '-m 256'
[df64dbc]96 elif platform == 'sparc64':
[a91d719]97 return 'system-sparc64', '--prom-env boot-args="console=devices/\\hw\\pci0\\00:03.0\\com1\\a"'
[df64dbc]98
[129b92c6]99def hdisk_mk():
[df64dbc]100 if not os.path.exists('hdisk.img'):
101 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
[f5ceb18]102
[129b92c6]103def qemu_bd_options():
104 if is_override('nohdd'):
105 return ''
106
107 hdisk_mk()
108
[5fdad22]109 return ' -drive file=hdisk.img,index=0,media=disk,format=raw'
[df64dbc]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():
[f5ceb18]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
[362654a]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'
[df64dbc]137
138def qemu_usb_options():
[f5ceb18]139 if is_override('nousb'):
140 return ''
141 return ' -usb'
[df64dbc]142
[f5ceb18]143def qemu_audio_options():
144 if is_override('nosnd'):
145 return ''
[089901e]146 return ' -device intel-hda -device hda-duplex'
[f5ceb18]147
[df425da]148def qemu_run(platform, machine, processor):
149 cfg = cfg_get(platform, machine, processor)
[df64dbc]150 suffix, options = platform_to_qemu_options(platform, machine)
151 cmd = 'qemu-' + suffix
152
153 cmdline = cmd
154 if options != '':
155 cmdline += ' ' + options
156
[f5ceb18]157 cmdline += qemu_bd_options()
158
159 if (not 'net' in cfg.keys()) or cfg['net']:
[df64dbc]160 cmdline += qemu_net_options()
[f5ceb18]161 if (not 'usb' in cfg.keys()) or cfg['usb']:
[df64dbc]162 cmdline += qemu_usb_options()
[f5ceb18]163 if (not 'audio' in cfg.keys()) or cfg['audio']:
164 cmdline += qemu_audio_options()
[df64dbc]165
[f5ceb18]166 if cfg['image'] == 'image.iso':
[df64dbc]167 cmdline += ' -boot d -cdrom image.iso'
[f5ceb18]168 elif cfg['image'] == 'image.boot':
[df64dbc]169 cmdline += ' -kernel image.boot'
170
[f5ceb18]171 if ('console' in cfg.keys()) and not cfg['console']:
[df64dbc]172 cmdline += ' -nographic'
173
174 title = 'HelenOS/' + platform
175 if machine != '':
176 title += ' on ' + machine
177 run_in_console(cmdline, title)
178 else:
[e4a1497]179 print(cmdline)
[f5ceb18]180 if not is_override('dryrun'):
181 subprocess.call(cmdline, shell = True)
[3f4c537a]182
[df425da]183def ski_run(platform, machine, processor):
[df64dbc]184 run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
185
[df425da]186def msim_run(platform, machine, processor):
[129b92c6]187 hdisk_mk()
[df64dbc]188 run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
189
[3f4c537a]190def spike_run(platform, machine, processor):
191 run_in_console('spike image.boot', 'HelenOS/risvc64 on Spike')
192
[df425da]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
[7f0580d]198 run_in_console('expect -c \'spawn %s %d; expect "ok " { send "boot\n" } timeout exp_continue; interact\'' % (term, port), 'HelenOS/sun4v on gem5')
[df425da]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)
[f5ceb18]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 },
[3f4c537a]259 'riscv64' : {
260 'run' : spike_run,
261 'image' : 'image.boot'
262 },
[f5ceb18]263 'sparc64' : {
264 'generic' : {
[df425da]265 'us' : {
266 'run' : qemu_run,
267 'image' : 'image.iso',
[0195374]268 'audio' : False,
269 'console' : False,
[df425da]270 },
271 'sun4v' : {
272 'run' : gem5_run,
273 }
[f5ceb18]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.")
[df64dbc]289
[df425da]290def fail(platform, machine):
291 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine))
292
293
[df64dbc]294def run():
[f5ceb18]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
[df64dbc]334 config = {}
335 autotool.read_config(autotool.CONFIG, config)
336
[f5ceb18]337 if 'PLATFORM' in config.keys():
[df64dbc]338 platform = config['PLATFORM']
[f5ceb18]339 else:
[df64dbc]340 platform = ''
341
[f5ceb18]342 if 'MACHINE' in config.keys():
[df64dbc]343 mach = config['MACHINE']
[f5ceb18]344 else:
[df64dbc]345 mach = ''
346
[df425da]347 if 'PROCESSOR' in config.keys():
348 processor = config['PROCESSOR']
349 else:
350 processor = ''
351
[df64dbc]352 try:
[df425da]353 emu_run = cfg_get(platform, mach, processor)['run']
354 emu_run(platform, mach, processor)
[df64dbc]355 except:
[df425da]356 fail(platform, mach)
[df64dbc]357 return
358
359run()
Note: See TracBrowser for help on using the repository browser.