board/qemu: define start qemu script outside of post-image script

The following moves the definition of the QEMU board's `start-qemu.sh`
helper script from being inlined in the post-image script into its own
file. This should, in theory, make it easier to maintain the script in
the future.

Signed-off-by: James Knight <james.d.knight@live.com>
[yann.morin.1998@free.fr:
  - don't sub-shell in the script
  - merge all 3 sed calls into one
  - create dest file with the sed, don't cp first
  - also substitute HOST_DIR
  - fix shellcheck
]
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
James Knight 2023-04-07 01:21:06 -04:00 committed by Yann E. MORIN
parent 6a6a11f64b
commit d9b244d8a3
2 changed files with 20 additions and 17 deletions

View File

@ -41,21 +41,10 @@ case ${DEFCONFIG_NAME} in
;;
esac
cat <<-_EOF_ > "${START_QEMU_SCRIPT}"
#!/bin/sh
(
BINARIES_DIR="\${0%/*}/"
cd \${BINARIES_DIR}
if [ "\${1}" = "serial-only" ]; then
EXTRA_ARGS='${SERIAL_ARGS}'
else
EXTRA_ARGS='${DEFAULT_ARGS}'
fi
export PATH="${HOST_DIR}/bin:\${PATH}"
exec ${QEMU_CMD_LINE} \${EXTRA_ARGS}
)
_EOF_
sed "s|@SERIAL_ARGS@|${SERIAL_ARGS}|g" \
"s|@DEFAULT_ARGS@|${DEFAULT_ARGS}|g" \
"s|@QEMU_CMD_LINE@|${QEMU_CMD_LINE}|g" \
"s|@HOST_DIR@|${HOST_DIR}|g" \
<"${QEMU_BOARD_DIR}/start-qemu.sh.in" \
>"${START_QEMU_SCRIPT}"
chmod +x "${START_QEMU_SCRIPT}"

View File

@ -0,0 +1,14 @@
#!/bin/sh
BINARIES_DIR="${0%/*}/"
# shellcheck disable=SC2164
cd "${BINARIES_DIR}"
if [ "${1}" = "serial-only" ]; then
EXTRA_ARGS='@SERIAL_ARGS@'
else
EXTRA_ARGS='@DEFAULT_ARGS@'
fi
export PATH="@HOST_DIR@/bin:${PATH}"
exec @QEMU_CMD_LINE@ ${EXTRA_ARGS}