From patchwork Tue Jan 25 17:13:08 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: 1584198 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=FT5g8TFb; 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 4JjtlB2RT4z9t5H for ; Wed, 26 Jan 2022 04:15:02 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 86030838A8; Tue, 25 Jan 2022 18:14:03 +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="FT5g8TFb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EE4B48389A; Tue, 25 Jan 2022 18:13:38 +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 EC84783877 for ; Tue, 25 Jan 2022 18:13:32 +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 DB32E61312; Tue, 25 Jan 2022 17:13:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5099CC340E8; Tue, 25 Jan 2022 17:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643130811; bh=eyKLcGefykjyy/fNZ13i12fKAicFE+d6PweCsRzYSdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FT5g8TFbD20eFT+Bc3wW7OhWUSmdcjgFt0uT78XtPobCtvGbJz7ieHchfHmGDpYw6 POyyqc75yS8cQnYjAr/HnfValvgyco8nfqBmVwkzqMv89rNY1ocu6BedckwU0k/CUk +gyf2c3V1OXmHLH1XrIEw5yUsv72Sl4s0WFkq/gn3TZW95E3U3WEcc9S0vn8F36yxS 1B7A6tHoFqtZUZY+2bnrksdUxY623HUBTu/iUZ5w6m89twyj5c+4UZQIW1TygQJFK5 ANjxdri0M4teCYcflPVo/FGagJQYaCMTHq07r9yJJaHOIS7eUxoPXpByLYCys+2CYb vSD0WIKJjMSdQ== 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 09/14] tools: kwboot: Force BootROM to flush input queue after boot pattern Date: Tue, 25 Jan 2022 18:13:08 +0100 Message-Id: <20220125171313.14498-10-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 Force the BootROM to flush its input queue after sending boot pattern. This ensures that after function kwboot_bootmsg() finishes, BootROM is able to start receiving xmodem packets without any specific delay or setup. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwboot.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tools/kwboot.c b/tools/kwboot.c index c413a8bf51..824ae005b2 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -717,6 +717,7 @@ out: static int kwboot_bootmsg(int tty, void *msg) { + struct kwboot_block block; int rc; char c; int count; @@ -747,7 +748,40 @@ kwboot_bootmsg(int tty, void *msg) kwboot_printv("\n"); - return rc; + if (rc) + return rc; + + /* + * At this stage we have sent more boot message patterns and BootROM + * (at least on Armada XP and 385) started interpreting sent bytes as + * part of xmodem packets. If BootROM is expecting SOH byte as start of + * a xmodem packet and it receives byte 0xff, then it throws it away and + * sends a NAK reply to host. If BootROM does not receive any byte for + * 2s when expecting some continuation of the xmodem packet, it throws + * away the partially received xmodem data and sends NAK reply to host. + * + * Therefore for starting xmodem transfer we have two options: Either + * wait 2s or send 132 0xff bytes (which is the size of xmodem packet) + * to ensure that BootROM throws away any partially received data. + */ + + /* flush output queue with remaining boot message patterns */ + tcflush(tty, TCOFLUSH); + + /* send one xmodem packet with 0xff bytes to force BootROM to re-sync */ + memset(&block, 0xff, sizeof(block)); + kwboot_tty_send(tty, &block, sizeof(block), 0); + + /* + * Sending 132 bytes via 115200B/8-N-1 takes 11.45 ms, reading 132 bytes + * takes 11.45 ms, so waiting for 30 ms should be enough. + */ + usleep(30 * 1000); + + /* flush remaining NAK replies from input queue */ + tcflush(tty, TCIFLUSH); + + return 0; } static int