blob: 6f7fb5225c80b98f80cf8c40bf3ff88950da0600 [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
Andrew Geissler84ad7c52020-06-27 00:00:16 -050041 #NEED TO FIX for next yocto release (dont need to switch ports anymore, they will be provided correctly upstream
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080042 # 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
43 if len(tcp_serial_ports) == 2:
44 APU_args[tcp_serial_ports[0]],APU_args[tcp_serial_ports[1]] = APU_args[tcp_serial_ports[1]],APU_args[tcp_serial_ports[0]]
45
Brad Bishop26bdd442019-08-16 17:08:17 -040046 mb_cmd = binpath + '/qemu-system-microblazeel ' + ' '.join(MB_args) + ' -machine-path ' + mach_path
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080047 apu_cmd = binpath + '/qemu-system-aarch64 ' + ' '.join(APU_args) + ' -machine-path ' + mach_path
48
49 # Debug prints
Brad Bishop26bdd442019-08-16 17:08:17 -040050 print('\n%s instance cmd: %s\n' % (mbtype, mb_cmd))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080051 print('APU instance cmd: %s\n' % apu_cmd)
52
53
54 # Invoke QEMU pmu instance
Brad Bishop26bdd442019-08-16 17:08:17 -040055 process_pmu = subprocess.Popen(mb_cmd, shell=True, stderr=subprocess.PIPE)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080056
57 # Invoke QEMU APU instance
58 process_apu = subprocess.Popen(apu_cmd, shell=True, stderr=subprocess.PIPE)
59 if process_apu.wait():
60 error_msg = '\nQEMU APU instance failed:\n%s' % process_apu.stderr.read().decode()
61
62else:
Brad Bishop26bdd442019-08-16 17:08:17 -040063 if mbtype == 'PMU':
64 error_msg = '\nError: Missing PMU ROM: %s' % PMU_rom
65 error_msg += '\nSee "meta-xilinx/README.qemu.md" for more information on accquiring the PMU ROM.\n'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080066
67shutil.rmtree(mach_path)
68sys.exit(error_msg)