From 61928d132341e7d6d68d92d4e2b93e3bb3005e6c Mon Sep 17 00:00:00 2001 From: okuji Date: Sat, 13 Oct 2001 12:02:30 +0000 Subject: [PATCH] Ensure that a serial port is set up before used. --- ChangeLog | 14 ++++++++++++++ THANKS | 1 + docs/grub.texi | 4 ++++ docs/stamp-vti | 4 ++-- docs/version.texi | 4 ++-- grub/asmstub.c | 7 +++++++ stage2/builtins.c | 15 ++++++++++++--- stage2/common.c | 3 ++- stage2/serial.c | 11 +++++++++-- stage2/serial.h | 5 ++++- stage2/shared.h | 1 + 11 files changed, 58 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index a48fa375d..2e0acc0a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2001-10-13 Yoshinori K. Okuji + + Based on a patch from Jeremy Katz : + * docs/grub.texi (Stage2 errors): Added documentation on the + error number 33 (Serial device not configured). + * grub/asmstub.c (serial_exists): New function. + * stage2/serial.c (serial_exists): Likewise. + * stage2/serial.h (serial_exists): New prototype. + * stage2/shared.h (grub_error_t): ERR_NEED_SERIAL is added. + * stage2/builtins.c (terminal_func) [SUPPORT_SERIAL]: If a + serial device is not configured yet, restore the terminal and + set ERRNUM to ERR_NEED_SERIAL. + * stage2/common.c (err_list): Added an item for ERR_NEED_SERIAL. + 2001-10-13 Yoshinori K. Okuji From Jason Thomas : diff --git a/THANKS b/THANKS index 237c2bc48..36802f5f2 100644 --- a/THANKS +++ b/THANKS @@ -40,6 +40,7 @@ Hisazumi Kenji HORIKAWA Kazunori Jan Fricke Jan Zerebecki +Jeremy Katz Jochen Hoenicke Johannes Kroeger John Tobey diff --git a/docs/grub.texi b/docs/grub.texi index 009580a1c..933c7c63e 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -3054,6 +3054,10 @@ should mount the partition with the @samp{-o notail} option. @item 32 : Must be authenticated This error is returned if you try to run a locked entry. You should enter a correct password before running such an entry. + +@item 33 : Serial device not configured +This error is returned if you try to change your terminal to a serial +one before initializing any serial device. @end table diff --git a/docs/stamp-vti b/docs/stamp-vti index f86e94aa3..770dd17d0 100644 --- a/docs/stamp-vti +++ b/docs/stamp-vti @@ -1,4 +1,4 @@ -@set UPDATED 5 July 2001 -@set UPDATED-MONTH July 2001 +@set UPDATED 13 October 2001 +@set UPDATED-MONTH October 2001 @set EDITION 0.90 @set VERSION 0.90 diff --git a/docs/version.texi b/docs/version.texi index f86e94aa3..770dd17d0 100644 --- a/docs/version.texi +++ b/docs/version.texi @@ -1,4 +1,4 @@ -@set UPDATED 5 July 2001 -@set UPDATED-MONTH July 2001 +@set UPDATED 13 October 2001 +@set UPDATED-MONTH October 2001 @set EDITION 0.90 @set VERSION 0.90 diff --git a/grub/asmstub.c b/grub/asmstub.c index 84b1da589..2978c1423 100644 --- a/grub/asmstub.c +++ b/grub/asmstub.c @@ -1026,6 +1026,13 @@ serial_get_port (int unit) return 0; } +/* Check if a serial port is set up. */ +int +serial_exists (void) +{ + return serial_fd >= 0; +} + /* Initialize a serial device. In the grub shell, PORT is unused. */ int serial_init (unsigned short port, unsigned int speed, diff --git a/stage2/builtins.c b/stage2/builtins.c index e22fa50d3..604759463 100644 --- a/stage2/builtins.c +++ b/stage2/builtins.c @@ -3914,9 +3914,18 @@ terminal_func (char *arg, int flags) #ifdef SUPPORT_SERIAL else if (grub_memcmp (arg, "serial", sizeof ("serial") - 1) == 0) { - terminal |= TERMINAL_SERIAL; - if (! default_terminal) - default_terminal = TERMINAL_SERIAL; + if (serial_exists ()) + { + terminal |= TERMINAL_SERIAL; + if (! default_terminal) + default_terminal = TERMINAL_SERIAL; + } + else + { + terminal = saved_terminal; + errnum = ERR_NEED_SERIAL; + return 1; + } } #endif /* SUPPORT_SERIAL */ else diff --git a/stage2/common.c b/stage2/common.c index 7ecd5928d..72d98cfa1 100644 --- a/stage2/common.c +++ b/stage2/common.c @@ -2,7 +2,7 @@ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1996 Erich Boleyn - * Copyright (C) 1999, 2000 Free Software Foundation, Inc. + * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -73,6 +73,7 @@ char *err_list[] = [ERR_GEOM] = "Selected cylinder exceeds maximum supported by BIOS", [ERR_NEED_LX_KERNEL] = "Linux kernel must be loaded before initrd", [ERR_NEED_MB_KERNEL] = "Multiboot kernel must be loaded before modules", + [ERR_NEED_SERIAL] = "Serial device not configured", [ERR_NO_DISK] = "Selected disk does not exist", [ERR_NO_PART] = "No such partition", [ERR_NUMBER_PARSING] = "Error while parsing number", diff --git a/stage2/serial.c b/stage2/serial.c index 99b4ddb01..10a8d2bd9 100644 --- a/stage2/serial.c +++ b/stage2/serial.c @@ -1,7 +1,7 @@ /* serial.c - serial device interface */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2000 Free Software Foundation, Inc. + * Copyright (C) 2000, 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ struct divisor }; /* Store the port number of a serial unit. */ -static unsigned short serial_port; +static unsigned short serial_port = -1; /* The table which lists common configurations. */ static struct divisor divisor_tab[] = @@ -102,6 +102,13 @@ serial_putchar (int c) outb (serial_port + UART_TX, c); } +/* Check if a serial port is set up. */ +int +serial_exists (void) +{ + return serial_port != -1; +} + /* Return the port number for the UNITth serial device. */ unsigned short serial_get_port (int unit) diff --git a/stage2/serial.h b/stage2/serial.h index a77dbb9da..3364688cf 100644 --- a/stage2/serial.h +++ b/stage2/serial.h @@ -1,7 +1,7 @@ /* serial.h - serial device interface */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2000 Free Software Foundation, Inc. + * Copyright (C) 2000, 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -93,6 +93,9 @@ unsigned short serial_get_port (int unit); int serial_init (unsigned short port, unsigned int speed, int word_len, int parity, int stop_bit_len); +/* Check if a serial port is set up. */ +int serial_exists (void); + #ifdef GRUB_UTIL /* Set the file name of a serial device (or a pty device). This is a function specific to the grub shell. */ diff --git a/stage2/shared.h b/stage2/shared.h index 59dd2853b..b92364006 100644 --- a/stage2/shared.h +++ b/stage2/shared.h @@ -541,6 +541,7 @@ typedef enum ERR_BAD_ARGUMENT, ERR_UNALIGNED, ERR_PRIVILEGED, + ERR_NEED_SERIAL, MAX_ERR_NUM } grub_error_t;