def connect(desc, *args, add_args=None, **kw): parser = argparse.ArgumentParser(description=desc) get_args(parser, *args, **kw) parser.add_argument("--ipaddress") parser.add_argument("--port") #, desc="Serial port") if add_args is not None: add_args(parser) args = parser.parse_args() if args.port: s = ServerProxy(args.port) s.start() while not s.ready: continue args.ipaddress = "127.0.0.1" elif not args.ipaddress: args.ipaddress = "{}.50".format(args.iprange) print("Connecting to {}".format(args.ipaddress)) test_dir = os.path.join(TOP_DIR, get_testdir(args)) wb = RemoteClient(args.ipaddress, 1234, csr_csv="{}/csr.csv".format(test_dir)) wb.open() print() print("Device DNA: {}".format(get_dna(wb))) print(" Git Rev: {}".format(get_git(wb))) print(" Platform: {}".format(get_platform(wb))) print(" Analyzer: {}".format(["No", "Yes"][hasattr(wb.regs, "analyzer")])) print(" XADC: {}".format(get_xadc(wb))) print() return args, wb
def main(): parser = argparse.ArgumentParser(description="Board flashing tool") make.get_args(parser) parser.add_argument( "--mode", default="image", choices=["image", "gateware", "bios", "firmware", "other"], help="Type of file to flash") parser.add_argument("--other-file", default=None) parser.add_argument("--address", type=int, help="Where to flash if using --mode=other") args = parser.parse_args() builddir = make.get_builddir(args) platform = make.get_platform(args) if args.mode == 'image': filename = make.get_image(builddir, "flash") address_start = 0 address_end = platform.spiflash_total_size elif args.mode == 'gateware': filename = make.get_gateware(builddir, "flash") address_start = 0 address_end = platform.gateware_size elif args.mode == 'bios': filename = make.get_bios(builddir, "flash") address_start = platform.gateware_size address_end = platform.gateware_size + make.BIOS_SIZE elif args.mode == 'firmware': if args.override_firmware: filename = args.override_firmware else: filename = make.get_firmware(builddir, "flash") address_start = platform.gateware_size + make.BIOS_SIZE address_end = platform.spiflash_total_size elif args.mode == 'other': filename = args.other_file address_start = args.address address_end = platform.spiflash_total_size else: assert False, "Unknown flashing mode." filepath = os.path.realpath(filename) assert address_start >= 0 assert os.path.exists(filepath), "%s not found at %s" % (args.mode, filepath) file_size = len(open(filepath, 'rb').read()) file_end = address_start + file_size assert file_end < address_end, "File is too big!\n%s file doesn't fit in %s space (%s extra bytes)." % ( filename, file_size, address_end - address_start) prog = make.get_prog(args, platform) prog.flash(address_start, filepath)
def main(): parser = argparse.ArgumentParser(description=__doc__) make.get_args(parser) parser.add_argument("--output-file", default="image.bin") parser.add_argument("--override-gateware") parser.add_argument("--override-bios") parser.add_argument("--firmware-name", default="HDMI2USB") parser.add_argument("--force-image-size") args = parser.parse_args() builddir = make.get_builddir(args) if os.path.sep not in args.output_file: args.output_file = os.path.join(builddir, args.output_file) output_file = args.output_file output_dir = os.path.dirname(output_file) assert os.path.exists(output_dir), ( "Directory %r doesn't exist!" % output_dir) gateware = make.get_gateware(builddir, "flash") if args.override_gateware: if args.override_gateware.lower() == "none": gateware = None else: gateware = args.override_gateware if gateware: assert os.path.exists(gateware), ( "Gateware file %r not found! " "Use --override-gateware=none for no gateware." % gateware) assert gateware.endswith('.bin'), ( "Gateware must be a .bin for flashing (not %s)." % gateware) bios = make.get_bios(builddir, "flash") if args.override_bios: if args.override_bios.lower() == "none": bios = None else: bios = args.override_bios if bios: assert os.path.exists(bios), ( "BIOS file %r not found! " "Use --override-bios=none for no BIOS." % bios) firmware = make.get_firmware(builddir, "flash") if args.override_firmware: if args.override_firmware.lower() == "none": firmware = None else: firmware = args.override_firmware if firmware: assert os.path.exists(firmware), ( "Firmware file %r not found! " "Use --override-firmware=none for no firmware." % firmware) assert firmware.endswith('.fbi'), ( "Firmware must be a MiSoC .fbi image.") platform = make.get_platform(args) gateware_pos = 0 bios_pos = platform.gateware_size firmware_pos = platform.gateware_size + make.BIOS_SIZE print() with open(output_file, "wb") as f: # FPGA gateware if gateware: gateware_data = open(gateware, "rb").read() else: gateware_data = b"" gateware = "Skipped" print(("Gateware @ 0x{:08x} ({:10} bytes) {:60}" " - Xilinx FPGA Bitstream" ).format(gateware_pos, len(gateware_data), gateware)) print(" ".join("{:02x}".format(i) for i in gateware_data[:64])) assert len(gateware_data) < platform.gateware_size f.seek(0) f.write(gateware_data) if bios: bios_data = open(bios, "rb").read() else: bios_data = b"" bios = "Skipped" # LiteX BIOS assert len(bios_data) < make.BIOS_SIZE f.seek(bios_pos) f.write(bios_data) print((" BIOS @ 0x{:08x} ({:10} bytes) {:60}" " - LiteX BIOS with CRC" ).format(bios_pos, len(bios_data), bios)) print(" ".join("{:02x}".format(i) for i in bios_data[:64])) if firmware: firmware_data = open(firmware, "rb").read() else: firmware_data = b"" firmware = "Skipped" # SoftCPU firmware print(("Firmware @ 0x{:08x} ({:10} bytes) {:60}" " - {} Firmware in FBI format (loaded into DRAM)" ).format( firmware_pos, len(firmware_data), firmware, args.firmware_name)) print(" ".join("{:02x}".format(i) for i in firmware_data[:64])) f.seek(firmware_pos) f.write(firmware_data) # Result remain = platform.spiflash_total_size - ( firmware_pos+len(firmware_data)) print("-"*40) print((" Remaining space {:10} bytes" " ({} Megabits, {:.2f} Megabytes)" ).format(remain, int(remain*8/1024/1024), remain/1024/1024)) total = platform.spiflash_total_size print((" Total space {:10} bytes" " ({} Megabits, {:.2f} Megabytes)" ).format(total, int(total*8/1024/1024), total/1024/1024)) if args.force_image_size: if args.force_image_size.lower() in ("true", "1"): flash_size = platform.spiflash_total_size else: flash_size = int(args.force_image_size) f.write(b'\xff' * (flash_size - f.tell())) print() print("Flash image: {}".format(output_file)) flash_image_data = open(output_file, "rb").read() print(" ".join("{:02x}".format(i) for i in flash_image_data[:64]))
def connect(desc, *args, add_args=None, **kw): parser = argparse.ArgumentParser(description=desc) get_args(parser, *args, **kw) # Common arguments parser.add_argument("--bind-ip", default="localhost", help="Host bind address") parser.add_argument("--bind-port", default=1234, help="Host bind port") # UART arguments parser.add_argument("--uart", action="store_true", help="Select UART interface") parser.add_argument("--uart-port", default=None, help="Set UART port") #parser.add_argument("--uart-baudrate", default=115200, # help="Set UART baudrate") # UDP arguments parser.add_argument("--udp", action="store_true", help="Select UDP interface") parser.add_argument("--udp-ip", default="192.168.100.50", help="Set UDP remote IP address") parser.add_argument("--udp-port", default=1234, help="Set UDP remote port") # PCIe arguments parser.add_argument("--pcie", action="store_true", help="Select PCIe interface") parser.add_argument("--pcie-bar", default=None, help="Set PCIe BAR") # USB arguments parser.add_argument("--usb", action="store_true", help="Select USB interface") parser.add_argument("--usb-vid", default=None, help="Set USB vendor ID") parser.add_argument("--usb-pid", default=None, help="Set USB product ID") parser.add_argument("--usb-max-retries", default=10, help="Number of times to try reconnecting to USB") if add_args is not None: add_args(parser) args = parser.parse_args() s = ServerProxy(args) s.start() while not s.ready: continue test_dir = os.path.join(TOP_DIR, get_testdir(args)) wb = RemoteClient(args.bind_ip, int(args.bind_port), csr_csv="{}/csr.csv".format(test_dir), debug=True) wb.open() print() print("Device DNA: {}".format(get_dna(wb))) print(" Git Rev: {}".format(get_git(wb))) print(" Platform: {}".format(get_platform(wb))) print(" Analyzer: {}".format(["No", "Yes"][hasattr(wb.regs, "analyzer")])) print(" XADC: {}".format(get_xadc(wb))) print() return args, wb