Changeset 7abf9a2 in mainline
- Timestamp:
- 2020-12-04T05:39:58Z (4 years ago)
- Children:
- a91cecd8
- Parents:
- 7a873f0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/ew.py
r7a873f0 r7abf9a2 48 48 TOOLS_DIR = os.path.dirname(inspect.getabsfile(inspect.currentframe())) 49 49 50 50 51 def read_config(): 51 "Read HelenOS build configuration" 52 53 inf = open(CONFIG, 'r') 54 config = {} 55 56 for line in inf: 57 res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line) 58 if (res): 59 config[res.group(1)] = res.group(2) 60 61 inf.close() 62 return config 52 "Read HelenOS build configuration" 53 54 inf = open(CONFIG, 'r') 55 config = {} 56 57 for line in inf: 58 res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line) 59 if (res): 60 config[res.group(1)] = res.group(2) 61 62 inf.close() 63 return config 64 63 65 64 66 def is_override(str): 65 if str in overrides.keys(): 66 return overrides[str] 67 return False 67 if str in overrides.keys(): 68 return overrides[str] 69 return False 70 68 71 69 72 def cfg_get(platform, machine, processor): 70 if machine == "" or "run" in emulators[platform]: 71 return emulators[platform] 72 elif processor == "" or "run" in emulators[platform][machine]: 73 return emulators[platform][machine] 74 else: 75 return emulators[platform][machine][processor] 73 if machine == "" or "run" in emulators[platform]: 74 return emulators[platform] 75 elif processor == "" or "run" in emulators[platform][machine]: 76 return emulators[platform][machine] 77 else: 78 return emulators[platform][machine][processor] 79 76 80 77 81 def termemu_detect(): 78 emus = ['gnome-terminal', 'xfce4-terminal', 'xterm'] 79 for termemu in emus: 80 try: 81 subprocess.check_output('which ' + termemu, shell = True) 82 return termemu 83 except: 84 pass 85 86 print('Could not find any of the terminal emulators %s.'%(emus)) 87 sys.exit(1) 82 emus = ['gnome-terminal', 'xfce4-terminal', 'xterm'] 83 for termemu in emus: 84 try: 85 subprocess.check_output('which ' + termemu, shell=True) 86 return termemu 87 except: 88 pass 89 90 print('Could not find any of the terminal emulators %s.' % (emus)) 91 sys.exit(1) 92 88 93 89 94 def run_in_console(cmd, title): 90 temu = termemu_detect() 91 if temu == 'gnome-terminal': 92 cmdline = temu + ' -- ' + cmd 93 else: 94 ecmd = cmd.replace('"', '\\"') 95 cmdline = temu + ' -T ' + '"' + title + '"' + ' -e "' + ecmd + '"' 96 97 print(cmdline) 98 if not is_override('dryrun'): 99 subprocess.call(cmdline, shell = True) 95 temu = termemu_detect() 96 if temu == 'gnome-terminal': 97 cmdline = temu + ' -- ' + cmd 98 else: 99 ecmd = cmd.replace('"', '\\"') 100 cmdline = temu + ' -T ' + '"' + title + '"' + ' -e "' + ecmd + '"' 101 102 print(cmdline) 103 if not is_override('dryrun'): 104 subprocess.call(cmdline, shell=True) 105 100 106 101 107 def get_host_native_width(): 102 return int(platform.architecture()[0].strip('bit')) 108 return int(platform.architecture()[0].strip('bit')) 109 103 110 104 111 def pc_options(guest_width): 105 opts = '' 106 107 # Do not enable KVM if running 64 bits HelenOS 108 # on 32 bits host 109 host_width = get_host_native_width() 110 if guest_width <= host_width and not is_override('nokvm'): 111 opts = opts + ' -enable-kvm' 112 113 # Remove the leading space 114 return opts[1:] 112 opts = '' 113 114 # Do not enable KVM if running 64 bits HelenOS 115 # on 32 bits host 116 host_width = get_host_native_width() 117 if guest_width <= host_width and not is_override('nokvm'): 118 opts = opts + ' -enable-kvm' 119 120 # Remove the leading space 121 # print(opts) 122 return opts[1:] 123 115 124 116 125 def malta_options(): 117 return '-cpu 4Kc -append "console=devices/\\hw\\pci0\\00:0a.0\\com1\\a"' 126 return '-cpu 4Kc -append "console=devices/\\hw\\pci0\\00:0a.0\\com1\\a"' 127 118 128 119 129 def find_firmware(name, environ_var, default_paths, extra_info=None): 120 """Find firmware image(s).""" 121 122 if environ_var in os.environ: 123 return os.environ[environ_var] 124 125 for path in default_paths: 126 if os.path.exists(path): 127 return path 128 129 sys.stderr.write("Cannot find %s binary image(s)!\n" % name) 130 sys.stderr.write( 131 "Either set %s environment variable accordingly or place the image(s) in one of the default locations: %s.\n" % 132 (environ_var, ", ".join(default_paths))) 133 if extra_info is not None: 134 sys.stderr.write(extra_info) 135 return None 130 """Find firmware image(s).""" 131 132 if environ_var in os.environ: 133 return os.environ[environ_var] 134 135 for path in default_paths: 136 if os.path.exists(path): 137 return path 138 139 sys.stderr.write("Cannot find %s binary image(s)!\n" % name) 140 sys.stderr.write( 141 "Either set %s environment variable accordingly or place the image(s) in one of the default locations: %s.\n" % 142 (environ_var, ", ".join(default_paths))) 143 if extra_info is not None: 144 sys.stderr.write(extra_info) 145 return None 146 136 147 137 148 def platform_to_qemu_options(platform, machine, processor): 138 139 140 141 142 143 144 145 '/usr/local/qemu-efi-aarch64/QEMU_EFI.fd',# Custom146 147 '/usr/share/qemu-efi-aarch64/QEMU_EFI.fd',# Ubuntu148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 149 if platform == 'amd64': 150 return 'system-x86_64', pc_options(64) 151 elif platform == 'arm32': 152 return 'system-arm', '-M integratorcp' 153 elif platform == 'arm64': 154 # Search for the EDK2 firmware image 155 default_paths = ( 156 '/usr/local/qemu-efi-aarch64/QEMU_EFI.fd', # Custom 157 '/usr/share/edk2/aarch64/QEMU_EFI.fd', # Fedora 158 '/usr/share/qemu-efi-aarch64/QEMU_EFI.fd', # Ubuntu 159 ) 160 extra_info = ("Pre-compiled binary can be obtained from " 161 "http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-AARCH64/RELEASE_GCC5/QEMU_EFI.fd.\n") 162 efi_path = find_firmware( 163 "EDK2", 'EW_QEMU_EFI_AARCH64', default_paths, extra_info) 164 if efi_path is None: 165 raise Exception 166 167 return 'system-aarch64', \ 168 '-M virt -cpu cortex-a57 -m 1024 -bios %s' % efi_path 169 elif platform == 'ia32': 170 return 'system-i386', pc_options(32) 171 elif platform == 'mips32': 172 if machine == 'lmalta': 173 return 'system-mipsel', malta_options() 174 elif machine == 'bmalta': 175 return 'system-mips', malta_options() 176 elif platform == 'ppc32': 177 return 'system-ppc', '-m 256' 178 elif platform == 'sparc64': 179 if machine != 'generic': 180 raise Exception 181 if processor == 'us': 182 return 'system-sparc64', '-M sun4u --prom-env boot-args="console=devices/\\hw\\pci0\\01:01.0\\com1\\a"' 183 184 # processor = 'sun4v' 185 opensparc_bins = find_firmware( 186 "OpenSPARC", 'OPENSPARC_BINARIES', 187 ('/usr/local/opensparc/image/', )) 188 if opensparc_bins is None: 189 raise Exception 190 191 return 'system-sparc64', '-M niagara -m 256 -L %s' % (opensparc_bins) 181 192 182 193 183 194 def hdisk_mk(): 184 if not os.path.exists('hdisk.img'): 185 subprocess.call(TOOLS_DIR + '/mkfat.py 1048576 dist/data hdisk.img', shell = True) 195 if not os.path.exists('hdisk.img'): 196 subprocess.call( 197 TOOLS_DIR + '/mkfat.py 1048576 dist/data hdisk.img', shell=True) 198 186 199 187 200 def qemu_bd_options(): 188 if is_override('nohdd'): 189 return '' 190 191 hdisk_mk() 192 193 hdd_options = '' 194 if 'hdd' in overrides.keys(): 195 if 'ata' in overrides['hdd'].keys(): 196 hdd_options += '' 197 elif 'virtio-blk' in overrides['hdd'].keys(): 198 hdd_options += ',if=virtio' 199 200 return ' -drive file=hdisk.img,index=0,media=disk,format=raw' + hdd_options 201 202 if is_override('nohdd'): 203 return '' 204 205 hdisk_mk() 206 207 hdd_options = '' 208 if 'hdd' in overrides.keys(): 209 if 'ata' in overrides['hdd'].keys(): 210 hdd_options += '' 211 elif 'virtio-blk' in overrides['hdd'].keys(): 212 hdd_options += ',if=virtio' 213 214 return ' -drive file=hdisk.img,index=0,media=disk,format=raw' + hdd_options 215 201 216 202 217 def qemu_nic_ne2k_options(): 203 return ' -device ne2k_isa,irq=5,netdev=n1' 218 return ' -device ne2k_isa,irq=5,netdev=n1' 219 204 220 205 221 def qemu_nic_e1k_options(): 206 return ' -device e1000,netdev=n1' 222 return ' -device e1000,netdev=n1' 223 207 224 208 225 def qemu_nic_rtl8139_options(): 209 return ' -device rtl8139,netdev=n1' 226 return ' -device rtl8139,netdev=n1' 227 210 228 211 229 def qemu_nic_virtio_options(): 212 return ' -device virtio-net,netdev=n1' 230 return ' -device virtio-net,netdev=n1' 231 213 232 214 233 def qemu_net_options(): 215 if is_override('nonet'): 216 return '' 217 218 nic_options = '' 219 if 'net' in overrides.keys(): 220 if 'e1k' in overrides['net'].keys(): 221 nic_options += qemu_nic_e1k_options() 222 if 'rtl8139' in overrides['net'].keys(): 223 nic_options += qemu_nic_rtl8139_options() 224 if 'ne2k' in overrides['net'].keys(): 225 nic_options += qemu_nic_ne2k_options() 226 if 'virtio-net' in overrides['net'].keys(): 227 nic_options += qemu_nic_virtio_options() 228 else: 229 # Use the default NIC 230 nic_options += qemu_nic_e1k_options() 231 232 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' 234 if is_override('nonet'): 235 return '' 236 237 nic_options = '' 238 if 'net' in overrides.keys(): 239 if 'e1k' in overrides['net'].keys(): 240 nic_options += qemu_nic_e1k_options() 241 if 'rtl8139' in overrides['net'].keys(): 242 nic_options += qemu_nic_rtl8139_options() 243 if 'ne2k' in overrides['net'].keys(): 244 nic_options += qemu_nic_ne2k_options() 245 if 'virtio-net' in overrides['net'].keys(): 246 nic_options += qemu_nic_virtio_options() 247 else: 248 # Use the default NIC 249 nic_options += qemu_nic_e1k_options() 250 251 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' 252 233 253 234 254 def qemu_usb_options(): 235 if is_override('nousb'): 236 return '' 237 return ' -usb' 255 if is_override('nousb'): 256 return '' 257 return ' -usb' 258 238 259 239 260 def qemu_xhci_options(): 240 if is_override('noxhci'): 241 return '' 242 return ' -device nec-usb-xhci,id=xhci' 261 if is_override('noxhci'): 262 return '' 263 return ' -device nec-usb-xhci,id=xhci' 264 243 265 244 266 def qemu_tablet_options(): 245 if is_override('notablet') or (is_override('nousb') and is_override('noxhci')): 246 return '' 247 return ' -device usb-tablet' 267 if is_override('notablet') or (is_override('nousb') and is_override('noxhci')): 268 return '' 269 return ' -device usb-tablet' 270 248 271 249 272 def qemu_audio_options(): 250 if is_override('nosnd'): 251 return '' 252 return ' -device intel-hda -device hda-duplex' 273 if is_override('nosnd'): 274 return '' 275 return ' -device intel-hda -device hda-duplex' 276 253 277 254 278 def qemu_run(platform, machine, processor): 255 cfg = cfg_get(platform, machine, processor) 256 suffix, options = platform_to_qemu_options(platform, machine, processor) 257 cmd = 'qemu-' + suffix 258 259 cmdline = cmd 260 if 'qemu_path' in overrides.keys(): 261 cmdline = overrides['qemu_path'] + cmd 262 263 if options != '': 264 cmdline += ' ' + options 265 266 if (not 'hdd' in cfg.keys() or cfg['hdd']): 267 cmdline += qemu_bd_options() 268 if (not 'net' in cfg.keys()) or cfg['net']: 269 cmdline += qemu_net_options() 270 if (not 'usb' in cfg.keys()) or cfg['usb']: 271 cmdline += qemu_usb_options() 272 if (not 'xhci' in cfg.keys()) or cfg['xhci']: 273 cmdline += qemu_xhci_options() 274 if (not 'tablet' in cfg.keys()) or cfg['tablet']: 275 cmdline += qemu_tablet_options() 276 if (not 'audio' in cfg.keys()) or cfg['audio']: 277 cmdline += qemu_audio_options() 278 279 console = ('console' in cfg.keys() and cfg['console']) 280 281 if (is_override('nographic')): 282 cmdline += ' -nographic' 283 284 if (not console and (not is_override('nographic')) and not is_override('noserial')): 285 cmdline += ' -serial stdio' 286 287 if (is_override('bigmem')): 288 cmdline += ' -m 4G' 289 290 if cfg['image'] == 'image.iso': 291 cmdline += ' -boot d -cdrom image.iso' 292 elif cfg['image'] == 'image.iso@arm64': 293 # Define image.iso cdrom backend. 294 cmdline += ' -drive if=none,file=image.iso,id=cdrom,media=cdrom' 295 # Define scsi bus. 296 cmdline += ' -device virtio-scsi-device' 297 # Define cdrom frontend connected to this scsi bus. 298 cmdline += ' -device scsi-cd,drive=cdrom' 299 elif cfg['image'] == 'image.boot': 300 cmdline += ' -kernel image.boot' 301 else: 302 cmdline += ' ' + cfg['image'] 303 304 if console: 305 cmdline += ' -nographic' 306 307 title = 'HelenOS/' + platform 308 if machine != '': 309 title += ' on ' + machine 310 if 'expect' in cfg.keys(): 311 cmdline = 'expect -c \'spawn %s; expect "%s" { send "%s" } timeout exp_continue; interact\'' % (cmdline, cfg['expect']['src'], cfg['expect']['dst']) 312 run_in_console(cmdline, title) 313 else: 314 print(cmdline) 315 if not is_override('dryrun'): 316 subprocess.call(cmdline, shell = True) 279 cfg = cfg_get(platform, machine, processor) 280 suffix, options = platform_to_qemu_options(platform, machine, processor) 281 cmd = 'qemu-' + suffix 282 283 if cpus: 284 cmd += ' -smp cpus=' + cpus + ' ' 285 286 cmdline = cmd 287 if 'qemu_path' in overrides.keys(): 288 cmdline = overrides['qemu_path'] + cmd 289 290 if options != '': 291 cmdline += ' ' + options 292 293 if (not 'hdd' in cfg.keys() or cfg['hdd']): 294 cmdline += qemu_bd_options() 295 if (not 'net' in cfg.keys()) or cfg['net']: 296 cmdline += qemu_net_options() 297 if (not 'usb' in cfg.keys()) or cfg['usb']: 298 cmdline += qemu_usb_options() 299 if (not 'xhci' in cfg.keys()) or cfg['xhci']: 300 cmdline += qemu_xhci_options() 301 if (not 'tablet' in cfg.keys()) or cfg['tablet']: 302 cmdline += qemu_tablet_options() 303 if (not 'audio' in cfg.keys()) or cfg['audio']: 304 cmdline += qemu_audio_options() 305 306 console = ('console' in cfg.keys() and cfg['console']) 307 308 if (is_override('nographic')): 309 cmdline += ' -nographic' 310 311 if (not console and (not is_override('nographic')) and not is_override('noserial')): 312 cmdline += ' -serial stdio' 313 314 if (is_override('bigmem')): 315 cmdline += ' -m 4G' 316 317 if cfg['image'] == 'image.iso': 318 cmdline += ' -boot d -cdrom image.iso' 319 elif cfg['image'] == 'image.iso@arm64': 320 # Define image.iso cdrom backend. 321 cmdline += ' -drive if=none,file=image.iso,id=cdrom,media=cdrom' 322 # Define scsi bus. 323 cmdline += ' -device virtio-scsi-device' 324 # Define cdrom frontend connected to this scsi bus. 325 cmdline += ' -device scsi-cd,drive=cdrom' 326 elif cfg['image'] == 'image.boot': 327 cmdline += ' -kernel image.boot' 328 else: 329 cmdline += ' ' + cfg['image'] 330 331 if console: 332 cmdline += ' -nographic' 333 334 title = 'HelenOS/' + platform 335 if machine != '': 336 title += ' on ' + machine 337 if 'expect' in cfg.keys(): 338 cmdline = 'expect -c \'spawn %s; expect "%s" { send "%s" } timeout exp_continue; interact\'' % ( 339 cmdline, cfg['expect']['src'], cfg['expect']['dst']) 340 run_in_console(cmdline, title) 341 else: 342 print(cmdline) 343 if not is_override('dryrun'): 344 subprocess.call(cmdline, shell=True) 345 317 346 318 347 def ski_run(platform, machine, processor): 319 run_in_console('ski -i ' + TOOLS_DIR + '/conf/ski.conf', 'HelenOS/ia64 on ski') 348 run_in_console('ski -i ' + TOOLS_DIR + 349 '/conf/ski.conf', 'HelenOS/ia64 on ski') 350 320 351 321 352 def msim_run(platform, machine, processor): 322 hdisk_mk() 323 run_in_console('msim -c ' + TOOLS_DIR + '/conf/msim.conf', 'HelenOS/mips32 on msim') 353 hdisk_mk() 354 run_in_console('msim -c ' + TOOLS_DIR + '/conf/msim.conf', 355 'HelenOS/mips32 on msim') 356 324 357 325 358 def spike_run(platform, machine, processor): 326 run_in_console('spike -m1073741824:1073741824 image.boot', 'HelenOS/risvc64 on Spike') 359 run_in_console('spike -m1073741824:1073741824 image.boot', 360 'HelenOS/risvc64 on Spike') 361 327 362 328 363 emulators = { 329 'amd64': {330 'run': qemu_run,331 'image': 'image.iso'332 333 'arm32': {334 'integratorcp': {335 'run': qemu_run,336 'image': 'image.boot',337 'net': False,338 'audio': False,339 'xhci': False,340 'tablet': False341 342 343 'arm64': {344 'virt': {345 'run': qemu_run,346 'image': 'image.iso@arm64',347 'audio': False,348 'console': True,349 'hdd': False,350 'net': False,351 'tablet': False,352 'usb': False,353 'xhci': False354 355 356 'ia32': {357 'run': qemu_run,358 'image': 'image.iso'359 360 'ia64': {361 'ski': {362 'run': ski_run363 364 365 'mips32': {366 'msim': {367 'run': msim_run368 369 'lmalta': {370 'run': qemu_run,371 'image': 'image.boot',372 'console': True373 374 'bmalta': {375 'run': qemu_run,376 'image': 'image.boot',377 'console': True378 379 380 'ppc32': {381 'run': qemu_run,382 'image': 'image.iso',383 'audio': False384 385 'riscv64': {386 'run': spike_run,387 'image': 'image.boot'388 389 'sparc64': {390 'generic': {391 'us': {392 'run': qemu_run,393 'image': 'image.iso',394 'audio': False,395 'console': True,396 'net': False,397 'usb': False,398 'xhci': False,399 'tablet': False400 401 'sun4v': {402 'run': qemu_run,403 'image': '-drive if=pflash,readonly=on,file=image.iso',404 'audio': False,405 'console': True,406 'net': False,407 'usb': False,408 'xhci': False,409 'tablet': False,410 'expect': {411 'src': 'ok ',412 'dst': 'boot\n'413 414 415 416 364 'amd64': { 365 'run': qemu_run, 366 'image': 'image.iso' 367 }, 368 'arm32': { 369 'integratorcp': { 370 'run': qemu_run, 371 'image': 'image.boot', 372 'net': False, 373 'audio': False, 374 'xhci': False, 375 'tablet': False 376 } 377 }, 378 'arm64': { 379 'virt': { 380 'run': qemu_run, 381 'image': 'image.iso@arm64', 382 'audio': False, 383 'console': True, 384 'hdd': False, 385 'net': False, 386 'tablet': False, 387 'usb': False, 388 'xhci': False 389 } 390 }, 391 'ia32': { 392 'run': qemu_run, 393 'image': 'image.iso' 394 }, 395 'ia64': { 396 'ski': { 397 'run': ski_run 398 } 399 }, 400 'mips32': { 401 'msim': { 402 'run': msim_run 403 }, 404 'lmalta': { 405 'run': qemu_run, 406 'image': 'image.boot', 407 'console': True 408 }, 409 'bmalta': { 410 'run': qemu_run, 411 'image': 'image.boot', 412 'console': True 413 }, 414 }, 415 'ppc32': { 416 'run': qemu_run, 417 'image': 'image.iso', 418 'audio': False 419 }, 420 'riscv64': { 421 'run': spike_run, 422 'image': 'image.boot' 423 }, 424 'sparc64': { 425 'generic': { 426 'us': { 427 'run': qemu_run, 428 'image': 'image.iso', 429 'audio': False, 430 'console': True, 431 'net': False, 432 'usb': False, 433 'xhci': False, 434 'tablet': False 435 }, 436 'sun4v': { 437 'run': qemu_run, 438 'image': '-drive if=pflash,readonly=on,file=image.iso', 439 'audio': False, 440 'console': True, 441 'net': False, 442 'usb': False, 443 'xhci': False, 444 'tablet': False, 445 'expect': { 446 'src': 'ok ', 447 'dst': 'boot\n' 448 }, 449 } 450 } 451 }, 417 452 } 418 453 454 419 455 def usage(): 420 print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0])) 421 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k|virtio-net] [-hdd ata|virtio-blk] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci] [-notablet]\n" % 422 os.path.basename(sys.argv[0])) 423 print("-d\tDry run: do not run the emulation, just print the command line.") 424 print("-h\tPrint the usage information and exit.") 425 print("-nohdd\tDisable hard disk, if applicable.") 426 print("-nokvm\tDisable KVM, if applicable.") 427 print("-nonet\tDisable networking support, if applicable.") 428 print("-nosnd\tDisable sound, if applicable.") 429 print("-nousb\tDisable USB support, if applicable.") 430 print("-noxhci\tDisable XHCI support, if applicable.") 431 print("-notablet\tDisable USB tablet (use only relative-position PS/2 mouse instead), if applicable.") 432 print("-nographic\tDisable graphical output. Serial port output must be enabled for this to be useful.") 433 print("-noserial\tDisable serial port output in the terminal.") 434 print("-bigmem\tSets maximum RAM size to 4GB.") 456 print("%s - emulator wrapper for running HelenOS\n" % 457 os.path.basename(sys.argv[0])) 458 print("%s [$] [-d] [-h] [-net e1k|rtl8139|ne2k|virtio-net] [-hdd ata|virtio-blk] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci] [-notablet]\n" % 459 os.path.basename(sys.argv[0])) 460 print("$\t to run multiple($) cpus") 461 print("-d\tDry run: do not run the emulation, just print the command line.") 462 print("-h\tPrint the usage information and exit.") 463 print("-nohdd\tDisable hard disk, if applicable.") 464 print("-nokvm\tDisable KVM, if applicable.") 465 print("-nonet\tDisable networking support, if applicable.") 466 print("-nosnd\tDisable sound, if applicable.") 467 print("-nousb\tDisable USB support, if applicable.") 468 print("-noxhci\tDisable XHCI support, if applicable.") 469 print("-notablet\tDisable USB tablet (use only relative-position PS/2 mouse instead), if applicable.") 470 print("-nographic\tDisable graphical output. Serial port output must be enabled for this to be useful.") 471 print("-noserial\tDisable serial port output in the terminal.") 472 print("-bigmem\tSets maximum RAM size to 4GB.") 473 435 474 436 475 def fail(platform, machine): 437 print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, machine)) 476 print("Cannot start emulation for the chosen configuration. (%s/%s)" % 477 (platform, machine)) 438 478 439 479 440 480 def run(): 441 expect_nic = False 442 expect_hdd = False 443 expect_qemu = False 444 445 for i in range(1, len(sys.argv)): 446 447 if expect_nic: 448 expect_nic = False 449 if not 'net' in overrides.keys(): 450 overrides['net'] = {} 451 if sys.argv[i] == 'e1k': 452 overrides['net']['e1k'] = True 453 elif sys.argv[i] == 'rtl8139': 454 overrides['net']['rtl8139'] = True 455 elif sys.argv[i] == 'ne2k': 456 overrides['net']['ne2k'] = True 457 elif sys.argv[i] == 'virtio-net': 458 overrides['net']['virtio-net'] = True 459 else: 460 usage() 461 exit() 462 continue 463 464 if expect_hdd: 465 expect_hdd = False 466 if not 'hdd' in overrides.keys(): 467 overrides['hdd'] = {} 468 if sys.argv[i] == 'ata': 469 overrides['hdd']['ata'] = True 470 elif sys.argv[i] == 'virtio-blk': 471 overrides['hdd']['virtio-blk'] = True 472 else: 473 usage() 474 exit() 475 continue 476 477 if expect_qemu: 478 expect_qemu = False 479 overrides['qemu_path'] = sys.argv[i] 480 481 elif sys.argv[i] == '-h': 482 usage() 483 exit() 484 elif sys.argv[i] == '-d': 485 overrides['dryrun'] = True 486 elif sys.argv[i] == '-net' and i < len(sys.argv) - 1: 487 expect_nic = True 488 elif sys.argv[i] == '-hdd' and i < len(sys.argv) - 1: 489 expect_hdd = True 490 elif sys.argv[i] == '-nohdd': 491 overrides['nohdd'] = True 492 elif sys.argv[i] == '-nokvm': 493 overrides['nokvm'] = True 494 elif sys.argv[i] == '-nonet': 495 overrides['nonet'] = True 496 elif sys.argv[i] == '-nosnd': 497 overrides['nosnd'] = True 498 elif sys.argv[i] == '-nousb': 499 overrides['nousb'] = True 500 elif sys.argv[i] == '-noxhci': 501 overrides['noxhci'] = True 502 elif sys.argv[i] == '-notablet': 503 overrides['notablet'] = True 504 elif sys.argv[i] == '-nographic': 505 overrides['nographic'] = True 506 elif sys.argv[i] == '-bigmem': 507 overrides['bigmem'] = True 508 elif sys.argv[i] == '-noserial': 509 overrides['noserial'] = True 510 elif sys.argv[i] == '-qemu_path' and i < len(sys.argv) - 1: 511 expect_qemu = True 512 else: 513 usage() 514 exit() 515 516 config = read_config() 517 518 if 'PLATFORM' in config.keys(): 519 platform = config['PLATFORM'] 520 else: 521 platform = '' 522 523 if 'MACHINE' in config.keys(): 524 mach = config['MACHINE'] 525 else: 526 mach = '' 527 528 if 'PROCESSOR' in config.keys(): 529 processor = config['PROCESSOR'] 530 else: 531 processor = '' 532 533 try: 534 emu_run = cfg_get(platform, mach, processor)['run'] 535 emu_run(platform, mach, processor) 536 except: 537 fail(platform, mach) 538 return 481 expect_nic = False 482 expect_hdd = False 483 expect_qemu = False 484 global cpus 485 cpus = '' 486 487 for i in range(1, len(sys.argv)): 488 489 if expect_nic: 490 expect_nic = False 491 if not 'net' in overrides.keys(): 492 overrides['net'] = {} 493 if sys.argv[i] == 'e1k': 494 overrides['net']['e1k'] = True 495 elif sys.argv[i] == 'rtl8139': 496 overrides['net']['rtl8139'] = True 497 elif sys.argv[i] == 'ne2k': 498 overrides['net']['ne2k'] = True 499 elif sys.argv[i] == 'virtio-net': 500 overrides['net']['virtio-net'] = True 501 else: 502 usage() 503 exit() 504 continue 505 506 if expect_hdd: 507 expect_hdd = False 508 if not 'hdd' in overrides.keys(): 509 overrides['hdd'] = {} 510 if sys.argv[i] == 'ata': 511 overrides['hdd']['ata'] = True 512 elif sys.argv[i] == 'virtio-blk': 513 overrides['hdd']['virtio-blk'] = True 514 else: 515 usage() 516 exit() 517 continue 518 519 if expect_qemu: 520 expect_qemu = False 521 overrides['qemu_path'] = sys.argv[i] 522 523 elif sys.argv[i] == '-h': 524 usage() 525 exit() 526 elif sys.argv[i].isdigit(): 527 cpus = sys.argv[i] 528 elif sys.argv[i] == '-d': 529 overrides['dryrun'] = True 530 elif sys.argv[i] == '-net' and i < len(sys.argv) - 1: 531 expect_nic = True 532 elif sys.argv[i] == '-hdd' and i < len(sys.argv) - 1: 533 expect_hdd = True 534 elif sys.argv[i] == '-nohdd': 535 overrides['nohdd'] = True 536 elif sys.argv[i] == '-nokvm': 537 overrides['nokvm'] = True 538 elif sys.argv[i] == '-nonet': 539 overrides['nonet'] = True 540 elif sys.argv[i] == '-nosnd': 541 overrides['nosnd'] = True 542 elif sys.argv[i] == '-nousb': 543 overrides['nousb'] = True 544 elif sys.argv[i] == '-noxhci': 545 overrides['noxhci'] = True 546 elif sys.argv[i] == '-notablet': 547 overrides['notablet'] = True 548 elif sys.argv[i] == '-nographic': 549 overrides['nographic'] = True 550 elif sys.argv[i] == '-bigmem': 551 overrides['bigmem'] = True 552 elif sys.argv[i] == '-noserial': 553 overrides['noserial'] = True 554 elif sys.argv[i] == '-qemu_path' and i < len(sys.argv) - 1: 555 expect_qemu = True 556 else: 557 usage() 558 exit() 559 560 config = read_config() 561 562 if 'PLATFORM' in config.keys(): 563 platform = config['PLATFORM'] 564 else: 565 platform = '' 566 567 if 'MACHINE' in config.keys(): 568 mach = config['MACHINE'] 569 else: 570 mach = '' 571 572 if 'PROCESSOR' in config.keys(): 573 processor = config['PROCESSOR'] 574 else: 575 processor = '' 576 577 try: 578 emu_run = cfg_get(platform, mach, processor)['run'] 579 emu_run(platform, mach, processor) 580 except: 581 fail(platform, mach) 582 return 583 539 584 540 585 run()
Note:
See TracChangeset
for help on using the changeset viewer.