From 051e2ecbfbb7373efbf7447c3e99549735638c84 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Tue, 24 May 2022 07:29:35 +0200 Subject: [PATCH] add option to bypass reset in SPI write mode. Adapt altera accordingly --- src/altera.cpp | 13 +++++++++++-- src/altera.hpp | 4 ++-- src/main.cpp | 7 +++++-- src/spiInterface.cpp | 5 +++-- src/spiInterface.hpp | 4 +++- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/altera.cpp b/src/altera.cpp index ef4cb3c..0337257 100644 --- a/src/altera.cpp +++ b/src/altera.cpp @@ -26,9 +26,10 @@ Altera::Altera(Jtag *jtag, const std::string &filename, const std::string &file_type, Device::prog_type_t prg_type, const std::string &device_package, bool verify, int8_t verbose, - bool skip_load_bridge): + bool skip_load_bridge, bool skip_reset): Device(jtag, filename, file_type, verify, verbose), - SPIInterface(filename, verbose, 256, verify, skip_load_bridge), + SPIInterface(filename, verbose, 256, verify, skip_load_bridge, + skip_reset), _svf(_jtag, _verbose), _device_package(device_package), _vir_addr(0x1000), _vir_length(14) { @@ -149,6 +150,14 @@ void Altera::programMem(RawParser &_bit) _jtag->set_state(Jtag::RUN_TEST_IDLE); } +bool Altera::post_flash_access() +{ + if (_skip_reset) + printInfo("Skip resetting device"); + else + reset(); + return true; +} bool Altera::prepare_flash_access() { diff --git a/src/altera.hpp b/src/altera.hpp index 3b7b611..ecdf84e 100644 --- a/src/altera.hpp +++ b/src/altera.hpp @@ -21,7 +21,7 @@ class Altera: public Device, SPIInterface { Device::prog_type_t prg_type, const std::string &device_package, bool verify, int8_t verbose, - bool skip_load_bridge); + bool skip_load_bridge, bool skip_reset); ~Altera(); void programMem(RawParser &_bit); @@ -66,7 +66,7 @@ class Altera: public Device, SPIInterface { protected: bool prepare_flash_access() override; - bool post_flash_access() override {reset(); return true;} + bool post_flash_access() override; private: /*! diff --git a/src/main.cpp b/src/main.cpp index 24fb006..7324b29 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,6 +69,7 @@ struct arguments { bool unprotect_flash; string flash_sector; bool skip_load_bridge; + bool skip_reset; }; int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *pins_config); @@ -85,7 +86,7 @@ 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, "127.0.0.1", - 0, false, "", false}; + 0, false, "", false, false}; /* parse arguments */ try { if (parse_opt(argc, argv, &args, &pins_config)) @@ -468,7 +469,7 @@ int main(int argc, char **argv) } else if (fab == "altera") { fpga = new Altera(jtag, args.bit_file, args.file_type, args.prg_type, args.fpga_part, args.verify, args.verbose, - args.skip_load_bridge); + args.skip_load_bridge, args.skip_reset); } else if (fab == "anlogic") { fpga = new Anlogic(jtag, args.bit_file, args.file_type, args.prg_type, args.verify, args.verbose); @@ -638,6 +639,8 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p cxxopts::value(args->reset)) ("skip-load-bridge", "skip writing bridge to SRAM when in write-flash mode", cxxopts::value(args->skip_load_bridge)) + ("skip-reset", "skip resetting the device when in write-flash mode", + cxxopts::value(args->skip_load_bridge)) ("spi", "SPI mode (only for FTDI in serial mode)", cxxopts::value(args->spi)) ("unprotect-flash", "Unprotect flash blocks", diff --git a/src/spiInterface.cpp b/src/spiInterface.cpp index 425dd42..08469e7 100644 --- a/src/spiInterface.cpp +++ b/src/spiInterface.cpp @@ -15,10 +15,11 @@ SPIInterface::SPIInterface():_spif_verbose(0), _spif_rd_burst(0), {} SPIInterface::SPIInterface(const std::string &filename, uint8_t verbose, - uint32_t rd_burst, bool verify, bool skip_load_bridge): + uint32_t rd_burst, bool verify, bool skip_load_bridge, + bool skip_reset): _spif_verbose(verbose), _spif_rd_burst(rd_burst), _spif_verify(verify), _skip_load_bridge(skip_load_bridge), - _spif_filename(filename) + _skip_reset(skip_reset), _spif_filename(filename) {} /* spiFlash generic acces */ diff --git a/src/spiInterface.hpp b/src/spiInterface.hpp index 7a9f180..8d71b1c 100644 --- a/src/spiInterface.hpp +++ b/src/spiInterface.hpp @@ -20,7 +20,8 @@ class SPIInterface { public: SPIInterface(); SPIInterface(const std::string &filename, uint8_t verbose, - uint32_t rd_burst, bool verify, bool skip_load_bridge = false); + uint32_t rd_burst, bool verify, bool skip_load_bridge = false, + bool skip_reset = false); virtual ~SPIInterface() {} bool protect_flash(uint32_t len); @@ -98,6 +99,7 @@ class SPIInterface { uint32_t _spif_rd_burst; bool _spif_verify; bool _skip_load_bridge; + bool _skip_reset; /*!< don't reset the device after write */ private: std::string _spif_filename;