From de37109767b6b415778f34cbac196c8418f7e371 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Tue, 30 Jan 2024 16:51:05 -0800 Subject: lib: Move IP checksum to commonlib This patch moves the IP checksum algorithm into commonlib to prepare for it being shared with libpayload. The current implementation is ancient and pretty hard to read (and does some unnecessary questionable things like the type-punning stuff which leads to suboptimal code generation), so this reimplements it from scratch (that also helps with the licensing). This algorithm is prepared to take in a pre-calculated "wide" checksum in a machine-register-sized data type which is then narrowed down to 16 bits (see RFC 1071 for why that's valid). This isn't used yet (and the code will get optimized out), but will be used later in this patch series for architecture-specific optimization. Change-Id: Ic04c714c00439a17fc04a8a6e730cc2aa19b8e68 Signed-off-by: Julius Werner Reviewed-on: https://review.coreboot.org/c/coreboot/+/80251 Reviewed-by: Yidi Lin Tested-by: build bot (Jenkins) Reviewed-by: Jakub Czapiga --- src/lib/coreboot_table.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/lib/coreboot_table.c') diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c index 800d2d4bf2..d93ba01037 100644 --- a/src/lib/coreboot_table.c +++ b/src/lib/coreboot_table.c @@ -2,10 +2,10 @@ #include #include +#include #include #include #include -#include #include #include #include @@ -432,10 +432,9 @@ static unsigned long lb_table_fini(struct lb_header *head) } first_rec = lb_first_record(head); - head->table_checksum = compute_ip_checksum(first_rec, - head->table_bytes); + head->table_checksum = ipchksum(first_rec, head->table_bytes); head->header_checksum = 0; - head->header_checksum = compute_ip_checksum(head, sizeof(*head)); + head->header_checksum = ipchksum(head, sizeof(*head)); printk(BIOS_DEBUG, "Wrote coreboot table at: %p, 0x%x bytes, checksum %x\n", head, head->table_bytes, head->table_checksum); -- cgit v1.2.3