shithub: riscv

Download patch

ref: 58fe52dc8cefee0513ac9afa4481d78ab3a54a83
parent: 75f5fdbb0df902d8d7e16a4489a04d92493eacae
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Jun 10 07:47:50 EDT 2023

9boot: implement *nocga= and *nokbd= kernel boot parameters

Some embedded pcs like the pcengine apu2 has a bios
that emulates cga and ps2 keyboard using the serial
console.

This leads to doubling of characters in the bootloader
console, as the code would output on both, the uart
and on the cga "screen".

To avoid this, *nocga= boot parameter is added,
which essentially disables the cga text mode. This
boot parameter might also be usefull for no-legacy
uefi machines that generally have no cga text mode
anymore.

Second, we add *nokbd= which makes both the kernel and
9boot stop accessing the ps2 keyboard.

--- a/sys/man/8/9boot
+++ b/sys/man/8/9boot
@@ -14,7 +14,7 @@
 After reading the configuration, the loader will automatically 
 attempt to boot the kernel that was specified by the
 .B bootfile=
-parameter. If there is no such parameter, a key
+parameter. If there is no such parameter, any key
 gets pressed on the keyboard or the kernel file was not
 found then the loader enters the interactive
 boot console.
@@ -183,6 +183,22 @@
 .IR ndb (6)
 .br
 .I https://uefi.org
+.SH BUGS
+The uart number is picked up from
+.B console=
+but the parameters are ignored as BIOS allows
+only a maximum baud-rate of 9600 so the setting
+.B "b9660 l8 s1"
+is assumed.
+Some BIOS emulate/redirect keyboard input
+and CGA output to the serial console,
+which causes doubling of characters.
+This can be avoided using
+.B *nokbd=
+and
+.B *nocga=
+parameters.
+Serial console is not supported by EFI.
 .SH HISTORY
 9boot first appeared in 9front (April, 2011).
 EFI support first appeared in 9front (Oct, 2014).
--- a/sys/man/8/plan9.ini
+++ b/sys/man/8/plan9.ini
@@ -451,7 +451,7 @@
 .SS \fLnora6=
 Disable automatic IPv6 configuration from incoming router advertisements.
 .SS DISKS, TAPES
-(S)ATA controllers are autodetected.
+PCI based controllers such as (S)ATA and NVMe are autodetected.
 .SS \fL*nodma=\fP
 disables dma on ata devices.
 .SS \fL*sd\fIXX\fLdma=on\fP
@@ -571,48 +571,11 @@
 The line
 .B serial=type=com
 can be used to specify settings for a PCMCIA modem.
-.SS \fLkbmap=\fIvalue\fP
-This specifies the keyboard map to use.
-.I Value
-can be a map file found in
-.B /sys/lib/kbmap
-on the ramdisk.
-.PP
-For example:
-.TP
-.B kbmap=colemak
-.SS \fLmouseport=\fIvalue\fP
-This specifies where the mouse is attached.
-.I Value
-can be a map file found in
-.B /sys/lib/kbmap
-on the ramdisk.
-.TP
-.B ps2
-the PS2 mouse/keyboard port.  The BIOS setup procedure
-should be used to configure the machine appropriately.
-.TP
-.B ps2intellimouse
-an Intellimouse on the PS2 port.
-.TP
-.B 0
-for COM1
-.TP
-.B 1
-for COM2
-.SS \fLmodemport=\fIvalue\fP
-Picks the UART line to call out on.
-This is used when connecting to a file server over
-an async line.
-.I Value
-is the number of the port.
 .SS \fLconsole=\fIvalue params\fP
-This is used to specify the console device.
-The default
-.I value
-is
-.BR cga ;
-a number
+This is used by the kernel and
+.IR 9boot (8)
+to specify the console device.
+A number
 .B 0
 or
 .B 1
@@ -632,8 +595,13 @@
 8 bit bytes, no parity, and one stop bit.
 If
 .I params
-is given, it will be used to further
+is given, it will be used by the kernel to further
 configure the uart.
