]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2004-09-10 Yoshinori K. Okuji <okuji@enbug.org>
authorokuji <okuji@localhost>
Fri, 10 Sep 2004 20:31:55 +0000 (20:31 +0000)
committerokuji <okuji@localhost>
Fri, 10 Sep 2004 20:31:55 +0000 (20:31 +0000)
  * normal/menu.c: Include grub/loader.h and grub/machine/time.h.
  (print_message): Add a missing newline.
  (run_menu): Added timeout support.
  (run_menu_entry): New local function.
  (grub_menu_run): Added support for booting.

  * kern/loader.c (grub_loader_is_loaded): New function.

  * include/grub/powerpc/ieee1275/time.h: Include grub/symbol.h.
  (grub_get_rtc): Exported.

  * include/grub/i386/pc/time.h: Include grub/symbol.h.
  (grub_get_rtc): Exported.

  * include/grub/normal.h (struct grub_command_list): Remove
  constant from the member `command'.

  * include/grub/loader.h (grub_loader_is_loaded): Declared.

  * include/grub/err.h (GRUB_ERR_INVALID_COMMAND): New constant.

  * conf/i386-pc.rmk (kernel_img_HEADERS): Added machine/time.h.

ChangeLog
conf/i386-pc.mk
conf/i386-pc.rmk
include/grub/err.h
include/grub/i386/pc/time.h
include/grub/loader.h
include/grub/normal.h
include/grub/powerpc/ieee1275/time.h
kern/loader.c
normal/menu.c

index fcfb850bfbc78c94b58beb9823648b770b63ea1a..57bae7e3f7120184db1ed38cf5fbfebc55e864dd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2004-09-10  Yoshinori K. Okuji  <okuji@enbug.org>
+
+       * normal/menu.c: Include grub/loader.h and grub/machine/time.h.
+       (print_message): Add a missing newline.
+       (run_menu): Added timeout support.
+       (run_menu_entry): New local function.
+       (grub_menu_run): Added support for booting.
+
+       * kern/loader.c (grub_loader_is_loaded): New function.
+
+       * include/grub/powerpc/ieee1275/time.h: Include grub/symbol.h.
+       (grub_get_rtc): Exported.
+
+       * include/grub/i386/pc/time.h: Include grub/symbol.h.
+       (grub_get_rtc): Exported.
+
+       * include/grub/normal.h (struct grub_command_list): Remove
+       constant from the member `command'.
+
+       * include/grub/loader.h (grub_loader_is_loaded): Declared.
+
+       * include/grub/err.h (GRUB_ERR_INVALID_COMMAND): New constant.
+
+       * conf/i386-pc.rmk (kernel_img_HEADERS): Added machine/time.h.
+
 2004-08-28  Marco Gerards  <metgerards@student.han.nl>
 
        Add support for the JFS filesystem.
index 87e5c151a32323a61e529f941d22dd83c1d3d3f5..be6ee07cc2d6d3d5a7d463512ca1c336e4ea4856 100644 (file)
@@ -249,11 +249,11 @@ kernel_img-symlist.d: symlist.c
 
 -include kernel_img-symlist.d
 
-kernel_img_HEADERS = boot.h device.h disk.h dl.h elf.h err.h \
+kernel_img_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
        file.h fs.h kernel.h loader.h misc.h mm.h net.h rescue.h symbol.h \
        term.h types.h machine/biosdisk.h machine/boot.h \
        machine/console.h machine/init.h machine/memory.h \
-       machine/loader.h machine/partition.h machine/vga.h arg.h env.h
+       machine/loader.h machine/partition.h machine/time.h machine/vga.h
 kernel_img_CFLAGS = $(COMMON_CFLAGS)
 kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
 kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200
index f06cc0ff3ff0a64d81b79ce6b3b6bafcee61a7ce..37c965de4073d16f7c43236891a0546233fc38dd 100644 (file)
@@ -29,11 +29,11 @@ kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \
        kern/env.c disk/i386/pc/biosdisk.c \
        term/i386/pc/console.c \
        symlist.c
