From a90a7b6fa55d62a271b69f5185b64aa50367afcf Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Wed, 6 Jul 2022 20:58:34 +0200 Subject: [PATCH] main: enable xvc_server --- README.md | 2 ++ doc/cable.yml | 7 +++++++ src/main.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d95c39b..8b3d0c9 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,8 @@ openFPGALoader -- a program to flash FPGA 2:debug -h, --help Give this help list --verify Verify write operation (SPI Flash only) + --xvc Xilinx Virtual Cable Functions + --port arg Xilinx Virtual Cable Port (default 3721) -V, --Version Print program version Mandatory or optional arguments to long options are also mandatory or optional diff --git a/doc/cable.yml b/doc/cable.yml index 0b3a8f3..6f9da3e 100644 --- a/doc/cable.yml +++ b/doc/cable.yml @@ -229,3 +229,10 @@ xvc-client: - Name: Xilinx Virtual Cable Description: Xilinx Virtual Cable (XVC) is a TCP/IP-based protocol that acts like a JTAG cable. URL: https://github.com/Xilinx/XilinxVirtualCable + + +xvc-server: + + - Name: Xilinx Virtual Cable (server side) + Description: Xilinx Virtual Cable (XVC) is a TCP/IP-based protocol that acts like a JTAG cable. + URL: https://github.com/Xilinx/XilinxVirtualCable diff --git a/src/main.cpp b/src/main.cpp index 63586dd..6c69db1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,7 @@ #include "spiFlash.hpp" #include "rawParser.hpp" #include "xilinx.hpp" +#include "xvc_server.hpp" #define DEFAULT_FREQ 6000000 @@ -71,8 +72,15 @@ struct arguments { string flash_sector; bool skip_load_bridge; bool skip_reset; + /* xvc server */ + bool xvc; + int port; + string interface; }; +int run_xvc_server(const struct arguments &args, const cable_t &cable, + const jtag_pins_conf_t *pins_config); + int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *pins_config); void displaySupported(const struct arguments &args); @@ -87,7 +95,10 @@ int main(int argc, char **argv) struct arguments args = {0, false, false, false, 0, "", "", "-", "", -1, 0, false, "-", false, false, false, false, Device::PRG_NONE, false, false, false, "", "", "", -1, 0, false, -1, 0, 0, 0, "127.0.0.1", - 0, false, "", false, false}; + 0, false, "", false, false, + /* xvc server */ + false, 3721, "-", + }; /* parse arguments */ try { if (parse_opt(argc, argv, &args, &pins_config)) @@ -370,8 +381,16 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } + /* ------------------- */ + /* XVC server */ + /* ------------------- */ + if (args.xvc) { + return run_xvc_server(args, cable, &pins_config); + } + /* jtag base */ + /* if no instruction from user -> select load */ if (args.prg_type == Device::PRG_NONE) args.prg_type = Device::WR_SRAM; @@ -466,6 +485,7 @@ int main(int argc, char **argv) string fab = fpga_list[idcode].manufacturer; + Device *fpga; try { if (fab == "xilinx") { @@ -538,6 +558,30 @@ int main(int argc, char **argv) delete(jtag); } +int run_xvc_server(const struct arguments &args, const cable_t &cable, + const jtag_pins_conf_t *pins_config) +{ + //create XVC instance + try { + XVC_server *xvc = NULL; + xvc = new XVC_server(args.port, cable, pins_config, args.device, + args.ftdi_serial, args.freq, args.verbose, args.ip_adr, + args.invert_read_edge, args.probe_firmware); + /* create connection */ + xvc->open_connection(); + /* start loop */ + xvc->listen_loop(); + /* close connection */ + xvc->close_connection(); + delete xvc; + } catch (std::exception &e) { + printError("XVC_server failed with " + string(e.what())); + return EXIT_FAILURE; + } + printInfo("Xilinx Virtual Cable Stopped! "); + return EXIT_SUCCESS; +} + // parse double from string in engineering notation // can deal with postfixes k and m, add more when required static int parse_eng(string arg, double *dst) { @@ -657,6 +701,10 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p ("h,help", "Give this help list") ("verify", "Verify write operation (SPI Flash only)", cxxopts::value(args->verify)) + ("xvc", "Xilinx Virtual Cable Functions", + cxxopts::value(args->xvc)) + ("port", "Xilinx Virtual Cable Port (default 3721)", + cxxopts::value(args->port)) ("V,Version", "Print program version"); options.parse_positional({"bitstream"}); @@ -786,6 +834,7 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p !args->detect && !args->protect_flash && !args->unprotect_flash && + !args->xvc && !args->reset) { printError("Error: bitfile not specified"); cout << options.help() << endl;