- Change the code that determines whether to use a serial console and

which serial device to use in that case respectively to not rely on
  the OFW names of the input/output and stdin/stdout devices. Instead
  check whether input and output refers to the same device and is of
  type serial (uart(4) was already doing this) and for the fallback
  to a serial console in case a keyboard is the selected input device
  but unplugged do the same for stdin and stdout in case the input
  device is nonexistent (PS/2 and USB keyboards) or has a 'keyboard'
  property (RS232 keyboards). Additionally also check whether the OFW
  did a fallback to a serial console in the same way in case the
  output device is nonexistent. While at it save on some variables
  and for sys/boot/sparc64/loader/metadata.c move the code in question
  to a new function md_bootserial() so it can be kept in sync with
  uart_cpu_getdev_console() more easily.
  This fixes selecting a serial console and the appropriate device
  when using a device path for the 'input-device' and 'output-device'
  OFW environment variables instead of an alias for the serial device
  to use or when using a screen alias that additionally denotes a
  video mode (like e.g. 'screen:r1024x768x60') but no keyboard is
  plugged in (amongst others). It also makes the code select a serial
  console in case the OFW did the same due to a misconfiguration like
  both 'input-device' and 'output-device' set to 'keyboard' or to a
  nonexisting device (whether the OFW does a fallback to a serial
  console in case of a misconfiguration or one ends up with just no
  console at all highly depends on the OBP version however).
- Reduce the size of buffers that only ever need to hold the string
  'serial' accordingly. Double the size of buffers that may need to
  hold a device path as e.g. '/pci@8,700000/ebus@5/serial@1,400000:a'
  exceeds 32 chars.
- Remove the package handle of the '/options' node from the argument
  list of uart_cpu_getdev_dbgport() as it's unused there and future
  use is also unlikely.

MFC after:	1 week
This commit is contained in:
Marius Strobl 2005-08-15 20:58:36 +00:00
parent f3447eb493
commit 1b279bfb52
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149111
2 changed files with 62 additions and 38 deletions

View File

