From 7d9c083844cec1cbbd72494210af20f17b3b7642 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
Date: Sun, 29 Jan 2023 18:38:11 +0100
Subject: [PATCH] cmd: mvebu/bubt: Do not modify image in A8K
 check_image_header()
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Change checksum verification code so it does require to modify image.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 cmd/mvebu/bubt.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index 820d342ae1..1b08ca9298 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -739,18 +739,14 @@ static int check_image_header(void)
 		return -ENOEXEC;
 	}
 
-	/* The checksum value is discarded from checksum calculation */
-	hdr->prolog_checksum = 0;
-
 	checksum = do_checksum32((u32 *)hdr, header_len);
+	checksum -= hdr->prolog_checksum;
 	if (checksum != checksum_ref) {
 		printf("Error: Bad Image checksum. 0x%x != 0x%x\n",
 		       checksum, checksum_ref);
 		return -ENOEXEC;
 	}
 
-	/* Restore the checksum before writing */
-	hdr->prolog_checksum = checksum_ref;
 	printf("Image checksum...OK!\n");
 
 	return 0;
-- 
2.39.5