From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE469C4708D for ; Fri, 6 Jan 2023 16:42:33 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 54421852B6; Fri, 6 Jan 2023 17:42:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="i5VM/mtV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3A8E985215; Fri, 6 Jan 2023 17:42:29 +0100 (CET) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 786C3852B6 for ; Fri, 6 Jan 2023 17:42:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mkorpershoek@baylibre.com Received: by mail-wm1-x32f.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so3958203wma.1 for ; Fri, 06 Jan 2023 08:42:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=nuyMhj2YGjaJ0Oy3qA24xqtH8FTFgyKN/sJQLl5AhZQ=; b=i5VM/mtVUWt5lZqYVIzn7n9ytP7jK+hMWdL08ihXYhAm7Ey6Rc1Bd9F1GdlbdLcMdn egydOD0eVsOscN5CGLMGXZTcZHcbI1f2HR7I8z3TxVGBQ+I1HWLz6jIgTm5AEB7AJZlK bQ60lN6xrbQBHmNqM1QF2yaJG1qCD/CBRnIDQ3AFNjHD56o3Kk7//hg/rZGlWk0EuNgN 1aryfla6j0zrmxUR3IpkEZill+2/y3xqXfHYHjfyNBXWdPuvoppTEoESLPr2GfTwzAc2 VQhMjbrG34gnAlS65OMOoNuCXZrIu+NYtOinHjT4WXLtUZL01jzlOsYYBAvf6PjD9P5T LqZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nuyMhj2YGjaJ0Oy3qA24xqtH8FTFgyKN/sJQLl5AhZQ=; b=UWW2kc/ktU1+AidGUGT7LZZU8UIwjxqKK0vmk1nHDtpBJ9YNxM0cgKklHoxdGAZCfK g4gHcYUJf8+DCjUl9f9sdPMG0EW/sK/VU8mQc8PoNC+/uOunJKvraHCWrHWy31oqYsKs IWlbzJFvBLlgTI2DMbD6Yah4PfdsPIBM4Q6mu0SXbHsyaqhypVPKDCUYmE0O2NsMCftJ Yn+buh/CmPPfE0Uqn5npf+WSuWhYsEErXA6qUNYPrjK1t7SnLBrenSF7kDI8ckZ3KU10 H8mdbcfTSYYO1siK5lLhjsmN1L1XqYNhjYksVg8+A2DCS9OLtyVZLASDXFdI/JEHeyv3 Dpzw== X-Gm-Message-State: AFqh2kq/PO4doQ2omyXald2SjrZjeQkyrb4L7EA5clt3g86JynV5BFsp tPtnLV71BB8LTWy4yxMJQimAOw== X-Google-Smtp-Source: AMrXdXtqUaq0jaCzMHGdvOeqFcxmdplBzvCkxzAVoNN329ite49167ItVhehuaF98qR+JYspewkflg== X-Received: by 2002:a05:600c:1c81:b0:3d1:e907:17cb with SMTP id k1-20020a05600c1c8100b003d1e90717cbmr39998802wms.1.1673023342856; Fri, 06 Jan 2023 08:42:22 -0800 (PST) Received: from localhost (lfbn-tou-1-905-105.w86-210.abo.wanadoo.fr. [86.210.136.105]) by smtp.gmail.com with ESMTPSA id j30-20020a05600c1c1e00b003cfa80443a0sm2603214wms.35.2023.01.06.08.42.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 08:42:22 -0800 (PST) From: Mattijs Korpershoek To: Dario Binacchi Cc: u-boot@lists.denx.de, Michael Trimarchi , Lukasz Majewski , Marek Vasut , linux-amarula@amarulasolutions.com Subject: Re: [PATCH v2] usb: gadget: fastboot: detach usb just before rebooting In-Reply-To: References: <20230104164658.2734718-1-dario.binacchi@amarulasolutions.com> <871qo98i5u.fsf@baylibre.com> <87v8ll6y65.fsf@baylibre.com> Date: Fri, 06 Jan 2023 17:42:21 +0100 Message-ID: <87fscn1uoi.fsf@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On Thu, Jan 05, 2023 at 14:25, Dario Binacchi wrote: > Hi Mattijs, > > On Thu, Jan 5, 2023 at 12:03 PM Mattijs Korpershoek > wrote: >> >> On Thu, Jan 05, 2023 at 10:10, Dario Binacchi wrote: >> >> > Hi Mattijs, >> > >> > On Thu, Jan 5, 2023 at 10:06 AM Mattijs Korpershoek >> > wrote: >> >> >> >> On Wed, Jan 04, 2023 at 17:46, Dario Binacchi wrote: >> >> >> >> > The patch fixes the following error when updating a BSH SMM S2 board: >> >> > 3:72>Start Cmd:FB[-t 8000]: ucmd nand write ${loadaddr} nanddtb ${filesize} >> >> > 3:72>Okay (0.023s) >> >> > 3:72>Start Cmd:FB: reboot >> >> > 3:72>Fail Bulk(R):LIBUSB_ERROR_IO(0s) >> >> > >> >> > The "fastboot reboot" command detaches the USB when it still needs to be >> >> > used. So let's detach the USB just before the reset. >> >> > >> >> > CC: Mattijs Korpershoek >> >> > Fixes: 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands") >> >> > Suggested-by: Michael Trimarchi >> >> > Signed-off-by: Dario Binacchi >> >> >> >> Hi Dario, >> >> >> >> Thank you for your patch and for reporting the problem. >> >> >> >> Unfortunately, applying it seems to break the problem I tried to >> >> solve with 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands") >> >> >> >> Does reverting 5f7e01e9d5d800 also solves your issue? >> > >> > Yes >> > >> >> >> >> I'll spend some time on this. >> > >> > Ok, thanks. So we can test on our hardware. >> >> So historically, I wanted to make this a "arch specific fix, as >> discussed in >> https://lore.kernel.org/u-boot/20220728-reset-usb-controller-v2-0-ef7657ce78b1@baylibre.com/ >> >> To me, the problem with calling g_dnl_trigger_detach() in the >> fastboot_func->in_req->complete() handler is that it's called too late. >> >> In fact, the main fastboot loop is as following: >> >> while (1) { >> if (g_dnl_detach()) >> break; >> if (ctrlc()) >> break; >> schedule(); >> usb_gadget_handle_interrupts(controller_index); >> } >> ret = CMD_RET_SUCCESS; >> >> exit: >> usb_gadget_release(controller_index); >> g_dnl_unregister(); >> g_dnl_clear_detach(); >> >> return ret; >> >> usb_gadget_handle_interrupts, will at some point, call complete() which will call compl_do_reset(). >> But in compl_do_reset(), we already reset the board >> (without going through the exit: section from cmd/fastboot.c) >> >> For the BSH SMM S2 board, since it's being updated with uuu, >> I assume that the host PC also triggers a call of acmd_complete() afterwards? >> >> Can you try the following diff as well, on top of your change? (for testing purposes) >> >> --- a/drivers/usb/gadget/f_fastboot.c >> +++ b/drivers/usb/gadget/f_fastboot.c >> @@ -492,7 +492,7 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req) >> >> static void compl_do_reset(struct usb_ep *ep, struct usb_request *req) >> { >> - do_exit_on_complete(ep, req); >> + usb_gadget_release(0); >> do_reset(NULL, 0, 0, NULL); >> } >> >> I suspect this will also break your flashing. > > No, I am able to flash and reset the board. > This change works. With some additional testing on my end, I can see that the final message (sending OKAY to the host) done on fastboot_func->in_ep is not done on my end. I think I am lucky that my controller driver (dwc2_udc_otg) delivers the message to my host anyways and calls done() even when messages are aborted. I think I have something that might be better. Dario, could you do another test for me, please? 1. Revert 5f7e01e9d5d800 ("usb: gadget: fastboot: detach usb on reboot commands") 2. Apply the following diff: diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index d0e92c7a071f..f4311328a2da 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -421,6 +421,7 @@ static int fastboot_tx_write_str(const char *buffer) static void compl_do_reset(struct usb_ep *ep, struct usb_request *req) { + g_dnl_unregister(); do_reset(NULL, 0, 0, NULL); } The call to g_dnl_unregister() will end up calling g_dnl_unbind() which calls usb_gadget_disconnect() where each controller can implement a soft disconnect (which I can do for dwc2_udc_otg) > >> >> > Regards Dario >> > >> >> >> >> > >> >> > --- >> >> > >> >> > Changes in v2: >> >> > - Add 'Suggested-by' tag. >> >> > >> >> > drivers/usb/gadget/f_fastboot.c | 12 ++++++------ >> >> > 1 file changed, 6 insertions(+), 6 deletions(-) >> >> > >> >> > diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c >> >> > index 07b1681c8a9a..0b3fae564d0a 100644 >> >> > --- a/drivers/usb/gadget/f_fastboot.c >> >> > +++ b/drivers/usb/gadget/f_fastboot.c >> >> > @@ -419,11 +419,6 @@ static int fastboot_tx_write_str(const char *buffer) >> >> > return fastboot_tx_write(buffer, strlen(buffer)); >> >> > } >> >> > >> >> > -static void compl_do_reset(struct usb_ep *ep, struct usb_request *req) >> >> > -{ >> >> > - do_reset(NULL, 0, 0, NULL); >> >> > -} >> >> > - >> >> > static unsigned int rx_bytes_expected(struct usb_ep *ep) >> >> > { >> >> > int rx_remain = fastboot_data_remaining(); >> >> > @@ -495,6 +490,12 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req) >> >> > do_exit_on_complete(ep, req); >> >> > } >> >> > >> >> > +static void compl_do_reset(struct usb_ep *ep, struct usb_request *req) >> >> > +{ >> >> > + do_exit_on_complete(ep, req); >> >> > + do_reset(NULL, 0, 0, NULL); >> >> > +} >> >> > + >> >> > #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) >> >> > static void do_acmd_complete(struct usb_ep *ep, struct usb_request *req) >> >> > { >> >> > @@ -544,7 +545,6 @@ 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: >> >> > -- >> >> > 2.32.0 >> > >> > >> > >> > -- >> > >> > Dario Binacchi >> > >> > Senior Embedded Linux Developer >> > >> > dario.binacchi@amarulasolutions.com >> > >> > __________________________________ >> > >> > >> > Amarula Solutions SRL >> > >> > Via Le Canevare 30, 31100 Treviso, Veneto, IT >> > >> > T. +39 042 243 5310 >> > info@amarulasolutions.com >> > >> > www.amarulasolutions.com > > > > -- > > Dario Binacchi > > Senior Embedded Linux Developer > > dario.binacchi@amarulasolutions.com > > __________________________________ > > > Amarula Solutions SRL > > Via Le Canevare 30, 31100 Treviso, Veneto, IT > > T. +39 042 243 5310 > info@amarulasolutions.com > > www.amarulasolutions.com