+Due to BIOS limitations,
+.IR 9boot (8)
+ignores
+.I params
+and always assumes the default configuration.
 Notice that there is no
 .B =
 sign in the
@@ -670,6 +638,39 @@
 console=net 192.168.2.10!1337/1,192.168.2.3!1337/0ea7deadbeef
 .EE
 .LP
+.SS KEYBOARD
+USB keyboards are automatically detected.
+.SS \fL*nokbd=\fP
+This inhibits the kernel and
+.IR 9boot (8)
+from reading from the PS2 keyboard.
+.SS \fLkbmap=\fIvalue\fP
+This specifies the keyboard map to use.
+.I Value
+can be a map file found in
+.B /sys/lib/kbmap
+on the ramdisk.
+.PP
+For example:
+.TP
+.B kbmap=colemak
+.SS MOUSE
+USB mice are automatically detected.
+.SS \fLmouseport=\fIvalue\fP
+This specifies where the mouse is attached.
+.TP
+.B ps2
+the PS2 mouse/keyboard port.  The BIOS setup procedure
+should be used to configure the machine appropriately.
+.TP
+.B ps2intellimouse
+an Intellimouse on the PS2 port.
+.TP
+.B 0
+for COM1
+.TP
+.B 1
+for COM2
 .SS "PC CARD"
 .SS \fLpccard0=disabled\fP
 Disable probing for and automatic configuration of PC card controllers.
@@ -746,9 +747,6 @@
 .B cpu
 and
 .B terminal.
-.SS \fL*debug=\fP
-Prevents cpu servers from rebooting on kernel panic, to enable
-inspection of panic messages.
 .SS \fLdebugfactotum=\fP
 Causes
 .IR boot (8)
@@ -782,7 +780,7 @@
 When
 .B secstore
 is not specified, then the authentication server is used.
-.SS PROCESSOR
+.SS MEMORY
 .SS \fL*e820=\fItype \fB0x\fIstart \fB0x\fIend ...\fP
 This variable is automatically generated by the boot loader (see
 .IR 9boot (8))
@@ -795,6 +793,13 @@
 and
 .I end
 addresses of the area.
+.SS \fLumbexclude=\fIvalue\fP
+Specifies a list of ranges of UMB to exclude from use by drivers.
+Ranges are inclusive on both ends and separated by commas.
+For example:
+.EX
+    umbexclude=0xD1800-0xD3FFF
+.EE
 .SS \fL*maxmem=\fIvalue\fP
 This defines the maximum physical address that the system will scan when sizing memory.
 By default the PC operating system will scan up to 3.75 gigabytes
@@ -824,6 +829,7 @@
 This limits the maximum amount of memory (in megabytes) the graphics
 image memory pool can grow. The default is unlimited for terminals
 and cpu servers.
+.SS PROCESSOR
 .SS \fL*noavx=\fP
 Disables AVX and AVX2 on AMD64 CPUs.
 .SS \fL*nomce=\fP
@@ -875,26 +881,15 @@
 problems on certain machines.
 .SS \fL*pcihinv=\fP
 Prints a summary of the detected PCI busses and devices.
+.\" .SS \fL*nobios=\fP
+.\" what does this do?  something with pci
+.SS \fL*debug=\fP
+Prevents cpu servers from rebooting on kernel panic, to enable
+inspection of panic messages.
 .SS \fL*nodumpstack=\fP
 Disable printing a stack dump on panic.
 Useful if there is only a limited cga screen available,
 otherwise the textual information about the panic may scroll off.
-.\" .SS \fL*nobios=\fP
-.\" what does this do?  something with pci
-.SS \fLioexclude=\fIvalue\fP
-Specifies a list of ranges of I/O ports to exclude from use by drivers.
-Ranges are inclusive on both ends and separated by commas.
-For example:
-.EX
-    ioexclude=0x330-0x337,0x430-0x43F
-.EE
-.SS \fLumbexclude=\fIvalue\fP
-Specifies a list of ranges of UMB to exclude from use by drivers.
-Ranges are inclusive on both ends and separated by commas.
-For example:
-.EX
-    umbexclude=0xD1800-0xD3FFF
-.EE
 .SS \fL*acpi=\fIvalue\fP
 This option controls the search for ACPI tables by the kernel.
 The
