All of lore.kernel.org
 help / color / mirror / Atom feed
From: Romain Naour <romain.naour@smile.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v4 4/9] configs/qemu{x86, x86_64}: add a serial console
Date: Sun,  9 Feb 2020 19:03:22 +0100	[thread overview]
Message-ID: <20200209180327.455426-5-romain.naour@smile.fr> (raw)
In-Reply-To: <20200209180327.455426-1-romain.naour@smile.fr>

The current Buildroot defconfigs for qemu_x86 and qemu_x86_64
instantiate a console on tty1, which appears on QEMU's
graphical window. Add a console on the serial port (ttyS0) to
be used later for gitlab testing.

This change is need since the script used for gitlab testing
needs to use a serial output with pexpect.

This change is similar to the one made for raspberrypi [1] to
handle HDMI and serial console:

This requires three changes:
 1. have two 'console=' entries in the kernel command line: tty1,
    then ttyS0;
 2. change BR2_TARGET_GENERIC_GETTY_PORT to "console", so it starts
    a getty on the last console= passed to the kernel, ttyS0;
 3. add a new getty on tty1 to the generated inittab.

Step 2 is actually obtained by removing BR2_TARGET_GENERIC_GETTY_PORT
entirely from the defconfigs, since "console" is the default value.

Step 3 requires a post-build script since the Buildroot makefiles can
configure only one console.

Note: instead of simply adding a new getty on ttyS0 (which would
work) this patch actually changes BR2_TARGET_GENERIC_GETTY_PORT to
instantiate a console on UART, then adds back tty1 via
post-build.sh. This is done only to avoid the "GENERIC_SERIAL" comment
where we instantiate a console on QEMU graphical window, then
instantiate a really-serial console on another line.

The result is these two inittab lines:

  console::respawn:/sbin/getty -L  console 0 vt100 # GENERIC_SERIAL
  tty1::respawn:/sbin/getty -L  tty1 0 vt100 # QEMU graphical window

[1] 20878a1017e2bf7eb8c5f870dc6d2641493cb0f9

Signed-off-by: Romain Naour <romain.naour@smile.fr>
---
 board/qemu/x86/post-build.sh    | 11 +++++++++++
 board/qemu/x86/readme.txt       |  2 +-
 board/qemu/x86_64/post-build.sh | 11 +++++++++++
 board/qemu/x86_64/readme.txt    |  2 +-
 configs/qemu_x86_64_defconfig   |  4 +++-
 configs/qemu_x86_defconfig      |  4 +++-
 6 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100755 board/qemu/x86/post-build.sh
 create mode 100755 board/qemu/x86_64/post-build.sh

diff --git a/board/qemu/x86/post-build.sh b/board/qemu/x86/post-build.sh
new file mode 100755
index 0000000000..bf83a002c2
--- /dev/null
+++ b/board/qemu/x86/post-build.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+set -u
+set -e
+
+# Add a console on tty1
+if [ -e ${TARGET_DIR}/etc/inittab ]; then
+    grep -qE '^tty1::' ${TARGET_DIR}/etc/inittab || \
+	sed -i '/GENERIC_SERIAL/a\
+tty1::respawn:/sbin/getty -L  tty1 0 vt100 # QEMU graphical window' ${TARGET_DIR}/etc/inittab
+fi
diff --git a/board/qemu/x86/readme.txt b/board/qemu/x86/readme.txt
index 42fc2439da..3bbafecf91 100644
--- a/board/qemu/x86/readme.txt
+++ b/board/qemu/x86/readme.txt
@@ -1,6 +1,6 @@
 Run the emulation with:
 
-  qemu-system-i386 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append "rootwait root=/dev/vda" -net nic,model=virtio -net user
+  qemu-system-i386 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append "rootwait root=/dev/vda console=tty1 console=ttyS0" -serial stdio -net nic,model=virtio -net user
 
 Optionally add -smp N to emulate a SMP system with N CPUs.
 
diff --git a/board/qemu/x86_64/post-build.sh b/board/qemu/x86_64/post-build.sh
new file mode 100755
index 0000000000..bf83a002c2
--- /dev/null
+++ b/board/qemu/x86_64/post-build.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+set -u
+set -e
+
+# Add a console on tty1
+if [ -e ${TARGET_DIR}/etc/inittab ]; then
+    grep -qE '^tty1::' ${TARGET_DIR}/etc/inittab || \
+	sed -i '/GENERIC_SERIAL/a\
+tty1::respawn:/sbin/getty -L  tty1 0 vt100 # QEMU graphical window' ${TARGET_DIR}/etc/inittab
+fi
diff --git a/board/qemu/x86_64/readme.txt b/board/qemu/x86_64/readme.txt
index 4a1c0c0ff5..93ac22a947 100644
--- a/board/qemu/x86_64/readme.txt
+++ b/board/qemu/x86_64/readme.txt
@@ -1,6 +1,6 @@
 Run the emulation with:
 
