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