Changeset 3e828ea in mainline for tools/ew.py


Ignore:
Timestamp:
2019-09-23T12:49:29Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9be2358
Parents:
9259d20 (diff), 1a4ec93f (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.
git-author:
Jiri Svoboda <jiri@…> (2019-09-22 12:49:07)
git-committer:
Jiri Svoboda <jiri@…> (2019-09-23 12:49:29)
Message:

Merge changes from master, especially Meson build

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/ew.py

    r9259d20 r3e828ea  
    3333"""
    3434
     35import inspect
    3536import os
     37import platform
     38import re
     39import subprocess
    3640import sys
    37 import subprocess
    38 import autotool
    39 import platform
    4041import thread
    4142import time
    4243
    4344overrides = {}
     45
     46CONFIG = 'Makefile.config'
     47
     48TOOLS_DIR = os.path.dirname(inspect.getabsfile(inspect.currentframe()))
     49
     50def 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
    4463
    4564def is_override(str):
     
    5776
    5877def termemu_detect():
    59         for termemu in ['xfce4-terminal', 'xterm']:
     78        emus = ['gnome-terminal', 'xfce4-terminal', 'xterm']
     79        for termemu in emus:
    6080                try:
    6181                        subprocess.check_output('which ' + termemu, shell = True)
     
    6484                        pass
    6585
     86        print('Could not find any of the terminal emulators %s.'%(emus))
     87        sys.exit(1)
     88
    6689def run_in_console(cmd, title):
    67         ecmd = cmd.replace('"', '\\"')
    68         cmdline = termemu_detect() + ' -T ' + '"' + title + '"' + ' -e "' + ecmd + '"'
     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
    6997        print(cmdline)
    7098        if not is_override('dryrun'):
     
    87115
    88116def malta_options():
    89         return '-cpu 4Kc'
     117        return '-cpu 4Kc -append "console=devices/\\hw\\pci0\\00:0a.0\\com1\\a"'
     118
     119def 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
    90136
    91137def platform_to_qemu_options(platform, machine, processor):
     
    94140        elif platform == 'arm32':
    95141                return 'system-arm', '-M integratorcp'
     142        elif platform == 'arm64':
     143                # Search for the EDK2 firmware image
     144                default_paths = (
     145                        '/usr/local/qemu-efi-aarch64/QEMU_EFI.fd', # Custom
     146                        '/usr/share/edk2/aarch64/QEMU_EFI.fd',     # Fedora
     147                        '/usr/share/qemu-efi-aarch64/QEMU_EFI.fd', # Ubuntu
     148                )
     149                extra_info = ("Pre-compiled binary can be obtained from "
     150                    "http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-AARCH64/RELEASE_GCC49/QEMU_EFI.fd.\n")
     151                efi_path = find_firmware(
     152                    "EDK2", 'EW_QEMU_EFI_AARCH64', default_paths, extra_info)
     153                if efi_path is None:
     154                        raise Exception
     155
     156                return 'system-aarch64', \
     157                    '-M virt -cpu cortex-a57 -m 1024 -bios %s' % efi_path
    96158        elif platform == 'ia32':
    97159                return 'system-i386', pc_options(32)
     
    108170                if processor == 'us':
    109171                        return 'system-sparc64', '-M sun4u --prom-env boot-args="console=devices/\\hw\\pci0\\01:01.0\\com1\\a"'
    110                 elif processor == 'sun4v':
    111                         default_path = '/usr/local/opensparc/image/'
    112                 try:
    113                         if os.path.exists(default_path):
    114                                 opensparc_bins = default_path
    115                         elif os.path.exists(os.environ['OPENSPARC_BINARIES']):
    116                                 opensparc_bins = os.environ['OPENSPARC_BINARIES']
    117                         else:
    118                                 raise Exception
    119                 except:
    120                         print("Cannot find OpenSPARC binary images!")
    121                         print("Either set OPENSPARC_BINARIES environment variable accordingly or place the images in %s." % (default_path))
     172
     173                # processor = 'sun4v'
     174                opensparc_bins = find_firmware(
     175                    "OpenSPARC", 'OPENSPARC_BINARIES',
     176                    ('/usr/local/opensparc/image/', ))
     177                if opensparc_bins is None:
    122178                        raise Exception
    123179
     
    127183def hdisk_mk():
    128184        if not os.path.exists('hdisk.img'):
    129                 subprocess.call('tools/mkfat.py 1048576 uspace/dist/data hdisk.img', shell = True)
     185                subprocess.call(TOOLS_DIR + '/mkfat.py 1048576 dist/data hdisk.img', shell = True)
    130186
    131187def qemu_bd_options():
     
    208264                cmdline += ' ' + options
    209265
    210         cmdline += qemu_bd_options()
    211 
     266        if (not 'hdd' in cfg.keys() or cfg['hdd']):
     267                cmdline += qemu_bd_options()
    212268        if (not 'net' in cfg.keys()) or cfg['net']:
    213269                cmdline += qemu_net_options()
     
    234290        if cfg['image'] == 'image.iso':
    235291                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'
    236299        elif cfg['image'] == 'image.boot':
    237300                cmdline += ' -kernel image.boot'
     
    254317
    255318def ski_run(platform, machine, processor):
    256         run_in_console('ski -i tools/conf/ski.conf', 'HelenOS/ia64 on ski')
     319        run_in_console('ski -i ' + TOOLS_DIR + '/conf/ski.conf', 'HelenOS/ia64 on ski')
    257320
    258321def msim_run(platform, machine, processor):
    259322        hdisk_mk()
    260         run_in_console('msim -c tools/conf/msim.conf', 'HelenOS/mips32 on msim')
     323        run_in_console('msim -c ' + TOOLS_DIR + '/conf/msim.conf', 'HelenOS/mips32 on msim')
    261324
    262325def spike_run(platform, machine, processor):
     
    276339                        'xhci' : False,
    277340                        'tablet' : False
     341                }
     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' : False
    278354                }
    279355        },
     
    438514                        exit()
    439515
    440         config = {}
    441         autotool.read_config(autotool.CONFIG, config)
     516        config = read_config()
    442517
    443518        if 'PLATFORM' in config.keys():
Note: See TracChangeset for help on using the changeset viewer.