[PATCH v2 09/18] bloblist: Checksum the entire bloblist

Raymond Mao raymond.mao at linaro.org
Mon Nov 27 20:50:20 CET 2023


From: Simon Glass <sjg at chromium.org>

Spec v0.9 specifies that the entire bloblist area is checksummed,
including unused portions. Update the code to follow this.

Signed-off-by: Simon Glass <sjg at chromium.org>
Signed-off-by: Raymond Mao <raymond.mao at linaro.org>
---
 common/bloblist.c |  9 +--------
 test/bloblist.c   | 10 ++++++++--
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/common/bloblist.c b/common/bloblist.c
index 70ec0c13e6..96e0a167c2 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -317,17 +317,10 @@ int bloblist_resize(uint tag, int new_size)
 
 static u32 bloblist_calc_chksum(struct bloblist_hdr *hdr)
 {
-	struct bloblist_rec *rec;
 	u8 chksum;
 
-	chksum = table_compute_checksum(hdr, hdr->hdr_size);
+	chksum = table_compute_checksum(hdr, hdr->alloced);
 	chksum += hdr->chksum;
-	foreach_rec(rec, hdr) {
-		chksum -= table_compute_checksum((void *)rec,
-						 rec_hdr_size(rec));
-		chksum -= table_compute_checksum((void *)rec +
-						 rec_hdr_size(rec), rec->size);
-	}
 
 	return chksum;
 }
diff --git a/test/bloblist.c b/test/bloblist.c
index 9e51735d83..32256be772 100644
--- a/test/bloblist.c
+++ b/test/bloblist.c
@@ -226,12 +226,18 @@ static int bloblist_test_checksum(struct unit_test_state *uts)
 	*data2 -= 1;
 
 	/*
-	 * Changing data outside the range of valid data should not affect
-	 * the checksum.
+	 * Changing data outside the range of valid data should affect the
+	 * checksum.
 	 */
 	ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
 	data[TEST_SIZE]++;
+	ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
+	data[TEST_SIZE]--;
+	ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
+
 	data2[TEST_SIZE2]++;
+	ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
+	data[TEST_SIZE]--;
 	ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
 
 	return 0;
-- 
2.25.1



More information about the U-Boot mailing list