tools/litex_client: Add --host argument to allow specifying Host's ip address.

Useful when LiteX server is run on a remote machine and script development is done
directly on dev machine.
This commit is contained in:
Florent Kermarrec 2022-07-19 16:10:14 +02:00
parent 25c0eed258
commit dccdc236a6
1 changed files with 45 additions and 18 deletions

View File

@ -88,15 +88,15 @@ class RemoteClient(EtherboneIPC, CSRBuilder):
# Utils --------------------------------------------------------------------------------------------
def reg2addr(csr_csv, reg):
bus = RemoteClient(csr_csv=csr_csv)
def reg2addr(host, csr_csv, reg):
bus = RemoteClient(host=host, csr_csv=csr_csv)
if hasattr(bus.regs, reg):
return getattr(bus.regs, reg).addr
else:
raise ValueError(f"Register {reg} not present, exiting.")
def dump_identifier(csr_csv, port):
bus = RemoteClient(csr_csv=csr_csv, port=port)
def dump_identifier(host, csr_csv, port):
bus = RemoteClient(host=host, csr_csv=csr_csv, port=port)
bus.open()
# On PCIe designs, CSR is remapped to 0 to limit BAR0 size.
@ -115,8 +115,8 @@ def dump_identifier(csr_csv, port):
bus.close()
def dump_registers(csr_csv, port, filter=None):
bus = RemoteClient(csr_csv=csr_csv, port=port)
def dump_registers(host, csr_csv, port, filter=None):
bus = RemoteClient(host=host, csr_csv=csr_csv, port=port)
bus.open()
# On PCIe designs, CSR is remapped to 0 to limit BAR0 size.
@ -129,8 +129,8 @@ def dump_registers(csr_csv, port, filter=None):
bus.close()
def read_memory(csr_csv, port, addr, length):
bus = RemoteClient(csr_csv=csr_csv, port=port)
def read_memory(host, csr_csv, port, addr, length):
bus = RemoteClient(host=host, csr_csv=csr_csv, port=port)
bus.open()
for offset in range(length//4):
@ -138,8 +138,8 @@ def read_memory(csr_csv, port, addr, length):
bus.close()
def write_memory(csr_csv, port, addr, data):
bus = RemoteClient(csr_csv=csr_csv, port=port)
def write_memory(host, csr_csv, port, addr, data):
bus = RemoteClient(host=host, csr_csv=csr_csv, port=port)
bus.open()
bus.write(addr, data)
@ -148,10 +148,10 @@ def write_memory(csr_csv, port, addr, data):
# Gui ----------------------------------------------------------------------------------------------
def run_gui(csr_csv, port):
def run_gui(host, csr_csv, port):
import dearpygui.dearpygui as dpg
bus = RemoteClient(csr_csv=csr_csv, port=port)
bus = RemoteClient(host, csr_csv=csr_csv, port=port)
bus.open()
def reboot_callback():
@ -209,6 +209,7 @@ def run_gui(csr_csv, port):
def main():
parser = argparse.ArgumentParser(description="LiteX Client utility.", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--csr-csv", default="csr.csv", help="CSR configuration file")
parser.add_argument("--host", default="localhost", help="Host ip address")
parser.add_argument("--port", default="1234", help="Host bind port.")
parser.add_argument("--ident", action="store_true", help="Dump SoC identifier.")
parser.add_argument("--regs", action="store_true", help="Dump SoC registers.")
@ -219,31 +220,57 @@ def main():
parser.add_argument("--gui", action="store_true", help="Run Gui.")
args = parser.parse_args()
host = args.host
csr_csv = args.csr_csv
port = int(args.port, 0)
if args.ident:
dump_identifier(csr_csv=csr_csv, port=port)
dump_identifier(
host = host,
csr_csv = csr_csv,
port = port,
)
if args.regs:
dump_registers(csr_csv=csr_csv, port=port, filter=args.filter)
dump_registers(
host = args.host,
csr_csv = csr_csv,
port = port,
filter = args.filter,
)
if args.read:
try:
addr = int(args.read, 0)
except ValueError:
addr = reg2addr(csr_csv, args.read)
read_memory(csr_csv=csr_csv, port=port, addr=addr, length=int(args.length, 0))
addr = reg2addr(host, csr_csv, args.read)
read_memory(
host = args.host,
csr_csv = csr_csv,
port = port,
addr = addr,
length = int(args.length, 0),
)
if args.write:
try:
addr = int(args.write[0], 0)
except ValueError:
addr = reg2addr(csr_csv, args.write[0])
write_memory(csr_csv=csr_csv, port=port, addr=addr, data=int(args.write[1], 0))
write_memory(
host = args.host,
csr_csv = csr_csv,
port = port,
addr = addr,
data = int(args.write[1], 0),
)
if args.gui:
run_gui(csr_csv=csr_csv, port=port)
run_gui(
host = args.host,
csr_csv = csr_csv,
port = port,
)
if __name__ == "__main__":
main()