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 E44EDC433F5 for ; Fri, 5 Nov 2021 22:30:24 +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 C02B160EE9 for ; Fri, 5 Nov 2021 22:30:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C02B160EE9 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 991178373F; Fri, 5 Nov 2021 23:30:21 +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="HGsqW5IA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1C1838373F; Fri, 5 Nov 2021 23:30:20 +0100 (CET) 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 8CD908373A for ; Fri, 5 Nov 2021 23:30:15 +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=pali@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 08D4D60EE9; Fri, 5 Nov 2021 22:30:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636151414; bh=x0XJ1O8/SBJdnGZM3V5Mptn2EkVJacmFjlYrENBXm+w=; h=From:To:Cc:Subject:Date:From; b=HGsqW5IAglBJrOcZSpewKqg3+7V3NZsmc9R0XD89FI3j5gsgCSQiqMhxnFB6gsOtY REw8WhwA9XbgCJgWOdOubT/3U6N1NPccANbWIRTAAxz5+65dHU9U1lkUUZM4BellhS 2Wktd+hXcjqrLjas55yrrxz9jXbOxS4vWzPHVqdc5vgfZ1SEG20dLy71hXPnCSCCIX F1ZIoczcERcbF/e/NFlxPtx5bVAB/gmTzV9H3cdrge6dbsiPZqRyX5+/HD2AFG8Z9X WNy3QFbRHzNvC8qbirM7zGjtSBTLcQ9WHClzw8L2sn1ETcXoqc1firSJU/FNUptPvI 2lnhouyqxN60Q== Received: by pali.im (Postfix) id D5DE9638; Fri, 5 Nov 2021 23:30:11 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese Cc: =?UTF-8?q?Marek=20Beh=C3=BAn?= , Tony Dinh , u-boot@lists.denx.de Subject: [PATCH] tools: kwboot: Fix sending Kirkwood v0 images Date: Fri, 5 Nov 2021 23:29:58 +0100 Message-Id: <20211105222958.17034-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 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 Properly calculate and align image header size to xmodem block size. Kirkwood v0 images do not have stored total size of header in header structure itself like it is for v1 images. So kwbheader_size() calculates size by traversing image structure itself. Aligning is done in kwboot by putting zero padding bytes between the header and data part. Signed-off-by: Pali Rohár Tested-by: Tony Dinh --- tools/kwboot.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/kwboot.c b/tools/kwboot.c index bacca1530110..4e4d544efd3f 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -1073,6 +1073,14 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate) hdrsz = kwbheader_size(img); + /* + * If header size is not aligned to xmodem block size (which applies + * for all images in kwbimage v0 format) then we have to ensure that + * the last xmodem block of header contains beginning of the data + * followed by the header. So align header size to xmodem block size. + */ + hdrsz += (KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ) % KWBOOT_XM_BLKSZ; + kwboot_printv("Waiting 2s and flushing tty\n"); sleep(2); /* flush isn't effective without it */ tcflush(tty, TCIOFLUSH); @@ -1083,12 +1091,17 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate) if (rc) return rc; - img += hdrsz; - size -= hdrsz; - - rc = kwboot_xmodem_one(tty, &pnum, 0, img, size, 0); - if (rc) - return rc; + /* + * If we have already sent image data as a part of the last + * xmodem header block then we have nothing more to send. + */ + if (hdrsz < size) { + img += hdrsz; + size -= hdrsz; + rc = kwboot_xmodem_one(tty, &pnum, 0, img, size, 0); + if (rc) + return rc; + } rc = kwboot_xm_finish(tty); if (rc) -- 2.20.1