/
xmutil
executable file
·392 lines (295 loc) · 12.5 KB
/
xmutil
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#!/usr/bin/env python3
"""
# Copyright (C) 2010 - 2021 Xilinx, Inc. All rights reserved.
# Copyright (C) 2022 - 2023 Advanced Micro Devices, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT
"""
import subprocess
import argparse
import re
import glob
import sys
import distro
import os.path
from periphery import GPIO
from periphery import I2C
from periphery import MMIO
cmds = {'boardid': '/usr/sbin/ipmi-fru',
'bootfw_status': '/usr/bin/image_update',
'bootfw_update': '/usr/bin/image_update',
'listapps': 'dfx-mgr-client',
'loadapp': 'dfx-mgr-client',
'unloadapp': 'dfx-mgr-client',
'xlnx_platformstats': '/usr/bin/xlnx_platformstats',
'ddrqos': '/usr/bin/ddr-qos',
'axiqos': '/usr/bin/axi-qos',
}
def pcie_format(match):
pcie = match.group(1)
if pcie is not None:
pcie = pcie.replace('h', '').replace(' ', '')
return f"""FRU Board PCIe Info:
Vendor ID: {pcie[0:4]}
Device ID: {pcie[4:8]}
SubVendor ID: {pcie[8:12]}
SubDevice ID: {pcie[12:16]}
"""
def uuid_format(match):
uuid = match.group(1)
if uuid is not None:
return "FRU Board UUID: " + uuid.replace('h', '').replace(' ', '')
def board_custom_format(fru):
# Common for all Xilinx boards
fru = fru.replace('FRU Board Custom Info:',
'FRU Board Revision Number:', 1)
fru = fru.replace('FRU Board Custom Info:', 'FRU Board PCIe Info:', 1)
fru = re.sub('FRU Board PCIe Info:(.*)\n', pcie_format, fru)
fru = fru.replace('FRU Board Custom Info:', 'FRU Board UUID:', 1)
fru = re.sub('FRU Board UUID:(.*)\n', uuid_format, fru)
return fru
def mac_format(fru):
# Kria SOM specific interpratation of MAC record
if re.search('FRU Board Product Name: SM.*', fru):
fru = fru.replace('FRU OEM MAC ID 0:', 'FRU OEM PS MAC ID 0:', 1)
# Kria Carrier card specific interpretation of MAC record
prod = re.search('FRU Board Product Name: SCK-(.*)-G', fru)
if prod and prod.group(1) == 'KR':
fru = fru.replace('FRU OEM MAC ID 0:', 'FRU OEM PS MAC ID 1:', 1)
fru = fru.replace('FRU OEM MAC ID 1:', 'FRU OEM PL MAC ID 0:', 1)
fru = fru.replace('FRU OEM MAC ID 2:', 'FRU OEM PL MAC ID 1:', 1)
elif prod and prod.group(1) == 'KD':
fru = fru.replace('FRU OEM MAC ID 0:', 'FRU OEM PL MAC ID 0:', 1)
fru = fru.replace('FRU OEM MAC ID 1:', 'FRU OEM PL MAC ID 1:', 1)
return fru
def free_form_format(fru):
# Kria SOM specific interpratation of MAC record
if re.search('FRU Board Product Name: SM.*', fru):
fru = fru.replace('FRU OEM Memory:', 'FRU OEM Primary Boot Device:', 1)
fru = fru.replace('FRU OEM Memory:',
'FRU OEM Secondary Boot Device:', 1)
fru = fru.replace('FRU OEM Memory:', 'FRU OEM PS DDR Memory:', 1)
fru = fru.replace('FRU OEM Memory:', 'FRU OEM PL DDR Memory:', 1)
return fru
def boardid_format(fru):
# Xilinx specific interpretation of custom board info
fru = board_custom_format(fru)
# Xilinx specific interpretation of MAC record
fru = mac_format(fru)
# Xilinx specific interpretation of free form record
fru = free_form_format(fru)
return fru
def get_eeprom(args):
eeprom = []
for arg in args:
if '--fru-file' in arg:
eeprom.append(arg.split('=')[1])
if not eeprom:
eeprom = glob.glob('/sys/devices/platform/axi/*.i2c/*/*/eeprom')
if not eeprom:
sys.exit('No EEPROM nodes found')
return eeprom
def boardid(args):
ignore = False
if any('--ignore-errors' in arg for arg in args):
ignore = True
for file in get_eeprom(args):
ret, fru = subprocess.getstatusoutput(cmds['boardid'] +
' --fru-file=' + file + ' --interpret-oem-data')
if not ignore and ret != 0:
print(fru)
sys.exit('\nipmi-fru returned error code ' + str(ret))
elif fru:
print('\n' + boardid_format(fru))
print('')
def product_name(args):
ignore = False
if any('--ignore-errors' in arg for arg in args):
ignore = True
prod = ''
som = ''
carrier = ''
for file in get_eeprom(args):
ret, fru = subprocess.getstatusoutput(cmds['boardid'] +
' --fru-file=' + file + ' --interpret-oem-data')
if not ignore and ret != 0:
raise RuntimeError('ipmi-fru returned error code ' + str(ret))
elif fru:
# Kria SOM
match = re.search('FRU Board Product Name: SM.*-K(.*)-.*', fru)
if match:
som = match.group(1)
continue
# Kria Carrier Card
match = re.search('FRU Board Product Name: SCK-(.*)-G', fru)
if match:
carrier = match.group(1).lower()
continue
# Other Xilinx Board
match = re.search('FRU Board Product Name: (.*)', fru)
if match:
prod = match.group(1).lower()
if som and carrier:
prod = carrier + som + '0'
return prod
def bootfw_status(args):
subprocess.run([cmds['bootfw_status'], '-p'])
def bootfw_update(args):
subprocess.run([cmds['bootfw_update']]+args)
def getpkgs(args):
if ('-h' in args) or ('--help' in args):
print("\ngetpkgs will use ipmi-fru to determine the target platform\nand search the package feed for compatible packagegroups\n")
exit()
try:
prod = product_name(args + [' --ignore-errors'])
except:
sys.exit("No valid product name found, can't search package feed")
print("\nSearching package feed for packages compatible with: " + prod + '\n')
if distro.id() == 'ubuntu':
subprocess.run('apt search xlnx-app-' + prod +
'- 2>/dev/null', shell=True)
elif distro.id() == 'petalinux':
subprocess.run('dnf list --available | grep packagegroup-' + prod +
'- | awk "!/-dev\./&&!/-lic\./&&!/-dbg\./&&!/-ptest\./"', shell=True)
def listapps(args):
subprocess.run([cmds['listapps'], '-listPackage'])
def loadapp(args):
subprocess.run([cmds['loadapp'], '-load']+args)
def unloadapp(args):
subprocess.run([cmds['unloadapp'], '-remove']+args)
def xlnx_platformstats(args):
subprocess.run([cmds['xlnx_platformstats']]+args)
def ddrqos(args):
subprocess.run([cmds['ddrqos']]+args)
def axiqos(args):
subprocess.run([cmds['axiqos']]+args)
def pl_node_state_update(state):
# PMU call for PL node request/release
pm_dev = open("/sys/kernel/debug/zynqmp-firmware/pm", "w")
pm_dev.write(state + " 69")
pm_dev.close()
def pl_sequencer_on():
pl_node_state_update("pm_request_node")
def pl_sequencer_off():
pl_node_state_update("pm_release_node")
def fetch_i2c_node(i2c_master):
os.chdir("/sys/devices/platform/axi/"+i2c_master+".i2c/")
i2c_dir = glob.glob('i2c-*')
return ("/dev/"+' '.join([str(elem) for elem in i2c_dir]))
def pl_sequencer_status():
#Pass ff030000 adrress of i2c master
i2c = I2C(fetch_i2c_node("ff030000"))
#Read 0xF2 register of PL Sequencer
msgs = [I2C.Message([0xF2]), I2C.Message([0x00], read=True)]
#0x68 is address of PL Sequencer
i2c.transfer(0x68, msgs)
i2c.close()
#Check 4th bit of 0XF2 register which is VCCOEN_PL
if ((msgs[1].data[0] >> 4) & 1) == 1:
print("PL sequencer is on \n")
elif ((msgs[1].data[0] >> 4) & 1) == 0:
print("PL sequencer is off \n")
else:
print("Unknown PL sequencer state, reg_value: ", hex(msgs[1].data[0]), "\n")
def pl_sequencer_on_via_i2c():
#Pass ff030000 adrress of i2c master
i2c = I2C(fetch_i2c_node("ff030000"))
msgs = [I2C.Message([0x08, 0x3E], read=False)]
# Write '0x3E' to PL sequencer power register for PL switch on
i2c.transfer(0x68, msgs)
i2c.close()
pl_node_state_update("pm_request_node")
def pl_sequencer_off_via_i2c():
pl_node_state_update("pm_release_node")
#Pass ff030000 adrress of i2c master
i2c = I2C(fetch_i2c_node("ff030000"))
# Write '0x00' to PL sequencer power register for PL switch off
msgs = [I2C.Message([0x08, 0x00], read=False)]
i2c.transfer(0x68, msgs)
i2c.close()
def pl_sequencer_status_via_i2c():
#Pass ff030000 adrress of i2c master
i2c = I2C(fetch_i2c_node("ff030000"))
msgs = [I2C.Message([0xF5]), I2C.Message([0x00], read=True)]
i2c.transfer(0x68, msgs)
i2c.close()
if msgs[1].data[0] == 0x9a:
print("PL sequencer is on \n")
elif msgs[1].data[0] == 0x04:
print("PL sequencer is off \n")
else:
print("Unknown PL sequencer state: ", hex(msgs[1].data[0]), "\n")
def pwrctl(args):
try:
product = product_name(args + [' --ignore-errors'])
except:
sys.exit("Error during product name fetching, can't perform pwrctl operation")
if len(sys.argv) < 3:
sys.exit("No argument provided to xmutil pwrctl. Run xmutil --help for usage.")
if product.find('kv260') != -1 or product.find('kr260') != -1:
if sys.argv[2] == "--off":
pl_sequencer_off_via_i2c()
elif sys.argv[2] == "--on":
pl_sequencer_on_via_i2c()
elif sys.argv[2] == "--status":
pl_sequencer_status_via_i2c()
elif product.find('kd240') != -1:
if sys.argv[2] == "--off":
pl_sequencer_off()
elif sys.argv[2] == "--on":
pl_sequencer_on()
elif sys.argv[2] == "--status":
pl_sequencer_status()
else:
print('Unkown device: xmutil pwrctl supports K24/K26 only\n')
def top(cmd, args):
globals()[cmd[0]](args)
def desktop_disable(args):
subprocess.run('systemctl isolate multi-user.target', shell=True)
def desktop_enable(args):
subprocess.run('systemctl isolate graphical.target', shell=True)
def dp_unbind(args):
subprocess.run(
'echo -n fd4a0000.display > /sys/bus/platform/drivers/zynqmp-display/unbind', shell=True)
def dp_bind(args):
subprocess.run(
'echo -n fd4a0000.display > /sys/bus/platform/drivers/zynqmp-display/bind', shell=True)
if __name__ == "__main__":
help_text = """
boardid: Reads FRU data based on EEPROM or file and prints information in human readable format.
--fru-file=<file> Pass a <file> containing fru data
--ignore-errors Ignore errors returned by fru-ipmi and print returned output
bootfw_status: Prints Qspi MFG version and date info along with persistent state values.
bootfw_update: Updates the primary boot device with a new BOOT.BIN in the inactive partition (either A or B).
getpkgs: Queries Xilinx package feeds and provides summary of relevant packages for active platform based on board ID information.
--fru-file=<file> Pass a <file> containing fru data
--ignore-errors Ignore errors returned by fru-ipmi and print returned output
listapps: Queries on target FW resource manager daemon of pre-built app bitstreams available on the platform and provides summary to CLI.
loadapp: Loads requested application configuration bitstream to programmable logic if the device is available.
unloadapp: Removes application bitstream. (Takes slot number, default 0)
xlnx_platformstats: Reads and prints a summary of the following performance related information:
CPU Utilization for each configured CPU
RAM utilization
Swap memory Utilization
SOM overall current, power, voltage utilization
SysMon Temperatures(s)
SOM power supply data summary reported by PMICs & ZU+ SysMon sources
ddrqos: Set QOS value for DDR slots on zynqmp platform.
axiqos: Set QOS value for AXI ports on zynqmp platform.
pwrctl: PL power control utility.
--off PL shutdown
--on PL powerup
--status PL power status
desktop_disable: Disable the desktop.
desktop_enable: Enable the desktop.
dp_unbind: Unbind the display driver.
dp_bind: Bind the display driver.
"""
if os.geteuid() != 0:
sys.exit("xmutil should be called with root privileges. Please try again using 'sudo'.")
parser = argparse.ArgumentParser(
description=help_text, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('cmd', choices=['boardid', 'bootfw_status', 'bootfw_update', 'getpkgs', 'listapps', 'loadapp', 'unloadapp', 'xlnx_platformstats',
'ddrqos', 'axiqos', 'pwrctl', 'desktop_disable', 'desktop_enable', 'dp_unbind', 'dp_bind'], type=str, nargs=1, help='Enter a function')
parser.add_argument('args', nargs=argparse.REMAINDER)
args = parser.parse_args()
top(args.cmd, args.args)