summaryrefslogtreecommitdiffstats
path: root/resources/utilities/ich9deblob/src/gbe/gbe.c
diff options
context:
space:
mode:
authorFrancis Rowe <info@gluglug.org.uk>2015-01-10 19:51:32 (EST)
committer Francis Rowe <info@gluglug.org.uk>2015-01-10 22:04:47 (EST)
commitb833801ae4a0179ff29a661a9932fe0f56173d80 (patch)
tree09f32bce0ed6c6aa8f8c26a1ef6dd4267a8fed52 /resources/utilities/ich9deblob/src/gbe/gbe.c
parent2e909117e9733070a23d4164ba7c30b2f8d825a9 (diff)
downloadlibreboot-b833801ae4a0179ff29a661a9932fe0f56173d80.zip
libreboot-b833801ae4a0179ff29a661a9932fe0f56173d80.tar.gz
libreboot-b833801ae4a0179ff29a661a9932fe0f56173d80.tar.bz2
ich9deblob/ich9gen: re-factor the gbe checksum function
Diffstat (limited to 'resources/utilities/ich9deblob/src/gbe/gbe.c')
-rw-r--r--resources/utilities/ich9deblob/src/gbe/gbe.c34
1 files changed, 7 insertions, 27 deletions
diff --git a/resources/utilities/ich9deblob/src/gbe/gbe.c b/resources/utilities/ich9deblob/src/gbe/gbe.c
index 5f4cffc..9a7f44f 100644
--- a/resources/utilities/ich9deblob/src/gbe/gbe.c
+++ b/resources/utilities/ich9deblob/src/gbe/gbe.c
@@ -32,42 +32,22 @@
* ---------------------------------------------------------------------
*/
-/* Read a 16-bit unsigned int from a supplied region buffer */
-uint16_t gbeGetRegionWordFrom8kBuffer(int wordOffset, uint8_t* regionData)
-{
- int byteOffset = wordOffset << 1;
-
- uint16_t* regionDataWordAddress = (uint16_t*)(regionData+byteOffset);
- uint16_t regionWord = *regionDataWordAddress;
-
- return regionWord;
-}
-
/* gbe checksum calculation (algorithm based on datasheet) */
-uint16_t gbeGetChecksumFrom8kBuffer(uint8_t* regionData, uint16_t desiredValue, int byteOffset)
+uint16_t gbeGetChecksumFrom8kBuffer(uint16_t* regionData, uint16_t desiredValue, int gbeRegionBase)
{
- int i;
- int wordOffset = byteOffset >> 1;
-
- uint16_t regionWord; /* store words here for adding to checksum */
- uint16_t checksum = 0; /* this gbe's checksum */
+ int wordOffset;
+ uint16_t total = 0;
- for (i = 0; i < 0x3F; i++) {
- regionWord = gbeGetRegionWordFrom8kBuffer(i+wordOffset, regionData);
- checksum += regionWord;
- }
- checksum = desiredValue - checksum;
+ for (wordOffset = 0; wordOffset < 0x3F; wordOffset++)
+ total += regionData[wordOffset + (gbeRegionBase>>1)];
- return checksum;
+ return desiredValue - total;
}
/* checksum calculation for 4k gbe struct (algorithm based on datasheet) */
uint16_t gbeGetChecksumFrom4kStruct(struct GBEREGIONRECORD_4K gbeStruct4k, uint16_t desiredValue)
{
- uint8_t gbeBuffer4k[GBEREGIONSIZE_4K];
- memcpy(&gbeBuffer4k, &gbeStruct4k, GBEREGIONSIZE_4K);
-
- return gbeGetChecksumFrom8kBuffer(gbeBuffer4k, desiredValue, 0);
+ return gbeGetChecksumFrom8kBuffer((uint16_t*)&gbeStruct4k, desiredValue, 0);
}
/* modify the gbe region extracted from a factory.rom dump */