Changes in tools/ew.py [9185e42:8a26f82] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/ew.py
r9185e42 r8a26f82 1 1 #!/usr/bin/env python 2 2 # 3 # Copyright (c) 2013 Jakub Jermar 3 # Copyright (c) 2013 Jakub Jermar 4 4 # All rights reserved. 5 5 # … … 33 33 """ 34 34 35 import os 36 import sys 37 import subprocess 35 import os 36 import subprocess 38 37 import autotool 39 38 import platform 40 import thread41 import time42 43 overrides = {}44 45 def is_override(str):46 if str in overrides.keys():47 return overrides[str]48 return False49 50 def 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 39 58 40 def run_in_console(cmd, title): 59 41 cmdline = 'xterm -T ' + '"' + title + '"' + ' -e ' + cmd 60 42 print(cmdline) 61 if not is_override('dryrun'): 62 subprocess.call(cmdline, shell = True); 43 subprocess.call(cmdline, shell = True); 63 44 64 45 def get_host_native_width(): … … 71 52 # on 32 bits host 72 53 host_width = get_host_native_width() 73 if guest_width <= host_width and not is_override('nokvm'):54 if guest_width <= host_width: 74 55 opts = opts + ' -enable-kvm' 75 56 … … 80 61 return '-cpu 4Kc' 81 62 82 def platform_to_qemu_options(platform, machine , processor):63 def platform_to_qemu_options(platform, machine): 83 64 if platform == 'amd64': 84 65 return 'system-x86_64', pc_options(64) 85 66 elif platform == 'arm32': 86 return 'system-arm', ' -M integratorcp'67 return 'system-arm', '' 87 68 elif platform == 'ia32': 88 69 return 'system-i386', pc_options(32) … … 93 74 return 'system-mips', malta_options() 94 75 elif platform == 'ppc32': 95 return 'system-ppc', ' -m 256'76 return 'system-ppc', '' 96 77 elif platform == 'sparc64': 97 if machine != 'generic': 98 raise Exception 99 if processor == 'us': 100 return 'system-sparc64', '-M sun4u --prom-env boot-args="console=devices/\\hw\\pci0\\00:03.0\\com1\\a"' 101 elif processor == 'sun4v': 102 default_path = '/usr/local/opensparc/image/' 103 try: 104 if os.path.exists(default_path): 105 opensparc_bins = default_path 106 elif os.path.exists(os.environ['OPENSPARC_BINARIES']): 107 opensparc_bins = os.environ['OPENSPARC_BINARIES'] 108 else: 109 raise Exception 110 except: 111 print("Cannot find OpenSPARC binary images!") 112 print("Either set OPENSPARC_BINARIES environment variable accordingly or place the images in %s." % (default_path)) 113 raise Exception 78 return 'system-sparc64', '' 114 79 115 return 'system-sparc64', '-M niagara -m 256 -L %s' % (opensparc_bins) 116 117 118 def hdisk_mk(): 80 def qemu_bd_options(): 119 81 if not os.path.exists('hdisk.img'): 120 82 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True) 121 122 def qemu_bd_options(): 123 if is_override('nohdd'): 124 return '' 125 126 hdisk_mk() 127 128 return ' -drive file=hdisk.img,index=0,media=disk,format=raw' 83 return ' -hda hdisk.img' 129 84 130 85 def qemu_nic_ne2k_options(): … … 138 93 139 94 def qemu_net_options(): 140 if is_override('nonet'): 141 return '' 142 143 nic_options = '' 144 if 'net' in overrides.keys(): 145 if 'e1k' in overrides['net'].keys(): 146 nic_options += qemu_nic_e1k_options() 147 if 'rtl8139' in overrides['net'].keys(): 148 nic_options += qemu_nic_rtl8139_options() 149 if 'ne2k' in overrides['net'].keys(): 150 nic_options += qemu_nic_ne2k_options() 151 else: 152 # Use the default NIC 153 nic_options += qemu_nic_e1k_options() 154 155 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' 95 nic_options = qemu_nic_e1k_options() 96 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' 156 97 157 98 def qemu_usb_options(): 158 if is_override('nousb'): 159 return '' 160 return ' -usb' 99 return '' 161 100 162 def qemu_audio_options(): 163 if is_override('nosnd'): 164 return '' 165 return ' -device intel-hda -device hda-duplex' 166 167 def qemu_run(platform, machine, processor): 168 cfg = cfg_get(platform, machine, processor) 169 suffix, options = platform_to_qemu_options(platform, machine, processor) 101 def qemu_run(platform, machine, console, image, networking, storage, usb): 102 suffix, options = platform_to_qemu_options(platform, machine) 170 103 cmd = 'qemu-' + suffix 171 104 … … 174 107 cmdline += ' ' + options 175 108 176 cmdline += qemu_bd_options() 109 if storage: 110 cmdline += qemu_bd_options() 111 if networking: 112 cmdline += qemu_net_options() 113 if usb: 114 cmdline += qemu_usb_options() 115 116 if image == 'image.iso': 117 cmdline += ' -boot d -cdrom image.iso' 118 elif image == 'image.boot': 119 cmdline += ' -kernel image.boot' 177 120 178 if (not 'net' in cfg.keys()) or cfg['net']: 179 cmdline += qemu_net_options() 180 if (not 'usb' in cfg.keys()) or cfg['usb']: 181 cmdline += qemu_usb_options() 182 if (not 'audio' in cfg.keys()) or cfg['audio']: 183 cmdline += qemu_audio_options() 184 185 if cfg['image'] == 'image.iso': 186 cmdline += ' -boot d -cdrom image.iso' 187 elif cfg['image'] == 'image.boot': 188 cmdline += ' -kernel image.boot' 189 else: 190 cmdline += ' ' + cfg['image'] 191 192 if ('console' in cfg.keys()) and not cfg['console']: 121 if not console: 193 122 cmdline += ' -nographic' 194 123 … … 196 125 if machine != '': 197 126 title += ' on ' + machine 198 if 'expect' in cfg.keys():199 cmdline = 'expect -c \'spawn %s; expect "%s" { send "%s" } timeout exp_continue; interact\'' % (cmdline, cfg['expect']['src'], cfg['expect']['dst'])200 127 run_in_console(cmdline, title) 201 128 else: 202 129 print(cmdline) 203 if not is_override('dryrun'): 204 subprocess.call(cmdline, shell = True) 205 206 def ski_run(platform, machine, processor): 130 subprocess.call(cmdline, shell = True) 131 132 def ski_run(platform, machine, console, image, networking, storage, usb): 207 133 run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski') 208 134 209 def msim_run(platform, machine, processor): 210 hdisk_mk() 135 def msim_run(platform, machine, console, image, networking, storage, usb): 211 136 run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim') 212 137 213 def spike_run(platform, machine, processor): 214 run_in_console('spike image.boot', 'HelenOS/risvc64 on Spike') 138 emulators = {} 139 emulators['amd64'] = {} 140 emulators['arm32'] = {} 141 emulators['ia32'] = {} 142 emulators['ia64'] = {} 143 emulators['mips32'] = {} 144 emulators['ppc32'] = {} 145 emulators['sparc64'] = {} 215 146 216 emulators = { 217 'amd64' : { 218 'run' : qemu_run, 219 'image' : 'image.iso' 220 }, 221 'arm32' : { 222 'integratorcp' : { 223 'run' : qemu_run, 224 'image' : 'image.boot', 225 'net' : False, 226 'audio' : False 227 } 228 }, 229 'ia32' : { 230 'run' : qemu_run, 231 'image' : 'image.iso' 232 }, 233 'ia64' : { 234 'ski' : { 235 'run' : ski_run 236 } 237 }, 238 'mips32' : { 239 'msim' : { 240 'run' : msim_run 241 }, 242 'lmalta' : { 243 'run' : qemu_run, 244 'image' : 'image.boot', 245 'console' : False 246 }, 247 'bmalta' : { 248 'run' : qemu_run, 249 'image' : 'image.boot', 250 'console' : False 251 }, 252 }, 253 'ppc32' : { 254 'run' : qemu_run, 255 'image' : 'image.iso', 256 'audio' : False 257 }, 258 'riscv64' : { 259 'run' : spike_run, 260 'image' : 'image.boot' 261 }, 262 'sparc64' : { 263 'generic' : { 264 'us' : { 265 'run' : qemu_run, 266 'image' : 'image.iso', 267 'audio' : False, 268 'console' : False, 269 }, 270 'sun4v' : { 271 'run' : qemu_run, 272 'image' : '-drive if=pflash,readonly=on,file=image.iso', 273 'audio' : False, 274 'console' : False, 275 'net' : False, 276 'usb' : False, 277 'expect' : { 278 'src' : 'ok ', 279 'dst' : 'boot\n' 280 }, 281 } 282 } 283 }, 284 } 285 286 def usage(): 287 print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0])) 288 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb]\n" % 289 os.path.basename(sys.argv[0])) 290 print("-d\tDry run: do not run the emulation, just print the command line.") 291 print("-h\tPrint the usage information and exit.") 292 print("-nohdd\tDisable hard disk, if applicable.") 293 print("-nokvm\tDisable KVM, if applicable.") 294 print("-nonet\tDisable networking support, if applicable.") 295 print("-nosnd\tDisable sound, if applicable.") 296 print("-nousb\tDisable USB support, if applicable.") 297 298 def fail(platform, machine): 299 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine)) 300 147 emulators['amd64'][''] = qemu_run, True, 'image.iso', True, True, True 148 emulators['arm32']['integratorcp'] = qemu_run, True, 'image.boot', False, False, False 149 emulators['ia32'][''] = qemu_run, True, 'image.iso', True, True, True 150 emulators['ia64']['ski'] = ski_run, False, 'image.boot', False, False, False 151 emulators['mips32']['msim'] = msim_run, False, 'image.boot', False, False, False 152 emulators['mips32']['lmalta'] = qemu_run, False, 'image.boot', False, False, False 153 emulators['mips32']['bmalta'] = qemu_run, False, 'image.boot', False, False, False 154 emulators['ppc32'][''] = qemu_run, True, 'image.iso', True, True, True 155 emulators['sparc64']['generic'] = qemu_run, True, 'image.iso', True, True, True 301 156 302 157 def run(): 303 expect_nic = False304 305 for i in range(1, len(sys.argv)):306 307 if expect_nic:308 expect_nic = False309 if not 'net' in overrides.keys():310 overrides['net'] = {}311 if sys.argv[i] == 'e1k':312 overrides['net']['e1k'] = True313 elif sys.argv[i] == 'rtl8139':314 overrides['net']['rtl8139'] = True315 elif sys.argv[i] == 'ne2k':316 overrides['net']['ne2k'] = True317 else:318 usage()319 exit()320 321 elif sys.argv[i] == '-h':322 usage()323 exit()324 elif sys.argv[i] == '-d':325 overrides['dryrun'] = True326 elif sys.argv[i] == '-net' and i < len(sys.argv) - 1:327 expect_nic = True328 elif sys.argv[i] == '-nohdd':329 overrides['nohdd'] = True330 elif sys.argv[i] == '-nokvm':331 overrides['nokvm'] = True332 elif sys.argv[i] == '-nonet':333 overrides['nonet'] = True334 elif sys.argv[i] == '-nosnd':335 overrides['nosnd'] = True336 elif sys.argv[i] == '-nousb':337 overrides['nousb'] = True338 else:339 usage()340 exit()341 342 158 config = {} 343 159 autotool.read_config(autotool.CONFIG, config) 344 160 345 if 'PLATFORM' in config.keys():161 try: 346 162 platform = config['PLATFORM'] 347 e lse:163 except: 348 164 platform = '' 349 165 350 if 'MACHINE' in config.keys():166 try: 351 167 mach = config['MACHINE'] 352 e lse:168 except: 353 169 mach = '' 354 170 355 if 'PROCESSOR' in config.keys():356 processor = config['PROCESSOR']357 else:358 processor = ''359 360 171 try: 361 emu_run = cfg_get(platform, mach, processor)['run'] 362 emu_run(platform, mach, processor) 172 emu_run, console, image, networking, storage, usb = emulators[platform][mach] 363 173 except: 364 fail(platform, mach)174 print("Cannot start emulation for the chosen configuration.") 365 175 return 366 176 177 emu_run(platform, mach, console, image, networking, storage, usb) 178 367 179 run()
Note:
See TracChangeset
for help on using the changeset viewer.