~tomleb/alpine-mkinitfs

317c1ec274c84e39e3f777a81e6484aa768e58ef — Natanael Copa 1 year, 4 months ago 86e617b
init: improve detection of serial consoles

fixes https://gitlab.alpinelinux.org/alpine/aports/-/issues/14927
2 files changed, 16 insertions(+), 2 deletions(-)

M initramfs-init.in
M tests/initramfs-init.test
M initramfs-init.in => initramfs-init.in +7 -2
@@ 104,17 104,22 @@ list_console_devices() {
	done
}

detect_serial_console() {
detect_serial_consoles() {
	local n=$(awk '$7 ~ /CTS/ || $7 ~ /DSR/ { print $1 }' "$ROOT"/proc/tty/driver/serial 2>/dev/null)
	if [ -n "$n" ]; then
		echo ttyS${n%:}
	fi
	for i in "$ROOT"/sys/class/tty/*; do
		if [ -e "$i"/device ]; then
			echo ${i##*/}
		fi
	done
}

setup_inittab_console() {
	term=vt100
	# Inquire the kernel for list of console= devices
	consoles="$(for c in console $KOPT_consoles $(detect_serial_console); do list_console_devices $c; done)"
	consoles="$(for c in console $KOPT_consoles $(detect_serial_consoles); do list_console_devices $c; done)"
	for tty in $consoles; do
		# ignore tty devices that gives I/O error
		if ! stty -g -F /dev/$tty >/dev/null 2>/dev/null; then

M tests/initramfs-init.test => tests/initramfs-init.test +9 -0
@@ 134,11 134,20 @@ initramfs_init_tmpfs_root_autodetect_serial_body() {
		3: uart:unknown port:000002E8 irq:3
	EOF

	mkdir -p sys/devices/platform/ARMH0011:00/tty/ttyAMA0
	ln -s ../../../ARMH0011:00 \
		sys/devices/platform/ARMH0011:00/tty/ttyAMA0/device

	mkdir -p sys/class/tty/
	ln -s ../../devices/platform/ARMH0011:00/tty/ttyAMA0 \
		sys/class/tty/ttyAMA0

	atf_check \
		-o ignore \
		initramfs-init
	atf_check \
		-o match:"ttyS0::respawn:/sbin/getty" \
		-o match:"ttyAMA0::respawn:/sbin/getty" \
		cat sysroot/etc/inittab
}