]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: kwbimage: Fix checksum calculation for v1 images
authorPierre Bourdon <delroth@gmail.com>
Sat, 25 Dec 2021 19:50:19 +0000 (20:50 +0100)
committerStefan Roese <sr@denx.de>
Wed, 5 Jan 2022 15:31:58 +0000 (16:31 +0100)
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>
Reviewed-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
tools/kwbimage.c

index da8bfe0518cb7ea742a0fe52123fe060c8eab593..224d8156be19ce03934557ea3e90a9882b75737b 100644 (file)
@@ -1400,9 +1400,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 */
@@ -1412,6 +1409,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;
 }