diff options
author | Francis Rowe <info@gluglug.org.uk> | 2014-12-28 20:33:27 (EST) |
---|---|---|
committer | Francis Rowe <info@gluglug.org.uk> | 2014-12-28 20:33:27 (EST) |
commit | cfc094637130f9a05673f82f3a45dfbd917c6ed8 (patch) | |
tree | 9b4765f08250ff3b888f787e47a6e7fc97a62a67 /resources | |
parent | b307eff6f026b1262433eb4d8389b774b3e0a9ff (diff) | |
download | libreboot-cfc094637130f9a05673f82f3a45dfbd917c6ed8.zip libreboot-cfc094637130f9a05673f82f3a45dfbd917c6ed8.tar.gz libreboot-cfc094637130f9a05673f82f3a45dfbd917c6ed8.tar.bz2 |
ich9gen: make it possible for user to change the Gbe MAC address
Example: ./ich9gen --macaddress AA:BB:CC:DD:EE:FF
Diffstat (limited to 'resources')
-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 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 * ------------------------------------------------------------------ */ |