Skip to contentSkip to conversation

raspberrypi, raspberrypi2: add a serial console

PATCH Superseded Luca Ceresoli 3 participants 4 messages Apr 17, 2016 – Apr 18, 2016 Broadcom BCM2711/BCM2835 Arm architecture

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 raspberrypi, raspberrypi2: add a serial console

The current Buildroot defconfigs for Raspberry Pi and Raspberry Pi 2 instantiate a console on tty1, which appears on HDMI. Add a console on the serial port (ttyAMA0) to be more consistent with other defconfigs and provide a better out-of-the-box experience to users used to have a serial console from Buildroot defconfigs.

This requires three changes:
1. have two 'console=' entries in the kernel command line: tty1,

    then ttyAMA0;
 2. change BR2_TARGET_GENERIC_GETTY_PORT to "console", so it starts
    a getty on the last console= passed to the kernel, ttyAMA0;

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 ttyAMA0 (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 an HDMI console, 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 # HDMI console

Cc Yann E. MORIN <[email protected]>
Cc Arnout Vandecappelle <[email protected]>

---

v2:
- remove BR2_TARGET_GENERIC_GETTY_PORT, it defaults to "console"
- rebase on current master

Tested on both Raspberry Pi B and Raspberry Pi 2, each on serial and HDMI console.

---
 board/raspberrypi/post-build.sh  | 9 +++++++++
 configs/raspberrypi2_defconfig   | 2 +-
 configs/raspberrypi_defconfig    | 2 +-
 package/rpi-firmware/cmdline.txt | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)
 create mode 100755 board/raspberrypi/post-build.sh
board/raspberrypi/post-build.sh new file +9 -0
new file mode 100755
index 000000000000..7eae14a88569
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+set -u
+set -e
+
+# Add a console on tty1
+grep -qE '^tty1::' ${TARGET_DIR}/etc/inittab || \
+sed -i '/GENERIC_SERIAL/a\
+tty1::respawn:/sbin/getty -L  tty1 0 vt100 # HDMI console' ${TARGET_DIR}/etc/inittab
configs/raspberrypi2_defconfig +1 -1
index 506330cd0780..7fc39c234c32 100644
@@ -5,7 +5,6 @@ BR2_ARM_FPU_NEON_VFPV4=y
 
 BR2_TOOLCHAIN_BUILDROOT_CXX=y
 
-BR2_TARGET_GENERIC_GETTY_PORT="tty1"
 BR2_SYSTEM_DHCP="eth0"
 
 # Linux headers same as kernel, a 4.1 series
@@ -33,4 +32,5 @@ BR2_PACKAGE_HOST_MTOOLS=y
 BR2_TARGET_ROOTFS_EXT2=y
 BR2_TARGET_ROOTFS_EXT2_4=y
 # BR2_TARGET_ROOTFS_TAR is not set
+BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi2/post-build.sh"
 BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi2/post-image.sh"
configs/raspberrypi_defconfig +1 -1
index 1795b2c03d53..8d13381105c1 100644
@@ -2,7 +2,6 @@ BR2_arm=y
 BR2_arm1176jzf_s=y
 BR2_ARM_EABIHF=y
 
-BR2_TARGET_GENERIC_GETTY_PORT="tty1"
 BR2_SYSTEM_DHCP="eth0"
 
 # Linux headers same as kernel, a 4.1 series
@@ -32,4 +31,5 @@ BR2_PACKAGE_HOST_MTOOLS=y
 BR2_TARGET_ROOTFS_EXT2=y
 BR2_TARGET_ROOTFS_EXT2_4=y
 # BR2_TARGET_ROOTFS_TAR is not set
+BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi/post-build.sh"
 BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi/post-image.sh"
package/rpi-firmware/cmdline.txt +1 -1
index 38aa3782621b..155a54693bff 100644
@@ -1 +1 @@
-root=/dev/mmcblk0p2 rootwait
+root=/dev/mmcblk0p2 rootwait console=tty1 console=ttyAMA0,115200
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/1 raspberrypi, raspberrypi2: add a serial console

Luca, All,

On 2016-04-17 23:45 +0200, Luca Ceresoli spake thusly:

Quoted 26 lines

The current Buildroot defconfigs for Raspberry Pi and Raspberry Pi 2 instantiate a console on tty1, which appears on HDMI. Add a console on the serial port (ttyAMA0) to be more consistent with other defconfigs and provide a better out-of-the-box experience to users used to have a serial console from Buildroot defconfigs.

This requires three changes:
1. have two 'console=' entries in the kernel command line: tty1,

    then ttyAMA0;
 2. change BR2_TARGET_GENERIC_GETTY_PORT to "console", so it starts
    a getty on the last console= passed to the kernel, ttyAMA0;

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 ttyAMA0 (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 an HDMI console, then instantiate a really-serial console on another line.

Quoted 8 lines

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 # HDMI console

Cc Yann E. MORIN <[email protected]>
Cc Arnout Vandecappelle <[email protected]>

Regards,
Yann E. MORIN.

Quoted 77 lines

---

v2:
- remove BR2_TARGET_GENERIC_GETTY_PORT, it defaults to "console"
- rebase on current master

Tested on both Raspberry Pi B and Raspberry Pi 2, each on serial and HDMI console.

---
 board/raspberrypi/post-build.sh  | 9 +++++++++
 configs/raspberrypi2_defconfig   | 2 +-
 configs/raspberrypi_defconfig    | 2 +-
 package/rpi-firmware/cmdline.txt | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)
 create mode 100755 board/raspberrypi/post-build.sh
