summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMarshall Dawson <marshalldawson3rd@gmail.com>2019-02-24 07:18:44 -0700
committerMartin Roth <martinroth@google.com>2019-03-07 16:00:30 +0000
commit8a45a4dc3f27e5088ea6e10322b52d503da90270 (patch)
treefb7f0158ae67069d793d7555816bcb3c31351aa4 /util
parent239286ca44b243aebaf71e3876daecdd9b1c899a (diff)
downloadcoreboot-8a45a4dc3f27e5088ea6e10322b52d503da90270.tar.xz
util/amdfwtool: Clarify call to fletcher32
The fletcher32 algorithm generates a sum over a range of 16-bit WORDs. Change the function's interface to be more generic, accepting a more intuitive size in BYTEs. Don't require the caller to understand the nature of the algorithm and convert to WORDs prior to calling. TEST=Verify no difference in amdfw.rom for google/grunt before and after the patch is applied Change-Id: Iad70558347cbdb3c51bd598479ee4484219c0869 Signed-off-by: Marshall Dawson <marshalldawson3rd@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/31728 Reviewed-by: Martin Roth <martinroth@google.com> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/amdfwtool/amdfwtool.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index 3ed6885624..e1c59aec6a 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -121,12 +121,15 @@ typedef unsigned short uint16_t;
* inserted 8 bytes after the beginning of the file.
* stderr: Used to print out error messages.
*/
-static uint32_t fletcher32(const uint16_t *pptr, int length)
+static uint32_t fletcher32(const void *data, int length)
{
uint32_t c0;
uint32_t c1;
uint32_t checksum;
int index;
+ const uint16_t *pptr = data;
+
+ length /= 2;
c0 = 0xFFFF;
c1 = 0xFFFF;
@@ -138,13 +141,15 @@ static uint32_t fletcher32(const uint16_t *pptr, int length)
c0 += *(pptr++);
c1 += c0;
if ((index % 360) == 0) {
- c0 = (c0 & 0xFFFF) + (c0 >> 16); // Sum0 modulo 65535 + the overflow
- c1 = (c1 & 0xFFFF) + (c1 >> 16); // Sum1 modulo 65535 + the overflow
+ /* Sums[0,1] mod 64K + overflow */
+ c0 = (c0 & 0xFFFF) + (c0 >> 16);
+ c1 = (c1 & 0xFFFF) + (c1 >> 16);
}
}
- c0 = (c0 & 0xFFFF) + (c0 >> 16); // Sum0 modulo 65535 + the overflow
- c1 = (c1 & 0xFFFF) + (c1 >> 16); // Sum1 modulo 65535 + the overflow
+ /* Sums[0,1] mod 64K + overflow */
+ c0 = (c0 & 0xFFFF) + (c0 >> 16);
+ c1 = (c1 & 0xFFFF) + (c1 >> 16);
checksum = (c1 << 16) | c0;
return checksum;
@@ -331,9 +336,9 @@ static void fill_psp_head(psp_directory_table *pspdir, uint32_t count)
/* checksum everything that comes after the Checksum field */
pspdir->header.checksum = fletcher32(
(void *)&pspdir->header.num_entries,
- (count * sizeof(psp_directory_entry)
+ count * sizeof(psp_directory_entry)
+ sizeof(pspdir->header.num_entries)
- + sizeof(pspdir->header.reserved)) / 2);
+ + sizeof(pspdir->header.reserved));
}
static uint32_t integrate_firmwares(char *base, uint32_t pos,
@@ -848,11 +853,11 @@ int main(int argc, char **argv)
combo_dir->header.reserved[1] = 0;
combo_dir->header.checksum = fletcher32(
(void *)&combo_dir->header.num_entries,
- (1 * sizeof(psp_directory_entry)
+ 1 * sizeof(psp_directory_entry)
+ sizeof(combo_dir->header.num_entries)
+ sizeof(combo_dir->header.lookup)
+ sizeof(combo_dir->header.reserved[0])
- + sizeof(combo_dir->header.reserved[1])) / 2);
+ + sizeof(combo_dir->header.reserved[1]));
#else
current = integrate_psp_firmwares(rom, current, psp2dir,
amd_psp2_fw_table, rom_size);