@ -45,6 +45,8 @@ extern struct tlb_entry *itlb_store;
extern int dtlb_slot;
extern int itlb_slot;
static int md_bootserial(void);
/*
* Return a 'boothowto' value corresponding to the kernel arguments in
* (kargs) and any relevant environment variables.
@ -68,8 +70,6 @@ static struct
int
md_getboothowto(char *kargs)
{
char buf[32], buf2[32];
phandle_t options;
char *cp;
int howto;
int active;
@ -126,25 +126,49 @@ md_getboothowto(char *kargs)
for (i = 0; howto_names[i].ev != NULL; i++)
if (getenv(howto_names[i].ev) != NULL)
howto |= howto_names[i].mask;
options = OF_finddevice("/options");
OF_getprop(options, "input-device", buf, sizeof(buf));
OF_getprop(options, "output-device", buf2, sizeof(buf2));
if (strncmp(buf, "tty", sizeof("tty") - 1) == 0 && strncmp(buf2, "tty",
sizeof("tty") - 1) == 0)
if (md_bootserial() != -1)
howto |= RB_SERIAL;
else if (strcmp(buf, "keyboard") == 0 && strcmp(buf2, "screen") == 0) {
phandle_t chosen;
ihandle_t stdin, stdout;
chosen = OF_finddevice("/chosen");
OF_getprop(chosen, "stdin", &stdin, sizeof(stdin));
OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
if (OF_instance_to_package(stdin) == OF_instance_to_package(stdout))
howto |= RB_SERIAL;
}
return(howto);
}
static int
md_bootserial(void)
{
char buf[64];
ihandle_t inst;
phandle_t input;
phandle_t node;
phandle_t output;
if ((node = OF_finddevice("/options")) == -1)
return(-1);
if (OF_getprop(node, "input-device", buf, sizeof(buf)) == -1)
return(-1);
input = OF_finddevice(buf);
if (OF_getprop(node, "output-device", buf, sizeof(buf)) == -1)
return(-1);
output = OF_finddevice(buf);
if (input == -1 || output == -1 || OF_getproplen(input, "keyboard") >= 0) {
if ((node = OF_finddevice("/chosen")) == -1)
return(-1);
if (OF_getprop(node, "stdin", &inst, sizeof(inst)) == -1)
return(-1);
if ((input = OF_instance_to_package(inst)) == -1)
return(-1);
if (OF_getprop(node, "stdout", &inst, sizeof(inst)) == -1)
return(-1);
if ((output = OF_instance_to_package(inst)) == -1)
return(-1);
}
if (input != output)
return(-1);
if (OF_getprop(input, "device_type", buf, sizeof(buf)) == -1)
return(-1);
if (strcmp(buf, "serial") != 0)
return(-1);
return(0);
}
/*
* Copy the environment into the load area starting at (addr).
* Each variable is formatted as <name>=<value>, with a single nul

View File

@ -78,8 +78,8 @@ uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
/*
* Get the package handle of the UART that is selected as the console, if
* the console is an UART of course. Note that we enforce that both stdin
* and stdout are selected.
* the console is an UART of course. Note that we enforce that both input
* and output are selected.
* Note that the currently active console (i.e. /chosen/stdout and
* /chosen/stdin) may not be the same as the device selected in the
* environment (ie /options/output-device and /options/input-device) because
@ -91,32 +91,32 @@ uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
static phandle_t
uart_cpu_getdev_console(phandle_t options, char *dev, size_t devsz)
{
char buf[32];
ihandle_t stdin, stdout;
phandle_t chosen, input;
char buf[sizeof("serial")];
ihandle_t inst;
phandle_t chosen, input, output;
if (OF_getprop(options, "input-device", dev, devsz) == -1)
return (-1);
if (OF_getprop(options, "output-device", buf, sizeof(buf)) == -1)
input = OF_finddevice(dev);
if (OF_getprop(options, "output-device", dev, devsz) == -1)
return (-1);
if (!strcmp(dev, "keyboard") && !strcmp(buf, "screen")) {
output = OF_finddevice(dev);
if (input == -1 || output == -1 ||
OF_getproplen(input, "keyboard") >= 0) {
if ((chosen = OF_finddevice("/chosen")) == -1)
return (-1);
if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1)
if (OF_getprop(chosen, "stdin", &inst, sizeof(inst)) == -1)
return (-1);
if ((input = OF_instance_to_package(stdin)) == -1)
if ((input = OF_instance_to_package(inst)) == -1)
return (-1);
if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
if (OF_getprop(chosen, "stdout", &inst, sizeof(inst)) == -1)
return (-1);
if (OF_instance_to_package(stdout) != input)
if ((output = OF_instance_to_package(inst)) == -1)
return (-1);
snprintf(dev, devsz, "ttya");
} else {
if ((input = OF_finddevice(dev)) == -1)
return (-1);
if (OF_finddevice(buf) != input)
return (-1);
}
if (input != output)
return (-1);
if (OF_getprop(input, "device_type", buf, sizeof(buf)) == -1)
return (-1);
if (strcmp(buf, "serial") != 0)
@ -132,9 +132,9 @@ uart_cpu_getdev_console(phandle_t options, char *dev, size_t devsz)
* the OF.
*/
static phandle_t
uart_cpu_getdev_dbgport(phandle_t options, char *dev, size_t devsz)
uart_cpu_getdev_dbgport(char *dev, size_t devsz)
{
char buf[32];
char buf[sizeof("serial")];
phandle_t input;
if (!getenv_string("hw.uart.dbgport", dev, devsz))
@ -158,7 +158,7 @@ uart_cpu_getdev_dbgport(phandle_t options, char *dev, size_t devsz)
static phandle_t
uart_cpu_getdev_keyboard(char *dev, size_t devsz)
{
char buf[32];
char buf[sizeof("serial")];
phandle_t input;
if ((input = OF_finddevice("keyboard")) == -1)
@ -181,7 +181,7 @@ uart_cpu_getdev_keyboard(char *dev, size_t devsz)
int
uart_cpu_getdev(int devtype, struct uart_devinfo *di)
{
char buf[32], dev[32], compat[32];
char buf[32], compat[32], dev[64];
phandle_t input, options;
bus_addr_t addr;
int baud, bits, error, space, stop;
@ -194,7 +194,7 @@ uart_cpu_getdev(int devtype, struct uart_devinfo *di)
input = uart_cpu_getdev_console(options, dev, sizeof(dev));
break;
case UART_DEV_DBGPORT:
input = uart_cpu_getdev_dbgport(options, dev, sizeof(dev));
input = uart_cpu_getdev_dbgport(dev, sizeof(dev));
break;
case UART_DEV_KEYBOARD:
input = uart_cpu_getdev_keyboard(dev, sizeof(dev));