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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28E8CC433FE for ; Fri, 24 Sep 2021 21:11:46 +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 AEF2861090 for ; Fri, 24 Sep 2021 21:11:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AEF2861090 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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 7E9628350C; Fri, 24 Sep 2021 23:10:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="irrC22gl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DA052834BB; Fri, 24 Sep 2021 23:08:34 +0200 (CEST) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 93C31834BB for ; Fri, 24 Sep 2021 23:07:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 990EB6135A; Fri, 24 Sep 2021 21:07:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632517672; bh=5l6rKz3UB0ly8A4USuCZG1qMQAhWZuGH6adKNd0SZo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=irrC22gl+nMgv6j5NtoK+YL/1vT+bBh+yT6YfskJU50CFeQCskKS/v/pmvoKLNseG JWb7ywc+TgQ4BszOijEhRMSB8zBzvVtbwa7C6W2v9P5Rt3QDY8BCGaKqFmNCVRsqy7 EE1p9KcSh6yv1CU2A8n7vDKUCZz/fm+8/nB2zbASVgzKXYxLa+5eBdxPvqFg8Iv+04 /QxnFLukyDt1mnVFVXJo35N7QiPEy4I6U2vkszyCMqR2yBI3KEosCO9UVWY7jsM3fQ Nk+sWIRiEC6E6PufJBerY4i6O5K23UJm1aaXTsRgpKxIkLmtD/JKZaNMyPfVFtRkjT RBoTcpAdHEXlA== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, pali@kernel.org, Chris Packham , Baruch Siach , Dennis Gilmore , Mario Six , Jon Nettleton , =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH u-boot-marvell v3 16/39] tools: kwboot: Prevent waiting indefinitely if no xmodem reply is received Date: Fri, 24 Sep 2021 23:06:53 +0200 Message-Id: <20210924210716.29752-17-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210924210716.29752-1-kabel@kernel.org> References: <20210924210716.29752-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 --- 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; + } } } -- 2.32.0