-kernel_img_HEADERS = boot.h device.h disk.h dl.h elf.h err.h \
+kernel_img_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
        file.h fs.h kernel.h loader.h misc.h mm.h net.h rescue.h symbol.h \
        term.h types.h machine/biosdisk.h machine/boot.h \
        machine/console.h machine/init.h machine/memory.h \
-       machine/loader.h machine/partition.h machine/vga.h arg.h env.h
+       machine/loader.h machine/partition.h machine/time.h machine/vga.h
 kernel_img_CFLAGS = $(COMMON_CFLAGS)
 kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
 kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200
index a630ec8aa4204a4b78d58f60a62db4425f6cbed9..04a96de1141e127321a41964969871ea0a71c2d8 100644 (file)
@@ -1,7 +1,7 @@
 /* err.h - error numbers and prototypes */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 2002,2003,2004  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -41,6 +41,7 @@ typedef enum
     GRUB_ERR_READ_ERROR,
     GRUB_ERR_WRITE_ERROR,
     GRUB_ERR_UNKNOWN_COMMAND,
+    GRUB_ERR_INVALID_COMMAND,
     GRUB_ERR_BAD_ARGUMENT,
     GRUB_ERR_BAD_PART_TABLE,
     GRUB_ERR_UNKNOWN_OS,
index ccef12732d9fe92388e8b8f55e817f7f55dbeab5..e95e6ee2cb930b553f9e3dcb8b89a70de36ad7d8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003  Free Software Foundation, Inc.
+ *  Copyright (C) 2003,2004  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
@@ -20,6 +20,8 @@
 #ifndef KERNEL_TIME_HEADER
 #define KERNEL_TIME_HEADER     1
 
+#include <grub/symbol.h>
+
 #ifdef GRUB_UTIL
 # include <time.h>
 # define GRUB_TICKS_PER_SECOND CLOCKS_PER_SEC
@@ -28,6 +30,6 @@
 #endif
 
 /* Return the real time in ticks.  */
-grub_uint32_t grub_get_rtc (void);
+grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void);
 
 #endif /* ! KERNEL_TIME_HEADER */
index 6ad8d792262730986d2b60b654a5027799244343..ce06023fae0eab250e118e3ec83f53b7c2920100 100644 (file)
@@ -1,7 +1,7 @@
 /* loader.h - OS loaders */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 2002,2003,2004  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
@@ -29,6 +29,7 @@
 extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
 extern grub_size_t EXPORT_VAR(grub_os_area_size);
 
+int EXPORT_FUNC(grub_loader_is_loaded) (void);
 void EXPORT_FUNC(grub_loader_set) (grub_err_t (*boot) (void),
                                   grub_err_t (*unload) (void));
 void EXPORT_FUNC(grub_loader_unset) (void);
index 14d0c5e1d67c0fea4abe0ed80896c6d5c05389a9..665fb85c846586c874d6dbc6bc39465389b1cb74 100644 (file)
@@ -70,7 +70,7 @@ typedef struct grub_command *grub_command_t;
 struct grub_command_list
 {
   /* The string of a command.  */
-  const char *command;
+  char *command;
 
   /* The next element.  */
   struct grub_command_list *next;
index dafbef397d8df4cc3a3c2822be914c7057619caa..8ef712e900826ec991e0fafe7381b4c950dfd9ca 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003 Marco Gerards <metgerards@student.han.nl>
+ *  Copyright (C) 2003,2004 Marco Gerards <metgerards@student.han.nl>
  *
  *  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
@@ -20,6 +20,8 @@
 #ifndef KERNEL_TIME_HEADER
 #define KERNEL_TIME_HEADER     1
 
+#include <grub/symbol.h>
+
 #ifdef GRUB_UTIL
 # include <time.h>
 # define GRUB_TICKS_PER_SECOND CLOCKS_PER_SEC
@@ -28,6 +30,6 @@
 #endif
 
 /* Return the real time in ticks.  */
-grub_uint32_t grub_get_rtc (void);
+grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void);
 
 #endif /* ! KERNEL_TIME_HEADER */
