From patchwork Tue Jan 25 17:13:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1584190 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=sh9nHsdA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jjtjz4MD9z9t6g for ; Wed, 26 Jan 2022 04:13:59 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DCDF983806; Tue, 25 Jan 2022 18:13:36 +0100 (CET) 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="sh9nHsdA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DB3D383809; Tue, 25 Jan 2022 18:13:29 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (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 4D66583680 for ; Tue, 25 Jan 2022 18:13:24 +0100 (CET) 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: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4BAB76130B; Tue, 25 Jan 2022 17:13:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9D1AC340EC; Tue, 25 Jan 2022 17:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643130802; bh=EXLWekh1eLLBLB1GvoKTANlFhKQZRFHJZMOSaG7ZQpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sh9nHsdA51h6EZMEHvEXOMApVgQ7LPTBLwLEbqplhfEq0UkfgrPAcrrPVUYxCKIVM MOuVMpX7OAC9oItyIaMNYkGRuNLD4GE1DKUimk72VLOO2M22hyH361S/rnhOV/AO/V rmjx4xS6RE3MPHPCqgn7IzoJfk9sH4kkspb2CLYUggS5JcoLCC+WtHiFctaoFL8K6S I+XAx33OFUP7mgUM8EAgIyAehTTlpikHgJn3UMganr24du8Lp0KMwd+qqEKbCxdamA NfBpVP4b+PUrfNBX+fZzaAp1/2C9J44no935ne6qfqnU7h6cKK8OH3MVtQbdHheUm8 /APOQ8IB/AU2w== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, pali@kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 03/14] tools: kwboot: Improve retrying logic for incomplete xmodem packets Date: Tue, 25 Jan 2022 18:13:02 +0100 Message-Id: <20220125171313.14498-4-kabel@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220125171313.14498-1-kabel@kernel.org> References: <20220125171313.14498-1-kabel@kernel.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean From: Pali Rohár Sometimes if the first byte of xmodem packet (SOH) is incorrectly transmitted, BootROM sends NAK for every non-SOH received byte, which makes BootROM and the host kwboot tool out of sync. BootROM automatically re-synchronizes after 2s pause by dropping its input queue. So when attempting retransmit for 9th time or later, ignore NAK reply from BootROM and either wait for valid ACK or let kwboot timeout, which implies re-synchronization. This fixes retransmission of xmodem packets and allows kwboot to work also without "Waiting ... and flushing tty" code which is at the beginning of kwboot xmodem transfer. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwboot.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/kwboot.c b/tools/kwboot.c index 1477c0f078..be9a751406 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -880,6 +880,7 @@ kwboot_baud_magic_handle(int fd, char c, int baudrate) static int kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm, + int ignore_nak_reply, int allow_non_xm, int *non_xm_print, int baudrate, int *baud_changed) { @@ -899,8 +900,14 @@ kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm, } /* If received xmodem reply, end. */ - if (_is_xm_reply(*c)) + if (_is_xm_reply(*c)) { + if (*c == NAK && ignore_nak_reply) { + timeout = recv_until - _now(); + if (timeout >= 0) + continue; + } break; + } /* * If receiving/printing non-xmodem text output is allowed and @@ -968,6 +975,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, } rc = kwboot_xm_recv_reply(fd, &c, retries < 3, + retries > 8, allow_non_xm, &non_xm_print, baudrate, &baud_changed); if (rc) @@ -1011,6 +1019,7 @@ kwboot_xm_finish(int fd) return rc; rc = kwboot_xm_recv_reply(fd, &c, retries < 3, + retries > 8, 0, NULL, 0, NULL); if (rc) return rc;