From 5657256aa9bbecef196fc609d25e263743287430 Mon Sep 17 00:00:00 2001
From: Francis Rowe <info@gluglug.org.uk>
Date: Mon, 22 Dec 2014 13:58:44 -0500
Subject: ich9deblob: move Gbe deblobbing to a separate function

---
(limited to 'resources')

diff --git a/resources/utilities/ich9deblob/ich9deblob.c b/resources/utilities/ich9deblob/ich9deblob.c
index 216c8d0..e2801e1 100644
--- a/resources/utilities/ich9deblob/ich9deblob.c
+++ b/resources/utilities/ich9deblob/ich9deblob.c
@@ -64,6 +64,7 @@ int structSizesIncorrect(struct DESCRIPTORREGIONRECORD descriptorDummy, struct G
 int systemIsBigEndian();
 int structBitfieldWrongOrder();
 int structMembersWrongOrder();
+struct GBEREGIONRECORD_8K deblobbedGbeStructFromFactory(struct GBEREGIONRECORD_8K factoryGbeStruct8k);
 
 int main(int argc, char *argv[])
 {
@@ -191,12 +192,8 @@ int main(int argc, char *argv[])
 
 	// ----------------------------------------------------------------------------------------------------------------
 
-	// 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
-	// the descriptor so that the main region is usable.
-	
-	deblobbedGbeStruct8k.backup.checkSum = gbeGetChecksumFrom4kStruct(deblobbedGbeStruct8k.backup, 0xBABA);
-	memcpy(&deblobbedGbeStruct8k.main, &deblobbedGbeStruct8k.backup, GBEREGIONSIZE>>1);
+	// Modify the Gbe descriptor (see function for details)
+	deblobbedGbeStruct8k = deblobbedGbeStructFromFactory(factoryGbeStruct8k);
 
 	// ----------------------------------------------------------------------------------------------------------------
 
@@ -390,6 +387,21 @@ int structBitfieldWrongOrder() {
 	return 0;
 }
 
+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
+	// the descriptor so that the main region is usable.
+	
+	struct GBEREGIONRECORD_8K deblobbedGbeStruct8k;
+	memcpy(&deblobbedGbeStruct8k, &factoryGbeStruct8k, GBEREGIONSIZE);
+	
+	deblobbedGbeStruct8k.backup.checkSum = gbeGetChecksumFrom4kStruct(deblobbedGbeStruct8k.backup, 0xBABA);
+	memcpy(&deblobbedGbeStruct8k.main, &deblobbedGbeStruct8k.backup, GBEREGIONSIZE>>1);
+	
+	return deblobbedGbeStruct8k;
+}
+
 // Modify the flash descriptor, to remove the ME/AMT, and disable all other regions
 // Only Flash Descriptor, Gbe and BIOS regions (BIOS region fills romSize-12k) are left.
 // Tested on ThinkPad X200 and X200S. X200T and other GM45 targets may also work.
--
cgit v0.9.1