aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/tools/tlv_eeprom/eeprom-path
diff options
context:
space:
mode:
authorMichael Auchter <michael.auchter@ni.com>2019-09-09 16:46:14 -0500
committerMartin Braun <martin@gnuradio.org>2021-05-31 05:28:47 -0700
commit530cb0a8aaaac906fe124086e780d6651241b0ad (patch)
tree8a5301163392b3d0c1642da0cb9ba2a9ea176401 /mpm/tools/tlv_eeprom/eeprom-path
parentfa997d52cc62c3c39f5b7560890e31d41e4eb9e9 (diff)
downloaduhd-530cb0a8aaaac906fe124086e780d6651241b0ad.tar.gz
uhd-530cb0a8aaaac906fe124086e780d6651241b0ad.tar.bz2
uhd-530cb0a8aaaac906fe124086e780d6651241b0ad.zip
mpm: add tlv_eeprom
Add support for parsing an eeprom that uses tag-length-value to store contents. Co-authored-by: Michael Auchter <michael.auchter@ni.com> Co-authored-by: Virendra Kakade <virendra.kakade@ni.com> Co-authored-by: Cristina Fuentes <cristina.fuentes@ni.com>
Diffstat (limited to 'mpm/tools/tlv_eeprom/eeprom-path')
-rw-r--r--mpm/tools/tlv_eeprom/eeprom-path36
1 files changed, 36 insertions, 0 deletions
diff --git a/mpm/tools/tlv_eeprom/eeprom-path b/mpm/tools/tlv_eeprom/eeprom-path
new file mode 100644
index 000000000..123c3b7f7
--- /dev/null
+++ b/mpm/tools/tlv_eeprom/eeprom-path
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+
+from pathlib import Path
+import sys
+
+DT_BASE = Path("/sys/firmware/devicetree/base")
+
+def find_eeprom(name):
+ with open(DT_BASE / "__symbols__" / name) as f:
+ dt_path = DT_BASE / f.read()[1:-1]
+
+ for dev in Path("/sys/bus/nvmem/devices").glob("*"):
+ of_node_path = dev / "of_node"
+ if of_node_path.exists() and dt_path.samefile(of_node_path):
+ return dev / "nvmem"
+
+def list_eeproms():
+ return [dev.name for dev in Path(DT_BASE / "__symbols__").glob("*_eeprom")]
+
+if __name__ == "__main__":
+ if len(sys.argv) != 2:
+ print("Return the path to an eeprom")
+ print("usage: %s <eeprom_name>" % sys.argv[0])
+ print("valid eeprom_names: " + ', '.join(list_eeproms()))
+ sys.exit(1)
+ name = sys.argv[1]
+ try:
+ path = find_eeprom(name)
+ if path is None:
+ print("%s: found symbol, but nvmem device not present"% sys.argv[0], file=sys.stderr)
+ sys.exit(1)
+ except:
+ print("%s: could not find nvmem device for devicetree symbol %s" % (sys.argv[0], name), file=sys.stderr)
+ sys.exit(1)
+
+ print(path)