I was tinkering with the GRUB last night and couldn't find a command to 
cause a short delay or timeout of some sort.  After looking through the 
source, I wrote this small patch to add a delay and "echo" function.

After using it for a short time, I'm tempted to change it to a 
countdown-style command with a prompt and a visible countdown like the 
menu timeout, but I don't see any acceptably simple way to do it.

Matthias
diff -u -r1.100 builtins.c
--- grub/stage2/builtins.c	2000/12/17 19:25:50	1.100
+++ grub/stage2/builtins.c	2001/01/02 02:10:49
@@ -772,6 +772,41 @@
 };
 
 
+/* delay */
+static int
+delay_func (char *arg, int flags)
+{
+  int delay_timeout, time1, time2 = -1;
+  if (! safe_parse_maxint (&arg, &delay_timeout))
+    return 1;
+
+  while ((time1 = getrtsecs()) == 0xFF);
+  while (1)
+    {
+      if (delay_timeout >= 0 && (time1 = getrtsecs()) != time2 && time1 != 0xFF)
+	{
+	  if (delay_timeout <= 0)
+	    {
+	      delay_timeout = -1;
+	      break;
+	    }
+	  delay_timeout--;
+	  time2  = time1;
+	}
+    }
+  return 0;
+}
+
+static struct builtin builtin_delay =
+{
+  "delay",
+  delay_func,
+  BUILTIN_MENU|BUILTIN_CMDLINE,
+  "delay SEC",
+  "Pause for a timeout, in SEC seconds, before continuing."
+};
+
+
 #ifdef GRUB_UTIL
 /* device */
 static int
@@ -930,6 +965,24 @@
 };
 
 
+/* echo */
+static int
+echo_func (char *arg, int flags)
+{
+  grub_printf ("%s\n", arg);
+	return 0;
+}
+
+static struct builtin builtin_echo =
+{
+  "echo",
+	echo_func,
+	BUILTIN_CMDLINE|BUILTIN_MENU,
+	"echo [MESSAGE]",
+	"Print MESSAGE"
+};
+
+
 static char embed_info[32];
 /* embed */
 /* Embed a Stage 1.5 in the first cylinder after MBR or in the
@@ -4085,6 +4138,7 @@
 #endif /* SUPPORT_NETBOOT */
 
 
+
 /* timeout */
 static int
 timeout_func (char *arg, int flags)
@@ -4309,6 +4363,7 @@
   &builtin_configfile,
   &builtin_debug,
   &builtin_default,
+  &builtin_delay,
 #ifdef GRUB_UTIL
   &builtin_device,
 #endif /* GRUB_UTIL */
@@ -4317,6 +4372,7 @@
 #endif /* SUPPORT_NETBOOT */
   &builtin_displayapm,
   &builtin_displaymem,
+	&builtin_echo,
   &builtin_embed,
   &builtin_fallback,
   &builtin_find,

Reply via email to