board/raspberrypi/post-build.sh new file +9 -0
new file mode 100755
index 000000000000..7eae14a88569
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+set -u
+set -e
+
+# Add a console on tty1
+grep -qE '^tty1::' ${TARGET_DIR}/etc/inittab || \
+sed -i '/GENERIC_SERIAL/a\
+tty1::respawn:/sbin/getty -L  tty1 0 vt100 # HDMI console' ${TARGET_DIR}/etc/inittab
configs/raspberrypi2_defconfig +1 -1
index 506330cd0780..7fc39c234c32 100644
@@ -5,7 +5,6 @@ BR2_ARM_FPU_NEON_VFPV4=y
 
 BR2_TOOLCHAIN_BUILDROOT_CXX=y
 
-BR2_TARGET_GENERIC_GETTY_PORT="tty1"
 BR2_SYSTEM_DHCP="eth0"
 
 # Linux headers same as kernel, a 4.1 series
@@ -33,4 +32,5 @@ BR2_PACKAGE_HOST_MTOOLS=y
 BR2_TARGET_ROOTFS_EXT2=y
 BR2_TARGET_ROOTFS_EXT2_4=y
 # BR2_TARGET_ROOTFS_TAR is not set
+BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi2/post-build.sh"
 BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi2/post-image.sh"
configs/raspberrypi_defconfig +1 -1
index 1795b2c03d53..8d13381105c1 100644
@@ -2,7 +2,6 @@ BR2_arm=y
 BR2_arm1176jzf_s=y
 BR2_ARM_EABIHF=y
 
-BR2_TARGET_GENERIC_GETTY_PORT="tty1"
 BR2_SYSTEM_DHCP="eth0"
 
 # Linux headers same as kernel, a 4.1 series
@@ -32,4 +31,5 @@ BR2_PACKAGE_HOST_MTOOLS=y
 BR2_TARGET_ROOTFS_EXT2=y
 BR2_TARGET_ROOTFS_EXT2_4=y
 # BR2_TARGET_ROOTFS_TAR is not set
+BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi/post-build.sh"
 BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi/post-image.sh"
package/rpi-firmware/cmdline.txt +1 -1
index 38aa3782621b..155a54693bff 100644
@@ -1 +1 @@
-root=/dev/mmcblk0p2 rootwait
+root=/dev/mmcblk0p2 rootwait console=tty1 console=ttyAMA0,115200
Signature · 1 line
1.9.1
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#2 lore raw

PATCH v2 1/1 raspberrypi, raspberrypi2: add a serial console

In reply to Luca Ceresoli

Hello,

Quoted 28 lines · Luca Ceresoli

The current Buildroot defconfigs for Raspberry Pi and Raspberry Pi 2 instantiate a console on tty1, which appears on HDMI. Add a console on the serial port (ttyAMA0) to be more consistent with other defconfigs and provide a better out-of-the-box experience to users used to have a serial console from Buildroot defconfigs.

This requires three changes:
1. have two 'console=' entries in the kernel command line: tty1,

    then ttyAMA0;
 2. change BR2_TARGET_GENERIC_GETTY_PORT to "console", so it starts
    a getty on the last console= passed to the kernel, ttyAMA0;

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 ttyAMA0 (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 an HDMI console, then instantiate a really-serial console on another line.

The result is these two inittab lines:

Quoted 8 lines

console::respawn:/sbin/getty -L console 0 vt100 # GENERIC_SERIAL tty1::respawn:/sbin/getty -L tty1 0 vt100 # HDMI console

Cc Yann E. MORIN <[email protected]>
Cc Arnout Vandecappelle <[email protected]>

---

Applied to master, thanks. Maybe this calls for an update of the RaspberryPi readme.txt file, to explicitly indicate that a getty will be running on both the HDMI/composite output *and* the serial port?

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#3 lore raw

PATCH v2 1/1 raspberrypi, raspberrypi2: add a serial console

Dear Thomas,

Quoted 38 lines · Thomas Petazzoni

Hello,

Quoted 35 lines · Luca Ceresoli

The current Buildroot defconfigs for Raspberry Pi and Raspberry Pi 2 instantiate a console on tty1, which appears on HDMI. Add a console on the serial port (ttyAMA0) to be more consistent with other defconfigs and provide a better out-of-the-box experience to users used to have a serial console from Buildroot defconfigs.

This requires three changes:
1. have two 'console=' entries in the kernel command line: tty1,

    then ttyAMA0;
 2. change BR2_TARGET_GENERIC_GETTY_PORT to "console", so it starts
    a getty on the last console= passed to the kernel, ttyAMA0;

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 ttyAMA0 (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 an HDMI console, 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 # HDMI console

Cc Yann E. MORIN <[email protected]>
Cc Arnout Vandecappelle <[email protected]>
Quoted 5 lines
Quoted 1 line

---

Applied to master, thanks. Maybe this calls for an update of the RaspberryPi readme.txt file, to explicitly indicate that a getty will be running on both the HDMI/composite output *and* the serial port?

Indeed a good suggestion! I'll have a look.

Thanks,

Signature · 1 line
Luca