[PATCH 08/14] bloblist: Change the checksum algorithm

Simon Glass sjg at chromium.org
Tue Jul 25 23:36:20 CEST 2023


Use a sinple 8-bit checksum for bloblist, as specified by the spec
version 0.9

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 common/bloblist.c  | 14 ++++++++------
 include/bloblist.h |  5 ++---
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/common/bloblist.c b/common/bloblist.c
index 96b82fe625c..77892582b90 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -13,6 +13,7 @@
 #include <malloc.h>
 #include <mapmem.h>
 #include <spl.h>
+#include <tables_csum.h>
 #include <asm/global_data.h>
 #include <u-boot/crc.h>
 
@@ -308,14 +309,15 @@ int bloblist_resize(uint tag, int new_size)
 static u32 bloblist_calc_chksum(struct bloblist_hdr *hdr)
 {
 	struct bloblist_rec *rec;
-	u32 chksum;
+	u8 chksum;
 
-	chksum = crc32(0, (unsigned char *)hdr,
-		       offsetof(struct bloblist_hdr, chksum));
+	chksum = table_compute_checksum(hdr, hdr->hdr_size);
+	chksum += hdr->chksum;
 	foreach_rec(rec, hdr) {
-		chksum = crc32(chksum, (void *)rec, rec_hdr_size(rec));
-		chksum = crc32(chksum, (void *)rec + rec_hdr_size(rec),
-			       rec->size);
+		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/include/bloblist.h b/include/bloblist.h
index 6592ea75403..ee3644878b2 100644
--- a/include/bloblist.h
+++ b/include/bloblist.h
@@ -156,11 +156,10 @@ enum bloblist_tag_t {
  * @alloced: Total size allocated so far for this bloblist. This starts out as
  *	sizeof(bloblist_hdr) since we need at least that much space to store a
  *	valid bloblist
- * @chksum: CRC32 for the entire bloblist allocated area. Since any of the
+ * @chksum: checksum for the entire bloblist allocated area. Since any of the
  *	blobs can be altered after being created, this checksum is only valid
  *	when the bloblist is finalised before jumping to the next stage of boot.
- *	Note that chksum is last to make it easier to exclude it from the
- *	checksum calculation.
+ *	This is the value needed to make all checksummed bytes sum to 0
  */
 struct bloblist_hdr {
 	u32 magic;
-- 
2.41.0.487.g6d72f3e995-goog



More information about the U-Boot mailing list