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 <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/80251
Reviewed-by: Yidi Lin <yidilin@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Jakub Czapiga <czapiga@google.com>
diff --git a/tests/lib/Makefile.mk b/tests/lib/Makefile.mk
index 0cab1ba..b8c4c71 100644
--- a/tests/lib/Makefile.mk
+++ b/tests/lib/Makefile.mk
@@ -22,7 +22,6 @@
tests-y += malloc-test
tests-y += memmove-test
tests-y += crc_byte-test
-tests-y += compute_ip_checksum-test
tests-y += memrange-test
tests-y += uuid-test
tests-y += bootmem-test
@@ -123,9 +122,6 @@
crc_byte-test-srcs += tests/lib/crc_byte-test.c
crc_byte-test-srcs += src/lib/crc_byte.c
-compute_ip_checksum-test-srcs += tests/lib/compute_ip_checksum-test.c
-compute_ip_checksum-test-srcs += src/lib/compute_ip_checksum.c
-
memrange-test-srcs += tests/lib/memrange-test.c
memrange-test-srcs += src/lib/memrange.c
memrange-test-srcs += tests/stubs/console.c
@@ -148,7 +144,7 @@
coreboot_table-test-srcs += tests/lib/coreboot_table-test.c
coreboot_table-test-srcs += tests/stubs/console.c
-coreboot_table-test-srcs += src/lib/compute_ip_checksum.c
+coreboot_table-test-srcs += src/commonlib/bsd/ipchksum.c
coreboot_table-test-srcs += src/lib/coreboot_table.c
coreboot_table-test-srcs += src/lib/imd_cbmem.c
coreboot_table-test-srcs += src/lib/imd.c