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 X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D41D9C433EF for ; Tue, 7 Sep 2021 10:06:30 +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 4874A603E7 for ; Tue, 7 Sep 2021 10:06:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4874A603E7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nic.cz 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 BB5AC83135; Tue, 7 Sep 2021 12:06:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nic.cz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="iGWK01uk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 00AFB832AD; Tue, 7 Sep 2021 11:59:24 +0200 (CEST) Received: from mail.nic.cz (lists.nic.cz [IPv6:2001:1488:800:400::400]) (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 2C5028334D for ; Tue, 7 Sep 2021 11:58:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nic.cz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=marek.behun@nic.cz Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:8747:7254:5571:3010]) by mail.nic.cz (Postfix) with ESMTPSA id BC4E0147F9B; Tue, 7 Sep 2021 11:58:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1631008720; bh=s1ftUYdLaGjkZJHHmXFeIDOqwoq3TnnukSDuI+0dKrY=; h=From:To:Date; b=iGWK01ukZdi+eXsrm2bT3DIBNyzI0YkNUIluOnICLqAdl2d8fP5dBMcA+U0Isok11 spe560otug00dgBPnae0Z1kRHiTDe9KkHpwMjUlVeSzCmbYjE2uQFP1Kwib5jVq2Z8 C+aPYJPzTFxh+RejCWSUdCNdvFe+efDSsTgnLdtI= 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 , Andrew Lunn , =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH u-boot-marvell v2 15/39] tools: kwboot: Allow greater timeout when executing header code Date: Tue, 7 Sep 2021 11:58:13 +0200 Message-Id: <20210907095837.14042-16-marek.behun@nic.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907095837.14042-1-marek.behun@nic.cz> References: <20210907095837.14042-1-marek.behun@nic.cz> 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 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..7362ef0d7a 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 * 1000 + (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