diff options
| author | Timothy Pearson <tpearson@raptorengineering.com> | 2018-06-02 14:44:30 -0500 |
|---|---|---|
| committer | Timothy Pearson <tpearson@raptorengineering.com> | 2018-06-03 04:51:36 -0500 |
| commit | 3e7dedf3f2ed30cdf38663d361bde2599102f149 (patch) | |
| tree | b9efb2eb4ef6cd099c03aa849de033a8a1a96bee /woferclock/write_vpd | |
| parent | a9ae58c7402d14c018a29f956a545b49ff030363 (diff) | |
| download | vpdtools-3e7dedf3f2ed30cdf38663d361bde2599102f149.tar.gz vpdtools-3e7dedf3f2ed30cdf38663d361bde2599102f149.zip | |
Add WoFerClock utility
Diffstat (limited to 'woferclock/write_vpd')
| -rwxr-xr-x | woferclock/write_vpd | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/woferclock/write_vpd b/woferclock/write_vpd new file mode 100755 index 0000000..0105d83 --- /dev/null +++ b/woferclock/write_vpd @@ -0,0 +1,80 @@ +#!/usr/bin/python +# +# Copyright (c) 2018 Raptor Engineering, LLC +# Released under the terms of the AGPL v3 + +import sys +import os +import binascii + +eeprom_bus = int(sys.argv[1]) +if sys.argv[2].startswith("0x") or sys.argv[2].startswith("0X"): + eeprom_address = int(sys.argv[2][2:], 16) +else: + eeprom_address = int(sys.argv[2]) +filename = sys.argv[3] + +with open(filename, 'rb') as f: + indata = f.read() + +raw_data = binascii.hexlify(indata) +vpd_length = len(raw_data) + +if vpd_length != 131072: + print "[ERROR] Invalid VPD length. Aborting!" + sys.exit(1) + +mod_ret = os.system("modprobe at24") +exit_code = os.WEXITSTATUS(mod_ret) +if exit_code != 0: + print "[ERROR] at24 driver load failed!" + sys.exit(1) + +with open("/sys/class/i2c-dev/i2c-" + str(eeprom_bus) + "/device/" + str(eeprom_bus) + "-" + format(eeprom_address, '04x') + "/eeprom", 'rb') as f: + origdata = f.read() + +original_data = binascii.hexlify(origdata) + +mod_ret = os.system("rmmod at24") +exit_code = os.WEXITSTATUS(mod_ret) +if exit_code != 0: + print "[ERROR] at24 driver unload failed!" + sys.exit(1) + +address = 0 +for i in range(0, vpd_length, 2): + if original_data[i:(i+2)] != raw_data[i:(i+2)]: + address_high = hex((address & 65280) >> 8) + address_low = hex(address & 255) + command = "i2cset -y " + str(eeprom_bus) + " 0x" + format(eeprom_address, '02x') + " " + address_high + " " + address_low + " 0x" + raw_data[i:(i+2)] + " i" + i2c_ret = os.system(command) + exit_code = os.WEXITSTATUS(i2c_ret) + if exit_code != 0: + # Retry + i2c_ret = os.system(command) + exit_code = os.WEXITSTATUS(i2c_ret) + if exit_code != 0: + print "[ERROR] Write failed!" + print "\tCommand was: " + command + sys.exit(1) + address = address + 1 + sys.stdout.write(format(address, '05d') + " / " + format((vpd_length / 2), '05d') + "\r") + sys.stdout.flush() + +print "" + +mod_ret = os.system("modprobe at24") +exit_code = os.WEXITSTATUS(mod_ret) +if exit_code != 0: + print "[ERROR] at24 driver load failed!" + sys.exit(1) + +with open("/sys/class/i2c-dev/i2c-" + str(eeprom_bus) + "/device/" + str(eeprom_bus) + "-" + format(eeprom_address, '04x') + "/eeprom", 'rb') as f: + readdata = f.read() + +readback_data = binascii.hexlify(readdata) +if (readback_data != raw_data): + print "[WARNING] Readback did NOT match provided file! VPD in unknown state!" + sys.exit(2) +else: + print "Done!" |

