blob: 2c92c686fbfc8652697e1132b2a14597f0a7a414 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001#!/usr/bin/env python3
Brad Bishop286d45c2018-10-02 15:21:57 -04002
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003# Xilinx QEMU wrapper to launch both PMU and APU instances (multiarch)
4import os
5import subprocess
6import sys
7import tempfile
8import shutil
Brad Bishop286d45c2018-10-02 15:21:57 -04009
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080010binpath = os.path.dirname(os.path.abspath(__file__))
11mach_path = tempfile.mkdtemp()
Brad Bishop286d45c2018-10-02 15:21:57 -040012
Brad Bishop286d45c2018-10-02 15:21:57 -040013
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080014# Separate PMU and APU arguments
15APU_args = sys.argv[1:]
16PMU_args = APU_args[APU_args.index('-pmu-args')+1]
17APU_args.remove('-pmu-args')
18APU_args.remove(PMU_args)
19PMU_args = PMU_args.split()
Brad Bishop286d45c2018-10-02 15:21:57 -040020
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080021PMU_rom = PMU_args[PMU_args.index('-kernel')+1]
22error_msg = None
Brad Bishop286d45c2018-10-02 15:21:57 -040023
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080024if 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
49else:
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
53shutil.rmtree(mach_path)
54sys.exit(error_msg)