]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kopenbsd serial support
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 19 Jan 2010 13:29:02 +0000 (14:29 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 19 Jan 2010 13:29:02 +0000 (14:29 +0100)
include/grub/i386/openbsd_bootarg.h
loader/i386/bsd.c

index cd99b14f28dec8685c46829b3e53341627ee10b6..935dfc0c8e4c34255594d8e629be8ed59162f958 100644 (file)
@@ -61,6 +61,7 @@
 #define OPENBSD_BOOTARG_END    -1
 
 #define        OPENBSD_BOOTARG_MMAP    0
+#define        OPENBSD_BOOTARG_CONSOLE 5
 
 struct grub_openbsd_bootargs
 {
@@ -69,4 +70,13 @@ struct grub_openbsd_bootargs
   grub_uint32_t ba_next;
 } __attribute__ ((packed));
 
+struct grub_openbsd_bootarg_console
+{
+  grub_uint32_t device;
+  grub_uint32_t speed;
+};
+
+#define GRUB_OPENBSD_COM_MAJOR 8
+#define GRUB_OPENBSD_VGA_MAJOR 12
+
 #endif
index 6643513b1d9f53d96f9020541051b8ad902c0867..7a8ddb89ae11efaeb85a77157e34bd47fa079906 100644 (file)
@@ -126,6 +126,8 @@ static const struct grub_arg_option openbsd_opts[] =
     {"single", 's', 0, N_("Boot into single mode."), 0, 0},
     {"kdb", 'd', 0, N_("Enter in KDB on boot."), 0, 0},
     {"root", 'r', 0, N_("Set root device."), "wdXY", ARG_TYPE_STRING},
+    {"serial", 'h', GRUB_ARG_OPTION_OPTIONAL, 
+     N_("Use serial console."), N_("comUNIT[,SPEED]"), ARG_TYPE_STRING},
     {0, 0, 0, 0, 0, 0}
   };
 
@@ -136,6 +138,7 @@ static const grub_uint32_t openbsd_flags[] =
 };
 
 #define OPENBSD_ROOT_ARG (ARRAY_SIZE (openbsd_flags) - 1)
+#define OPENBSD_SERIAL_ARG (ARRAY_SIZE (openbsd_flags))
 
 static const struct grub_arg_option netbsd_opts[] =
   {
@@ -1410,6 +1413,51 @@ grub_cmd_openbsd (grub_extcmd_t cmd, int argc, char *argv[])
   else
     bootdev = 0;
 
+  if (cmd->state[OPENBSD_SERIAL_ARG].set)
+    {
+      struct grub_openbsd_bootarg_console serial;
+      char *ptr;
+      unsigned port = 0;
+      unsigned speed = 9600;
+
+      grub_memset (&serial, 0, sizeof (serial));
+
+      if (cmd->state[OPENBSD_SERIAL_ARG].arg)
+       {
+         ptr = cmd->state[OPENBSD_SERIAL_ARG].arg;
+         if (grub_memcmp (ptr, "com", sizeof ("com") - 1) != 0)
+           return grub_error (GRUB_ERR_BAD_ARGUMENT,
+                              "only com0-com3 are supported");
+         ptr += sizeof ("com") - 1;
+         port = grub_strtoul (ptr, &ptr, 0);
+         if (port >= 4)
+           return grub_error (GRUB_ERR_BAD_ARGUMENT,
+                              "only com0-com3 are supported");
+         if (*ptr == ',')
+           {
+             ptr++; 
+             speed = grub_strtoul (ptr, &ptr, 0);
+             if (grub_errno)
+               return grub_errno;
+           }
+       }
+
+      serial.device = (GRUB_OPENBSD_COM_MAJOR << 8) | port;
+      serial.speed = speed;
+         
+      grub_bsd_add_meta (OPENBSD_BOOTARG_CONSOLE, &serial, sizeof (serial));
+      bootflags |= OPENBSD_RB_SERCONS;
+    }
+  else
+    {
+      struct grub_openbsd_bootarg_console serial;
+
+      grub_memset (&serial, 0, sizeof (serial));
+      serial.device = (GRUB_OPENBSD_VGA_MAJOR << 8);
+      grub_bsd_add_meta (OPENBSD_BOOTARG_CONSOLE, &serial, sizeof (serial));
+      bootflags &= ~OPENBSD_RB_SERCONS;
+    }
+
   if (grub_bsd_load (argc, argv) == GRUB_ERR_NONE)
     {
       grub_loader_set (grub_openbsd_boot, grub_bsd_unload, 1);