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 <james.d.knight@live.com>
[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 <yann.morin.1998@free.fr>
This commit is contained in:
James Knight 2023-04-07 01:21:07 -04:00 committed by Yann E. MORIN
parent b32d7c99c6
commit 16c497e0a6

View File

@ -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} "$@"