index ea7c774a15e7cc233a074981c596d888ae8ac42e..2c1dbe2ed912512c6b470062a676ec4a3cb3a66f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 2002,2003,2004  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -27,6 +27,12 @@ static grub_err_t (*grub_loader_unload_func) (void);
 
 static int grub_loader_loaded;
 
+int
+grub_loader_is_loaded (void)
+{
+  return grub_loader_loaded;
+}
+
 void
 grub_loader_set (grub_err_t (*boot) (void),
                 grub_err_t (*unload) (void))
index a6a7de7531921d7e09df500141fca109a4079664..f001b11ab738f069899838c2c21d2539f4028989 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 2003  Free Software Foundation, Inc.
+ *  Copyright (C) 2003,2004  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
@@ -20,6 +20,8 @@
 #include <grub/normal.h>
 #include <grub/term.h>
 #include <grub/misc.h>
+#include <grub/loader.h>
+#include <grub/machine/time.h>
 
 /* FIXME: These below are all runaround.  */
 
@@ -80,7 +82,7 @@ print_message (int nested)
       Press enter to boot the selected OS, \'e\' to edit the\n\
       commands before booting, or \'c\' for a command-line.");
   if (nested)
-    grub_printf ("\
+    grub_printf ("\n\
       ESC to return previous menu.");
 }
 
@@ -170,6 +172,7 @@ static int
 run_menu (grub_menu_t menu, int nested)
 {
   int first, offset;
+  unsigned long saved_time;
   
   grub_setcursor (0);
   
@@ -184,80 +187,153 @@ run_menu (grub_menu_t menu, int nested)
   init_page (nested);
   print_entries (menu, first, offset);
   grub_refresh ();
+
+  /* Initialize the time.  */
+  saved_time = grub_get_rtc ();
   
   while (1)
     {
       int c;
 
-      c = GRUB_TERM_ASCII_CHAR (grub_getkey ());
-      switch (c)
+      if (menu->timeout > 0)
        {
-       case 16:
-       case '^':
-         if (offset > 0)
+         unsigned long current_time;
+
+         current_time = grub_get_rtc ();
+         if (current_time - saved_time >= GRUB_TICKS_PER_SECOND)
            {
-             print_entry (4 + offset, 0, get_entry (menu, first + offset));
-             offset--;
-             print_entry (4 + offset, 1, get_entry (menu, first + offset));
+             menu->timeout--;
+             saved_time = current_time;
            }
-         else if (first > 0)
+         
+         grub_gotoxy (3, 22);
+         grub_printf ("The highlighted entry will be booted automatically in %d seconds.    ",
+                      menu->timeout);
+         grub_gotoxy (74, 4 + offset);
+         grub_refresh ();
+       }
+
+      if (menu->timeout == 0)
+       return menu->default_entry;
+      
+      if (grub_checkkey () >= 0 || menu->timeout < 0)
+       {
+         c = GRUB_TERM_ASCII_CHAR (grub_getkey ());
+         
+         if (menu->timeout >= 0)
            {
-             first--;
-             print_entries (menu, first, offset);
+             grub_gotoxy (3, 22);
+              grub_printf ("                                                                 ");
+              menu->timeout = -1;
+              menu->fallback_entry = -1;
+             grub_gotoxy (74, 4 + offset);
            }
-         break;
-
-       case 14:
-       case 'v':
-         if (menu->size > first + offset + 1)
+         
+         switch (c)
            {
-             if (offset < 11)
+           case 16:
+           case '^':
+             if (offset > 0)
                {
                  print_entry (4 + offset, 0,
                               get_entry (menu, first + offset));
-                 offset++;
+                 offset--;
                  print_entry (4 + offset, 1,
                               get_entry (menu, first + offset));
                }
-             else
+             else if (first > 0)
                {
-                 first++;
+                 first--;
                  print_entries (menu, first, offset);
                }
-           }
-         break;
-
-       case '\n':
-       case '\r':
-       case 6:
-         grub_setcursor (1);
-         return first + offset;
-
-       case '\e':
-         if (nested)
-           {
+             break;
+             
+           case 14:
+           case 'v':
+             if (menu->size > first + offset + 1)
+               {
+                 if (offset < 11)
+                   {
+                     print_entry (4 + offset, 0,
+                                  get_entry (menu, first + offset));
+                     offset++;
+                     print_entry (4 + offset, 1,
+                                  get_entry (menu, first + offset));
+                   }
+                 else
+                   {
+                     first++;
+                     print_entries (menu, first, offset);
+                   }
+               }
+             break;
+             
+           case '\n':
+           case '\r':
+           case 6:
+             grub_setcursor (1);
+             return first + offset;
+             
+           case '\e':
+             if (nested)
+               {
+                 grub_setcursor (1);
+                 return -1;
+               }
+             break;
+             
+           case 'c':
              grub_setcursor (1);
-             return -1;
+             grub_cmdline_run (1);
+             grub_setcursor (0);
+             init_page (nested);
+             print_entries (menu, first, offset);
+             break;
+             
+           default:
+             break;
            }
-         break;
+         
+         grub_refresh ();
+       }
+    }
 
-       case 'c':
-         grub_setcursor (1);
-         grub_cmdline_run (1);
-         grub_setcursor (0);
-         init_page (nested);
-         print_entries (menu, first, offset);
-         break;
+  /* Never reach here.  */
+  return -1;
+}
 
