From 16c497e0a66d4ab02d0bb6eb689340ba5d5b566f Mon Sep 17 00:00:00 2001 From: James Knight Date: Fri, 7 Apr 2023 01:21:07 -0400 Subject: [PATCH] board/qemu/start-qemu.sh.in: rework argument handling Provides the ability to forward command line options directly to QEMU. When invoking `start-qemu.sh`, users can forward arguments by adding a double dash (`--`) into the argument set, and any trailing arguments will be forwarded into QEMU. For example, `start-qemu.sh -- --help`. The original implementation supported a "serial-only" command line argument to help run in a non-graphical mode for some use cases. These changes try to promote a newly added `--serial-only` argument to drive this mode; that being said, a `serial-only` argument will still be accepted for backwards compatibility. Signed-off-by: James Knight [yann.morin.1998@free.fr: - drop the warning: unknown options cause 'exit 1' already, and any leftover is explicitly for qemu. - use false/true instead of 0/1 ] Signed-off-by: Yann E. MORIN --- board/qemu/start-qemu.sh.in | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/board/qemu/start-qemu.sh.in b/board/qemu/start-qemu.sh.in index 4dc9bfbb0d..cbc33a76d1 100644 --- a/board/qemu/start-qemu.sh.in +++ b/board/qemu/start-qemu.sh.in @@ -4,11 +4,20 @@ BINARIES_DIR="${0%/*}/" # shellcheck disable=SC2164 cd "${BINARIES_DIR}" -if [ "${1}" = "serial-only" ]; then +mode_serial=false +while [ "$1" ]; do + case "$1" in + --serial-only|serial-only) mode_serial=true; shift;; + --) shift; break;; + *) echo "unknown option: $1" >&2; exit 1;; + esac +done + +if ${mode_serial}; then EXTRA_ARGS='@SERIAL_ARGS@' else EXTRA_ARGS='@DEFAULT_ARGS@' fi export PATH="@HOST_DIR@/bin:${PATH}" -exec @QEMU_CMD_LINE@ ${EXTRA_ARGS} +exec @QEMU_CMD_LINE@ ${EXTRA_ARGS} "$@"