From ee3da92d85aea4dad6d6d7c82b23407b85547325 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Mon, 9 Jan 2023 01:35:13 +0100 Subject: [PATCH] tools: kwbimage: Fix generating of kwbimage v0 header checksum MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Checksum for v0 image must be generated after filling all fields in the main header. Otherwise it would be invalid. Exactly same problem for v1 images was already fixed in the past in commit 9203c73895ab ("tools: kwbimage: Fix checksum calculation for v1 images"). Fixes: 5c61710c9880 ("tools: kwbimage: Properly set srcaddr in kwbimage v0") Signed-off-by: Pali Rohár --- tools/kwbimage.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index b6deb978f6..1128c934dd 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1009,8 +1009,6 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, e = image_find_option(IMAGE_CFG_NAND_BADBLK_LOCATION); if (e) main_hdr->nandbadblklocation = e->nandbadblklocation; - main_hdr->checksum = image_checksum8(image, - sizeof(struct main_hdr_v0)); /* * For SATA srcaddr is specified in number of sectors. @@ -1049,6 +1047,9 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, sizeof(struct ext_hdr_v0)); } + main_hdr->checksum = image_checksum8(image, + sizeof(struct main_hdr_v0)); + *imagesz = headersz; return image; } -- 2.39.5