All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: "Stefan Roese" <sr@denx.de>, "Marek Behún" <marek.behun@nic.cz>,
	"Tony Dinh" <mibodhi@gmail.com>
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	[thread overview]
Message-ID: <20220217094340.9048-3-pali@kernel.org> (raw)
In-Reply-To: <20220217094340.9048-1-pali@kernel.org>

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 <pali@kernel.org>
Tested-by: Tony Dinh <mibodhi@gmail.com>
Reviewed-by: Stefan Roese <sr@denx.de>
---
 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


  parent reply	other threads:[~2022-02-17  9:44 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-15 18:59 [PATCH u-boot-marvell 0/7] tools: kwbimage: Support for parsing extended v0 format Pali Rohár
2022-02-15 18:59 ` [PATCH u-boot-marvell 1/7] tools: kwbimage: Define structures for extended kwbimage v0 headers Pali Rohár
2022-02-16  9:47   ` Stefan Roese
2022-02-15 18:59 ` [PATCH u-boot-marvell 2/7] tools: kwbimage: Fix calculating size of kwbimage v0 header Pali Rohár
2022-02-16  9:47   ` Stefan Roese
2022-02-15 18:59 ` [PATCH u-boot-marvell 3/7] tools: kwbimage: Add support for dumping extended and binary v0 headers Pali Rohár
2022-02-16  9:48   ` Stefan Roese
2022-02-15 18:59 ` [PATCH u-boot-marvell 4/7] tools: kwbimage: Do not show mkimage error message in dumpimage Pali Rohár
2022-02-16  9:48   ` Stefan Roese
2022-02-15 18:59 ` [PATCH u-boot-marvell 5/7] tools: kwbimage: Add support for NAND_BLKSZ and NAND_BADBLK_LOCATION for v0 images Pali Rohár
2022-02-16  9:48   ` Stefan Roese
2022-02-15 18:59 ` [PATCH u-boot-marvell 6/7] tools: kwbimage: Fix help how to extract DDR3 training code Pali Rohár
2022-02-16  9:49   ` Stefan Roese
2022-02-15 18:59 ` [PATCH u-boot-marvell 7/7] tools: kwbimage: Add me as an author of kwbimage Pali Rohár
2022-02-16  9:49   ` Stefan Roese
2022-02-16  9:55 ` [PATCH u-boot-marvell 0/7] tools: kwbimage: Support for parsing extended v0 format Tony Dinh
2022-02-17  7:10 ` Stefan Roese
2022-02-17  9:18   ` Pali Rohár
2022-02-17  9:43 ` [PATCH u-boot-marvell v2 " Pali Rohár
2022-02-17  9:43   ` [PATCH u-boot-marvell v2 1/7] tools: kwbimage: Define structures for extended kwbimage v0 headers Pali Rohár
2022-02-17  9:43   ` Pali Rohár [this message]
2022-02-17  9:43   ` [PATCH u-boot-marvell v2 3/7] tools: kwbimage: Add support for dumping extended and binary " Pali Rohár
2022-02-17 10:57     ` Stefan Roese
2022-02-17  9:43   ` [PATCH u-boot-marvell v2 4/7] tools: kwbimage: Do not show mkimage error message in dumpimage Pali Rohár
2022-02-17  9:43   ` [PATCH u-boot-marvell v2 5/7] tools: kwbimage: Add support for NAND_BLKSZ and NAND_BADBLK_LOCATION for v0 images Pali Rohár
2022-02-17  9:43   ` [PATCH u-boot-marvell v2 6/7] tools: kwbimage: Fix help how to extract DDR3 training code Pali Rohár
2022-02-17  9:43   ` [PATCH u-boot-marvell v2 7/7] tools: kwbimage: Add me as an author of kwbimage Pali Rohár
2022-02-17 15:39   ` [PATCH u-boot-marvell v2 0/7] tools: kwbimage: Support for parsing extended v0 format Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220217094340.9048-3-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=marek.behun@nic.cz \
    --cc=mibodhi@gmail.com \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.