-  qemu-system-x86_64 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append "rootwait root=/dev/vda" -net nic,model=virtio -net user
+  qemu-system-x86_64 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append "rootwait root=/dev/vda console=tty1 console=ttyS0" -serial stdio -net nic,model=virtio -net user
 
 Optionally add -smp N to emulate a SMP system with N CPUs.
 
diff --git a/configs/qemu_x86_64_defconfig b/configs/qemu_x86_64_defconfig
index cbd0413a90..b561e42e51 100644
--- a/configs/qemu_x86_64_defconfig
+++ b/configs/qemu_x86_64_defconfig
@@ -3,12 +3,14 @@ BR2_x86_64=y
 
 # System
 BR2_SYSTEM_DHCP="eth0"
-BR2_TARGET_GENERIC_GETTY_PORT="tty1"
 
 # Filesystem
 BR2_TARGET_ROOTFS_EXT2=y
 # BR2_TARGET_ROOTFS_TAR is not set
 
+# Image
+BR2_ROOTFS_POST_BUILD_SCRIPT="board/qemu/x86_64/post-build.sh"
+
 # Linux headers same as kernel, a 4.19 series
 BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_19=y
 
diff --git a/configs/qemu_x86_defconfig b/configs/qemu_x86_defconfig
index 6ca3ab9627..52f1744344 100644
--- a/configs/qemu_x86_defconfig
+++ b/configs/qemu_x86_defconfig
@@ -4,12 +4,14 @@ BR2_x86_pentiumpro=y
 
 # System
 BR2_SYSTEM_DHCP="eth0"
-BR2_TARGET_GENERIC_GETTY_PORT="tty1"
 
 # Filesystem
 BR2_TARGET_ROOTFS_EXT2=y
 # BR2_TARGET_ROOTFS_TAR is not set
 
+# Image
+BR2_ROOTFS_POST_BUILD_SCRIPT="board/qemu/x86/post-build.sh"
+
 # Linux headers same as kernel, a 4.19 series
 BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_19=y
 
-- 
2.24.1

  parent reply	other threads:[~2020-02-09 18:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-09 18:03 [Buildroot] [PATCH v4 0/9] gitlab Qemu runtime testing Romain Naour
2020-02-09 18:03 ` [Buildroot] [PATCH v4 1/9] configs/qemu_ppc_mac99_defconfig: add usual comments for Kconfig symbols Romain Naour
2020-02-10  2:32   ` Joel Stanley
2020-02-16 21:22   ` Peter Korsgaard
2020-02-09 18:03 ` [Buildroot] [PATCH v4 2/9] configs/qemu_pcc_mac99: build host-qemu for runtime testing Romain Naour
2020-02-10  2:31   ` Joel Stanley
2020-02-16 21:23   ` Peter Korsgaard
2020-02-09 18:03 ` [Buildroot] [PATCH v4 3/9] configs/qemu_m68k_q800: remove host-qemu Romain Naour
2020-02-09 18:12   ` Romain Naour
2020-02-09 18:49     ` Romain Naour
2020-02-16 21:24       ` Peter Korsgaard
2020-02-09 18:03 ` Romain Naour [this message]
2020-02-16 21:28   ` [Buildroot] [PATCH v4 4/9] configs/qemu{x86, x86_64}: add a serial console Peter Korsgaard
2020-02-09 18:03 ` [Buildroot] [PATCH v4 5/9] board/qemu: add defconfig file name as tag before the qemu command line Romain Naour
2020-02-10 13:08   ` Thomas Petazzoni
2020-02-10 13:37     ` Romain Naour
2020-02-10 14:40       ` Thomas Petazzoni
2020-02-09 18:03 ` [Buildroot] [PATCH v4 6/9] board/qemu: add post-image script for gitlab qemu testing Romain Naour
2020-02-10 13:09   ` Thomas Petazzoni
2020-02-10 13:47     ` Romain Naour
2020-02-10 14:41       ` Thomas Petazzoni
2020-02-10 13:13   ` Thomas Petazzoni
2020-02-10 13:49     ` Romain Naour
2020-02-09 18:03 ` [Buildroot] [PATCH v4 7/9] configs/qemu*: use the post-image script with "$(BR2_DEFCONFIG)" as argument Romain Naour
2020-02-09 18:03 ` [Buildroot] [PATCH v4 8/9] support/scripts/boot-qemu-image.py: boot Qemu images with Qemu-system Romain Naour
2020-02-09 18:03 ` [Buildroot] [PATCH v4 9/9] gitlab.yml.in*: enable Qemu gitlab testing Romain Naour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200209180327.455426-5-romain.naour@smile.fr \
    --to=romain.naour@smile.fr \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.