All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: Christian Hewitt <christianshewitt@gmail.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	 Marek Vasut <marex@denx.de>, Lukasz Majewski <lukma@denx.de>
Cc: u-boot@lists.denx.de, Simon Glass <sjg@chromium.org>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	u-boot-amlogic@groups.io
Subject: [PATCH v2 1/2] usb: gadget: fastboot: detach usb on reboot commands
Date: Fri, 07 Oct 2022 11:38:22 +0200	[thread overview]
Message-ID: <20220728-reset-usb-controller-v2-1-ef7657ce78b1@baylibre.com> (raw)
In-Reply-To: <20220728-reset-usb-controller-v2-0-ef7657ce78b1@baylibre.com>

When host issues "fastboot reboot fastboot", it's expected that the
board drops the USB connection before resetting.

On some boards, such as Khadas VIM3L and SEI610, this is not the case.

We observe the following error:
$ fastboot reboot fastboot
Rebooting into fastboot                            OKAY [  0.004s]
fastboot: error: Failed to boot into userspace fastboot; one or more components might be unbootable.

This does not happen when we use the RST button on the board.
It can be reproduced in linux with:
  # echo b > /proc/sysrq-trigger

In this case, we hit a undefined hardware behavior, where D+ and D-
are in an unknown state. Therefore the host can't detect usb
disconnection.

Make sure we always call usb_gadget_release() when a "fastboot reboot"
command is issued.

Note: usb_gadget_release() should be called before g_dnl_unregister()
because g_dnl_unregister() triggers a complete() call on each
endpoint (thus calling do_reset()).

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
---
 cmd/fastboot.c                  | 2 +-
 drivers/usb/gadget/f_fastboot.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/cmd/fastboot.c b/cmd/fastboot.c
index dd223b1554da..b498e4b22bb3 100644
--- a/cmd/fastboot.c
+++ b/cmd/fastboot.c
@@ -83,9 +83,9 @@ static int do_fastboot_usb(int argc, char *const argv[],
 	ret = CMD_RET_SUCCESS;
 
 exit:
+	usb_gadget_release(controller_index);
 	g_dnl_unregister();
 	g_dnl_clear_detach();
-	usb_gadget_release(controller_index);
 
 	return ret;
 #else
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index d0e92c7a071f..07b1681c8a9a 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -544,6 +544,7 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 		case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
 		case FASTBOOT_COMMAND_REBOOT_RECOVERY:
 			fastboot_func->in_req->complete = compl_do_reset;
+			g_dnl_trigger_detach();
 			break;
 #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
 		case FASTBOOT_COMMAND_ACMD:

-- 
b4 0.11.0-dev-5166b

  reply	other threads:[~2022-10-07  9:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07  9:38 [PATCH v2 0/2] fastboot/mach-meson: release usb_gadget on reboot commands Mattijs Korpershoek
2022-10-07  9:38 ` Mattijs Korpershoek [this message]
2022-10-10 16:08   ` [PATCH v2 1/2] usb: gadget: fastboot: detach usb " Marek Vasut
2022-10-07  9:38 ` [PATCH v2 2/2] mach-meson: g12a: reset usb controller in reset_misc() Mattijs Korpershoek
2022-10-10 16:09   ` Marek Vasut
2022-10-10 16:22     ` Neil Armstrong
2022-10-10 17:16       ` Marek Vasut
2022-10-11  7:12         ` neil.armstrong
2022-10-11  7:12           ` Neil Armstrong
2022-10-11 15:39           ` Marek Vasut
2022-10-11 16:36             ` Mattijs Korpershoek
2022-10-11 17:57               ` neil.armstrong
2022-10-11 17:57                 ` Neil Armstrong
2022-11-23 15:45                 ` Mattijs Korpershoek

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=20220728-reset-usb-controller-v2-1-ef7657ce78b1@baylibre.com \
    --to=mkorpershoek@baylibre.com \
    --cc=christianshewitt@gmail.com \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=neil.armstrong@linaro.org \
    --cc=sjg@chromium.org \
    --cc=u-boot-amlogic@groups.io \
    --cc=u-boot@lists.denx.de \
    /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.