Skip to content

Commit

Permalink
Merge pull request #22 from thom311/th/reformat-black
Browse files Browse the repository at this point in the history
[th/reformat-black] black: reformat all code with python black
  • Loading branch information
bn222 authored Aug 21, 2024
2 parents b300b3f + 292dcf7 commit a65579f
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 108 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Check style, test

on:
push:
branches:
pull_request:
branches:

jobs:
check3_9:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install black
- name: Check code formatting with Black
run: |
black --version
black --check --diff .
14 changes: 12 additions & 2 deletions bfb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ import time


def main():
parser = argparse.ArgumentParser(description='Downloads BFB images and sends it to the BF.')
parser.add_argument('-i', '--id', dest='id', default=0, action='store', type=int, help='Specify the id of the BF.')
parser = argparse.ArgumentParser(
description="Downloads BFB images and sends it to the BF."
)
parser.add_argument(
"-i",
"--id",
dest="id",
default=0,
action="store",
type=int,
help="Specify the id of the BF.",
)
args = parser.parse_args()
_ = common_bf.find_bf_pci_addresses_or_quit(args.id)

Expand Down
7 changes: 6 additions & 1 deletion common_bf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def run(cmd: str, env: dict = os.environ.copy()):
ret = proc.returncode
return Result(out, err, ret)


def all_interfaces():
out = run("lshw -c network -businfo").out
ret = {}
Expand All @@ -25,15 +26,17 @@ def all_interfaces():
continue
pci, dev = e.split()[0:2]
before_network = e.split("network")[0].strip()
desc = e[len(before_network):].strip()[len("network"):].strip()
desc = e[len(before_network) :].strip()[len("network") :].strip()
ret[pci] = desc
return ret


def find_bf_pci_addresses():
ai = all_interfaces()
bfs = [e for e in ai.items() if "BlueField" in e[1]]
return [k.split("@")[1] for k, v in bfs]


def find_bf_pci_addresses_or_quit(bf_id):
bf_pci = find_bf_pci_addresses()
if not bf_pci:
Expand All @@ -44,6 +47,7 @@ def find_bf_pci_addresses_or_quit(bf_id):
sys.exit(-1)
return bf_pci[bf_id]


def mst_flint(pci):
out = run(f"mstflint -d {pci} q").out
ret = {}
Expand All @@ -61,6 +65,7 @@ def mst_flint(pci):
ret[key] = value
return ret


def bf_version(pci):
out = run("lshw -c network -businfo").out
for e in out.split("\n"):
Expand Down
18 changes: 15 additions & 3 deletions console
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ import argparse


def main():
parser = argparse.ArgumentParser(description='Select BF to connect to with a console.')
parser.add_argument('-i', '--id', dest='id', default=0, action='store', type=int, help='Specify the id of the BF.')
parser = argparse.ArgumentParser(
description="Select BF to connect to with a console."
)
parser.add_argument(
"-i",
"--id",
dest="id",
default=0,
action="store",
type=int,
help="Specify the id of the BF.",
)
args = parser.parse_args()
_ = common_bf.find_bf_pci_addresses_or_quit(args.id)
os.system(f"minicom --color on --baudrate 115200 --device /dev/rshim{args.id//2}/console")
os.system(
f"minicom --color on --baudrate 115200 --device /dev/rshim{args.id//2}/console"
)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions cx_fwup
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os, sys


def main():
os.system("chmod +x mlxup")
r = os.system("/mlxup -y")
Expand Down
28 changes: 14 additions & 14 deletions dpu-tools/dpu-tools
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def console(args):
backed_up = False
temp_file_path = ""

with open(minirc_path, 'w') as new_file:
with open(minirc_path, "w") as new_file:
new_file.write("pu rtscts No\n")
os.system(minicom_cmd)

Expand All @@ -52,9 +52,9 @@ def console(args):

def find_bus_pci_address(address: str) -> str:
pattern = r"(\d+):(\d+)\.(\d+)"

match = re.match(pattern, address)

if match:
bus = match.group(1)
device = match.group(2)
Expand All @@ -81,32 +81,32 @@ def list_dpus(args):
print("----- -------- ------------ ------")
for i, (k, (d, kind)) in enumerate(devs.items()):
print(f"{i: 5d} {k.ljust(8)} {d.ljust(12)} {kind}")



def main():
parser = argparse.ArgumentParser(description='Tools to interact with an IPU')
subparsers = parser.add_subparsers(title='subcommands', description='Valid subcommands', dest='subcommand')
parser = argparse.ArgumentParser(description="Tools to interact with an IPU")
subparsers = parser.add_subparsers(
title="subcommands", description="Valid subcommands", dest="subcommand"
)

reset_parser = subparsers.add_parser('reset', help='Reset the IPU')
reset_parser = subparsers.add_parser("reset", help="Reset the IPU")
reset_parser.set_defaults(func=reset)

list_parser = subparsers.add_parser('list', help='list devices')
list_parser = subparsers.add_parser("list", help="list devices")
list_parser.set_defaults(func=list_dpus)

console_parser = subparsers.add_parser('console', help='Open console for the IPU')
console_parser = subparsers.add_parser("console", help="Open console for the IPU")
console_parser.set_defaults(func=console)
console_parser.add_argument('target', choices=['imc', 'acc'], help="Specify imc or acc as the target")

console_parser.add_argument(
"target", choices=["imc", "acc"], help="Specify imc or acc as the target"
)

args = parser.parse_args()
if hasattr(args, 'func'):
if hasattr(args, "func"):
args.func(args)
else:
parser.print_help()


if __name__ == "__main__":
main()


16 changes: 14 additions & 2 deletions fwdefaults
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import os, sys
import common_bf
import argparse


def main():
parser = argparse.ArgumentParser(description='Resets the firmware settings on the BF to defaults.')
parser.add_argument('-i', '--id', dest='id', default=0, action='store', type=int, help='Specify the id of the BF.')
parser = argparse.ArgumentParser(
description="Resets the firmware settings on the BF to defaults."
)
parser.add_argument(
"-i",
"--id",
dest="id",
default=0,
action="store",
type=int,
help="Specify the id of the BF.",
)
args = parser.parse_args()
bf = common_bf.find_bf_pci_addresses_or_quit(args.id)
os.system(f"mstconfig -y -d {bf} r")


if __name__ == "__main__":
main()
48 changes: 34 additions & 14 deletions fwup
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,37 @@ class RemoteAPI:
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', }
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,
"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,
"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'
"action": "get_download_info",
"version": version,
"distro": distro,
"os": os_param,
"arch": "x64",
}
r = requests.post(self._remote_url, data=data)
return r.json()
Expand Down Expand Up @@ -89,9 +91,27 @@ def update_bf_firmware(args):


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)')
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)
Expand Down
14 changes: 12 additions & 2 deletions fwversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
import common_bf
import argparse


def main():
parser = argparse.ArgumentParser(description='Shows firmware version.')
parser.add_argument('-i', '--id', dest='id', default=0, action='store', type=int, help='Specify the id of the BF-2.')
parser = argparse.ArgumentParser(description="Shows firmware version.")
parser.add_argument(
"-i",
"--id",
dest="id",
default=0,
action="store",
type=int,
help="Specify the id of the BF-2.",
)
args = parser.parse_args()
bf = common_bf.find_bf_pci_addresses_or_quit(args.id)
print(common_bf.mst_flint(bf)["FW Version"])


if __name__ == "__main__":
main()
Loading

0 comments on commit a65579f

Please sign in to comment.