blob: ba0e274303ad44af589fcd6f123b9804b02a0ccb [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:]
Brad Bishop26bdd442019-08-16 17:08:17 -040016mbtype=''
Brad Bishop286d45c2018-10-02 15:21:57 -040017
Brad Bishop26bdd442019-08-16 17:08:17 -040018if '-pmu-args' in APU_args:
19 MB_args = APU_args[APU_args.index('-pmu-args')+1]
20 APU_args.remove('-pmu-args')
21 APU_args.remove(MB_args)
22 MB_args = MB_args.split()
23 PMU_rom = MB_args[MB_args.index('-kernel')+1]
24 mbtype='PMU'
25elif '-plm-args' in APU_args:
26 MB_args = APU_args[APU_args.index('-plm-args')+1]
27 APU_args.remove('-plm-args')
28 APU_args.remove(MB_args)
29 MB_args = MB_args.split()
30 mbtype='PLM'
31else:
32 error_msg = '\nMultiarch not setup properly.'
33 sys.exit(error_msg)
34
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080035error_msg = None
Brad Bishop26bdd442019-08-16 17:08:17 -040036if (mbtype == 'PMU' and os.path.exists(PMU_rom)) or mbtype == 'PLM':
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080037
38 # We need to switch tcp serial arguments (if they exist, e.g. qemurunner) to get the output correctly
39 tcp_serial_ports = [i for i, s in enumerate(APU_args) if 'tcp:127.0.0.1:' in s]
40
41 # 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
42 if len(tcp_serial_ports) == 2:
43 APU_args[tcp_serial_ports[0]],APU_args[tcp_serial_ports[1]] = APU_args[tcp_serial_ports[1]],APU_args[tcp_serial_ports[0]]
44
Brad Bishop26bdd442019-08-16 17:08:17 -040045 mb_cmd = binpath + '/qemu-system-microblazeel ' + ' '.join(MB_args) + ' -machine-path ' + mach_path
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080046 apu_cmd = binpath + '/qemu-system-aarch64 ' + ' '.join(APU_args) + ' -machine-path ' + mach_path
47
48 # Debug prints
Brad Bishop26bdd442019-08-16 17:08:17 -040049 print('\n%s instance cmd: %s\n' % (mbtype, mb_cmd))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080050 print('APU instance cmd: %s\n' % apu_cmd)
51
52
53 # Invoke QEMU pmu instance
Brad Bishop26bdd442019-08-16 17:08:17 -040054 process_pmu = subprocess.Popen(mb_cmd, shell=True, stderr=subprocess.PIPE)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055
56 # Invoke QEMU APU instance
57 process_apu = subprocess.Popen(apu_cmd, shell=True, stderr=subprocess.PIPE)
58 if process_apu.wait():
59 error_msg = '\nQEMU APU instance failed:\n%s' % process_apu.stderr.read().decode()
60
61else:
Brad Bishop26bdd442019-08-16 17:08:17 -040062 if mbtype == 'PMU':
63 error_msg = '\nError: Missing PMU ROM: %s' % PMU_rom
64 error_msg += '\nSee "meta-xilinx/README.qemu.md" for more information on accquiring the PMU ROM.\n'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080065
66shutil.rmtree(mach_path)
67sys.exit(error_msg)