Browse Source

package/petitboot: run petitboot UI on consoles

Display the petitboot UI instead of a login prompt, allowing the
configuration of custom tty(s) as we do for the login prompt.

petitboot already depends on udev, so let's use it instead of rcS to
launch pb-console. This has the advantage of easily wildcarding the list
of ttys ("hvc*") and enables hotplug devices ("ttyUSB0").

Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
Reza Arbab 1 year ago
parent
commit
f7c2b6fefd
4 changed files with 55 additions and 1 deletions
  1. 8 0
      package/petitboot/Config.in
  2. 36 0
      package/petitboot/pb-console
  3. 10 0
      package/petitboot/petitboot.mk
  4. 1 1
      system/Config.in

+ 8 - 0
package/petitboot/Config.in

@@ -25,3 +25,11 @@ comment "petitboot needs a toolchain w/ wchar, dynamic library, threads, udev /d
 	depends on !BR2_USE_WCHAR || BR2_STATIC_LIBS || \
 	depends on !BR2_USE_WCHAR || BR2_STATIC_LIBS || \
 		!BR2_TOOLCHAIN_HAS_THREADS || \
 		!BR2_TOOLCHAIN_HAS_THREADS || \
 		!BR2_PACKAGE_HAS_UDEV
 		!BR2_PACKAGE_HAS_UDEV
+
+config BR2_PACKAGE_PETITBOOT_GETTY_PORT
+	string "TTY port(s)"
+	default "console"
+	depends on BR2_PACKAGE_PETITBOOT
+	help
+	  Specify a space-separated list of ports to run the petitboot
+	  UI on. Wildcards are allowed. Example: "hvc* ttys0 ttyS*"

+ 36 - 0
package/petitboot/pb-console

@@ -0,0 +1,36 @@
+#!/bin/sh
+
+DAEMON="pb-console"
+
+PB_CONSOLE_PORT=${2:-"console"}
+PB_CONSOLE_ARGS="--getty --detach -- -n -i 0 $PB_CONSOLE_PORT linux"
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/petitboot" ] && . "/etc/default/petitboot"
+
+start() {
+	printf 'Starting %s on %s: ' "$DAEMON" "$PB_CONSOLE_PORT"
+	mkdir -p /var/log/petitboot
+
+	# shellcheck disable=SC2086 # we need the word splitting
+	start-stop-daemon -S -q -x "/usr/libexec/petitboot/$DAEMON" \
+		-- $PB_CONSOLE_ARGS
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+case "$1" in
+	start)
+		"$1";;
+	stop|restart|reload)
+		;;
+	*)
+		echo "Usage: $0 {start|stop|restart|reload} [port]"
+		exit 1
+		;;
+esac

+ 10 - 0
package/petitboot/petitboot.mk

@@ -46,6 +46,8 @@ else
 PETITBOOT_CONF_OPTS += --without-fdt
 PETITBOOT_CONF_OPTS += --without-fdt
 endif
 endif
 
 
+PETITBOOT_GETTY_PORT = $(patsubst %,'%',$(call qstrip,$(BR2_PACKAGE_PETITBOOT_GETTY_PORT)))
+
 define PETITBOOT_POST_INSTALL
 define PETITBOOT_POST_INSTALL
 	$(INSTALL) -D -m 0755 $(@D)/utils/bb-kexec-reboot \
 	$(INSTALL) -D -m 0755 $(@D)/utils/bb-kexec-reboot \
 		$(TARGET_DIR)/usr/libexec/petitboot/bb-kexec-reboot
 		$(TARGET_DIR)/usr/libexec/petitboot/bb-kexec-reboot
@@ -55,6 +57,14 @@ define PETITBOOT_POST_INSTALL
 		$(TARGET_DIR)/etc/petitboot/boot.d/90-sort-dtb
 		$(TARGET_DIR)/etc/petitboot/boot.d/90-sort-dtb
 	$(INSTALL) -m 0755 -D $(PETITBOOT_PKGDIR)/S15pb-discover \
 	$(INSTALL) -m 0755 -D $(PETITBOOT_PKGDIR)/S15pb-discover \
 		$(TARGET_DIR)/etc/init.d/S15pb-discover
 		$(TARGET_DIR)/etc/init.d/S15pb-discover
+	$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
+		$(TARGET_DIR)/etc/init.d/pb-console
+
+	mkdir -p $(TARGET_DIR)/etc/udev/rules.d
+	(for port in $(PETITBOOT_GETTY_PORT); do \
+		printf 'SUBSYSTEM=="tty", KERNEL=="%s", RUN+="/etc/init.d/pb-console start $$name"\n' "$$port"; \
+	done) > $(TARGET_DIR)/etc/udev/rules.d/petitboot-console-ui.rules
+
 	mkdir -p $(TARGET_DIR)/usr/share/udhcpc/default.script.d/
 	mkdir -p $(TARGET_DIR)/usr/share/udhcpc/default.script.d/
 	ln -sf /usr/sbin/pb-udhcpc \
 	ln -sf /usr/sbin/pb-udhcpc \
 		$(TARGET_DIR)/usr/share/udhcpc/default.script.d/
 		$(TARGET_DIR)/usr/share/udhcpc/default.script.d/

+ 1 - 1
system/Config.in

@@ -403,7 +403,7 @@ config BR2_SYSTEM_BIN_SH
 
 
 menuconfig BR2_TARGET_GENERIC_GETTY
 menuconfig BR2_TARGET_GENERIC_GETTY
 	bool "Run a getty (login prompt) after boot"
 	bool "Run a getty (login prompt) after boot"
-	default y
+	default y if !BR2_PACKAGE_PETITBOOT
 
 
 if BR2_TARGET_GENERIC_GETTY
 if BR2_TARGET_GENERIC_GETTY
 config BR2_TARGET_GENERIC_GETTY_PORT
 config BR2_TARGET_GENERIC_GETTY_PORT