From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1c7gXK-00044r-Sh for mharc-grub-devel@gnu.org; Fri, 18 Nov 2016 05:36:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7gXI-00043b-W4 for grub-devel@gnu.org; Fri, 18 Nov 2016 05:36:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7gXF-0004Nq-Tg for grub-devel@gnu.org; Fri, 18 Nov 2016 05:36:49 -0500 Received: from mga03.intel.com ([134.134.136.65]:22030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c7gXF-0004Nj-Jm for grub-devel@gnu.org; Fri, 18 Nov 2016 05:36:45 -0500 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP; 18 Nov 2016 02:36:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,509,1473145200"; d="scan'208";a="32188685" Received: from jlahtine-desk.ger.corp.intel.com ([10.252.15.134]) by orsmga004.jf.intel.com with ESMTP; 18 Nov 2016 02:36:42 -0800 From: Joonas Lahtinen To: grub-devel@gnu.org Cc: Joonas Lahtinen , Andrei Borzenkov Subject: [PATCH v2] serial: Poll USB devices if usbX serial port is missing Date: Fri, 18 Nov 2016 12:36:38 +0200 Message-Id: <1479465398-23174-1-git-send-email-joonas.lahtinen@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <7b9507a2-8bd4-2da7-8a04-333377e42bec@gmail.com> References: <7b9507a2-8bd4-2da7-8a04-333377e42bec@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Nov 2016 10:36:50 -0000 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. v2: - Use grub_term_poll_usb to avoid module dependency (Andrei) Cc: Andrei Borzenkov Signed-off-by: Joonas Lahtinen --- grub-core/term/serial.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index db80b3b..1a009a9 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,26 @@ 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_term_poll_usb) + { + grub_term_poll_usb (1); + again = 1; + } + else + { + break; + } + } + if (!port) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("serial port `%s' isn't found"), -- 2.7.4