]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Allow IEEE1275 ports on path even if it wasn't detected automatically.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 14 Apr 2013 15:01:31 +0000 (17:01 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 14 Apr 2013 15:01:31 +0000 (17:01 +0200)
Needed on OpenBIOS due to incomplete device tree.

ChangeLog
grub-core/term/ieee1275/serial.c
grub-core/term/serial.c
include/grub/ieee1275/console.h

index 10880614d9b381a0185a12682c46ad5bb0a7a9d2..df9e3000330df933cb807242d549c7d41280e122 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-04-14  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Allow IEEE1275 ports on path even if it wasn't detected automatically.
+       Needed on OpenBIOS due to incomplete device tree.
+
 2013-04-14  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/disk/ieee1275/ofdisk.c: Iterate over bootpath even if it
index cda97d0d590ea1942fa515a78add3d4a1d255137..9e71ca4b88d15b90e472e9824af7c2c066955689 100644 (file)
@@ -23,6 +23,7 @@
 #include <grub/mm.h>
 #include <grub/time.h>
 #include <grub/i18n.h>
+#include <grub/ieee1275/console.h>
 
 #define IEEE1275_IHANDLE_INVALID  ((grub_ieee1275_cell_t) 0)
 
@@ -216,11 +217,59 @@ dev_iterate (struct grub_ieee1275_devalias *alias)
   return 0;
 }
 
+static const char *
+add_port (struct ofserial_hash_ent *ent)
+{
+  struct grub_serial_port *port;
+  char *ptr;
+  grub_err_t err;
+
+  if (!ent->shortest)
+    return NULL;
+
+  port = grub_zalloc (sizeof (*port));
+  if (!port)
+    return NULL;
+  port->name = grub_malloc (sizeof ("ieee1275/")
+                           + grub_strlen (ent->shortest));
+  port->elem = ent;
+  if (!port->name)
+    return NULL;
+  ptr = grub_stpcpy (port->name, "ieee1275/");
+  grub_strcpy (ptr, ent->shortest);
+
+  port->driver = &grub_ofserial_driver;
+  err = grub_serial_config_defaults (port);
+  if (err)
+    grub_print_error ();
+
+  grub_serial_register (port);
+
+  return port->name;
+}
+
+const char *
+grub_ofserial_add_port (const char *path)
+{
+  struct ofserial_hash_ent *ent;
+  char *name = grub_strdup (path);
+  char *can = grub_strdup (path);
+
+  if (!name || ! can)
+    {
+      grub_free (name);
+      grub_free (can);
+      return NULL;
+    }
+
+  ent = ofserial_hash_add (name, can);
+  return add_port (ent);
+}
+
 void
 grub_ofserial_init (void)
 {
   unsigned i;
-  grub_err_t err;
   struct grub_ieee1275_devalias alias;
 
   FOR_IEEE1275_DEVALIASES(alias)
@@ -230,32 +279,9 @@ grub_ofserial_init (void)
   
   for (i = 0; i < ARRAY_SIZE (ofserial_hash); i++)
     {
-      static struct ofserial_hash_ent *ent;
+      struct ofserial_hash_ent *ent;
       for (ent = ofserial_hash[i]; ent; ent = ent->next)
-       {
-         struct grub_serial_port *port;
-         char *ptr;
-         if (!ent->shortest)
-           continue;
-
-         port = grub_zalloc (sizeof (*port));
-         if (!port)
-           return;
-         port->name = grub_malloc (sizeof ("ieee1275/")
-                                   + grub_strlen (ent->shortest));
-         port->elem = ent;
-         if (!port->name)
-           return;
-         ptr = grub_stpcpy (port->name, "ieee1275/");
-         grub_strcpy (ptr, ent->shortest);
-
-         port->driver = &grub_ofserial_driver;
-         err = grub_serial_config_defaults (port);
-         if (err)
-           grub_print_error ();
-
-         grub_serial_register (port);
-       }
+       add_port (ent);
     }
 }
 
index cfcfe8484db26580a41091c7e57c60f90df31c11..96f9d7f29e6ebdd86c26d5e95ca1e20f18004c22 100644 (file)
@@ -31,6 +31,9 @@
 #ifdef GRUB_MACHINE_MIPS_LOONGSON
 #include <grub/machine/kernel.h>
 #endif
+#ifdef GRUB_MACHINE_IEEE1275
+#include <grub/ieee1275/console.h>
+#endif
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -149,6 +152,19 @@ grub_serial_find (const char *name)
     }
 #endif
 
+#ifdef GRUB_MACHINE_IEEE1275
+  if (!port && grub_memcmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) == 0)
+    {
+      name = grub_ofserial_add_port (&name[sizeof ("ieee1275/") - 1]);
+      if (!name)
+       return NULL;
+
+      FOR_SERIAL_PORTS (port)
+       if (grub_strcmp (port->name, name) == 0)
+         break;
+    }
+#endif
+
   return port;
 }
 
index e054f54f547de46c0d77b2775158c4fc2eb9471d..bdd98fe060f6a472caace7e1d4d9f8fb44dfb163 100644 (file)
@@ -28,4 +28,7 @@ void grub_console_init_lately (void);
 /* Finish the console system.  */
 void grub_console_fini (void);
 
+const char *
+grub_ofserial_add_port (const char *name);
+
 #endif /* ! GRUB_CONSOLE_MACHINE_HEADER */