From 260a00f345f2d355b151d6a7c1f2018cfad8c0fc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 14 Apr 2013 17:01:31 +0200 Subject: [PATCH 303/482] Allow IEEE1275 ports on path even if it wasn't detected automatically. Needed on OpenBIOS due to incomplete device tree. --- ChangeLog | 5 +++ grub-core/term/ieee1275/serial.c | 78 ++++++++++++++++++++++++++-------------- grub-core/term/serial.c | 16 +++++++++ include/grub/ieee1275/console.h | 3 ++ 4 files changed, 76 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1088061..df9e300 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2013-04-14 Vladimir Serbinenko + 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 + * grub-core/disk/ieee1275/ofdisk.c: Iterate over bootpath even if it would be otherwise excluded. diff --git a/grub-core/term/ieee1275/serial.c b/grub-core/term/ieee1275/serial.c index cda97d0..9e71ca4 100644 --- a/grub-core/term/ieee1275/serial.c +++ b/grub-core/term/ieee1275/serial.c @@ -23,6 +23,7 @@ #include #include #include +#include #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); } } diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index cfcfe84..96f9d7f 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -31,6 +31,9 @@ #ifdef GRUB_MACHINE_MIPS_LOONGSON #include #endif +#ifdef GRUB_MACHINE_IEEE1275 +#include +#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; } diff --git a/include/grub/ieee1275/console.h b/include/grub/ieee1275/console.h index e054f54..bdd98fe 100644 --- a/include/grub/ieee1275/console.h +++ b/include/grub/ieee1275/console.h @@ -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 */ -- 1.8.2.1