forked from bn222/dpu-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fwup
executable file
·101 lines (81 loc) · 3.09 KB
/
fwup
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
#!/bin/env python3
import sys
import requests
import common_bf
import argparse
class RemoteAPI:
def __init__(self, bf_version):
self._remote_url = f"https://downloaders.azurewebsites.net/downloaders/bluefield{bf_version}_fw_downloader/helper.php"
def get_latest_version(self):
data = {'action': 'get_versions', }
response = requests.post(self._remote_url, data=data)
return response.json()["latest"]
def get_distros(self, v):
data = {
'action': 'get_distros',
'version': v,
}
r = requests.post(self._remote_url, data=data)
return r.json()
def get_os(self, version, distro):
data = {
'action': 'get_oses',
'version': version,
'distro': distro,
}
r = requests.post(self._remote_url, data=data)
return r.json()[0]
def get_download_info(self, version, distro, os_param):
data = {
'action': 'get_download_info',
'version': version,
'distro': distro,
'os': os_param,
'arch': 'x64'
}
r = requests.post(self._remote_url, data=data)
return r.json()
def update_bf_firmware(args):
bf = common_bf.find_bf_pci_addresses_or_quit(args.id)
target_psid = common_bf.mst_flint(bf)["PSID"]
bf_version = common_bf.bf_version(bf)
if bf_version is None:
print(f"Couldn't detect Bluefield version on PCI address {bf}")
sys.exit(-1)
print(f"Bluefield-{bf_version} detected")
r = RemoteAPI(bf_version)
if args.version:
version = args.version
print("Installing specified version: %s" % version)
else:
version = r.get_latest_version()
print("Installing latest version: %s" % version)
if common_bf.mst_flint(bf)["FW Version"] == version:
print(f"currently already on {version}")
return 0
d = r.get_distros(version)
print("Distros: %s" % d)
for e in d:
os_param = r.get_os(version, e)
print(os_param)
if os_param != target_psid:
continue
url = r.get_download_info(version, e, os_param)["files"][0]["url"]
print(url)
common_bf.run(f"wget -q {url} -O fw.zip")
ret = common_bf.run("unzip -o fw.zip")
bin_name = [x for x in ret.out.split(" ") if ".bin" in x]
if len(bin_name) != 1:
print("unexpected number of binaries to download")
common_bf.run(f"mstflint -y -d {bf} -i {bin_name[0]} burn")
common_bf.run(f"mstfwreset -y -d {bf} r")
return 0
def main():
parser = argparse.ArgumentParser(description='Specify the id of the BF. Updates the firmware on the BF to the latest avaible one.')
parser.add_argument('-i', '--id', dest='id', default=0, action='store', type=int, help='Specify the id of the BF.')
parser.add_argument('-v','--version', dest='version', default='', action='store', type=str, help='specify a specific firmware version to install (i.e. 24.35.1012)')
args = parser.parse_args()
r = update_bf_firmware(args)
sys.exit(r)
if __name__ == "__main__":
main()