From 5fb5182f8ad3e2a02bd0f01134c26302a51bc702 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Fri, 15 Jan 2010 11:48:15 +0100 Subject: [PATCH] comX notation support --- include/grub/i386/pc/serial.h | 3 +++ loader/i386/bsd.c | 26 ++++++++++++++++++-------- term/i386/pc/serial.c | 8 ++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/include/grub/i386/pc/serial.h b/include/grub/i386/pc/serial.h index 0632ff79d..4038f50fb 100644 --- a/include/grub/i386/pc/serial.h +++ b/include/grub/i386/pc/serial.h @@ -64,4 +64,7 @@ /* Turn on DTR, RTS, and OUT2. */ #define UART_ENABLE_MODEM 0x0B +unsigned short +grub_serial_hw_get_port (const unsigned int unit); + #endif /* ! GRUB_SERIAL_MACHINE_HEADER */ diff --git a/loader/i386/bsd.c b/loader/i386/bsd.c index 3565884d5..49c846c31 100644 --- a/loader/i386/bsd.c +++ b/loader/i386/bsd.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef GRUB_MACHINE_PCBIOS #include @@ -137,7 +138,7 @@ static const struct grub_arg_option netbsd_opts[] = {"silent", 'z', 0, N_("Supress normal output (warnings remain)."), 0, 0}, {"root", 'r', 0, N_("Set root device."), N_("DEVICE"), ARG_TYPE_STRING}, {"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} }; @@ -1275,15 +1276,24 @@ grub_cmd_netbsd (grub_extcmd_t cmd, int argc, char *argv[]) if (cmd->state[NETBSD_SERIAL_ARG].arg) { ptr = cmd->state[NETBSD_SERIAL_ARG].arg; - serial.addr = grub_strtoul (ptr, &ptr, 0); - if (grub_errno) - return grub_errno; - if (*ptr != ',') - return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid format"); - ptr++; - serial.speed = grub_strtoul (ptr, &ptr, 0); + 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); if (grub_errno) return grub_errno; + + if (*ptr == ',') + { + ptr++; + serial.speed = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) + return grub_errno; + } } grub_bsd_add_meta (NETBSD_BTINFO_CONSOLE, &serial, sizeof (serial)); diff --git a/term/i386/pc/serial.c b/term/i386/pc/serial.c index 8d09f6211..b94b09553 100644 --- a/term/i386/pc/serial.c +++ b/term/i386/pc/serial.c @@ -74,8 +74,8 @@ static const unsigned short serial_hw_io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 } #endif /* Return the port number for the UNITth serial device. */ -static inline unsigned short -serial_hw_get_port (const unsigned int unit) +unsigned short +grub_serial_hw_get_port (const unsigned int unit) { if (unit < GRUB_SERIAL_PORT_NUM) return serial_hw_io_addr[unit]; @@ -498,7 +498,7 @@ grub_cmd_serial (grub_extcmd_t cmd, unsigned int unit; 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) return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad unit number"); } @@ -608,7 +608,7 @@ GRUB_MOD_INIT(serial) N_("Configure serial port."), options); /* 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.word_len = UART_8BITS_WORD; serial_settings.parity = UART_NO_PARITY;