summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMarshall Dawson <marshalldawson3rd@gmail.com>2019-07-23 07:24:30 -0600
committerPatrick Georgi <pgeorgi@google.com>2019-07-29 05:58:08 +0000
commitb85ddc5d44cb76fa3dbec461c949fb79b66decec (patch)
tree7fbd6557424a824e9caaaaaeed309e4664287b7b /util
parentdffa781558535bec98d2ebee0a0cb84d62e2f535 (diff)
downloadcoreboot-b85ddc5d44cb76fa3dbec461c949fb79b66decec.tar.xz
util/amdfwtool: Correct fletcher32 algorithm
Change the fletcher32 checksum calculation to match PSP and AGESA implementations. The symptom of the failure has only been noted in Picasso's BIOS Directory Table, when a BIOS binary image of different sizes were passed to amdfwtool. The PSP halts the boot process with the bad BDT checksum, and if allowed to continue, AGESA asserts later due to a failed BDT verification. This version has been verified to produce the same result as found at https://en.wikipedia.org/wiki/Fletcher%27s_checksum. TEST=Build apu2, bettong, grunt and verify before/after amdfw.rom is unchanged. Change-Id: I2ba2c49a70aa81c15acaab0be6b4c95e7891234f Signed-off-by: Marshall Dawson <marshalldawson3rd@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/34574 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Martin Roth <martinroth@google.com>
Diffstat (limited to 'util')
-rw-r--r--util/amdfwtool/amdfwtool.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index 1ecb7aaaab..4c5b2163d4 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -148,17 +148,15 @@ static uint32_t fletcher32(const void *data, int length)
c0 = 0xFFFF;
c1 = 0xFFFF;
- for (index = 0; index < length; index++) {
- /*
- * Ignore the contents of the checksum field.
- */
+ while (length) {
+ index = length >= 359 ? 359 : length;
+ length -= index;
+ do {
c0 += *(pptr++);
c1 += c0;
- if ((index % 360) == 0) {
- /* Sums[0,1] mod 64K + overflow */
- c0 = (c0 & 0xFFFF) + (c0 >> 16);
- c1 = (c1 & 0xFFFF) + (c1 >> 16);
- }
+ } while (--index);
+ c0 = (c0 & 0xFFFF) + (c0 >> 16);
+ c1 = (c1 & 0xFFFF) + (c1 >> 16);
}
/* Sums[0,1] mod 64K + overflow */