git: 2cb490901141 - main - cons: Add boot option to mute boot messages after banner

From: Justin Hibbits <jhibbits_at_FreeBSD.org>
Date: Tue, 30 Apr 2024 20:24:17 UTC
The branch main has been updated by jhibbits:

URL: https://cgit.FreeBSD.org/src/commit/?id=2cb49090114108d594195b9b32c762391340484c

commit 2cb49090114108d594195b9b32c762391340484c
Author:     Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2024-04-30 20:07:30 +0000
Commit:     Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2024-04-30 20:23:47 +0000

    cons: Add boot option to mute boot messages after banner
    
    This is useful for embedded systems, where it provides feedback that the
    kernel has booted, but avoids printing the probe messages.  If both
    mutemsgs and verbose are set, verbose cancels the mute.
    
    Additionally, this unmutes the console on panic, so a user can see what
    happened leading up to the panic.
    
    Obtained from:  Juniper Networks, Inc.
---
 sys/kern/kern_cons.c     | 14 +++++++++++++-
 sys/kern/kern_shutdown.c |  3 +++
 sys/kern/subr_boot.c     |  6 ++++--
 sys/sys/cons.h           |  2 ++
 sys/sys/reboot.h         |  1 +
 5 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/sys/kern/kern_cons.c b/sys/kern/kern_cons.c
index a99699ed5bce..040aa3932a1a 100644
--- a/sys/kern/kern_cons.c
+++ b/sys/kern/kern_cons.c
@@ -103,7 +103,7 @@ int	cons_avail_mask = 0;	/* Bit mask. Each registered low level console
 				 * this bit cleared.
 				 */
 
-static int cn_mute;
+int cn_mute;
 SYSCTL_INT(_kern, OID_AUTO, consmute, CTLFLAG_RW, &cn_mute, 0,
     "State of the console muting");
 
@@ -138,6 +138,18 @@ kbdinit(void)
 
 }
 
+static void
+mute_console(void *data __unused)
+{
+
+	if ((boothowto & (RB_MUTEMSGS | RB_VERBOSE)) == RB_MUTEMSGS) {
+		printf("-- Muting boot messages --\n");
+		cn_mute = 1;
+	}
+}
+
+SYSINIT(mute_console, SI_SUB_COPYRIGHT, SI_ORDER_ANY, mute_console, NULL);
+
 void
 cninit(void)
 {
diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c
index b0a3c3fa9e91..afeb320405d0 100644
--- a/sys/kern/kern_shutdown.c
+++ b/sys/kern/kern_shutdown.c
@@ -942,6 +942,9 @@ vpanic(const char *fmt, va_list ap)
 		newpanic = 1;
 	}
 
+	/* Unmute when panic */
+	cn_mute = 0;
+
 	if (newpanic) {
 		(void)vsnprintf(buf, sizeof(buf), fmt, ap);
 		panicstr = buf;
diff --git a/sys/kern/subr_boot.c b/sys/kern/subr_boot.c
index 5b80200a2f7d..b721abf7013c 100644
--- a/sys/kern/subr_boot.c
+++ b/sys/kern/subr_boot.c
@@ -70,6 +70,7 @@ static struct
 	{ "boot_gdb",		RB_GDB},
 	{ "boot_multicons",	RB_MULTIPLE},
 	{ "boot_mute",		RB_MUTE},
+	{ "boot_mutemsgs",	RB_MUTEMSGS},
 	{ "boot_pause",		RB_PAUSE},
 	{ "boot_serial",	RB_SERIAL},
 	{ "boot_single",	RB_SINGLE},
@@ -133,10 +134,10 @@ boot_parse_arg(const char *v)
 
 #if 0
 /* Need to see if this is better or worse than the meat of the #else */
-static const char howto_switches[] = "aCdrgDmphsv";
+static const char howto_switches[] = "aCdrgDmMphsv";
 static int howto_masks[] = {
 	RB_ASKNAME, RB_CDROM, RB_KDB, RB_DFLTROOT, RB_GDB, RB_MULTIPLE,
-	RB_MUTE, RB_PAUSE, RB_SERIAL, RB_SINGLE, RB_VERBOSE
+	RB_MUTE, RB_MUTEMSGS, RB_PAUSE, RB_SERIAL, RB_SINGLE, RB_VERBOSE
 };
 
 	opts = strchr(kargs, '-');
@@ -160,6 +161,7 @@ static int howto_masks[] = {
 			case 'd': howto |= RB_KDB; break;
 			case 'D': howto |= RB_MULTIPLE; break;
 			case 'm': howto |= RB_MUTE; break;
+			case 'M': howto |= RB_MUTEMSGS; break;
 			case 'g': howto |= RB_GDB; break;
 			case 'h': howto |= RB_SERIAL; break;
 			case 'p': howto |= RB_PAUSE; break;
diff --git a/sys/sys/cons.h b/sys/sys/cons.h
index 191d77598b77..78df26858376 100644
--- a/sys/sys/cons.h
+++ b/sys/sys/cons.h
@@ -94,6 +94,8 @@ struct consdev {
 
 #ifdef _KERNEL
 
+extern	int cn_mute;
+
 extern	struct msgbuf consmsgbuf; /* Message buffer for constty. */
 extern	struct tty *constty;	/* Temporary virtual console. */
 
diff --git a/sys/sys/reboot.h b/sys/sys/reboot.h
index 78572365e158..26e78632fb2c 100644
--- a/sys/sys/reboot.h
+++ b/sys/sys/reboot.h
@@ -60,6 +60,7 @@
 #define	RB_PAUSE	0x100000 /* pause after each output line during probe */
 #define	RB_REROOT	0x200000 /* unmount the rootfs and mount it again */
 #define	RB_POWERCYCLE	0x400000 /* Power cycle if possible */
+#define	RB_MUTEMSGS	0x800000 /* start up with console muted after banner */
 #define	RB_PROBE	0x10000000	/* Probe multiple consoles */
 #define	RB_MULTIPLE	0x20000000	/* use multiple consoles */