diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Makefile.mk | 3 | ||||
-rw-r--r-- | src/lib/compute_ip_checksum.c | 53 | ||||
-rw-r--r-- | src/lib/coreboot_table.c | 7 |
3 files changed, 3 insertions, 60 deletions
diff --git a/src/lib/Makefile.mk b/src/lib/Makefile.mk index fd3f464ffd..2a95be9d10 100644 --- a/src/lib/Makefile.mk +++ b/src/lib/Makefile.mk @@ -116,8 +116,6 @@ ramstage-y += rtc.c romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c romstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c -bootblock-y += compute_ip_checksum.c -romstage-y += compute_ip_checksum.c romstage-y += dimm_info_util.c ifeq ($(CONFIG_COMPILER_GCC),y) bootblock-$(CONFIG_ARCH_BOOTBLOCK_X86_32) += gcc.c @@ -145,7 +143,6 @@ ramstage-y += malloc.c ramstage-y += dimm_info_util.c ramstage-y += delay.c ramstage-y += fallback_boot.c -ramstage-y += compute_ip_checksum.c ramstage-y += cbfs.c ramstage-y += lzma.c lzmadecode.c ramstage-y += stack.c diff --git a/src/lib/compute_ip_checksum.c b/src/lib/compute_ip_checksum.c deleted file mode 100644 index 913f25c10c..0000000000 --- a/src/lib/compute_ip_checksum.c +++ /dev/null @@ -1,53 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ - -#include <stdint.h> -#include <ip_checksum.h> - -unsigned long compute_ip_checksum(const void *addr, unsigned long length) -{ - const uint8_t *ptr; - volatile union { - uint8_t byte[2]; - uint16_t word; - } value; - unsigned long sum; - unsigned long i; - /* In the most straight forward way possible, - * compute an ip style checksum. - */ - sum = 0; - ptr = addr; - for (i = 0; i < length; i++) { - unsigned long v; - v = ptr[i]; - if (i & 1) - v <<= 8; - /* Add the new value */ - sum += v; - /* Wrap around the carry */ - if (sum > 0xFFFF) - sum = (sum + (sum >> 16)) & 0xFFFF; - } - value.byte[0] = sum & 0xff; - value.byte[1] = (sum >> 8) & 0xff; - return (~value.word) & 0xFFFF; -} - -unsigned long add_ip_checksums(unsigned long offset, unsigned long sum, - unsigned long new) -{ - unsigned long checksum; - sum = ~sum & 0xFFFF; - new = ~new & 0xFFFF; - if (offset & 1) { - /* byte swap the sum if it came from an odd offset - * since the computation is endian independent this - * works. - */ - new = ((new >> 8) & 0xff) | ((new << 8) & 0xff00); - } - checksum = sum + new; - if (checksum > 0xFFFF) - checksum -= 0xFFFF; - return (~checksum) & 0xFFFF; -} 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 <acpi/acpi.h> #include <arch/cbconfig.h> +#include <commonlib/bsd/ipchksum.h> #include <console/console.h> #include <console/uart.h> #include <identity.h> -#include <ip_checksum.h> #include <boot/coreboot_tables.h> #include <boot/tables.h> #include <boot_device.h> @@ -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); |