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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 877F1C433EF for ; Fri, 1 Oct 2021 06:21:15 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0891D61A54 for ; Fri, 1 Oct 2021 06:21:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0891D61A54 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3B032832AF; Fri, 1 Oct 2021 08:21:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1633069273; bh=05S1SgKHHDBmY9ohJximgLxdU1xeyzaAzKcaN5DHgis=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=O6/+OzyEwOnjabY/ldgNiosfhU6jHhF3ZSFwDGA2kA9nAi+IKCoJETA/sKe1fnG0C JldlbDM2lA3EQnH7kPWZLkLCyk7+xi5/GT83tb3r05EAkPCYOoLPudd/nd0WXQc5lS 8xDRq/2Q3ybbLUXdX4qqKgZFd/b5OT46UNraor/f73ZYlz4RvbXwRaeYA/IWZnKkDk NMU0c2FgFeDx6bZJHZ0jIqqxJSPnaeJAoEaL27FXZvwClU+4sKY6J0ezLENVZncPAO 000srnzLIE95ZcQFpjxRbvJZtLPWHS2njPTeK78wfPabDWTP9hgM/OmJPWnzBxVGrB M5l1YctAZxNag== Received: by phobos.denx.de (Postfix, from userid 109) id 06B7483267; Fri, 1 Oct 2021 08:21:11 +0200 (CEST) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [IPv6:2001:67c:2050:1::465:204]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2A5EA83267 for ; Fri, 1 Oct 2021 08:21:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp102.mailbox.org (smtp102.mailbox.org [80.241.60.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4HLKkD0gwSzQjcJ; Fri, 1 Oct 2021 08:21:08 +0200 (CEST) Subject: Re: [PATCH u-boot-marvell v3 16/39] tools: kwboot: Prevent waiting indefinitely if no xmodem reply is received To: =?UTF-8?Q?Marek_Beh=c3=ban?= Cc: u-boot@lists.denx.de, pali@kernel.org, Chris Packham , Baruch Siach , Dennis Gilmore , Mario Six , Jon Nettleton , =?UTF-8?Q?Marek_Beh=c3=ban?= References: <20210924210716.29752-1-kabel@kernel.org> <20210924210716.29752-17-kabel@kernel.org> From: Stefan Roese Message-ID: <194de5fb-4739-e923-0fc0-78f6f3aad4fc@denx.de> Date: Fri, 1 Oct 2021 08:21:03 +0200 MIME-Version: 1.0 In-Reply-To: <20210924210716.29752-17-kabel@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: EEB99273 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean On 24.09.21 23:06, Marek Behún wrote: > From: Marek Behún > > Currently if BootROM fails to respond with ACK/NAK to a xmodem block, we > will be waiting indefinitely for such response. > > Make sure that we only wait at most 1 second (blk_rsp_timeo) for ACK/NAK > for each block in case non-xmodem text output is not being expected. > Interpret this timeout expiration as NAK, to try to send the block > again. > > On the other hand, if timeout expires without ACK while some non-xmodem > output was already received (DDR training output, for example), we know > that the block was received, since the code is being executed, so in > this case exit with ETIMEDOUT. > > Signed-off-by: Marek Behún Reviewed-by: Stefan Roese Thanks, Stefan > --- > tools/kwboot.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/tools/kwboot.c b/tools/kwboot.c > index cf6e32c6fa..8c11dca5ed 100644 > --- a/tools/kwboot.c > +++ b/tools/kwboot.c > @@ -407,17 +407,18 @@ static int > kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print) > { > int timeout = allow_non_xm ? KWBOOT_HDR_RSP_TIMEO : blk_rsp_timeo; > - uint64_t recv_until = 0; > + uint64_t recv_until = _now() + timeout; > int rc; > > - *non_xm_print = 0; > + if (non_xm_print) > + *non_xm_print = 0; > > while (1) { > rc = kwboot_tty_recv(fd, c, 1, timeout); > if (rc) { > if (errno != ETIMEDOUT) > return rc; > - else if (recv_until && recv_until < _now()) > + else if (allow_non_xm && *non_xm_print) > return -1; > else > *c = NAK; > @@ -430,12 +431,19 @@ kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print) > /* > * If printing non-xmodem text output is allowed and such a byte > * was received, print it and increase receiving time. > + * Otherwise decrease timeout by time elapsed. > */ > if (allow_non_xm) { > recv_until = _now() + timeout; > putchar(*c); > fflush(stdout); > *non_xm_print = 1; > + } else { > + timeout = recv_until - _now(); > + if (timeout < 0) { > + errno = ETIMEDOUT; > + return -1; > + } > } > } > > Viele Grüße, Stefan -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de