comX notation support

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-01-15 11:48:15 +01:00
parent 2386d586b9
commit 5fb5182f8a
3 changed files with 25 additions and 12 deletions

View file

@ -64,4 +64,7 @@
/* Turn on DTR, RTS, and OUT2. */ /* Turn on DTR, RTS, and OUT2. */
#define UART_ENABLE_MODEM 0x0B #define UART_ENABLE_MODEM 0x0B
unsigned short
grub_serial_hw_get_port (const unsigned int unit);
#endif /* ! GRUB_SERIAL_MACHINE_HEADER */ #endif /* ! GRUB_SERIAL_MACHINE_HEADER */

View file

@ -33,6 +33,7 @@
#include <grub/command.h> #include <grub/command.h>
#include <grub/extcmd.h> #include <grub/extcmd.h>
#include <grub/i18n.h> #include <grub/i18n.h>
#include <grub/i386/pc/serial.h>
#ifdef GRUB_MACHINE_PCBIOS #ifdef GRUB_MACHINE_PCBIOS
#include <grub/machine/biosnum.h> #include <grub/machine/biosnum.h>
@ -137,7 +138,7 @@ static const struct grub_arg_option netbsd_opts[] =
{"silent", 'z', 0, N_("Supress normal output (warnings remain)."), 0, 0}, {"silent", 'z', 0, N_("Supress normal output (warnings remain)."), 0, 0},
{"root", 'r', 0, N_("Set root device."), N_("DEVICE"), ARG_TYPE_STRING}, {"root", 'r', 0, N_("Set root device."), N_("DEVICE"), ARG_TYPE_STRING},
{"serial", 'h', GRUB_ARG_OPTION_OPTIONAL, {"serial", 'h', GRUB_ARG_OPTION_OPTIONAL,
N_("Use serial console."), N_("ADDR,SPEED"), ARG_TYPE_STRING}, N_("Use serial console."), N_("[ADDR|comUNIT][,SPEED]"), ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0}
}; };
@ -1275,16 +1276,25 @@ grub_cmd_netbsd (grub_extcmd_t cmd, int argc, char *argv[])
if (cmd->state[NETBSD_SERIAL_ARG].arg) if (cmd->state[NETBSD_SERIAL_ARG].arg)
{ {
ptr = cmd->state[NETBSD_SERIAL_ARG].arg; ptr = cmd->state[NETBSD_SERIAL_ARG].arg;
if (grub_memcmp (ptr, "com", sizeof ("com") - 1) == 0)
{
ptr += sizeof ("com") - 1;
serial.addr
= grub_serial_hw_get_port (grub_strtoul (ptr, &ptr, 0));
}
else
serial.addr = grub_strtoul (ptr, &ptr, 0); serial.addr = grub_strtoul (ptr, &ptr, 0);
if (grub_errno) if (grub_errno)
return grub_errno; return grub_errno;
if (*ptr != ',')
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid format"); if (*ptr == ',')
{
ptr++; ptr++;
serial.speed = grub_strtoul (ptr, &ptr, 0); serial.speed = grub_strtoul (ptr, &ptr, 0);
if (grub_errno) if (grub_errno)
return grub_errno; return grub_errno;
} }
}
grub_bsd_add_meta (NETBSD_BTINFO_CONSOLE, &serial, sizeof (serial)); grub_bsd_add_meta (NETBSD_BTINFO_CONSOLE, &serial, sizeof (serial));
} }

View file

@ -74,8 +74,8 @@ static const unsigned short serial_hw_io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }
#endif #endif
/* Return the port number for the UNITth serial device. */ /* Return the port number for the UNITth serial device. */
static inline unsigned short unsigned short
serial_hw_get_port (const unsigned int unit) grub_serial_hw_get_port (const unsigned int unit)
{ {
if (unit < GRUB_SERIAL_PORT_NUM) if (unit < GRUB_SERIAL_PORT_NUM)
return serial_hw_io_addr[unit]; return serial_hw_io_addr[unit];
@ -498,7 +498,7 @@ grub_cmd_serial (grub_extcmd_t cmd,
unsigned int unit; unsigned int unit;
unit = grub_strtoul (state[0].arg, 0, 0); unit = grub_strtoul (state[0].arg, 0, 0);
serial_settings.port = serial_hw_get_port (unit); serial_settings.port = grub_serial_hw_get_port (unit);
if (!serial_settings.port) if (!serial_settings.port)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad unit number"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad unit number");
} }
@ -608,7 +608,7 @@ GRUB_MOD_INIT(serial)
N_("Configure serial port."), options); N_("Configure serial port."), options);
/* Set default settings. */ /* Set default settings. */
serial_settings.port = serial_hw_get_port (0); serial_settings.port = grub_serial_hw_get_port (0);
serial_settings.divisor = serial_get_divisor (9600); serial_settings.divisor = serial_get_divisor (9600);
serial_settings.word_len = UART_8BITS_WORD; serial_settings.word_len = UART_8BITS_WORD;
serial_settings.parity = UART_NO_PARITY; serial_settings.parity = UART_NO_PARITY;