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 08130C433F5 for ; Fri, 24 Sep 2021 21:11:26 +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 81D0D6140A for ; Fri, 24 Sep 2021 21:11:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 81D0D6140A 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 00218834DD; Fri, 24 Sep 2021 23:10:27 +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="DXOAOGHw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CCE8B83502; Fri, 24 Sep 2021 23:08:28 +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 9268E834AB for ; Fri, 24 Sep 2021 23:07:47 +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 A89FB61350; Fri, 24 Sep 2021 21:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632517666; bh=zT1lIkvWGB+f+TlJUw/z8mEURN9UHlLojT6Z61Yg5cU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DXOAOGHwG2/dCdLljJ3GX/IGMLyikWeBemB6kOXAXOl6YFtJtap4DSujCDTHvPEly 8E4YIitjFdxHlSb3B6grOhohp8cDNJfTt8duuBSgU1dT7j7jm1xtNQwulZu8jL+8bu u00JRtoG5PviJiLbhv3iQEty2w20GQpa+TZTLgaNVVCWhGbBzE9uasPRtjB/kVFYD7 gPfXBxsA3xWS+7jmxa62mQIDlein4LQ9JE58woVIMctB9luGtvQdUPJcczhffAZMnM Y8oV0PyAVWmBgxAgrd9sApJLQ3kXA8U+Pb3wC8NPZT1H7MyMsGJlTK+nRlnle9s49U +jB2Bku/OgZkg== 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 13/39] tools: kwboot: Allow non-xmodem text output from BootROM only in a specific case Date: Fri, 24 Sep 2021 23:06:50 +0200 Message-Id: <20210924210716.29752-14-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: Pali Rohár When sending image header / image data, BootROM does not send any non-xmodem text output. We should therefore interpret unknown bytes in the xmodem protocol as errors and resend current packet. This should improve the transfer in case there are errors on the UART line. Text output from BootROM may only happen after whole image header is sent and before ACK for the last packet of image header is received. In this case BootROM may execute code from the image, which may interact with UART (U-Boot SPL, for example, prints stuff on UART). Print received non-xmodem output from BootROM only in this case. Signed-off-by: Pali Rohár [ refactored & simplified ] Signed-off-by: Marek Behún --- tools/kwboot.c | 70 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/tools/kwboot.c b/tools/kwboot.c index 2e5684b91c..4636622a6c 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -382,33 +382,62 @@ _is_xm_reply(char c) } static int -kwboot_xm_sendblock(int fd, struct kwboot_block *block) +kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm) +{ + int rc; + + while (1) { + rc = kwboot_tty_recv(fd, c, 1, blk_rsp_timeo); + if (rc) { + if (errno != ETIMEDOUT) + return rc; + *c = NAK; + } + + /* If received xmodem reply, end. */ + if (_is_xm_reply(*c)) + break; + + /* + * If printing non-xmodem text output is allowed and such a byte + * was received, print it. + */ + if (allow_non_xm) { + putchar(*c); + fflush(stdout); + } + } + + return 0; +} + +static int +kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, + int *done_print) { int rc, retries; char c; + *done_print = 0; + retries = 16; do { rc = kwboot_tty_send(fd, block, sizeof(*block)); if (rc) return rc; - do { - rc = kwboot_tty_recv(fd, &c, 1, blk_rsp_timeo); - if (rc) { - if (errno != ETIMEDOUT) - return rc; - c = NAK; - } - - if (!_is_xm_reply(c)) - printf("%c", c); + if (allow_non_xm && !*done_print) { + kwboot_progress(100, '.'); + kwboot_printv("Done\n"); + *done_print = 1; + } - } while (!_is_xm_reply(c)); + rc = kwboot_xm_recv_reply(fd, &c, allow_non_xm); + if (rc) + return rc; - if (c != ACK) + if (!allow_non_xm && c != ACK) kwboot_progress(-1, '+'); - } while (c == NAK && retries-- > 0); rc = -1; @@ -435,6 +464,7 @@ static int kwboot_xmodem_one(int tty, int *pnum, int header, const uint8_t *data, size_t size) { + int done_print = 0; size_t sent, left; int rc; @@ -446,22 +476,28 @@ kwboot_xmodem_one(int tty, int *pnum, int header, const uint8_t *data, while (sent < size) { struct kwboot_block block; + int last_block; size_t blksz; blksz = kwboot_xm_makeblock(&block, data, left, (*pnum)++); data += blksz; - rc = kwboot_xm_sendblock(tty, &block); + last_block = (left <= blksz); + + rc = kwboot_xm_sendblock(tty, &block, header && last_block, + &done_print); if (rc) goto out; sent += blksz; left -= blksz; - kwboot_progress(sent * 100 / size, '.'); + if (!done_print) + kwboot_progress(sent * 100 / size, '.'); } - kwboot_printv("Done\n"); + if (!done_print) + kwboot_printv("Done\n"); return 0; out: -- 2.32.0