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 8AC96C3DA7A for ; Thu, 5 Jan 2023 11:03:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B93A38559D; Thu, 5 Jan 2023 12:03:37 +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="HVe2PaYS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C9BCC855A3; Thu, 5 Jan 2023 12:03:35 +0100 (CET) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (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 645EF84231 for ; Thu, 5 Jan 2023 12:03:32 +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-x332.google.com with SMTP id g25-20020a7bc4d9000000b003d97c8d4941so1014232wmk.4 for ; Thu, 05 Jan 2023 03:03:32 -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=FPyKny9x7DzDmibvlkL9ppvugwXmETwb9jOxRzWE7pU=; b=HVe2PaYSGv+adop4Liu3V4IkI07r4yDSPo2oIfHyObwpfhhxsvE5GSd0Kqopy+91D9 QR7VclEtwNdXumCj6+fe3GEqBpojOIR7UOvWQRYmfjBakpvyXmeFFak5q3aQ/iiYdAHB GM/ZKeYfhSJrxWieVQUHRINXVv04v1gDsmyJjTWZwtlkTrdNb44gCWrpR/JoSNQSEVwF 7lZ+9NK8yER2lfi0d46IrrjM7S8EAuRbrLHxOWaCOjh0fxaLoV9OvJNn0jkqmBTEEtMP EARrZIauIoTkLMA0v0wqnUw0TmFKCu5qUx96s+wPtnZhHrI1YEAwuZ39hTVCJkhBD4PF gybQ== 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=FPyKny9x7DzDmibvlkL9ppvugwXmETwb9jOxRzWE7pU=; b=ijeFKX5OIWxCdqZcNJGxiFMHQsSi7At9gQT0Wxbp4JmFrPCDsYb+iDt1XaR4GKh48q d+uNw4P3PhHS7C1Y2CP7DdHCIMLhRw9EJ+5FoxNnQu/gBxypa9MNtpKI9qVqWWml6izK RvnNnBwW37tRPONq75Q2hubGg2MFRtR2wSn2OfseOD7Q8mrZ1NpgeAJtc7Il7QPjmesF LFDwkUtgEt08XzvJyjSefena1GZXBrzmD0MQ5gppmJEw0m+antakZY8W9x6vesR0R4I9 z8GqaRsyuQYEvUa227q0acTMA9h/H+BqjgjSV1zQkb6A/xHQsjgX051LfqHAJNlX+WlM Wixg== X-Gm-Message-State: AFqh2krb6Zl9MDiC0RrqsfirR5ojqE/Dnr9L4tANW//V2BtDrQwbxdDf 7nz42OWmU5jISnCWeYKSUq8FvA== X-Google-Smtp-Source: AMrXdXvWfbwv5qi4fz252P20400grxgNr6U9cFSRAYgdI+y7VcxtGZEBN2bRzM5RlRO0PBx/sWZwzg== X-Received: by 2002:a05:600c:2146:b0:3d1:f762:da7f with SMTP id v6-20020a05600c214600b003d1f762da7fmr38932016wml.2.1672916611896; Thu, 05 Jan 2023 03:03:31 -0800 (PST) Received: from localhost ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id ay14-20020a05600c1e0e00b003d9a71ee54dsm2033546wmb.36.2023.01.05.03.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 03:03:31 -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> Date: Thu, 05 Jan 2023 12:03:30 +0100 Message-ID: <87v8ll6y65.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 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. > 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