-       default:
+/* Run a menu entry.  */
+static void
+run_menu_entry (grub_menu_entry_t entry)
+{
+  grub_command_list_t cl;
+
+  for (cl = entry->command_list; cl != 0; cl = cl->next)
+    {
+      grub_command_t c;
+      
+      c = grub_command_find (cl->command);
+      if (! c)
+       break;
+      
+      if (! (c->flags & GRUB_COMMAND_FLAG_CMDLINE))
+       {
+         grub_error (GRUB_ERR_INVALID_COMMAND,
+                     "invalid command `%s'",
+                     cl->command);
          break;
        }
       
-      grub_refresh ();
+      if (! (c->flags & GRUB_COMMAND_FLAG_NO_ECHO))
+       grub_printf ("%s\n", cl->command);
+      
+      if (grub_command_execute (cl->command) != 0)
+       break;
     }
-
-  /* Never reach here.  */
-  return -1;
+  
+  if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
+    /* Implicit execution of boot, only if something is loaded.  */
+    grub_command_execute ("boot");
 }
 
 void
@@ -266,11 +342,42 @@ grub_menu_run (grub_menu_t menu, int nested)
   while (1)
     {
       int boot_entry;
+      grub_menu_entry_t e;
       
       boot_entry = run_menu (menu, nested);
       if (boot_entry < 0)
        break;
 
-      /* FIXME: Boot the entry.  */
+      grub_cls ();
+      grub_setcursor (1);
+
+      e = get_entry (menu, boot_entry);
+      grub_printf ("  Booting \'%s\'\n\n", e->title);
+  
+      run_menu_entry (e);
+
+      /* Deal with a fallback entry.  */
+      /* FIXME: Mutiple fallback entries like GRUB Legacy.  */
+      if (menu->fallback_entry >= 0)
+       {
+         grub_print_error ();
+         grub_errno = GRUB_ERR_NONE;
+         
+         e = get_entry (menu, menu->fallback_entry);
+         menu->fallback_entry = -1;
+         grub_printf ("\n  Falling back to \'%s\'\n\n", e->title);
+         run_menu_entry (e);
+       }
+
+      if (grub_errno != GRUB_ERR_NONE)
+       {
+         grub_print_error ();
+         grub_errno = GRUB_ERR_NONE;
+
+         /* Wait until the user pushes any key so that the user
+            can see what happened.  */
+         grub_printf ("\nPress any key to continue...");
+         (void) grub_getkey ();
+       }
     }
 }