@@ -927,6 +922,13 @@
 battery life (see
 .IR stats (8)).
 It is not on by default because it causes problems on some laptops.
+.SS \fLioexclude=\fIvalue\fP
+Specifies a list of ranges of I/O ports to exclude from use by drivers.
+Ranges are inclusive on both ends and separated by commas.
+For example:
+.EX
+    ioexclude=0x330-0x337,0x430-0x43F
+.EE
 .SS USB
 .SS \fL*nousbprobe=\fP
 Disable USB host controller detection.
@@ -945,9 +947,15 @@
 will use the dynamically assigned usb device address to name
 usb devices instead of the device unique name.
 .SS VIDEO
+.SS \fL*nocga=\fP
+This inhibits the kernel and
+.IR 9boot (8)
+from using the CGA text console.
 .SS \fLmonitor=\fIvalue\fP
 .SS \fLvgasize=\fIvalue\fP
 These are used not by the kernel but by
+.B screenrc
+which is called from
 .I termrc
 (see
 .IR cpurc (8))
--- a/sys/src/9/pc/cga.c
+++ b/sys/src/9/pc/cga.c
@@ -201,6 +201,9 @@
 {
 	static int once;
 
+	if(getconf("*nocga"))
+		return;
+
 	cgapos = cgaregr(0x0E)<<8;
 	cgapos |= cgaregr(0x0F);
 	cgapos *= 2;
--- a/sys/src/9/pc/devkbd.c
+++ b/sys/src/9/pc/devkbd.c
@@ -382,6 +382,9 @@
 		panic("kbdreset");
 	qnoblock(kbd.q, 1);
 
+	if(getconf("*nokbd"))
+		return;
+
 	/* wait for a quiescent controller */
 	try = 1000;
 	while(try-- > 0 && (c = inb(Status)) & (Outbusy | Inready)) {
--- a/sys/src/boot/pc/fns.h
+++ b/sys/src/boot/pc/fns.h
@@ -1,6 +1,8 @@
 /* handy strings in l.s */
 extern char origin[];
 extern char uart;
+extern char nocga;
+extern char nokbd;
 extern char hex[];
 extern char bootname[];
 
--- a/sys/src/boot/pc/l.s
+++ b/sys/src/boot/pc/l.s
@@ -292,6 +292,12 @@
 TEXT uart(SB), $0
 	BYTE $0xff
 
+TEXT nocga(SB), $0
+	BYTE $0x00
+
+TEXT nokbd(SB), $0
+	BYTE $0x00
+
 TEXT hex(SB), $0
 	BYTE $'0'; BYTE $'1'; BYTE $'2'; BYTE $'3';
 	BYTE $'4'; BYTE $'5'; BYTE $'6'; BYTE $'7';
--- a/sys/src/boot/pc/sub.c
+++ b/sys/src/boot/pc/sub.c
@@ -6,8 +6,9 @@
 void
 putc(int c)
 {
-	cgaputc(c);
-	if(uart != -1)
+	if(!nocga)
+		cgaputc(c);
+	if(uart >= 0)
 		uartputc(uart, c);
 }
 
@@ -111,10 +112,11 @@
 int
 getc(void)
 {
-	int c;
+	int c = 0;
 
-	c = kbdgetc();
-	if(c == 0 && uart != -1)
+	if(!nokbd)
+		c = kbdgetc();
+	if(c == 0 && uart >= 0)
 		c = uartgetc(uart);
 	return c;
 }
@@ -284,6 +286,10 @@
 			apmconf(line[3] - '0');
 			continue;
 		}
+		if(memcmp("*nocga", line, 6) == 0)
+			nocga = 1;
+		if(memcmp("*nokbd", line, 6) == 0)
+			nokbd = 1;
 		if(memcmp("console", line, 8) == 0)
 			uartconf(p);