-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfru-print
executable file
·79 lines (69 loc) · 3.11 KB
/
fru-print
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
# Copyright (C) 2020 - 2022 Xilinx, Inc. All rights reserved.
# SPDX-License-Identifier: MIT
import argparse, yaml, sys
from glob import glob
from fru import load
parser = argparse.ArgumentParser(description='print fru data of SOM/CC eeprom')
parser.add_argument('-b','--board', action='store', choices=['som','cc'], type=str, help='Enter som or cc')
parser.add_argument('-f','--field', action='store', nargs="+", type=str, help='enter fields to index using. (if entering one arg, it\'s assumed the field is from board area)')
parser.add_argument('-s','--sompath', type=str, nargs="?", default='/sys/bus/i2c/devices/*50/eeprom', help='enter path to SOM EEPROM')
parser.add_argument('-c','--ccpath', type=str, nargs="?", default='/sys/bus/i2c/devices/*51/eeprom', help='enter path to CC EEPROM')
parser.add_argument('-d','--device', type=str, nargs="?", default='', help='enter path to EEPROM device e.g. /sys/bus/i2c/devices/1-0050/eeprom')
args = parser.parse_args()
if args.device:
try:
device=glob(args.device)[0]
except:
sys.exit('\ndevice path is incorrect: ' + args.device)
elif args.board == 'som':
try:
som=glob(args.sompath)[0]
except:
sys.exit('\nsompath is incorrect:' + args.sompath)
elif args.board == 'cc':
try:
cc=glob(args.ccpath)[0]
except:
sys.exit('\nccpath is incorrect: ' + args.ccpath)
else:
try:
som=glob(args.sompath)[0]
cc=glob(args.ccpath)[0]
except:
sys.exit('\nOne of the following paths is wrong:\nsom path: ' + args.sompath + '\n' + 'cc path: ' + args.ccpath)
if args.field and args.board is None and args.device is None:
parser.error('\nIf entering a field, need board or device input as well')
elif args.board and args.field is None:
try:
print(yaml.dump(load(eval(args.board)), default_flow_style=False, allow_unicode=True))
except ValueError:
print("ERROR: Malformed FRU data\n")
elif args.device and args.field is None:
try:
print(yaml.dump(load(device), default_flow_style=False, allow_unicode=True))
except ValueError:
print("ERROR: Malformed FRU data\n")
elif (args.board or args.device) and args.field:
try:
if len(args.field) == 1:
if args.board:
print(load(eval(args.board))['board'][args.field[0]])
elif args.device:
print(load(args.device)['board'][args.field[0]])
else:
if args.board:
data = load(eval(args.board))
elif args.device:
data = load(args.device)
for field in args.field:
data = data[field]
print(data)
except ValueError:
print("ERROR: Malformed FRU data\n")
except KeyError:
print("ERROR: "+str(args.field)+" is not a valid input for field.\nmultiple key values can be provided to the field arg, ex. -f multirecord DC_Load_Record max_V\n\
If just one value is given, it is assumed the field is under the board area.\n")
else:
both={'som':load(som), 'cc':load(cc)}
print(yaml.dump(both,default_flow_style=False, allow_unicode=True))