[Buildroot] [PATCH v5 2/5] board/qemu: add post-image script for gitlab qemu testing

Romain Naour romain.naour at smile.fr
Mon Feb 17 20:50:27 UTC 2020

This commit add a post-image script to be used by each qemu
board defconfig in order to generate start-qemu.sh in BINARIES_DIR.
The start-qemu.sh script can be used by Buildroot user to start
Qemu or by a gitlab CI.
start-qemu.sh is not started automatically at the end of the build.

To find the correct qemu command line, we use the second post
script argument which must contain "$(BR2_DEFCONFIG)"


The post-image script expect something like
"/path/to/qemu_aarch64_virt_defconfig" in BR2_DEFCONFIG.

Doing a basename allow to retrieve the name of the defconfig
file that should match on on the "tag" previously introduced in
readme.txt files.

The script start-qemu.sh is able to modify the qemu command
line if CI_JOB_NAME defined in the environment. This allow
to disable the graphical output and redirect serial I/Os to

Only sh4/sh4eb needs a special handling by adding
"-serial stdio -display none" instead of "-display none".

Signed-off-by: Romain Naour <romain.naour at smile.fr>
v5: update the script after Thomas's review [1] [2]

[1] http://lists.busybox.net/pipermail/buildroot/2020-February/273820.html
[2] http://lists.busybox.net/pipermail/buildroot/2020-February/273822.html
 board/qemu/post-image.sh | 50 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100755 board/qemu/post-image.sh

diff --git a/board/qemu/post-image.sh b/board/qemu/post-image.sh
new file mode 100755
index 0000000000..804c5f6110
--- /dev/null
+++ b/board/qemu/post-image.sh
@@ -0,0 +1,50 @@
+QEMU_BOARD_DIR="$(dirname $0)"
+DEFCONFIG_NAME="$(basename $2)"
+if [[ "${DEFCONFIG_NAME}" =~ ^"qemu_*" ]]; then
+    # Not a Qemu defconfig, can't test.
+    exit 0
+# Search for "# qemu_*_defconfig" tag in all readme.txt files.
+# Qemu command line on multilines using back slash are accepted.
+QEMU_CMD_LINE=$(sed -r ':a; /\\$/N; s/\\\n//; s/\t/ /; ta; /# '${DEFCONFIG_NAME}'$/!d; s/#.*//' ${README_FILES})
+if [ -z "$QEMU_CMD_LINE" ]; then
+    # No Qemu cmd line found, can't test.
+    exit 0
+# Replace output/images path by ${IMAGE_DIR} since the script
+# will be in the same directory as the kernel and the rootfs images.
+# Test if we are running in gitlab
+if [ -n "$CI_JOB_NAME" ]; then
+    # Remove -serial stdio if present
+    QEMU_CMD_LINE=${QEMU_CMD_LINE//-serial stdio/}
+    # Disable graphical output and redirect serial I/Os to console
+    case ${DEFCONFIG_NAME} in
+        # Special case for SH4
+        qemu_sh4eb_r2d_defconfig | qemu_sh4_r2d_defconfig)
+            QEMU_CMD_LINE="$QEMU_CMD_LINE -serial stdio -display none"
+            ;;
+        *)
+            QEMU_CMD_LINE="$QEMU_CMD_LINE -nographic"
+            ;;
+    esac
+IMAGE_DIR="\$(dirname \$0)"

More information about the buildroot mailing list