From cfc094637130f9a05673f82f3a45dfbd917c6ed8 Mon Sep 17 00:00:00 2001 From: Francis Rowe Date: Sun, 28 Dec 2014 20:33:27 -0500 Subject: ich9gen: make it possible for user to change the Gbe MAC address Example: ./ich9gen --macaddress AA:BB:CC:DD:EE:FF --- (limited to 'resources') diff --git a/resources/utilities/ich9deblob/src/ich9gen.c b/resources/utilities/ich9deblob/src/ich9gen.c index 583957e..81fd182 100644 --- a/resources/utilities/ich9deblob/src/ich9gen.c +++ b/resources/utilities/ich9deblob/src/ich9gen.c @@ -22,6 +22,9 @@ int main(int argc, char *argv[]) { + int i, j; + unsigned char customMacAddress[6]; /* Only set/used if the user wants to */ + struct GBEREGIONRECORD_8K gbeStruct8k = generatedGbeStruct8k(); struct DESCRIPTORREGIONRECORD descriptorStruct4M = generatedDescriptorStructRom4M(); struct DESCRIPTORREGIONRECORD descriptorStruct8M = generatedDescriptorStructRom8M(); @@ -41,7 +44,56 @@ int main(int argc, char *argv[]) /* * ------------------------------------------------------------------ - * Down to business + * Arguments given on the terminal + * ------------------------------------------------------------------ + */ + + + if(argc==3) { + + /* If user provides their own MAC address, it will be used. + * Otherwise, ich9gen will simply use the default one. + * + * However, if the user provides an invalid MAC address, then ich9gen + * will exit. */ + if(0==strcmp(argv[1],"--macaddress")) { + /* 6 hex chars format (example): AA:BB:CC:DD:EE:FF */ + if (strlen(argv[2]) != 17) { + printf("ich9gen: invalid mac address format (wrong length)\n"); + return 1; + } + for(i=2; i<14; i+=3) { + if(argv[2][i]!=':') { + printf("ich9gen: invalid mac address format (non-color characters used as spacing)\n"); + return 1; + } + } + for(i=0; i<6; i++) { + /* Go through each nibble of the byte */ + for(j=0; j<2; j++) { + if(argv[2][(i*3)+j]>='a' && argv[2][(i*3)+j]<='f') + customMacAddress[i] |= (argv[2][(i*3)+j] - 87) << ((j^1) << 2); + else if(argv[2][(i*3)+j]>='A' && argv[2][(i*3)+j]<='F') + customMacAddress[i] |= (argv[2][(i*3)+j] - 55) << ((j^1) << 2); + else if(argv[2][(i*3)+j]>='0' && argv[2][(i*3)+j]<='9') + customMacAddress[i] |= (argv[2][(i*3)+j] - 48) << ((j^1) << 2); + else { + printf("ich9gen: invalid mac address format (non-hex characters)\n"); + return 1; + } + } + } + /* Now that the new MAC address is verified, use it */ + memcpy(&gbeStruct8k.main.macAddress, &customMacAddress, 6); /* Update MAC address in main Gbe */ + gbeStruct8k.main.checkSum = gbeGetChecksumFrom4kStruct(gbeStruct8k.main, GBECHECKSUMTOTAL); /* Fix the checksum */ + memcpy(&gbeStruct8k.backup, &gbeStruct8k.main, GBEREGIONSIZE_4K); /* Copy to the backup */ + } + + } + + /* + * ------------------------------------------------------------------ + * Generate the 12KiB files, ready to be used in a libreboot image * ------------------------------------------------------------------ */ -- cgit v0.9.1