git: 3662862f558f - main - rc: syscons: Add UEFI special case

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Wed, 08 Feb 2023 07:54:28 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=3662862f558f6afbdb53b1d6570c482c7d180580

commit 3662862f558f6afbdb53b1d6570c482c7d180580
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2023-01-31 10:26:36 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2023-02-08 07:53:20 +0000

    rc: syscons: Add UEFI special case
    
    Changing cursor, screenmap and setting blanktime doesn't work when booted
    with vt(4) and UEFI so add a special case for those depending on machdep.bootmethods.
    I have no way to test if this can work with vt(4) and bios boot so just in case
    keep calling those for this.
    
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D38293
---
 libexec/rc/rc.d/syscons | 83 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 55 insertions(+), 28 deletions(-)

diff --git a/libexec/rc/rc.d/syscons b/libexec/rc/rc.d/syscons
index caca9dd33f37..1251363ff33f 100755
--- a/libexec/rc/rc.d/syscons
+++ b/libexec/rc/rc.d/syscons
@@ -50,8 +50,11 @@ _sc_config=
 _sc_console=
 _sc_initdone=
 _sc_keymap_msg=
+_sc_bootmethod=
 sc_init()
 {
+	local bootmethod
+
 	if [ -z "${_sc_initdone}" ]; then
 		if [ -z "${_sc_console}" ]; then
 			if [ x`sysctl -n kern.vty` = x"vt" ]; then
@@ -61,6 +64,23 @@ sc_init()
 			fi
 			_sc_config="${_sc_console}"
 		fi
+		if [ -z "${_sc_bootmethod}" ]; then
+			bootmethod=$(sysctl -qn machdep.bootmethod)
+			case ${bootmethod} in
+				UEFI)
+					_sc_bootmethod="uefi"
+					;;
+				BIOS)
+					_sc_bootmethod="bios"
+					;;
+				PVH)
+					_sc_bootmethod="pvh"
+					;;
+				*)
+					_sc_bootmethod="uefi" # Default to UEFI
+					;;
+			esac
+		fi
 		echo -n "Configuring ${_sc_config}:"
 		_sc_initdone=yes
 	fi
@@ -259,16 +279,8 @@ syscons_precmd()
 	return 0
 }
 
-syscons_start()
+syscons_bios_start()
 {
-	# keyboard
-	#
-	if [ -n "${keyboard}" ]; then
-		syscons_setkeyboard ${keyboard}
-	fi
-
-	syscons_configure_keyboard
-
 	# cursor type
 	#
 	case ${cursor} in
@@ -291,62 +303,77 @@ syscons_start()
 		;;
 	esac
 
-	# font 8x16
+	# blank time
 	#
-	case ${font8x16} in
+	case ${blanktime} in
 	[Nn][Oo] | '')
 		;;
 	*)
 		sc_init
-		echo -n ' font8x16';	vidcontrol < ${viddev} -f 8x16 ${font8x16}
+		echo -n ' blanktime';	vidcontrol < ${viddev} -t ${blanktime}
 		;;
 	esac
 
-	# font 8x14
+	# screen saver
 	#
-	case ${font8x14} in
+	case ${saver} in
 	[Nn][Oo] | '')
 		;;
 	*)
 		sc_init
-		echo -n ' font8x14';	vidcontrol < ${viddev} -f 8x14 ${font8x14}
+		echo -n ' screensaver'
+		for i in `kldstat | awk '$5 ~ "_saver\.ko$" { print $5 }'`; do
+			kldunload ${i}
+		done
+		load_kld -e _saver ${saver}_saver
 		;;
 	esac
+}
 
-	# font 8x8
+syscons_start()
+{
+	# keyboard
 	#
-	case ${font8x8} in
+	if [ -n "${keyboard}" ]; then
+		syscons_setkeyboard ${keyboard}
+	fi
+
+	syscons_configure_keyboard
+
+	if [ "${_sc_bootmethod}" = "bios" ]; then
+		syscons_bios_start
+	fi
+
+	# font 8x16
+	#
+	case ${font8x16} in
 	[Nn][Oo] | '')
 		;;
 	*)
 		sc_init
-		echo -n ' font8x8';	vidcontrol < ${viddev} -f 8x8 ${font8x8}
+		echo -n ' font8x16';	vidcontrol < ${viddev} -f 8x16 ${font8x16}
 		;;
 	esac
 
-	# blank time
+	# font 8x14
 	#
-	case ${blanktime} in
+	case ${font8x14} in
 	[Nn][Oo] | '')
 		;;
 	*)
 		sc_init
-		echo -n ' blanktime';	vidcontrol < ${viddev} -t ${blanktime}
+		echo -n ' font8x14';	vidcontrol < ${viddev} -f 8x14 ${font8x14}
 		;;
 	esac
 
-	# screen saver
+	# font 8x8
 	#
-	case ${saver} in
+	case ${font8x8} in
 	[Nn][Oo] | '')
 		;;
 	*)
 		sc_init
-		echo -n ' screensaver'
-		for i in `kldstat | awk '$5 ~ "_saver\.ko$" { print $5 }'`; do
-			kldunload ${i}
-		done
-		load_kld -e _saver ${saver}_saver
+		echo -n ' font8x8';	vidcontrol < ${viddev} -f 8x8 ${font8x8}
 		;;
 	esac