Make the ipchecksum function usable in the ipv6 stack.
Change-Id: I84048de2f6e67502b2042c04f9fd0d25fd50b384
diff --git a/src/base/ipchecksum.c b/src/base/ipchecksum.c
index 12e4c4e..7789b9e 100644
--- a/src/base/ipchecksum.c
+++ b/src/base/ipchecksum.c
@@ -30,23 +30,18 @@
#include <stddef.h>
#include <stdint.h>
-uint16_t ipchecksum(const void *vptr, size_t nbytes)
+uint16_t ipchecksum(const void *_ptr, size_t nbytes, uint16_t _sum)
{
- int sum, oddbyte;
- const uint16_t *ptr = vptr;
+ uint32_t sum = (uint16_t)~_sum;
+ const uint16_t *ptr = _ptr;
- sum = 0;
while (nbytes > 1) {
sum += *ptr++;
nbytes -= 2;
}
- if (nbytes == 1) {
- oddbyte = 0;
- ((uint8_t *)&oddbyte)[0] = *(uint8_t *)ptr;
- ((uint8_t *)&oddbyte)[1] = 0;
- sum += oddbyte;
- }
- sum = (sum >> 16) + (sum & 0xffff);
- sum += (sum >> 16);
- return (~sum);
+ if (nbytes)
+ sum += (uint32_t)*(uint8_t *)ptr;
+ while (sum > 0xffff)
+ sum = (sum >> 16) + (sum & 0xffff);
+ return ~sum;
}
diff --git a/src/base/ipchecksum.h b/src/base/ipchecksum.h
index f7318b0..9b5cd2e 100644
--- a/src/base/ipchecksum.h
+++ b/src/base/ipchecksum.h
@@ -31,6 +31,6 @@
#include <stddef.h>
#include <stdint.h>
-uint16_t ipchecksum(const void *ptr, size_t nbytes);
+uint16_t ipchecksum(const void *ptr, size_t nbytes, uint16_t sum);
#endif
diff --git a/src/libpayload/include/coreboot_tables.h b/src/libpayload/include/coreboot_tables.h
index 53e91ed..647d701 100644
--- a/src/libpayload/include/coreboot_tables.h
+++ b/src/libpayload/include/coreboot_tables.h
@@ -331,7 +331,7 @@
static inline uint16_t cb_checksum(const void *ptr, unsigned len)
{
- return ipchecksum(ptr, len);
+ return ipchecksum(ptr, len, 0);
}
static inline const char *cb_mb_vendor_string(const struct cb_mainboard *cbm)
diff --git a/src/module/handoff/coreboot.c b/src/module/handoff/coreboot.c
index 7428c11..488bbc4 100644
--- a/src/module/handoff/coreboot.c
+++ b/src/module/handoff/coreboot.c
@@ -279,14 +279,14 @@
return -1;
/* Make sure the checksums match. */
- if (ipchecksum((uint16_t *)header, sizeof(*header)) != 0)
+ if (ipchecksum((uint16_t *)header, sizeof(*header), 0) != 0)
return -1;
if (!header->table_bytes)
return 0;
if (ipchecksum((uint16_t *)(ptr + sizeof(*header)),
- header->table_bytes) != header->table_checksum)
+ header->table_bytes, 0) != header->table_checksum)
return -1;
info->header = header;
diff --git a/src/module/netboot.c b/src/module/netboot.c
index c919a3f..aecbbcb 100644
--- a/src/module/netboot.c
+++ b/src/module/netboot.c
@@ -82,6 +82,7 @@
srand(timer_raw_value());
+ printf("About to netboot.\n");
if (CONFIG_GIGABOOT)
gigaboot();
else