From 7ebc7625d5b4b7748f950e8dfe90a92c331f339f Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Mon, 7 Mar 2022 11:33:41 +0100 Subject: [PATCH] tools/litex_client: Add --csr-csv support. Useful to debug multi-FPGA projects. --- litex/tools/litex_client.py | 50 +++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/litex/tools/litex_client.py b/litex/tools/litex_client.py index 5daa46049..05a771e14 100644 --- a/litex/tools/litex_client.py +++ b/litex/tools/litex_client.py @@ -86,15 +86,15 @@ class RemoteClient(EtherboneIPC, CSRBuilder): # Utils -------------------------------------------------------------------------------------------- -def reg2addr(reg): - bus = RemoteClient() +def reg2addr(csr_csv, reg): + bus = RemoteClient(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(port): - bus = RemoteClient(port=port) +def dump_identifier(csr_csv, port): + bus = RemoteClient(csr_csv=csr_csv, port=port) bus.open() # On PCIe designs, CSR is remapped to 0 to limit BAR0 size. @@ -113,8 +113,8 @@ def dump_identifier(port): bus.close() -def dump_registers(port, filter=None): - bus = RemoteClient(port=port) +def dump_registers(csr_csv, port, filter=None): + bus = RemoteClient(csr_csv=csr_csv, port=port) bus.open() # On PCIe designs, CSR is remapped to 0 to limit BAR0 size. @@ -127,8 +127,8 @@ def dump_registers(port, filter=None): bus.close() -def read_memory(port, addr, length): - bus = RemoteClient(port=port) +def read_memory(csr_csv, port, addr, length): + bus = RemoteClient(csr_csv=csr_csv, port=port) bus.open() for offset in range(length//4): @@ -136,8 +136,8 @@ def read_memory(port, addr, length): bus.close() -def write_memory(port, addr, data): - bus = RemoteClient(port=port) +def write_memory(csr_csv, port, addr, data): + bus = RemoteClient(csr_csv=csr_csv, port=port) bus.open() bus.write(addr, data) @@ -148,36 +148,38 @@ def write_memory(port, addr, data): def main(): parser = argparse.ArgumentParser(description="LiteX Client utility.", formatter_class=argparse.ArgumentDefaultsHelpFormatter) - 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.") - parser.add_argument("--filter", default=None, help="Registers filter (to be used with --regs).") - parser.add_argument("--read", default=None, help="Do a MMAP Read to SoC bus (--read addr/reg).") - parser.add_argument("--write", default=None, nargs=2, help="Do a MMAP Write to SoC bus (--write addr/reg data).") - parser.add_argument("--length", default="4", help="MMAP access length.") + parser.add_argument("--csr-csv", default="csr.csv", help="CSR configuration file") + 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.") + parser.add_argument("--filter", default=None, help="Registers filter (to be used with --regs).") + parser.add_argument("--read", default=None, help="Do a MMAP Read to SoC bus (--read addr/reg).") + parser.add_argument("--write", default=None, nargs=2, help="Do a MMAP Write to SoC bus (--write addr/reg data).") + parser.add_argument("--length", default="4", help="MMAP access length.") args = parser.parse_args() - port = int(args.port, 0) + csr_csv = args.csr_csv + port = int(args.port, 0) if args.ident: - dump_identifier(port=port) + dump_identifier(csr_csv=csr_csv, port=port) if args.regs: - dump_registers(port=port, filter=args.filter) + dump_registers(csr_csv=csr_csv, port=port, filter=args.filter) if args.read: if isinstance(args.read, str): - addr = reg2addr(args.read) + addr = reg2addr(csr_csv, args.read) else: addr = int(args.read, 0) - read_memory(port=port, addr=addr, length=int(args.length, 0)) + read_memory(csr_csv=csr_csv, port=port, addr=addr, length=int(args.length, 0)) if args.write: if isinstance(args.write[0], str): - addr = reg2addr(args.write[0]) + addr = reg2addr(csr_csv, args.write[0]) else: addr = int(args.write[0], 0) - write_memory(port=port, addr=addr, data=int(args.write[1], 0)) + write_memory(csr_csv=csr_csv, port=port, addr=addr, data=int(args.write[1], 0)) if __name__ == "__main__": main()