From 530cb0a8aaaac906fe124086e780d6651241b0ad Mon Sep 17 00:00:00 2001 From: Michael Auchter Date: Mon, 9 Sep 2019 16:46:14 -0500 Subject: mpm: add tlv_eeprom Add support for parsing an eeprom that uses tag-length-value to store contents. Co-authored-by: Michael Auchter Co-authored-by: Virendra Kakade Co-authored-by: Cristina Fuentes --- mpm/tools/tlv_eeprom/eeprom-path | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 mpm/tools/tlv_eeprom/eeprom-path (limited to 'mpm/tools/tlv_eeprom/eeprom-path') 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 " % 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) -- cgit v1.2.3