All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
To: grub-devel@gnu.org
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Subject: [PATCH 2/2] serial: Poll USB devices if usbX serial port is missing
Date: Thu, 10 Nov 2016 15:45:39 +0200	[thread overview]
Message-ID: <1478785539-2919-2-git-send-email-joonas.lahtinen@linux.intel.com> (raw)
In-Reply-To: <1478785539-2919-1-git-send-email-joonas.lahtinen@linux.intel.com>

If usbX serial port is missing, try to poll USB devices. This makes them
appear at least on Intel NUC devices DN2820FYKH and DCCP847DYE.

This fixes cases where you try to configure usbX serial at the beginning
of a script, like:

  serial usb0 --speed=115200 --word=8 --parity=none --stop=1
  terminal_output --append serial_usb0
  terminal_input --append serial_usb0

Without this patch the above would fail with:

  serial port `usb0' isn't found

Strangely, adding 'usb' command before the serial initialization
made it work, and even moving the terminal_output and input command
to be before. This is due to the terminal_output command detecting
"serial_usb" and running USB polling if the output is missing. 'usb'
command from usbtest module always polls USB devices.

As it is the logical thing to configure the serial port before adding
it as an output or input, this patch makes things works as expected.
Most online resources mentioning GRUB and USB serial adapters also do
mention the above order, so there must be quite many struggling with
this problem on platforms where USB needs to be polled in order for
the detection to happen.

Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 grub-core/term/serial.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c
index db80b3b..1f856a2 100644
--- a/grub-core/term/serial.c
+++ b/grub-core/term/serial.c
@@ -191,6 +191,7 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
   struct grub_serial_port *port;
   struct grub_serial_config config;
   grub_err_t err;
+  int again;
 
   if (state[OPTION_UNIT].set)
     {
@@ -212,7 +213,25 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
   if (!name)
     name = "com0";
 
-  port = grub_serial_find (name);
+  again = 0;
+  while(1)
+    {
+      port = grub_serial_find (name);
+
+      if (port || again)
+	break;
+
+      if (grub_memcmp (name, "usb", sizeof ("usb") - 1) == 0)
+	{
+	  grub_usb_poll_devices(1);
+	  again = 1;
+	}
+      else
+	{
+	  break;
+	}
+    }
+
   if (!port)
     return grub_error (GRUB_ERR_BAD_ARGUMENT, 
 		       N_("serial port `%s' isn't found"),
-- 
2.7.4



  reply	other threads:[~2016-11-10 14:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-10 13:45 [PATCH 1/2] .gitignore: Add grub-core/build-grub-module-verifier Joonas Lahtinen
2016-11-10 13:45 ` Joonas Lahtinen [this message]
2016-11-12  9:18   ` [PATCH 2/2] serial: Poll USB devices if usbX serial port is missing Andrei Borzenkov
2016-11-18 10:36     ` [PATCH v2] " Joonas Lahtinen
2016-11-18 12:21       ` Andrei Borzenkov
2016-11-21 14:05         ` Joonas Lahtinen
2016-11-21 19:08           ` Andrei Borzenkov
2016-11-12  9:08 ` [PATCH 1/2] .gitignore: Add grub-core/build-grub-module-verifier Andrei Borzenkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478785539-2919-2-git-send-email-joonas.lahtinen@linux.intel.com \
    --to=joonas.lahtinen@linux.intel.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.