From cbd923db57f8c7b26d77adb118c01a3cbf70b507 Mon Sep 17 00:00:00 2001 From: Francis Rowe Date: Sun, 11 Jan 2015 03:58:32 +0000 Subject: ich9deblob: re-factor main function --- resources/utilities/ich9deblob/src/ich9deblob.c | 172 +++++++----------------- 1 file changed, 52 insertions(+), 120 deletions(-) (limited to 'resources/utilities/ich9deblob/src') diff --git a/resources/utilities/ich9deblob/src/ich9deblob.c b/resources/utilities/ich9deblob/src/ich9deblob.c index d025a64c..18b5c81a 100644 --- a/resources/utilities/ich9deblob/src/ich9deblob.c +++ b/resources/utilities/ich9deblob/src/ich9deblob.c @@ -49,37 +49,18 @@ int main() { - /* - * descriptor region. Will have an actual descriptor struct mapped to it (from the factory.rom dump) - * and then it will be modified (deblobbed) to remove the ME/AMT - */ - uint8_t factoryDescriptorBuffer[DESCRIPTORREGIONSIZE]; - struct DESCRIPTORREGIONRECORD factoryDescriptorStruct; - struct DESCRIPTORREGIONRECORD deblobbedDescriptorStruct; + struct DESCRIPTORREGIONRECORD descriptorStruct; + uint8_t* descriptorBuffer = (uint8_t*)&descriptorStruct; - /* - * gbe region. Well have actual gbe buffer mapped to it (from the factory.rom dump) - * and then it will be modified to correct the main region - */ - uint8_t factoryGbeBuffer8k[GBEREGIONSIZE_8K]; - struct GBEREGIONRECORD_8K factoryGbeStruct8k; - struct GBEREGIONRECORD_8K deblobbedGbeStruct8k; - - /* - * Used to store the location of the Gbe - * region inside the factory.rom image. - */ - uint32_t factoryGbeRegionStart; + struct GBEREGIONRECORD_8K gbeStruct8k; + uint8_t* gbeBuffer8k = (uint8_t*)&gbeStruct8k; + uint32_t gbeRegionStart; - /* names of the files that this utility will handle */ - char* factoryRomFilename = "factory.rom"; /* user-supplied factory.bin dump (original firmware) */ - char* deblobbedDescriptorFilename = "deblobbed_descriptor.bin"; /* descriptor+gbe: to be dd'd to beginning of a libreboot image */ + char* romFilename = "factory.rom"; + char* descriptorGbeFilename = "deblobbed_descriptor.bin"; - /* Used when reading the factory.rom to extract descriptor/gbe regions */ unsigned int bufferLength; - - /* For storing the size of the factory.rom dump in bytes */ - unsigned int factoryRomSize; + unsigned int romSize; /* * ------------------------------------------------------------------ @@ -87,7 +68,7 @@ int main() * ------------------------------------------------------------------ */ - if (systemOrCompilerIncompatible(factoryDescriptorStruct, factoryGbeStruct8k)) return 1; + if (systemOrCompilerIncompatible(descriptorStruct, gbeStruct8k)) return 1; /* If true, fail with error message */ /* @@ -95,92 +76,55 @@ int main() * Extract the descriptor and gbe regions from the factory.rom dump * ------------------------------------------------------------------ */ - FILE* fileStream = NULL; - fileStream = fopen(factoryRomFilename, "rb"); /* open factory.rom */ - if (NULL == fileStream) + FILE* fp = NULL; + fp = fopen(romFilename, "rb"); /* open factory.rom */ + if (NULL == fp) { - printf("\nerror: could not open factory.rom\n"); - fclose(fileStream); + printf("\nerror: could not open %s\n", romFilename); + fclose(fp); return 1; } - printf("\nfactory.rom opened successfully\n"); + printf("\n%s opened successfully\n", romFilename); /* * Get the descriptor region dump from the factory.rom * (goes in factoryDescriptorBuffer variable) */ - bufferLength = fread(factoryDescriptorBuffer, 1, DESCRIPTORREGIONSIZE, fileStream); + bufferLength = fread(descriptorBuffer, 1, DESCRIPTORREGIONSIZE, fp); if (DESCRIPTORREGIONSIZE != bufferLength) // { - printf("\nerror: could not read descriptor from factory.rom (%i) bytes read\n", bufferLength); - fclose(fileStream); + printf("\nerror: could not read descriptor from %s (%i) bytes read\n", romFilename, bufferLength); + fclose(fp); return 1; } printf("\ndescriptor region read successfully\n"); - /* - * copy descriptor buffer into descriptor struct memory - * factoryDescriptorStruct is an instance of a struct that actually - * defines the locations of all these variables in the descriptor, - * as defined in the datasheets. This allows us to map the extracted - * descriptor over the struct so that it can then be modified - * for libreboot's purpose - */ - memcpy(&factoryDescriptorStruct, &factoryDescriptorBuffer, DESCRIPTORREGIONSIZE); - /* - * ^ the above is just for reference if needed. The modifications will be made here: - */ - memcpy(&deblobbedDescriptorStruct, &factoryDescriptorBuffer, DESCRIPTORREGIONSIZE); - /* - * Get the gbe region dump from the factory.rom - */ - - /* - * get original GBe region location - * (it will be moved to the beginning of the flash, after the descriptor region) - * note for example, factoryGbeRegionStart is set to <