Use "p->sum -= checksum()" style for setting checksums.
Some code cleared the original checksum and then calculated a new one,
others manipulated the checksum range to not include the old
checksum. However, this was error prone - use the "-=" syntax
consistently to reduce possible errors.
diff --git a/src/acpi.c b/src/acpi.c
index f140f1a..72977b1 100644
--- a/src/acpi.c
+++ b/src/acpi.c
@@ -236,7 +236,7 @@
memcpy(h->oem_table_id + 4, (void*)&sig, 4);
h->oem_revision = cpu_to_le32(1);
h->asl_compiler_revision = cpu_to_le32(1);
- h->checksum = -checksum(h, len);
+ h->checksum -= checksum(h, len);
}
#define SSDT_SIGNATURE 0x54445353// SSDT
@@ -369,7 +369,7 @@
rsdp->signature = RSDP_SIGNATURE;
memcpy(rsdp->oem_id, CONFIG_APPNAME6, 6);
rsdp->rsdt_physical_address = cpu_to_le32(rsdt_addr);
- rsdp->checksum = -checksum(rsdp, 20);
+ rsdp->checksum -= checksum(rsdp, 20);
RsdpAddr = rsdp;
/* RSDT */
diff --git a/src/ata.c b/src/ata.c
index 3b609c5..699eecd 100644
--- a/src/ata.c
+++ b/src/ata.c
@@ -951,8 +951,7 @@
fdpt->a0h_signature = 0xa0;
// Checksum structure.
- u8 sum = checksum(fdpt, sizeof(*fdpt)-1);
- fdpt->checksum = -sum;
+ fdpt->checksum -= checksum(fdpt, sizeof(*fdpt));
}
// Map a drive (that was registered via add_bcv_hd)
diff --git a/src/coreboot.c b/src/coreboot.c
index 859928f..b8479c5 100644
--- a/src/coreboot.c
+++ b/src/coreboot.c
@@ -62,8 +62,7 @@
memcpy((void*)bios_table_cur_addr, pos, length);
struct mptable_floating_s *newp = (void*)bios_table_cur_addr;
newp->physaddr = bios_table_cur_addr + length;
- newp->checksum = 0;
- newp->checksum = -checksum(newp, sizeof(*newp));
+ newp->checksum -= checksum(newp, sizeof(*newp));
memcpy((void*)bios_table_cur_addr + length, (void*)p->physaddr, mpclength);
bios_table_cur_addr += length + mpclength;
}
diff --git a/src/mptable.c b/src/mptable.c
index 47aee24..e81bd62 100644
--- a/src/mptable.c
+++ b/src/mptable.c
@@ -44,7 +44,7 @@
floating->physaddr = (u32)config;
floating->length = 1;
floating->spec_rev = 4;
- floating->checksum = -checksum(floating, sizeof(*floating));
+ floating->checksum -= checksum(floating, sizeof(*floating));
// Config structure.
memset(config, 0, sizeof(*config));
@@ -106,7 +106,7 @@
}
// Set checksum.
- config->checksum = -checksum(config, config->length);
+ config->checksum -= checksum(config, config->length);
dprintf(1, "MP table addr=0x%x MPC table addr=0x%x size=0x%x\n",
(u32)floating, (u32)config, length);
diff --git a/src/pirtable.c b/src/pirtable.c
index a96ffbc..a83d4f7 100644
--- a/src/pirtable.c
+++ b/src/pirtable.c
@@ -100,6 +100,6 @@
dprintf(3, "init PIR table\n");
PIR_TABLE.pir.signature = PIR_SIGNATURE;
- PIR_TABLE.pir.checksum = -checksum(&PIR_TABLE, sizeof(PIR_TABLE));
+ PIR_TABLE.pir.checksum -= checksum(&PIR_TABLE, sizeof(PIR_TABLE));
PirOffset = (u32)&PIR_TABLE.pir - BUILD_BIOS_ADDR;
}
diff --git a/src/pnpbios.c b/src/pnpbios.c
index cf78f00..7d9ece5 100644
--- a/src/pnpbios.c
+++ b/src/pnpbios.c
@@ -99,5 +99,5 @@
PNPHEADER.real_ip = (u32)entry_pnp_real - BUILD_BIOS_ADDR;
PNPHEADER.prot_ip = (u32)entry_pnp_prot - BUILD_BIOS_ADDR;
- PNPHEADER.checksum = -checksum(&PNPHEADER, sizeof(PNPHEADER));
+ PNPHEADER.checksum -= checksum(&PNPHEADER, sizeof(PNPHEADER));
}
diff --git a/src/post.c b/src/post.c
index 638f95a..b018935 100644
--- a/src/post.c
+++ b/src/post.c
@@ -209,7 +209,7 @@
boot_prep();
// Setup bios checksum.
- BiosChecksum = -checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE - 1);
+ BiosChecksum -= checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE);
// Prep for boot process.
make_bios_readonly();
diff --git a/src/smbios.c b/src/smbios.c
index 40812e3..e9a4b31 100644
--- a/src/smbios.c
+++ b/src/smbios.c
@@ -244,12 +244,9 @@
ep->number_of_structures = number_of_structures;
ep->smbios_bcd_revision = 0x24;
- ep->checksum = 0;
- ep->intermediate_checksum = 0;
+ ep->checksum -= checksum(start, 0x10);
- ep->checksum = -checksum(start, 0x10);
-
- ep->intermediate_checksum = -checksum(start + 0x10, ep->length - 0x10);
+ ep->intermediate_checksum -= checksum(start + 0x10, ep->length - 0x10);
}
/* Type 0 -- BIOS Information */