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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2DDF5C433EF for ; Thu, 17 Feb 2022 09:44:52 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CA80983AA5; Thu, 17 Feb 2022 10:44:43 +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="VvvjP4J2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F349783A7B; Thu, 17 Feb 2022 10:44:30 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) (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 1599D83A9B for ; Thu, 17 Feb 2022 10:44: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=pali@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 ams.source.kernel.org (Postfix) with ESMTPS id B26B9B82159; Thu, 17 Feb 2022 09:44:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57985C340E8; Thu, 17 Feb 2022 09:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645091059; bh=uCRHkEbBTbb2J/nYPriZavPOeuFwiuXDLIoEqJBN8sw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VvvjP4J2huGEX79gRNqa3nlAKj8N0VmfkOKyMX7wA5IraECL809aZap3w41cZHuGs 0WhKwplpT3Ftm6GIXZolCyoQnjt0w6QJae4oL9lMUJVHTPbAI6ceM0LP8C4FqepYoi uSx6uISQRnsDUuYh+U+xc4Pq2eFaLvVjG7Vp5UDS51aVx817hcG9xJD+nApn0aVh7S +D1TfezZBcpJQ3lhTMCUM//UM4szEX8C2O3fEheqw6np65/L1YsTata8AUmxIifddr qaqxoCzs7Qm07a9HLl7LyG7MPZsf9kW60laEA/OCRqiQmWw9OttSOX2XPTo22gSyBl 9IpLaU1f/VULA== Received: by pali.im (Postfix) id 33EEF1257; Thu, 17 Feb 2022 10:44:17 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Tony Dinh Cc: u-boot@lists.denx.de Subject: [PATCH u-boot-marvell v2 2/7] tools: kwbimage: Fix calculating size of kwbimage v0 header Date: Thu, 17 Feb 2022 10:43:35 +0100 Message-Id: <20220217094340.9048-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220217094340.9048-1-pali@kernel.org> References: <20220215185925.16060-1-pali@kernel.org> <20220217094340.9048-1-pali@kernel.org> 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.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 Extended and binary headers are optional and are part of the image header. Fixes kwboot to determinate correct length of Dove images. Signed-off-by: Pali Rohár Tested-by: Tony Dinh Reviewed-by: Stefan Roese --- tools/kwbimage.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/kwbimage.h b/tools/kwbimage.h index 706bebddf4fa..502b6d503305 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -240,8 +240,20 @@ static inline size_t kwbheader_size(const void *header) if (kwbimage_version(header) == 0) { const struct main_hdr_v0 *hdr = header; + /* + * First extension header starts immediately after the main + * header without any padding. Between extension headers is + * 0x20 byte padding. There is no padding after the last + * extension header. First binary code header starts immediately + * after the last extension header (or immediately after the + * main header if there is no extension header) without any + * padding. There is no padding between binary code headers and + * neither after the last binary code header. + */ return sizeof(*hdr) + - hdr->ext ? sizeof(struct ext_hdr_v0) : 0; + hdr->ext * sizeof(struct ext_hdr_v0) + + ((hdr->ext > 1) ? ((hdr->ext - 1) * 0x20) : 0) + + hdr->bin * sizeof(struct bin_hdr_v0); } else { const struct main_hdr_v1 *hdr = header; -- 2.20.1