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 D17C7C433EF for ; Tue, 15 Feb 2022 19:00:37 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CA612839E8; Tue, 15 Feb 2022 20:00:18 +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="tEdDSEpq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 46D00836A8; Tue, 15 Feb 2022 19:59:55 +0100 (CET) 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 204DC83845 for ; Tue, 15 Feb 2022 19:59:46 +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 dfw.source.kernel.org (Postfix) with ESMTPS id ACE1661731; Tue, 15 Feb 2022 18:59:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CBDCC340EB; Tue, 15 Feb 2022 18:59:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644951584; bh=7Xv27Ih/7Ze9VoAj8FIHUR2aQ35pCYnmO26LYEG1Buo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tEdDSEpqYitnfOcfG46NwebTHl8mf8AT2Sii7OnscULIYiYCZ3psdnWoH9W3MXoT8 IeDpxMBVaQbVxXVzlJr3FKTUgAg1kNyuEWoiIYXsJQbG6HbsjnlyaiFHn1aGP3Wns/ /cMs+p7dBK5TYb23TRI2Bo2jAAM/nkzzSeMcxC7zbq5J7ZlKj+/ibGvyEQw0FlqfkJ wqkijRqfSh91y3eR3eNcCYE7GDjh8k4VRVtpLGCwkuGouynROwdqT12h1tpy5319Cc TPifqa67wtGO5bnirrAtLjYJGvh6OpnY+9YdbAD96VAv1oP3xAP+tXherIRqrQyk6J 0TMauh1K/UHtw== Received: by pali.im (Postfix) id 295AD2B24; Tue, 15 Feb 2022 19:59:42 +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 2/7] tools: kwbimage: Fix calculating size of kwbimage v0 header Date: Tue, 15 Feb 2022 19:59:20 +0100 Message-Id: <20220215185925.16060-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220215185925.16060-1-pali@kernel.org> References: <20220215185925.16060-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 --- 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