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 | |
| 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 Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 45 | 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] | 46 | apu_cmd = binpath + '/qemu-system-aarch64 ' + ' '.join(APU_args) + ' -machine-path ' + mach_path |
| 47 | |
| 48 | # Debug prints |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 49 | print('\n%s instance cmd: %s\n' % (mbtype, mb_cmd)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 50 | print('APU instance cmd: %s\n' % apu_cmd) |
| 51 | |
| 52 | |
| 53 | # Invoke QEMU pmu instance |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 54 | process_pmu = subprocess.Popen(mb_cmd, shell=True, stderr=subprocess.PIPE) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 55 | |
| 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 | |
| 61 | else: |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 62 | 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 65 | |
| 66 | shutil.rmtree(mach_path) |
| 67 | sys.exit(error_msg) |