diff options
author | Francis Rowe <info@gluglug.org.uk> | 2014-12-24 00:33:45 +0000 |
---|---|---|
committer | Francis Rowe <info@gluglug.org.uk> | 2014-12-24 00:42:02 +0000 |
commit | 8ff050d3893f0115b8bd3f1feda5d032f89fbc32 (patch) | |
tree | 6f8a493c19c2f4bcc59adebb7a88bcea97a7b3ea /resources/utilities/ich9deblob/gbe/gbe.h | |
parent | 1082934d042a5f8b397afc48a0b92edd8d779610 (diff) | |
download | librebootfr-8ff050d3893f0115b8bd3f1feda5d032f89fbc32.tar.gz librebootfr-8ff050d3893f0115b8bd3f1feda5d032f89fbc32.zip |
ich9deblob: Replace makefile (use dependencies)
Use .h and .c files properly. Use header guards. Define function
names in .h files (actual functions in the .c files), and so on.
Move all functions from the .h files to corresponding .c files.
Diffstat (limited to 'resources/utilities/ich9deblob/gbe/gbe.h')
-rw-r--r-- | resources/utilities/ich9deblob/gbe/gbe.h | 81 |
1 files changed, 6 insertions, 75 deletions
diff --git a/resources/utilities/ich9deblob/gbe/gbe.h b/resources/utilities/ich9deblob/gbe/gbe.h index 0e3f0595..9647d806 100644 --- a/resources/utilities/ich9deblob/gbe/gbe.h +++ b/resources/utilities/ich9deblob/gbe/gbe.h @@ -33,9 +33,6 @@ #ifndef GBESTRUCT_H #define GBESTRUCT_H -#include <stdio.h> -#include <string.h> - /* Size of the full gbe region in bytes */ #define GBEREGIONSIZE_8K 0x2000 /* @@ -80,79 +77,13 @@ struct GBEREGIONRECORD_8K { /* * --------------------------------------------------------------------- - * Gbe functions: + * Function declarations (keep gcc/make happy. check them in gbe.c) * --------------------------------------------------------------------- */ - -/* Read a 16-bit unsigned int from a supplied region buffer */ -unsigned short gbeGetRegionWordFrom8kBuffer(int index, char* regionData) -{ - return *((unsigned short*)(regionData + (index * 2))); -} - -/* - * checksum calculation for 8k gbe region (algorithm based on datasheet) - * also works for 4k buffers, so long as isBackup remains false - */ -unsigned short gbeGetChecksumFrom8kBuffer(char* regionData, unsigned short desiredValue, char isBackup) -{ - int i; - - unsigned short regionWord; /* store words here for adding to checksum */ - unsigned short checksum = 0; /* this gbe's checksum */ - unsigned short offset = 0; /* in bytes, from the start of the gbe region. */ - - /* - * if isBackup is true, use 2nd gbe region ("backup" region) - * this function uses *word* not *byte* indexes, hence the bit shift. - */ - if (isBackup) offset = GBEREGIONSIZE_4K>>1; - - for (i = 0; i < 0x3F; i++) { - regionWord = gbeGetRegionWordFrom8kBuffer(i+offset, regionData); - checksum += regionWord; - } - checksum = desiredValue - checksum; - return checksum; -} - -/* checksum calculation for 4k gbe struct (algorithm based on datasheet) */ -unsigned short gbeGetChecksumFrom4kStruct(struct GBEREGIONRECORD_4K gbeStruct4k, unsigned short desiredValue) -{ - char gbeBuffer4k[GBEREGIONSIZE_4K]; - memcpy(&gbeBuffer4k, &gbeStruct4k, GBEREGIONSIZE_4K); - return gbeGetChecksumFrom8kBuffer(gbeBuffer4k, desiredValue, 0); -} - -/* modify the gbe region extracted from a factory.rom dump */ -struct GBEREGIONRECORD_8K deblobbedGbeStructFromFactory(struct GBEREGIONRECORD_8K factoryGbeStruct8k) -{ - /* - * Correct the main gbe region. By default, the X200 (as shipped from Lenovo) comes - * with a broken main gbe region, where the backup gbe region is used instead. Modify - * it so that the main region is usable. - */ - - struct GBEREGIONRECORD_8K deblobbedGbeStruct8k; - memcpy(&deblobbedGbeStruct8k, &factoryGbeStruct8k, GBEREGIONSIZE_8K); - - deblobbedGbeStruct8k.backup.checkSum = gbeGetChecksumFrom4kStruct(deblobbedGbeStruct8k.backup, 0xBABA); - memcpy(&deblobbedGbeStruct8k.main, &deblobbedGbeStruct8k.backup, GBEREGIONSIZE_4K); - - /* - * Debugging: - * calculate the 0x3F'th 16-bit uint to make the desired final checksum for GBe - * observed checksum matches (from X200 factory.rom dumps) on main: 0x3ABA 0x34BA 0x40BA. spec defined as 0xBABA. - * X200 ships with a broken main gbe region by default (invalid checksum, and more) - * The "backup" gbe regions on these machines are correct, though, and is what the machines default to - * For libreboot's purpose, we can do much better than that by fixing the main one... below is only debugging - */ - printf("\nfactory Gbe (main): calculated Gbe checksum: 0x%hx and actual GBe checksum: 0x%hx\n", gbeGetChecksumFrom4kStruct(factoryGbeStruct8k.main, 0xBABA), factoryGbeStruct8k.main.checkSum); - printf("factory Gbe (backup) calculated Gbe checksum: 0x%hx and actual GBe checksum: 0x%hx\n", gbeGetChecksumFrom4kStruct(factoryGbeStruct8k.backup, 0xBABA), factoryGbeStruct8k.backup.checkSum); - printf("\ndeblobbed Gbe (main): calculated Gbe checksum: 0x%hx and actual GBe checksum: 0x%hx\n", gbeGetChecksumFrom4kStruct(deblobbedGbeStruct8k.main, 0xBABA), deblobbedGbeStruct8k.main.checkSum); - printf("deblobbed Gbe (backup) calculated Gbe checksum: 0x%hx and actual GBe checksum: 0x%hx\n", gbeGetChecksumFrom4kStruct(deblobbedGbeStruct8k.backup, 0xBABA), deblobbedGbeStruct8k.backup.checkSum); - - return deblobbedGbeStruct8k; -} + +unsigned short gbeGetRegionWordFrom8kBuffer(int index, char* regionData); +unsigned short gbeGetChecksumFrom8kBuffer(char* regionData, unsigned short desiredValue, char isBackup); +unsigned short gbeGetChecksumFrom4kStruct(struct GBEREGIONRECORD_4K gbeStruct4k, unsigned short desiredValue); +struct GBEREGIONRECORD_8K deblobbedGbeStructFromFactory(struct GBEREGIONRECORD_8K factoryGbeStruct8k); #endif |