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 63DE6C433F5 for ; Fri, 1 Oct 2021 06:19:27 +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 CF5CB61A57 for ; Fri, 1 Oct 2021 06:19:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CF5CB61A57 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 11F13831B2; Fri, 1 Oct 2021 08:19:25 +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=1633069165; bh=MMyEMODxwloc5LdCfMd4jKZBrhW02Kd4TFTocfivy0A=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=rWfegR8HIRAm9G/qi6C14l1yPyx8SgcKdwFM0n9u+ujy4iwMMv+iSGst8DixforXL o5T9lsrjWKD2UjO8Co5aj7eKPFwG1PB/pATN1KUj7wT42O4cG82b7k8FBfiehwgq6i VwIf1Gq6PoA0TUPCiQs683q/J4sKegPTVLefdGy1YnLEgvluPV2P2cum8BLRwlXOMh 8FWY4SOkT4iQiiB1QfoeGzzr8PkLH7eFCPEpvMA5lJDhLk4c9X4id/snVopRwqqfVw rw+qUkrtojvPNDRabFjSRj94xxHFpp9HieiNsj00LMZ7DKoJH+gQF9jXYNrSsKLHZP juAHybdSW3Kvg== Received: by phobos.denx.de (Postfix, from userid 109) id 041E98320D; Fri, 1 Oct 2021 08:19:24 +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 E74238311B for ; Fri, 1 Oct 2021 08:19:20 +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 smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (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 4HLKh8692tzQkd5; Fri, 1 Oct 2021 08:19:20 +0200 (CEST) Subject: Re: [PATCH u-boot-marvell v3 13/39] tools: kwboot: Allow non-xmodem text output from BootROM only in a specific case 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-14-kabel@kernel.org> From: Stefan Roese Message-ID: <67352dda-b114-ba17-bd82-59c0a7d2fa80@denx.de> Date: Fri, 1 Oct 2021 08:19:02 +0200 MIME-Version: 1.0 In-Reply-To: <20210924210716.29752-14-kabel@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 89E461887 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: 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 Reviewed-by: Stefan Roese Thanks, Stefan > --- > 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: > 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