diff options
Diffstat (limited to 'resources/utilities/ich9deblob')
-rw-r--r-- | resources/utilities/ich9deblob/src/ich9gen.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/resources/utilities/ich9deblob/src/ich9gen.c b/resources/utilities/ich9deblob/src/ich9gen.c index 583957e3..81fd1821 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 * ------------------------------------------------------------------ */ |