[Buildroot] [PATCH 1/1] board/qemu/post-image.sh: flexible qemu launch options

Romain Naour romain.naour at smile.fr
Sat Jul 23 16:33:49 UTC 2022


Hello James,

Le 17/07/2022 à 17:57, James Knight a écrit :
> Tweaking the generated QEMU launch helper script to provide more
> flexibility for users. These changes provide:
> 
> - 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 ability to use a host system's QEMU. While a Buildroot generated
>    QEMU should work for most cases, a developer may wish to use the
>    system's QEMU for options which may not have been configured in the
>    Buildroot's QEMU build (e.g. configuring a different display mode).
> 
> 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.

The start-qemu.sh script is actually used by the Buildroot gitlab-ci to test do
a runtime test (boot test) for all Qemu defconfigs.

The qemu command line is extracted from qemu readme.txt files and stored in
generated start-qemu.sh script.

So only this qemu command line command line is supposed to work out of the box.
If you let the used customize the qemu command line, it can raise some issue.

The "serial-only" option is used in boot-qemu-image.py [1] to use the serial
interface in the CI.

[1]
https://git.buildroot.net/buildroot/tree/support/scripts/boot-qemu-image.py?h=2022.05#n27

> 
> Signed-off-by: James Knight <james.d.knight at live.com>
> ---
>  board/qemu/post-image.sh | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/board/qemu/post-image.sh b/board/qemu/post-image.sh
> index 88f0413496..f303211569 100755
> --- a/board/qemu/post-image.sh
> +++ b/board/qemu/post-image.sh
> @@ -47,14 +47,27 @@ cat <<-_EOF_ > "${START_QEMU_SCRIPT}"
>  	BINARIES_DIR="\${0%/*}/"
>  	cd \${BINARIES_DIR}
>  
> -	if [ "\${1}" = "serial-only" ]; then
> +	mode_host=0
> +	mode_serial=0
> +	while [[ \$1 == -* ]]; do
> +	    case "\$1" in
> +	    --host) mode_host=1; shift;;

Naming stuff is hard, here we want an option to use Qemu installed on the host
system, not from host-qemu (--host may be misleading).

> +	    --serial-only|serial-only) mode_serial=1; shift;;
> +	    --) shift; break;;
> +	    -*) echo "unknown option: \$1" 1>&2; exit 1;;
> +	    esac
> +	done
> +
> +	if [ \$mode_serial -eq 1 ]; then
>  	    EXTRA_ARGS='${SERIAL_ARGS}'
>  	else
>  	    EXTRA_ARGS='${DEFAULT_ARGS}'
>  	fi
>  
> -	export PATH="${HOST_DIR}/bin:\${PATH}"
> -	exec ${QEMU_CMD_LINE} \${EXTRA_ARGS}
> +	if [ \$mode_host -ne 1 ]; then
> +	    export PATH="${HOST_DIR}/bin:\${PATH}"
> +	fi
> +	exec ${QEMU_CMD_LINE} \${EXTRA_ARGS} "\$@"

I would throw a warning if $@ is not empty, just to warn the user.
Actually using Qemu installed on the host may be really old and not able to boot
the system...

Best regards,
Romain

>  	)
>  _EOF_
>  




More information about the buildroot mailing list