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 39B58C3DA7A for ; Thu, 5 Jan 2023 15:29:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EAB6B855C1; Thu, 5 Jan 2023 16:29:18 +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="vgt/Ujs9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4001B855C9; Thu, 5 Jan 2023 16:29:17 +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 DFAD4855C1 for ; Thu, 5 Jan 2023 16:29:13 +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 p1-20020a05600c1d8100b003d8c9b191e0so1587686wms.4 for ; Thu, 05 Jan 2023 07:29:13 -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=oT85O3Gj0EAtaBCOOP3Ne8qsDIVdIFQvC/9MvG+hzw4=; b=vgt/Ujs9NUSvOTBFTAN7ORUHxS+Z2C5OC/t7wkhXAsBt6GpNXh7THda2pmn/02roeb W53hl+f3EKrnr1UqG0bO5H50fmKwHHxNDYWZL6S6p6YxWPUmBFNBTHn5j6acLQjbPTtb g+LRFr4kgg8htO5xQ90iJfhEFV9mpqypSYI3zIwO4XoAsqVc70rmTkEVGLHqWteLdylt 0DxsPP5NXFnWRqopHn7BW8VMsQqckgZhKJIRX31UYEcSCC7JTeNMiOjimmYYYh/fI2IW Yzj5lxWhN+Sim5Rl3oyZ8AbS3Ngjk0lGkPdwBkr8pbX8P8TXD/+wXkltYuCmr7KYYNQ+ /J1w== 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=oT85O3Gj0EAtaBCOOP3Ne8qsDIVdIFQvC/9MvG+hzw4=; b=ieXEgmuI++Slg2EHYDEZMM0rjYdUp/Lh3fk2VAERieE5iIXQ9jh9k3utkawRhAnNJt yHMvm8LYwmFs/MY3n5C+cFNUbqTAsw5Vo6ykIAbFTeuphco8DddS6FmJa6CnL6Rt4meo Blq50V4DQMBbxpJg2S1pNgtXkrinFvlACKuSzd0GiJ2gLQzNg6ebrT8NPzYcJbEWaJWN gfuyh+nZXw29dpOyqYEi7lAvlJzq35M7RGaHwdPsVguY/QcKx9sMaPbcsfxjWr66icV0 H7l3MDdd9rOzR9ReeOdKyalH9Lvu4xxf1w3HuatQPuALY1vn4PPOwiurPj0ufHkBVwZo h+VQ== X-Gm-Message-State: AFqh2kr5PVXGsCDdCY6yvYgDymbl50ypGcNtgwwXqGIGvRoUEDNMqD5E ns6X2kB9hvoXZcu3spdr6ZaODg== X-Google-Smtp-Source: AMrXdXu4od8k7inQwMFYaY3d/gizvghz74n0YWkaz6UikcrPEZ4kiv23y9MkjGwWSDZC6urMP2EwfA== X-Received: by 2002:a05:600c:228b:b0:3d2:37a4:222a with SMTP id 11-20020a05600c228b00b003d237a4222amr40896498wmf.38.1672932553327; Thu, 05 Jan 2023 07:29:13 -0800 (PST) Received: from localhost ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id p16-20020a05600c469000b003d9b87296a9sm3010056wmo.25.2023.01.05.07.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 07:29:12 -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: Thu, 05 Jan 2023 16:29:11 +0100 Message-ID: <87sfgp6lvc.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. Huh. Ok. I will do some more debugging on my end. Thank you for your patience. > >> >> > 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