blob: 123c3b7f72f8e4a9d679e6632ce7cb443358d9c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)
|