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 BEE22C433FE for ; Fri, 24 Sep 2021 21:11: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 3309561425 for ; Fri, 24 Sep 2021 21:11:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3309561425 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 00A0483537; Fri, 24 Sep 2021 23:10:18 +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="Lcy/+x++"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 688DB83502; Fri, 24 Sep 2021 23:08:27 +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 AAD5F834FF for ; Fri, 24 Sep 2021 23:07:51 +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 9E3D16135D; Fri, 24 Sep 2021 21:07:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632517670; bh=y35e5LdDrGPi1c6dg1p73jnmFgXFikYNCf0uT2vHNg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lcy/+x++Zx1DCdH54g/SasiIXJxhXSs4b8gfNJIOPSq9QnpnF8WIbkwYgq+4lMZ4q 48yZewYfA1u4VSheDYRyWKVBgGeAjUIKildty6rb0MxvC7ZZMytgJy6GeFBzwI33Eq I3mKbrSsAVvUHb90LW566Iudt+JAvpXBkfMScDCFDY90ugN+oKbcgJ3fv1I69/XUab Bs0e6da6frWnBwgdeWcYbvVKDNPBpMi+5DqnSmRuUlg/cSDtmxQ+qegmYrAcvumwyI jJtDn72o0PdIMxb50wNO5eJ5+E7onIsQU2ON+5vdKZvbKnLMAj64tsXcwKxKT9l4wH TVon0R0xJ3yPQ== 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 15/39] tools: kwboot: Allow greater timeout when executing header code Date: Fri, 24 Sep 2021 23:06:52 +0200 Message-Id: <20210924210716.29752-16-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 When executing header code (which contains U-Boot SPL in most cases), wait 10s after every non-xmodem character received (i.e. printed by U-Boot SPL) before timing out. Sometimes DDR training, which runs in SPL, may be slow. Signed-off-by: Marek BehĂșn --- tools/kwboot.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tools/kwboot.c b/tools/kwboot.c index 2f4c61bed6..cf6e32c6fa 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -68,6 +69,7 @@ struct kwboot_block { } __packed; #define KWBOOT_BLK_RSP_TIMEO 1000 /* ms */ +#define KWBOOT_HDR_RSP_TIMEO 10000 /* ms */ static int kwboot_verbose; @@ -375,6 +377,26 @@ kwboot_xm_makeblock(struct kwboot_block *block, const void *data, return n; } +static uint64_t +_now(void) +{ + struct timespec ts; + + if (clock_gettime(CLOCK_MONOTONIC, &ts)) { + static int err_print; + + if (!err_print) { + perror("clock_gettime() does not work"); + err_print = 1; + } + + /* this will just make the timeout not work */ + return -1ULL; + } + + return ts.tv_sec * 1000ULL + (ts.tv_nsec + 500000) / 1000000; +} + static int _is_xm_reply(char c) { @@ -384,16 +406,21 @@ _is_xm_reply(char c) 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; int rc; *non_xm_print = 0; while (1) { - rc = kwboot_tty_recv(fd, c, 1, blk_rsp_timeo); + rc = kwboot_tty_recv(fd, c, 1, timeout); if (rc) { if (errno != ETIMEDOUT) return rc; - *c = NAK; + else if (recv_until && recv_until < _now()) + return -1; + else + *c = NAK; } /* If received xmodem reply, end. */ @@ -402,9 +429,10 @@ 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. + * was received, print it and increase receiving time. */ if (allow_non_xm) { + recv_until = _now() + timeout; putchar(*c); fflush(stdout); *non_xm_print = 1; -- 2.32.0