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 BADA7C433EF for ; Wed, 10 Nov 2021 08:21:01 +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 E1F7C611C0 for ; Wed, 10 Nov 2021 08:21:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E1F7C611C0 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 79ABE83986; Wed, 10 Nov 2021 09:20:58 +0100 (CET) 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=1636532459; bh=KQdjrF2UJsVFbEarcZrN+qEeyfUOc7J9Ffh+mVN/1+8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gv5dfmD98jVCJHq5ZlWKTFG0hrlON2Bz8ByzKbJzl68TecPkoPui1NIdz787r5/Ma 9s8ijA78HZSXE7oZxpZyhK6zO0Stwk8Iig/SNJ+pb64jkB6eJWSgajumFI8+gr5w8k VoaKJUpmLG5cV9cJ30h0XZ2dC+S0OetVm+liOvmDoPz1GIYRH74xQTfUBkGCw4UPA/ yQqAmI1/m47V3AqSwUfdBfR1LwZmI7uSfZ2cZ8sFJ4vngtA+ps8h+PrORDNJYspdZ9 550cInj36JOO3d1vGn4vsBHLajCelhB3NtIOBr2xre5XE5UtMq/cI/bWS1rHtMlwAW /BXQJb9LZEhUA== Received: by phobos.denx.de (Postfix, from userid 109) id 84AAA83986; Wed, 10 Nov 2021 09:20:56 +0100 (CET) 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 916F483983 for ; Wed, 10 Nov 2021 09:20:53 +0100 (CET) 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 smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:105:465:1:4:0]) (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 4HpyTx3bmbzQl4Y; Wed, 10 Nov 2021 09:20:53 +0100 (CET) Message-ID: <93f2dd9b-e054-8a94-7227-b772870aa9fe@denx.de> Date: Wed, 10 Nov 2021 09:20:48 +0100 MIME-Version: 1.0 Subject: Re: [PATCH] tools: kwboot: Fix sending Kirkwood v0 images Content-Language: en-US To: =?UTF-8?Q?Pali_Roh=c3=a1r?= Cc: =?UTF-8?Q?Marek_Beh=c3=ban?= , Tony Dinh , u-boot@lists.denx.de References: <20211105222958.17034-1-pali@kernel.org> From: Stefan Roese In-Reply-To: <20211105222958.17034-1-pali@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed 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 On 05.11.21 23:29, Pali Rohár wrote: > 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 Reviewed-by: Stefan Roese Thanks, Stefan > --- > 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) > Viele Grüße, Stefan Roese -- 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