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:] |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 16 | mbtype='' |
Brad Bishop | 286d45c | 2018-10-02 15:21:57 -0400 | [diff] [blame] | 17 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 18 | if '-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' |
| 25 | elif '-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' |
| 31 | else: |
| 32 | error_msg = '\nMultiarch not setup properly.' |
| 33 | sys.exit(error_msg) |
| 34 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 35 | error_msg = None |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 36 | if (mbtype == 'PMU' and os.path.exists(PMU_rom)) or mbtype == 'PLM': |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 37 | |
| 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 Geissler | 84ad7c5 | 2020-06-27 00:00:16 -0500 | [diff] [blame] | 41 | #NEED TO FIX for next yocto release (dont need to switch ports anymore, they will be provided correctly upstream |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 42 | # 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 Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 46 | mb_cmd = binpath + '/qemu-system-microblazeel ' + ' '.join(MB_args) + ' -machine-path ' + mach_path |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 47 | apu_cmd = binpath + '/qemu-system-aarch64 ' + ' '.join(APU_args) + ' -machine-path ' + mach_path |
| 48 | |
| 49 | # Debug prints |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 50 | print('\n%s instance cmd: %s\n' % (mbtype, mb_cmd)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 51 | print('APU instance cmd: %s\n' % apu_cmd) |
| 52 | |
| 53 | |
| 54 | # Invoke QEMU pmu instance |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 55 | process_pmu = subprocess.Popen(mb_cmd, shell=True, stderr=subprocess.PIPE) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 56 | |
| 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 | |
| 62 | else: |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 63 | 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 66 | |
| 67 | shutil.rmtree(mach_path) |
| 68 | sys.exit(error_msg) |