diff --git a/src/altera.cpp b/src/altera.cpp index fdef8c3..a773531 100644 --- a/src/altera.cpp +++ b/src/altera.cpp @@ -31,7 +31,7 @@ Altera::Altera(Jtag *jtag, const std::string &filename, Device(jtag, filename, file_type, verify, verbose), SPIInterface(filename, verbose, 256, verify, skip_load_bridge, skip_reset), - _svf(_jtag, _verbose), _device_package(device_package), + _device_package(device_package), _vir_addr(0x1000), _vir_length(14) { if (prg_type == Device::RD_FLASH) { @@ -216,13 +216,9 @@ void Altera::program(unsigned int offset, bool unprotect_flash) */ /* mem mode -> svf */ if (_mode == Device::MEM_MODE) { - if (_file_extension == "svf") { - _svf.parse(_filename); - } else { - RawParser _bit(_filename, false); - _bit.parse(); - programMem(_bit); - } + RawParser _bit(_filename, false); + _bit.parse(); + programMem(_bit); } else if (_mode == Device::SPI_MODE) { // reverse only bitstream raw binaries data no bool reverseOrder = false; diff --git a/src/altera.hpp b/src/altera.hpp index 12af383..c336eef 100644 --- a/src/altera.hpp +++ b/src/altera.hpp @@ -99,7 +99,6 @@ class Altera: public Device, SPIInterface { void shiftVDR(uint8_t * tx, uint8_t * rx, uint32_t len, int end_state = Jtag::UPDATE_DR, bool debug = false); - SVF_jtag _svf; std::string _device_package; uint32_t _vir_addr; /**< addr affected to virtual jtag */ uint32_t _vir_length; /**< length of virtual jtag IR */ diff --git a/src/anlogic.cpp b/src/anlogic.cpp index d42d050..9c0b966 100644 --- a/src/anlogic.cpp +++ b/src/anlogic.cpp @@ -29,7 +29,7 @@ Anlogic::Anlogic(Jtag *jtag, const std::string &filename, const std::string &file_type, Device::prog_type_t prg_type, bool verify, int8_t verbose): Device(jtag, filename, file_type, verify, verbose), - SPIInterface(filename, verbose, 0, verify), _svf(_jtag, _verbose) + SPIInterface(filename, verbose, 0, verify) { if (prg_type == Device::RD_FLASH) { _mode = Device::READ_MODE; @@ -64,11 +64,6 @@ void Anlogic::program(unsigned int offset, bool unprotect_flash) if (_mode == Device::NONE_MODE) return; - if (_file_extension == "svf") { - _svf.parse(_filename); - return; - } - AnlogicBitParser bit(_filename, (_mode == Device::MEM_MODE), _verbose); printInfo("Parse file ", false); diff --git a/src/anlogic.hpp b/src/anlogic.hpp index 970a3b4..20fd23b 100644 --- a/src/anlogic.hpp +++ b/src/anlogic.hpp @@ -73,8 +73,6 @@ class Anlogic: public Device, SPIInterface { */ virtual bool post_flash_access() override {reset(); return true;} - private: - SVF_jtag _svf; }; #endif // SRC_ANLOGIC_HPP_ diff --git a/src/main.cpp b/src/main.cpp index db04aa6..03efc8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,7 @@ #include "spiFlash.hpp" #include "rawParser.hpp" #include "xilinx.hpp" +#include "svf_jtag.hpp" #ifdef ENABLE_XVC #include "xvc_server.hpp" #endif @@ -496,7 +497,20 @@ int main(int argc, char **argv) jtag->device_select(index); - /* check if selected device is supported + /* detect svf file and program the device */ + if (!args.bit_file.empty() && + ((!args.file_type.empty() && args.file_type == "svf") || + (args.bit_file.substr(args.bit_file.find_last_of(".") + 1) == "svf"))) { + SVF_jtag *svf = new SVF_jtag(jtag, args.verbose); + try { + svf->parse(args.bit_file); + } catch (std::exception &e) { + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } + + /* check if selected device is supported * mainly used in conjunction with --index-chain */ if (fpga_list.find(idcode) == fpga_list.end()) { diff --git a/src/svf_jtag.cpp b/src/svf_jtag.cpp index 75a7b52..bd1800f 100644 --- a/src/svf_jtag.cpp +++ b/src/svf_jtag.cpp @@ -42,8 +42,8 @@ static unsigned char *parse_hex(string const &in, size_t byte_length, { unsigned char *txbuf = new unsigned char[byte_length]; char c; - size_t last_iter = in.size() - (2 * byte_length); - for (size_t i = (in.size() - 1), pos = 0; i >= last_iter; i--, pos++) { + ssize_t last_iter = in.size() - (2 * byte_length); + for (ssize_t i = (in.size() - 1), pos = 0; i >= last_iter; i--, pos++) { if (i < 0) { c = default_value ? 0x0f : 0x00; } else {