From patchwork Tue Jan 25 17:13:05 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: 1584195 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=ARkCtiW4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4Jjtkc2HJ0z9t6g for ; Wed, 26 Jan 2022 04:14:32 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 35D188384C; Tue, 25 Jan 2022 18:13:55 +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="ARkCtiW4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A191383373; Tue, 25 Jan 2022 18:13:34 +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=unavailable 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 A27CD830D0 for ; Tue, 25 Jan 2022 18:13:28 +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 970DB60F9A; Tue, 25 Jan 2022 17:13:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09236C340E7; Tue, 25 Jan 2022 17:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643130807; bh=6fLTfW/cCqAZujZQOzYt07ZTgMaJYTyI4Ls0UKg6mG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ARkCtiW40bndFzRRqbA41JpGK5TdF+U3X4fx8lyOfmykqMOZeOKeJAXmPuxWJjgEl BJ6jLWDCkBqwXOYuBJAnFAFlRIiHn0Uz1cHHPqN3MmrhMwOVoLaj8DwxMe8VhI15kf H+3iY+PukFvA9r/RaMJ3KVeAM53+DkH3oYLmspe9SSCOPgBEG5w57rGNxBLqIf6aN6 PQdXmN8zENePglQNiLTDLQ37OrBrtR2BfHlC2P8PQbwqTEAr1PFnJ6v+N1RejKzhGy zhDw2rgvOVu8PTe3NWI+hM2F+o08u4lib3FXfZhqEexzXYU3G+hcFbVs4daY8p+ACH EpItzEBFbsFQQ== 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 06/14] tools: kwboot: Fix handling of repeated xmodem packets Date: Tue, 25 Jan 2022 18:13:05 +0100 Message-Id: <20220125171313.14498-7-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 Unfortunately during some stages of xmodem transfer, A385 BootROM is not able to handle repeated xmodem packets. So if an error occurs during that stage, stop the transfer and return failure. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwboot.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tools/kwboot.c b/tools/kwboot.c index a619a6c3c1..dfac8aed7b 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -946,7 +946,7 @@ kwboot_xm_recv_reply(int fd, char *c, int stop_on_non_xm, static int kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, - int *done_print, int baudrate) + int *done_print, int baudrate, int allow_retries) { int non_xm_print, baud_changed; int rc, err, retries; @@ -977,7 +977,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, if (!allow_non_xm && c != ACK) kwboot_progress(-1, '+'); - } while (c == NAK && retries++ < 16); + } while (c == NAK && allow_retries && retries++ < 16); if (non_xm_print) kwboot_printv("\n"); @@ -1044,8 +1044,30 @@ kwboot_xmodem_one(int tty, int *pnum, int header, const uint8_t *data, last_block = (left <= blksz); + /* + * Handling of repeated xmodem packets is completely broken in + * Armada 385 BootROM - it completely ignores xmodem packet + * numbers, they are only used for checksum verification. + * BootROM can handle a retry of the xmodem packet only during + * the transmission of kwbimage header and only if BootROM + * itself sent NAK response to previous attempt (it does it on + * checksum failure). During the transmission of kwbimage data + * part, BootROM always expects next xmodem packet, even if it + * sent NAK to previous attempt - there is absolutely no way to + * repair incorrectly transmitted xmodem packet during kwbimage + * data part upload. Also, if kwboot receives non-ACK/NAK + * response (meaning that original BootROM response was damaged + * on UART) there is no way to detect if BootROM accepted xmodem + * packet or not and no way to check if kwboot could repeat the + * packet or not. + * + * Stop transfer and return failure if kwboot receives unknown + * reply if non-xmodem reply is not allowed (for all xmodem + * packets except the last header packet) or when non-ACK reply + * is received during data part transfer. + */ rc = kwboot_xm_sendblock(tty, &block, header && last_block, - &done_print, baudrate); + &done_print, baudrate, header); if (rc) goto out;