All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre Bourdon <delroth@gmail.com>
To: u-boot@lists.denx.de
Cc: "Pali Rohár" <pali@kernel.org>,
	"Marek Behún" <marek.behun@nic.cz>,
	"Pierre Bourdon" <delroth@gmail.com>
Subject: [PATCH] tools: kwbimage: Fix checksum calculation for v1 images
Date: Sat, 25 Dec 2021 20:50:19 +0100	[thread overview]
Message-ID: <20211225195019.1509965-1-delroth@gmail.com> (raw)

Recent changes caused fields in the image main header to be modified
after the header checksum had already been computed. Move the checksum
computation to once again be the last operation performed on the header.

Fixes: 2b0980c24027 ("tools: kwbimage: Fill the real header size into the main header")

Signed-off-by: Pierre Bourdon <delroth@gmail.com>
---
 tools/kwbimage.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 875f636c7a..0951d7861c 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1398,9 +1398,6 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 					       headersz, image, secure_hdr))
 		return NULL;
 
-	/* Calculate and set the header checksum */
-	main_hdr->checksum = image_checksum8(main_hdr, headersz);
-
 	*imagesz = headersz;
 
 	/* Fill the real header size without padding into the main header */
@@ -1410,6 +1407,9 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 	main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF);
 	main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16;
 
+	/* Calculate and set the header checksum */
+	main_hdr->checksum = image_checksum8(main_hdr, headersz);
+
 	return image;
 }
 
-- 
2.34.0


             reply	other threads:[~2021-12-25 19:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-25 19:50 Pierre Bourdon [this message]
2021-12-25 19:59 ` [PATCH] tools: kwbimage: Fix checksum calculation for v1 images Pali Rohár
2022-01-05 15:30 ` Stefan Roese
2022-01-05 17:27   ` 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=20211225195019.1509965-1-delroth@gmail.com \
    --to=delroth@gmail.com \
    --cc=marek.behun@nic.cz \
    --cc=pali@kernel.org \
    --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.