From 7059c15960120e837fd7f996066bdb7b3c2b2c94 Mon Sep 17 00:00:00 2001 From: Mark Featherston Date: Fri, 10 Nov 2023 14:00:13 -0700 Subject: [PATCH] Add user device list for non-fpga JTAG devices --- src/jtag.cpp | 11 +++++++++-- src/jtag.hpp | 5 ++++- src/main.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/jtag.cpp b/src/jtag.cpp index 52ad6e0..f12eb07 100644 --- a/src/jtag.cpp +++ b/src/jtag.cpp @@ -77,11 +77,13 @@ Jtag::Jtag(const cable_t &cable, const jtag_pins_conf_t *pin_conf, const string &dev, const string &serial, uint32_t clkHZ, int8_t verbose, const string &ip_adr, int port, - const bool invert_read_edge, const string &firmware_path): + const bool invert_read_edge, const string &firmware_path, + const std::map &user_misc_devs): _verbose(verbose > 1), _state(RUN_TEST_IDLE), _tms_buffer_size(128), _num_tms(0), - _board_name("nope"), device_index(0), _curr_tdi(1) + _board_name("nope"), device_index(0), _curr_tdi(1), + _user_misc_devs(user_misc_devs) { switch (cable.type) { case MODE_ANLOGICCABLE: @@ -246,6 +248,11 @@ bool Jtag::search_and_insert_device_with_idcode(uint32_t idcode) if (misc != misc_dev_list.end()) irlength = misc->second.irlength; } + if (irlength == -1) { + auto misc = this->_user_misc_devs.find(idcode); + if (misc != this->_user_misc_devs.end()) + irlength = misc->second.irlength; + } if (irlength == -1) return false; diff --git a/src/jtag.hpp b/src/jtag.hpp index 9e8307e..3d91409 100644 --- a/src/jtag.hpp +++ b/src/jtag.hpp @@ -12,6 +12,7 @@ #include "board.hpp" #include "cable.hpp" +#include "part.hpp" #include "jtagInterface.hpp" class Jtag { @@ -21,7 +22,8 @@ class Jtag { const std::string &serial, uint32_t clkHZ, int8_t verbose, const std::string &ip_adr, int port, const bool invert_read_edge = false, - const std::string &firmware_path = ""); + const std::string &firmware_path = "", + const std::map &user_misc_devs = {}); ~Jtag(); /* maybe to update */ @@ -146,6 +148,7 @@ class Jtag { int _num_tms; unsigned char *_tms_buffer; std::string _board_name; + const std::map& _user_misc_devs; int device_index; /*!< index for targeted FPGA */ diff --git a/src/main.cpp b/src/main.cpp index 3ec55ee..4bab4a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,6 +91,7 @@ struct arguments { string interface; string mcufw; bool conmcu; + std::map user_misc_devs; }; int run_xvc_server(const struct arguments &args, const cable_t &cable, @@ -119,7 +120,7 @@ int main(int argc, char **argv) "127.0.0.1", 0, false, false, "", false, false, /* xvc server */ false, 3721, "-", - "", false, // mcufw conmcu + "", false, {} // mcufw conmcu, user_misc_dev_list }; /* parse arguments */ try { @@ -446,7 +447,8 @@ int main(int argc, char **argv) try { jtag = new Jtag(cable, &pins_config, args.device, args.ftdi_serial, args.freq, args.verbose, args.ip_adr, args.port, - args.invert_read_edge, args.probe_firmware); + args.invert_read_edge, args.probe_firmware, + args.user_misc_devs); } catch (std::exception &e) { printError("JTAG init failed with: " + string(e.what())); return EXIT_FAILURE; @@ -479,6 +481,11 @@ int main(int argc, char **argv) t, misc_dev_list[t].name.c_str(), misc_dev_list[t].irlength); + } else if (args.user_misc_devs.find(t) != args.user_misc_devs.end()) { + printf("\tidcode 0x%x\n\ttype %s\n\tirlength %d\n", + t, + args.user_misc_devs[t].name.c_str(), + args.user_misc_devs[t].irlength); } } if (args.detect == true) { @@ -765,6 +772,8 @@ int parse_opt(int argc, char **argv, struct arguments *args, "write bitstream in flash (default: false)") ("index-chain", "device index in JTAG-chain", cxxopts::value(args->index_chain)) + ("misc-device", "add JTAG non-FPGA devices ", + cxxopts::value>()) ("ip", "IP address (XVC and remote bitbang client)", cxxopts::value(args->ip_adr)) ("list-boards", "list all supported boards", @@ -846,6 +855,32 @@ int parse_opt(int argc, char **argv, struct arguments *args, return 1; } + if (result.count("misc-device")) { + auto misc_devices = result["misc-device"].as>(); + for (auto &dev : misc_devices) { + uint32_t idcode; + int irlen; + std:string name; + std::stringstream ss(dev); + std::string item; + std::vector tokens; + + while (std::getline(ss, item, ',')) { + tokens.push_back(item); + } + + if (tokens.size() != 3) { + printError("Error: invalid format for misc-device."); + throw std::exception(); + } + + idcode = std::stoul(tokens[0], nullptr, 16); + irlen = std::stoi(tokens[1]); + name = tokens[2]; + args->user_misc_devs[idcode] = {name, irlen}; + } + } + if (result.count("write-flash") && result.count("write-sram") && result.count("dump-flash")) { printError("Error: both write to flash and write to ram enabled");