Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 2 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 3 | # Xilinx QEMU wrapper to launch both PMU and APU instances (multiarch) |
| 4 | import os |
| 5 | import subprocess |
| 6 | import sys |
| 7 | import tempfile |
| 8 | import shutil |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 9 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 10 | binpath = os.path.dirname(os.path.abspath(__file__)) |
| 11 | mach_path = tempfile.mkdtemp() |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 12 | |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 13 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 14 | # Separate PMU and APU arguments |
| 15 | APU_args = sys.argv[1:] |
| 16 | PMU_args = APU_args[APU_args.index('-pmu-args')+1] |
| 17 | APU_args.remove('-pmu-args') |
| 18 | APU_args.remove(PMU_args) |
| 19 | PMU_args = PMU_args.split() |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 20 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 21 | PMU_rom = PMU_args[PMU_args.index('-kernel')+1] |
| 22 | error_msg = None |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 23 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 24 | if os.path.exists(PMU_rom): |
| 25 | |
| 26 | # We need to switch tcp serial arguments (if they exist, e.g. qemurunner) to get the output correctly |
| 27 | tcp_serial_ports = [i for i, s in enumerate(APU_args) if 'tcp:127.0.0.1:' in s] |
| 28 | |
| 29 | # We can only switch these if there are exactly two, otherwise we can't assume what is being executed so we leave it as is |
| 30 | if len(tcp_serial_ports) == 2: |
| 31 | APU_args[tcp_serial_ports[0]],APU_args[tcp_serial_ports[1]] = APU_args[tcp_serial_ports[1]],APU_args[tcp_serial_ports[0]] |
| 32 | |
| 33 | pmu_cmd = binpath + '/qemu-system-microblazeel ' + ' '.join(PMU_args) + ' -machine-path ' + mach_path |
| 34 | apu_cmd = binpath + '/qemu-system-aarch64 ' + ' '.join(APU_args) + ' -machine-path ' + mach_path |
| 35 | |
| 36 | # Debug prints |
| 37 | print('\nPMU instance cmd: %s\n' % pmu_cmd) |
| 38 | print('APU instance cmd: %s\n' % apu_cmd) |
| 39 | |
| 40 | |
| 41 | # Invoke QEMU pmu instance |
| 42 | process_pmu = subprocess.Popen(pmu_cmd, shell=True, stderr=subprocess.PIPE) |
| 43 | |
| 44 | # Invoke QEMU APU instance |
| 45 | process_apu = subprocess.Popen(apu_cmd, shell=True, stderr=subprocess.PIPE) |
| 46 | if process_apu.wait(): |
| 47 | error_msg = '\nQEMU APU instance failed:\n%s' % process_apu.stderr.read().decode() |
| 48 | |
| 49 | else: |
| 50 | error_msg = '\nError: Missing PMU ROM: %s' % PMU_rom |
| 51 | error_msg += '\nSee "meta-xilinx/README.qemu.md" for more information on accquiring the PMU ROM.\n' |
| 52 | |
| 53 | shutil.rmtree(mach_path) |
| 54 | sys.exit(error_msg) |