diff options
| -rw-r--r-- | meta-xilinx-core/recipes-devtools/qemu/files/qemu-system-aarch64-multiarch | 113 |
1 files changed, 66 insertions, 47 deletions
diff --git a/meta-xilinx-core/recipes-devtools/qemu/files/qemu-system-aarch64-multiarch b/meta-xilinx-core/recipes-devtools/qemu/files/qemu-system-aarch64-multiarch index 370e694b..1dcac990 100644 --- a/meta-xilinx-core/recipes-devtools/qemu/files/qemu-system-aarch64-multiarch +++ b/meta-xilinx-core/recipes-devtools/qemu/files/qemu-system-aarch64-multiarch | |||
| @@ -13,58 +13,77 @@ mach_path = tempfile.mkdtemp() | |||
| 13 | 13 | ||
| 14 | # Separate PMU and APU arguments | 14 | # Separate PMU and APU arguments |
| 15 | APU_args = sys.argv[1:] | 15 | APU_args = sys.argv[1:] |
| 16 | mbtype='' | 16 | PMU_args = [] |
| 17 | PLM_args = [] | ||
| 17 | 18 | ||
| 18 | if '-pmu-args' in APU_args: | 19 | if '-pmu-args' in APU_args: |
| 19 | MB_args = APU_args[APU_args.index('-pmu-args')+1] | 20 | pmu_args_idx = APU_args.index('-pmu-args') |
| 20 | APU_args.remove('-pmu-args') | 21 | PMU_args = APU_args[pmu_args_idx+1].split() |
| 21 | APU_args.remove(MB_args) | 22 | del APU_args[pmu_args_idx:pmu_args_idx+2] |
| 22 | MB_args = MB_args.split() | 23 | |
| 23 | PMU_rom = MB_args[MB_args.index('-kernel')+1] | 24 | if '-plm-args' in APU_args: |
| 24 | mbtype='PMU' | 25 | plm_args_idx = APU_args.index('-plm-args') |
| 25 | elif '-plm-args' in APU_args: | 26 | PLM_args = APU_args[plm_args_idx+1].split() |
| 26 | MB_args = APU_args[APU_args.index('-plm-args')+1] | 27 | del APU_args[plm_args_idx:plm_args_idx+2] |
| 27 | APU_args.remove('-plm-args') | 28 | |
| 28 | APU_args.remove(MB_args) | 29 | if PMU_args and PLM_args: |
| 29 | MB_args = MB_args.split() | 30 | sys.exit("\nError: -pmu-args can not be used with -plm-args\n") |
| 30 | mbtype='PLM' | 31 | |
| 31 | elif '--help' in APU_args: | 32 | if ('--help' in APU_args) or (not PMU_args and not PLM_args): |
| 32 | mbtype='help' | 33 | print("AMD FPGA QEMU multiarch wrapper\n") |
| 33 | else: | 34 | print("Version 2024.1") |
| 34 | error_msg = '\nMultiarch not setup properly.' | 35 | print("") |
| 35 | sys.exit(error_msg) | 36 | print("Usage:") |
| 36 | 37 | print(" %s <APU options> [-pmu-args <pmu options>]" % (sys.argv[0])) | |
| 37 | error_msg = None | 38 | print(" %s <APU options> [-plm-args <plm options>]" % (sys.argv[0])) |
| 38 | if (mbtype == 'PMU' and os.path.exists(PMU_rom)) or mbtype == 'PLM': | 39 | print("") |
| 39 | 40 | sys.exit(1) | |
| 40 | # We need to switch tcp serial arguments (if they exist, e.g. qemurunner) to get the output correctly | 41 | |
| 41 | tcp_serial_ports = [i for i, s in enumerate(APU_args) if 'tcp:127.0.0.1:' in s] | 42 | if PMU_args: |
| 42 | 43 | PMU_rom = PMU_args[PMU_args.index('-kernel')+1] | |
| 43 | #NEED TO FIX for next yocto release (dont need to switch ports anymore, they will be provided correctly upstream | ||
| 44 | # 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 | ||
| 45 | if len(tcp_serial_ports) == 2: | ||
| 46 | APU_args[tcp_serial_ports[0]],APU_args[tcp_serial_ports[1]] = APU_args[tcp_serial_ports[1]],APU_args[tcp_serial_ports[0]] | ||
| 47 | |||
| 48 | mb_cmd = binpath + '/qemu-system-microblazeel ' + ' '.join(MB_args) + ' -machine-path ' + mach_path | ||
| 49 | apu_cmd = binpath + '/qemu-system-aarch64 ' + ' '.join(APU_args) + ' -machine-path ' + mach_path | ||
| 50 | |||
| 51 | # Debug prints | ||
| 52 | print('\n%s instance cmd: %s\n' % (mbtype, mb_cmd)) | ||
| 53 | print('APU instance cmd: %s\n' % apu_cmd) | ||
| 54 | |||
| 55 | |||
| 56 | # Invoke QEMU pmu instance | ||
| 57 | process_pmu = subprocess.Popen(mb_cmd, shell=True, stderr=subprocess.PIPE) | ||
| 58 | |||
| 59 | # Invoke QEMU APU instance | ||
| 60 | process_apu = subprocess.Popen(apu_cmd, shell=True, stderr=subprocess.PIPE) | ||
| 61 | if process_apu.wait(): | ||
| 62 | error_msg = '\nQEMU APU instance failed:\n%s' % process_apu.stderr.read().decode() | ||
| 63 | 44 | ||
| 64 | else: | 45 | if not os.path.exists(PMU_rom): |
| 65 | if mbtype == 'PMU': | ||
| 66 | error_msg = '\nError: Missing PMU ROM: %s' % PMU_rom | 46 | error_msg = '\nError: Missing PMU ROM: %s' % PMU_rom |
| 67 | error_msg += '\nSee "meta-xilinx/README.qemu.md" for more information on accquiring the PMU ROM.\n' | 47 | error_msg += '\nSee "meta-xilinx/README.qemu.md" for more information on accquiring the PMU ROM.\n' |
| 48 | sys.exit(error_msg) | ||
| 49 | |||
| 50 | # We need to switch tcp serial arguments (if they exist, e.g. qemurunner) to get the output correctly | ||
| 51 | tcp_serial_ports = [i for i, s in enumerate(APU_args) if 'tcp:127.0.0.1:' in s] | ||
| 52 | |||
| 53 | #NEED TO FIX for next yocto release (dont need to switch ports anymore, they will be provided correctly upstream | ||
| 54 | # 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 | ||
| 55 | if len(tcp_serial_ports) == 2: | ||
| 56 | APU_args[tcp_serial_ports[0]],APU_args[tcp_serial_ports[1]] = APU_args[tcp_serial_ports[1]],APU_args[tcp_serial_ports[0]] | ||
| 57 | |||
| 58 | mb_cmd = "" | ||
| 59 | if PMU_args: | ||
| 60 | mb_cmd = binpath + '/qemu-system-microblazeel ' + ' '.join(PMU_args) + ' -machine-path ' + mach_path | ||
| 61 | |||
| 62 | print("PMU instance cmd: %s\n" % mb_cmd) | ||
| 63 | |||
| 64 | if PLM_args: | ||
| 65 | mb_cmd = binpath + '/qemu-system-microblazeel ' + ' '.join(PLM_args) + ' -machine-path ' + mach_path | ||
| 66 | |||
| 67 | print("PLM instance cmd: %s\n" % mb_cmd) | ||
| 68 | |||
| 69 | apu_cmd = binpath + '/qemu-system-aarch64 ' + ' '.join(APU_args) + ' -machine-path ' + mach_path | ||
| 70 | |||
| 71 | print("APU instance cmd: %s\n" % apu_cmd) | ||
| 72 | |||
| 73 | |||
| 74 | if mb_cmd: | ||
| 75 | process_mb = subprocess.Popen(mb_cmd, shell=True, stderr=subprocess.PIPE) | ||
| 76 | |||
| 77 | if apu_cmd: | ||
| 78 | process_apu = subprocess.Popen(apu_cmd, shell=True, stderr=subprocess.PIPE) | ||
| 79 | |||
| 80 | error_msg = "" | ||
| 81 | if apu_cmd and process_apu.wait(): | ||
| 82 | # We only check for failures on the MB instance if APU fails | ||
| 83 | error_msg += '\nQEMU APU instance failed:\n%s' % process_apu.stderr.read().decode() | ||
| 84 | |||
| 85 | if mb_cmd and process_mb.wait(): | ||
| 86 | error_msg += '\nQEMU MB instance failed:\n%s' % process_mb.stderr.read().decode() | ||
| 68 | 87 | ||
| 69 | shutil.rmtree(mach_path) | 88 | shutil.rmtree(mach_path) |
| 70 | sys.exit(error_msg) | 89 | sys.exit(error_msg) |
