diff --git a/tools/idf_py_actions/qemu_ext.py b/tools/idf_py_actions/qemu_ext.py index 716af4ad95..610e24a7a4 100644 --- a/tools/idf_py_actions/qemu_ext.py +++ b/tools/idf_py_actions/qemu_ext.py @@ -5,6 +5,7 @@ import binascii import fnmatch import json import os +import shlex import shutil import socket import subprocess @@ -279,9 +280,6 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict: if options.wait_for_gdb or gdb: qemu_args += ['-gdb', f'tcp::{QEMU_PORT_GDB}', '-S'] - if qemu_extra_args: - qemu_args += qemu_extra_args.split(' ') - if graphics: qemu_args += ['-display', 'sdl'] else: @@ -293,6 +291,12 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict: # Launch QEMU! if not options.bg_mode: qemu_args += ['-serial', 'mon:stdio'] + + # Adding qemu_extra_args at the end ensures the monitor is the + # primary serial port if another -serial argument is present. + if qemu_extra_args: + qemu_args += shlex.split(qemu_extra_args) + yellow_print('Running qemu (fg): ' + ' '.join(qemu_args)) subprocess.run(qemu_args) else: @@ -301,6 +305,11 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict: else: qemu_args += ['-serial', f'tcp::{QEMU_PORT_SERIAL},server,nowait'] + # Adding qemu_extra_args at the end ensures the monitor is the + # primary serial port if another -serial argument is present. + if qemu_extra_args: + qemu_args += shlex.split(qemu_extra_args) + yellow_print('Running qemu (bg): ' + ' '.join(qemu_args)) qemu_proc = subprocess.Popen(qemu_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) wait_for_socket(QEMU_PORT_SERIAL)