Changeset 0c2d9bb in mainline for tools/ew.py


Ignore:
Timestamp:
2013-12-25T22:54:29Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b51cf2c
Parents:
f7a33de (diff), ac36aed (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/ew.py

    rf7a33de r0c2d9bb  
    3434
    3535import os
     36import sys
    3637import subprocess
    3738import autotool
    3839import platform
    3940
     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
    4054def run_in_console(cmd, title):
    4155        cmdline = 'xterm -T ' + '"' + title + '"' + ' -e ' + cmd
    4256        print(cmdline)
    43         subprocess.call(cmdline, shell = True);
     57        if not is_override('dryrun'):
     58                subprocess.call(cmdline, shell = True);
    4459
    4560def get_host_native_width():
     
    5267        # on 32 bits host
    5368        host_width = get_host_native_width()
    54         if guest_width <= host_width:
     69        if guest_width <= host_width and not is_override('nokvm'):
    5570                opts = opts + ' -enable-kvm'
    5671       
     
    7994
    8095def qemu_bd_options():
     96        if is_override('nohdd'):
     97                return ''
     98
    8199        if not os.path.exists('hdisk.img'):
    82100                subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
     101
    83102        return ' -hda hdisk.img'
    84103
     
    93112
    94113def qemu_net_options():
    95         nic_options = qemu_nic_e1k_options()
     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
    96129        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'
    97130
    98131def qemu_usb_options():
    99         return ''
    100 
    101 def qemu_run(platform, machine, console, image, networking, storage, usb):
     132        if is_override('nousb'):
     133                return ''
     134        return ' -usb'
     135
     136def qemu_audio_options():
     137        if is_override('nosnd'):
     138                return ''
     139        return ' -soundhw sb16'
     140
     141def qemu_run(platform, machine):
     142        cfg = cfg_get(platform, machine)
    102143        suffix, options = platform_to_qemu_options(platform, machine)
    103144        cmd = 'qemu-' + suffix
     
    107148                cmdline += ' ' + options
    108149
    109         if storage:
    110                 cmdline += qemu_bd_options()
    111         if networking:
     150        cmdline += qemu_bd_options()
     151
     152        if (not 'net' in cfg.keys()) or cfg['net']:
    112153                cmdline += qemu_net_options()
    113         if usb:
     154        if (not 'usb' in cfg.keys()) or cfg['usb']:
    114155                cmdline += qemu_usb_options()
     156        if (not 'audio' in cfg.keys()) or cfg['audio']:
     157                cmdline += qemu_audio_options()
    115158       
    116         if image == 'image.iso':
     159        if cfg['image'] == 'image.iso':
    117160                cmdline += ' -boot d -cdrom image.iso'
    118         elif image == 'image.boot':
     161        elif cfg['image'] == 'image.boot':
    119162                cmdline += ' -kernel image.boot'
    120163
    121         if not console:
     164        if ('console' in cfg.keys()) and not cfg['console']:
    122165                cmdline += ' -nographic'
    123166
     
    128171        else:
    129172                print(cmdline)
    130                 subprocess.call(cmdline, shell = True)
     173                if not is_override('dryrun'):
     174                        subprocess.call(cmdline, shell = True)
    131175               
    132 def ski_run(platform, machine, console, image, networking, storage, usb):
     176def ski_run(platform, machine):
    133177        run_in_console('ski -i contrib/conf/ski.conf', 'HelenOS/ia64 on ski')
    134178
    135 def msim_run(platform, machine, console, image, networking, storage, usb):
     179def msim_run(platform, machine):
    136180        run_in_console('msim -c contrib/conf/msim.conf', 'HelenOS/mips32 on msim')
    137181
    138 emulators = {}
    139 emulators['amd64'] = {}
    140 emulators['arm32'] = {}
    141 emulators['ia32'] = {}
    142 emulators['ia64'] = {}
    143 emulators['mips32'] = {}
    144 emulators['ppc32'] = {}
    145 emulators['sparc64'] = {}
    146 
    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
     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.")
    156245
    157246def run():
     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
    158286        config = {}
    159287        autotool.read_config(autotool.CONFIG, config)
    160288
     289        if 'PLATFORM' in config.keys():
     290                platform = config['PLATFORM']
     291        else:
     292                platform = ''
     293
     294        if 'MACHINE' in config.keys():
     295                mach = config['MACHINE']
     296        else:
     297                mach = ''
     298
    161299        try:
    162                 platform = config['PLATFORM']
     300                emu_run = cfg_get(platform, mach)['run']
    163301        except:
    164                 platform = ''
    165 
    166         try:
    167                 mach = config['MACHINE']
    168         except:
    169                 mach = ''
    170 
    171         try:
    172                 emu_run, console, image, networking, storage, usb = emulators[platform][mach]
    173         except:
    174                 print("Cannot start emulation for the chosen configuration.")
     302                print("Cannot start emulation for the chosen configuration. (%s/%s)" % (platform, mach))
    175303                return
    176304
    177         emu_run(platform, mach, console, image, networking, storage, usb)
     305        emu_run(platform, mach)
    178306
    179307run()
Note: See TracChangeset for help on using the changeset viewer.