From 1908ccd83b965c2d2b0eadb390120200fcf1d8ab Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Tue, 8 Aug 2023 16:54:27 +0300 Subject: [PATCH] make output buffer const --- src/altera.cpp | 8 +++--- src/altera.hpp | 4 +-- src/anlogic.cpp | 8 +++--- src/anlogic.hpp | 4 +-- src/anlogicBitParser.cpp | 4 +-- src/anlogicCable.cpp | 10 +++---- src/anlogicCable.hpp | 6 ++--- src/ch347jtag.cpp | 14 +++++----- src/ch347jtag.hpp | 8 +++--- src/ch552_jtag.cpp | 4 +-- src/ch552_jtag.hpp | 4 +-- src/cmsisDAP.cpp | 49 ++++++++++++++++++----------------- src/cmsisDAP.hpp | 6 ++--- src/colognechip.cpp | 14 +++++----- src/colognechip.hpp | 12 ++++----- src/colognechipCfgParser.cpp | 2 +- src/configBitstreamParser.hpp | 5 ++-- src/dfu.cpp | 14 +++++----- src/dfu.hpp | 14 +++++----- src/dirtyJtag.cpp | 10 +++---- src/dirtyJtag.hpp | 4 +-- src/efinix.cpp | 4 +-- src/efinix.hpp | 4 +-- src/efinixHexParser.cpp | 2 +- src/fsparser.cpp | 4 +-- src/ftdiJtagBitbang.cpp | 4 +-- src/ftdiJtagBitbang.hpp | 4 +-- src/ftdiJtagMPSSE.cpp | 4 +-- src/ftdiJtagMPSSE.hpp | 4 +-- src/ftdispi.cpp | 8 +++--- src/ftdispi.hpp | 4 +-- src/gowin.cpp | 22 ++++++++-------- src/gowin.hpp | 8 +++--- src/ice40.cpp | 6 ++--- src/ice40.hpp | 6 ++--- src/jlink.cpp | 21 ++++++++------- src/jlink.hpp | 4 +-- src/jtag.cpp | 6 ++--- src/jtag.hpp | 4 +-- src/jtagInterface.hpp | 4 +-- src/lattice.cpp | 36 ++++++++++++------------- src/lattice.hpp | 4 +-- src/libgpiodJtagBitbang.cpp | 8 +++--- src/libgpiodJtagBitbang.hpp | 4 +-- src/remoteBitbang_client.cpp | 6 ++--- src/remoteBitbang_client.hpp | 4 +-- src/spiFlash.cpp | 6 ++--- src/spiFlash.hpp | 4 +-- src/spiInterface.cpp | 2 +- src/spiInterface.hpp | 6 ++--- src/usbBlaster.cpp | 10 +++---- src/usbBlaster.hpp | 4 +-- src/xilinx.cpp | 23 ++++++++-------- src/xilinx.hpp | 4 +-- src/xilinxMapParser.cpp | 2 +- src/xvc_client.cpp | 11 ++++---- src/xvc_client.hpp | 4 +-- 57 files changed, 235 insertions(+), 230 deletions(-) diff --git a/src/altera.cpp b/src/altera.cpp index ad1febb..0415725 100644 --- a/src/altera.cpp +++ b/src/altera.cpp @@ -78,7 +78,7 @@ void Altera::reset() void Altera::programMem(RawParser &_bit) { int byte_length = _bit.getLength()/8; - uint8_t *data = _bit.getData(); + const uint8_t *data = _bit.getData(); uint32_t clk_period = 1e9/static_cast(_jtag->getClkFreq()); @@ -232,7 +232,7 @@ void Altera::program(unsigned int offset, bool unprotect_flash) reverseOrder = true; /* prepare data to write */ - uint8_t *data = NULL; + const uint8_t *data = NULL; int length = 0; RawParser bit(_filename, reverseOrder); @@ -266,7 +266,7 @@ int Altera::idCode() /* SPI interface */ -int Altera::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) +int Altera::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) { /* +1 because send first cmd + len byte + 1 for rx due to a delay of * one bit @@ -291,7 +291,7 @@ int Altera::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) return 0; } -int Altera::spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) +int Altera::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) { return spi_put(tx[0], &tx[1], rx, len-1); } diff --git a/src/altera.hpp b/src/altera.hpp index f76afc5..1c359d0 100644 --- a/src/altera.hpp +++ b/src/altera.hpp @@ -65,9 +65,9 @@ class Altera: public Device, SPIInterface { return SPIInterface::bulk_erase_flash(); } - int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) override; - int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override; + int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override; int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose = false) override; diff --git a/src/anlogic.cpp b/src/anlogic.cpp index 9c0b966..19856c8 100644 --- a/src/anlogic.cpp +++ b/src/anlogic.cpp @@ -77,7 +77,7 @@ void Anlogic::program(unsigned int offset, bool unprotect_flash) if (_verbose) bit.displayHeader(); - uint8_t *data = bit.getData(); + const uint8_t *data = bit.getData(); int len = bit.getLength() / 8; if (_mode == Device::SPI_MODE) { @@ -110,7 +110,7 @@ void Anlogic::program(unsigned int offset, bool unprotect_flash) ProgressBar progress("Loading", len, 50, _quiet); int pos = 0; - uint8_t *ptr = data; + const uint8_t *ptr = data; while (len > 0) { int xfer_len = (len > 512)?512:len; int tx_end; @@ -184,7 +184,7 @@ bool Anlogic::prepare_flash_access() * In write only operations to care about this delay */ -int Anlogic::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) +int Anlogic::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) { int xfer_len = len + 1; if (rx) @@ -210,7 +210,7 @@ int Anlogic::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) } return 0; } -int Anlogic::spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) +int Anlogic::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) { int xfer_len = len; if (rx) diff --git a/src/anlogic.hpp b/src/anlogic.hpp index 20fd23b..8864e3c 100644 --- a/src/anlogic.hpp +++ b/src/anlogic.hpp @@ -57,9 +57,9 @@ class Anlogic: public Device, SPIInterface { return SPIInterface::dump(base_addr, len); } - int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) override; - int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override; + int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override; int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose=false) override; diff --git a/src/anlogicBitParser.cpp b/src/anlogicBitParser.cpp index 771169c..376b072 100644 --- a/src/anlogicBitParser.cpp +++ b/src/anlogicBitParser.cpp @@ -109,9 +109,9 @@ int AnlogicBitParser::parse() for (auto it = blocks.begin(); it != blocks.end(); it++) { for (size_t xpos = 0; xpos < it->size(); xpos++) { if (_reverseOrder == true) - _bit_data += reverseByte(((*it)[xpos])); + _bit_data.push_back(reverseByte(((*it)[xpos]))); else - _bit_data += ((*it)[xpos]); + _bit_data.push_back((*it)[xpos]); } } _bit_length = _bit_data.size() * 8; diff --git a/src/anlogicCable.cpp b/src/anlogicCable.cpp index 50d13c3..f54fd92 100644 --- a/src/anlogicCable.cpp +++ b/src/anlogicCable.cpp @@ -123,7 +123,7 @@ int AnlogicCable::setClkFreq(uint32_t clkHZ) } ret = libusb_bulk_transfer(dev_handle, ANLOGICCABLE_CONF_EP, - buf, 2, &actual_length, 1000); + buf, 2, &actual_length, 1000); if (ret < 0) { cerr << "setClkFreq: usb bulk write failed " << ret << endl; return -EXIT_FAILURE; @@ -137,7 +137,7 @@ int AnlogicCable::setClkFreq(uint32_t clkHZ) return clkHZ; } -int AnlogicCable::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int AnlogicCable::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { (void) flush_buffer; @@ -148,7 +148,7 @@ int AnlogicCable::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) uint8_t mask = (ANLOGICCABLE_TCK_PIN << 4); int full_len = len; - uint8_t *tx_ptr = tms; + const uint8_t *tx_ptr = tms; while (full_len > 0) { /* when len > buffer capacity -> limit to capacity @@ -219,13 +219,13 @@ int AnlogicCable::flush() return 0; } -int AnlogicCable::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) +int AnlogicCable::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { uint8_t buf[512]; uint8_t mask = (ANLOGICCABLE_TCK_PIN << 4); int full_len = len; - uint8_t *tx_ptr = tx; + const uint8_t *tx_ptr = tx; uint8_t *rx_ptr = rx; while (full_len > 0) { diff --git a/src/anlogicCable.hpp b/src/anlogicCable.hpp index 49b1eb2..3ec4c4f 100644 --- a/src/anlogicCable.hpp +++ b/src/anlogicCable.hpp @@ -25,9 +25,9 @@ class AnlogicCable : public JtagInterface { int setClkFreq(uint32_t clkHZ) override; /* TMS */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /* TDI */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /* clk */ int toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len) override; @@ -45,7 +45,7 @@ class AnlogicCable : public JtagInterface { private: int write(uint8_t *in_buf, uint8_t *out_buf, int len, int rd_len); - libusb_device_handle *dev_handle; + libusb_device_handle *dev_handle; libusb_context *usb_ctx; }; #endif // SRC_ANLOGICCABLE_HPP_ diff --git a/src/ch347jtag.cpp b/src/ch347jtag.cpp index 96ab5c3..3f59352 100644 --- a/src/ch347jtag.cpp +++ b/src/ch347jtag.cpp @@ -193,7 +193,7 @@ CH347Jtag::CH347Jtag(uint32_t clkHZ, int8_t verbose): } libusb_bulk_transfer(dev_handle, CH347JTAG_READ_EP, ibuf, 512, &actual_length, CH347JTAG_TIMEOUT); - setClkFreq(clkHZ); + _setClkFreq(clkHZ); return; usb_release: libusb_release_interface(dev_handle, CH347JTAG_INTF); @@ -221,7 +221,7 @@ CH347Jtag::~CH347Jtag() } } -int CH347Jtag::setClkFreq(uint32_t clkHZ) +int CH347Jtag::_setClkFreq(uint32_t clkHZ) { unsigned i = 0, sl = 2000000; if (clkHZ <= 2000000) { @@ -244,7 +244,7 @@ int CH347Jtag::setClkFreq(uint32_t clkHZ) return _clkHZ; } -int CH347Jtag::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int CH347Jtag::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { (void) flush_buffer; @@ -307,15 +307,15 @@ int CH347Jtag::toggleClk(uint8_t tms, uint8_t tdi, uint32_t len) return EXIT_SUCCESS; } -int CH347Jtag::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) +int CH347Jtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { if (!tx || !len) return 0; unsigned bytes = (len - ((end)?1:0)) / 8; unsigned bits = len - bytes * 8; uint8_t *rptr = rx; - uint8_t *tptr = tx; - uint8_t *txend = &tx[bytes]; + const uint8_t *tptr = tx; + const uint8_t *txend = tx + bytes; uint8_t cmd = (rx) ? CMD_BYTES_WR : CMD_BYTES_WO; while (tptr < txend) { unsigned avail = sizeof(obuf) - 3; @@ -349,7 +349,7 @@ int CH347Jtag::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) cmd = (rx) ? CMD_BITS_WR : CMD_BITS_WO; uint8_t *ptr = &obuf[3]; uint8_t x = 0; - uint8_t *bptr = &tx[bytes]; + const uint8_t *bptr = &tx[bytes]; for (unsigned i = 0; i < bits; ++i) { uint8_t txb = bptr[i >> 3]; uint8_t _tdi = (txb & (1 << (i & 7))) ? SIG_TDI : 0; diff --git a/src/ch347jtag.hpp b/src/ch347jtag.hpp index ee6fe04..a02fc1e 100644 --- a/src/ch347jtag.hpp +++ b/src/ch347jtag.hpp @@ -13,12 +13,12 @@ class CH347Jtag : public JtagInterface { CH347Jtag(uint32_t clkHZ, int8_t verbose); virtual ~CH347Jtag(); - int setClkFreq(uint32_t clkHZ) override; - + int setClkFreq(uint32_t clkHZ) override { return _setClkFreq(clkHZ); }; + int _setClkFreq(uint32_t clkHZ); /* TMS */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /* TDI */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /* clk */ int toggleClk(uint8_t tms, uint8_t tdo, uint32_t clk_len) override; diff --git a/src/ch552_jtag.cpp b/src/ch552_jtag.cpp index 79d329f..7462f78 100644 --- a/src/ch552_jtag.cpp +++ b/src/ch552_jtag.cpp @@ -88,7 +88,7 @@ int CH552_jtag::setClkFreq(uint32_t clkHZ) { return ret; } -int CH552_jtag::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int CH552_jtag::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { (void) flush_buffer; display("%s %d %d\n", __func__, len, (len/8)+1); @@ -172,7 +172,7 @@ int CH552_jtag::flush() return ret; } -int CH552_jtag::writeTDI(uint8_t *tdi, uint8_t *tdo, uint32_t len, bool last) +int CH552_jtag::writeTDI(const uint8_t *tdi, uint8_t *tdo, uint32_t len, bool last) { bool rd_mode = (tdo) ? true : false; /* 3 possible case : diff --git a/src/ch552_jtag.hpp b/src/ch552_jtag.hpp index 3bbbf00..bd3fd5d 100644 --- a/src/ch552_jtag.hpp +++ b/src/ch552_jtag.hpp @@ -32,11 +32,11 @@ class CH552_jtag : public JtagInterface, private FTDIpp_MPSSE { uint32_t getClkFreq() override {return FTDIpp_MPSSE::getClkFreq();} /* TMS */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /* clock */ int toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len) override; /* TDI */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /*! * \brief return internal buffer size (in byte). diff --git a/src/cmsisDAP.cpp b/src/cmsisDAP.cpp index a4270ee..9aecdd9 100644 --- a/src/cmsisDAP.cpp +++ b/src/cmsisDAP.cpp @@ -49,11 +49,11 @@ enum cmsisdap_info_id { INFO_ID_PID = 0x02, // Get the Product ID (string). INFO_ID_SERNUM = 0x03, // Get the Serial Number (string). INFO_ID_FWVERS = 0x04, // Get the CMSIS-DAP Firmware - // Version (string). + // Version (string). INFO_ID_TARGET_DEV_VENDOR = 0x05, // Get the Target Device Vendor (string). INFO_ID_TARGET_DEV_NAME = 0x06, // Get the Target Device Name (string). INFO_ID_HWCAP = 0xF0, // Get information about the - // Capabilities (BYTE) of the Debug Unit + // Capabilities (BYTE) of the Debug Unit INFO_ID_SWO_TEST_TIM_PARAM = 0xF1, // Get the Test Domain Timer parameter INFO_ID_SWO_TRACE_BUF_SIZE = 0xFD, // Get the SWO Trace Buffer Size (WORD). INFO_ID_MAX_PKT_CNT = 0xFE, // Get the maximum Packet Count (BYTE). @@ -186,23 +186,23 @@ CmsisDAP::CmsisDAP(const cable_t &cable, int index, int8_t verbose):_verbose(ver * 0 -> info * 1 -> len (1: info0, 2: info0, info1) * Available transfer protocols to target: - Info0 - Bit 0: 1 = SWD Serial Wire Debug communication is implemented - 0 = SWD Commands not implemented - Info0 - Bit 1: 1 = JTAG communication is implemented - 0 = JTAG Commands not implemented - Serial Wire Trace (SWO) support: - Info0 - Bit 2: 1 = SWO UART - UART Serial Wire Output is implemented - 0 = not implemented - Info0 - Bit 3: 1 = SWO Manchester - Manchester Serial Wire Output is implemented - 0 = not implemented - Command extensions for transfer protocol: - Info0 - Bit 4: 1 = Atomic Commands - Atomic Commands support is implemented - 0 = Atomic Commands not implemented - Time synchronisation via Test Domain Timer: - Info0 - Bit 5: 1 = Test Domain Timer - debug unit support for Test Domain Timer is implemented - 0 = not implemented - SWO Streaming Trace support: - Info0 - Bit 6: 1 = SWO Streaming Trace is implemented (0 = not implemented). + Info0 - Bit 0: 1 = SWD Serial Wire Debug communication is implemented + 0 = SWD Commands not implemented + Info0 - Bit 1: 1 = JTAG communication is implemented + 0 = JTAG Commands not implemented + Serial Wire Trace (SWO) support: + Info0 - Bit 2: 1 = SWO UART - UART Serial Wire Output is implemented + 0 = not implemented + Info0 - Bit 3: 1 = SWO Manchester - Manchester Serial Wire Output is implemented + 0 = not implemented + Command extensions for transfer protocol: + Info0 - Bit 4: 1 = Atomic Commands - Atomic Commands support is implemented + 0 = Atomic Commands not implemented + Time synchronisation via Test Domain Timer: + Info0 - Bit 5: 1 = Test Domain Timer - debug unit support for Test Domain Timer is implemented + 0 = not implemented + SWO Streaming Trace support: + Info0 - Bit 6: 1 = SWO Streaming Trace is implemented (0 = not implemented). */ memset(_buffer, 0, 63); int res = read_info(INFO_ID_HWCAP, _buffer, 63); @@ -313,7 +313,7 @@ int CmsisDAP::setClkFreq(uint32_t clkHZ) * flush the buffer * tms states are written only if max or if flush_buffer set */ -int CmsisDAP::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int CmsisDAP::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { /* nothing to send * check if the buffer must be flushed @@ -349,14 +349,15 @@ int CmsisDAP::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) /* 0x14 + number of sequence + seq1 details + tdi + seq2 details + tdi + ... */ -int CmsisDAP::writeJtagSequence(uint8_t tms, uint8_t *tx, uint8_t *rx, +int CmsisDAP::writeJtagSequence(uint8_t tms, const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { int ret; int real_len = len - (end ? 1 : 0); // full xfer size according to end - uint8_t *rx_ptr = rx, *tx_ptr = tx; // rd & wr ptr + uint8_t *rx_ptr = rx; + const uint8_t *tx_ptr = tx; // rd & wr ptr int xfer_byte_len, xfer_bit_len; // size of one sequence - // in byte and bit + // in byte and bit int byte_to_read = 0; // for rd operation number of read in one xfer /* constant part of all sequences info byte */ uint8_t seq_info_base = ((rx) ? DAP_JTAG_SEQ_TDO_CAPTURE : 0) | @@ -462,7 +463,7 @@ int CmsisDAP::writeJtagSequence(uint8_t tms, uint8_t *tx, uint8_t *rx, /* send TDI by filling jtag sequence * tx buffer is considered to be correctly aligned (LSB first) */ -int CmsisDAP::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) +int CmsisDAP::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { return writeJtagSequence(0, tx, rx, len, end); } diff --git a/src/cmsisDAP.hpp b/src/cmsisDAP.hpp index e32b2c4..ef692dc 100644 --- a/src/cmsisDAP.hpp +++ b/src/cmsisDAP.hpp @@ -44,7 +44,7 @@ class CmsisDAP: public JtagInterface { * \param[in] flush_buffer: force buffer to be send or not * \return <= 0 if something wrong, len otherwise */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /*! * \brief write and read len bits with optional tms set to 1 if end @@ -54,7 +54,7 @@ class CmsisDAP: public JtagInterface { * \param[in] end: if true tms is set to one with the last tdi bit * \return <= 0 if something wrong, len otherwise */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /*! * \brief send a serie of clock cycle with constant TMS and TDI @@ -95,7 +95,7 @@ class CmsisDAP: public JtagInterface { uint8_t *rx_buff, int rx_len); void display_info(uint8_t info, uint8_t type); - int writeJtagSequence(uint8_t tms, uint8_t *tx, uint8_t *rx, + int writeJtagSequence(uint8_t tms, const uint8_t *tx, uint8_t *rx, uint32_t len, bool end); bool _verbose; /**< display more message */ diff --git a/src/colognechip.cpp b/src/colognechip.cpp index 67a053d..b066b3c 100644 --- a/src/colognechip.cpp +++ b/src/colognechip.cpp @@ -187,7 +187,7 @@ void CologneChip::program(unsigned int offset, bool unprotect_flash) cfg->parse(); - uint8_t *data = cfg->getData(); + const uint8_t *data = cfg->getData(); int length = cfg->getLength() / 8; switch (_mode) { @@ -214,7 +214,7 @@ void CologneChip::program(unsigned int offset, bool unprotect_flash) * Write configuration into FPGA latches via SPI after active reset. * CFG_MD[3:0] must be set to 0x40 (SPI passive). */ -void CologneChip::programSPI_sram(uint8_t *data, int length) +void CologneChip::programSPI_sram(const uint8_t *data, int length) { /* hold device in reset for a moment */ reset(); @@ -234,7 +234,7 @@ void CologneChip::programSPI_sram(uint8_t *data, int length) * done, release reset to start FPGA in active SPI mode (load from flash). * CFG_MD[3:0] must be set to 0x00 (SPI active). */ -void CologneChip::programSPI_flash(unsigned int offset, uint8_t *data, +void CologneChip::programSPI_flash(unsigned int offset, const uint8_t *data, int length, bool unprotect_flash) { /* hold device in reset during flash write access */ @@ -266,7 +266,7 @@ void CologneChip::programSPI_flash(unsigned int offset, uint8_t *data, * Write configuration into FPGA latches via JTAG after active reset. * CFG_MD[3:0] must be set to 0xF0 (JTAG). */ -void CologneChip::programJTAG_sram(uint8_t *data, int length) +void CologneChip::programJTAG_sram(const uint8_t *data, int length) { /* hold device in reset for a moment */ reset(); @@ -303,7 +303,7 @@ void CologneChip::programJTAG_sram(uint8_t *data, int length) * Write configuration to flash via JTAG-SPI-bypass. The FPGA will not start * as it is in JTAG mode with CFG_MD[3:0] set to 0xF0 (JTAG). */ -void CologneChip::programJTAG_flash(unsigned int offset, uint8_t *data, +void CologneChip::programJTAG_flash(unsigned int offset, const uint8_t *data, int length, bool unprotect_flash) { /* hold device in reset for a moment */ @@ -327,7 +327,7 @@ void CologneChip::programJTAG_flash(unsigned int offset, uint8_t *data, /** * Overrides spi_put() to access SPI components via JTAG-SPI-bypass. */ -int CologneChip::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) +int CologneChip::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) { int xfer_len = len + 1; uint8_t jtx[xfer_len+2]; @@ -358,7 +358,7 @@ int CologneChip::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) /** * Overrides spi_put() to access SPI components via JTAG-SPI-bypass. */ -int CologneChip::spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) +int CologneChip::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) { int xfer_len = len; uint8_t jtx[xfer_len+2]; diff --git a/src/colognechip.hpp b/src/colognechip.hpp index e4d081d..35ae837 100644 --- a/src/colognechip.hpp +++ b/src/colognechip.hpp @@ -48,17 +48,17 @@ class CologneChip: public Device, SPIInterface { void reset() override; private: - void programSPI_sram(uint8_t *data, int length); - void programSPI_flash(unsigned int offset, uint8_t *data, int length, + void programSPI_sram(const uint8_t *data, int length); + void programSPI_flash(unsigned int offset, const uint8_t *data, int length, bool unprotect_flash); - void programJTAG_sram(uint8_t *data, int length); - void programJTAG_flash(unsigned int offset, uint8_t *data, int length, + void programJTAG_sram(const uint8_t *data, int length); + void programJTAG_flash(unsigned int offset, const uint8_t *data, int length, bool unprotect_flash); /* spi interface via jtag */ - int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) override; - int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override; + int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override; int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose=false) override; diff --git a/src/colognechipCfgParser.cpp b/src/colognechipCfgParser.cpp index 0d4faad..b5b0fbd 100644 --- a/src/colognechipCfgParser.cpp +++ b/src/colognechipCfgParser.cpp @@ -22,7 +22,7 @@ int CologneChipCfgParser::parse() std::string val = buffer.substr(0, buffer.find("//")); val.erase(std::remove_if(val.begin(), val.end(), ::isspace), val.end()); if (val != "") { - _bit_data += std::stol(val, nullptr, 16); + _bit_data.push_back(std::stol(val, nullptr, 16)); } } _bit_length = _bit_data.size() * 8; diff --git a/src/configBitstreamParser.hpp b/src/configBitstreamParser.hpp index fe7a66c..718a7af 100644 --- a/src/configBitstreamParser.hpp +++ b/src/configBitstreamParser.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include class ConfigBitstreamParser { @@ -19,7 +20,7 @@ class ConfigBitstreamParser { bool verbose = false); virtual ~ConfigBitstreamParser(); virtual int parse() = 0; - uint8_t *getData() {return (uint8_t*)_bit_data.c_str();} + const uint8_t *getData() const {return _bit_data.data();} int getLength() {return _bit_length;} /** @@ -62,7 +63,7 @@ class ConfigBitstreamParser { int _bit_length; int _file_size; bool _verbose; - std::string _bit_data; + std::vector _bit_data; std::string _raw_data; /**< unprocessed file content */ std::map _hdr; }; diff --git a/src/dfu.cpp b/src/dfu.cpp index cd36c3a..68ca792 100644 --- a/src/dfu.cpp +++ b/src/dfu.cpp @@ -312,8 +312,8 @@ int DFU::searchDFUDevices() if (_verbose > 0) { printf("%04x:%04x (bus %d, device %2d)\n", - desc.idVendor, desc.idProduct, - libusb_get_bus_number(usb_dev), + desc.idVendor, desc.idProduct, + libusb_get_bus_number(usb_dev), libusb_get_device_address(usb_dev)); } @@ -435,12 +435,12 @@ int DFU::parseDFUDescriptor(const struct libusb_interface_descriptor *intf, /* abstraction to send/receive to control */ int DFU::send(bool out, uint8_t brequest, uint16_t wvalue, - unsigned char *data, uint16_t length) + const uint8_t *data, uint16_t length) { uint8_t type = out ? DFU_REQUEST_OUT : DFU_REQUEST_IN; int ret = libusb_control_transfer(dev_handle, type, brequest, wvalue, curr_intf, - data, length, 5000); + const_cast(data), length, 5000); if (ret < 0) { if (checkDevicePresent()) { /* close device ? */ @@ -624,8 +624,8 @@ void DFU::displayDFU() printf("Found DFU:\n"); for (unsigned int i = 0; i < dfu_dev.size(); i++) { printf("%04x:%04x (bus %d, device %2d),", - dfu_dev[i].vid, dfu_dev[i].pid, - dfu_dev[i].bus, dfu_dev[i].device); + dfu_dev[i].vid, dfu_dev[i].pid, + dfu_dev[i].bus, dfu_dev[i].device); printf(" path: %d",dfu_dev[i].path[0]); for (size_t j = 1; j < strlen(((const char *)dfu_dev[i].path)); j++) printf(".%d", dfu_dev[i].path[j]); @@ -690,7 +690,7 @@ int DFU::download() } int ret, ret_val = EXIT_SUCCESS; - uint8_t *buffer, *ptr; + const uint8_t *buffer, *ptr; int size, xfer_len; int bMaxPacketSize0 = dfu_dev[dev_idx].bMaxPacketSize0; diff --git a/src/dfu.hpp b/src/dfu.hpp index 149dd79..1501dc2 100644 --- a/src/dfu.hpp +++ b/src/dfu.hpp @@ -52,12 +52,12 @@ class DFU { * \brief dfu descriptor structure (not provided by libusb */ struct dfu_desc { - uint8_t bLength; - uint8_t bDescriptorType; - uint8_t bmAttributes; - uint16_t wDetachTimeOut; - uint16_t wTransferSize; - uint16_t bcdDFUVersion; + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bmAttributes; + uint16_t wDetachTimeOut; + uint16_t wTransferSize; + uint16_t bcdDFUVersion; } __attribute__((__packed__)); struct dfu_dev { @@ -200,7 +200,7 @@ class DFU { * \brief send an IN/OUT request */ int send(bool out, uint8_t brequest, uint16_t wvalue, - unsigned char *data, uint16_t length); + const uint8_t *data, uint16_t length); /*! * \brief fill specific DFU structure with extra descriptor * \param[in] intf: interface descriptor with extra area diff --git a/src/dirtyJtag.cpp b/src/dirtyJtag.cpp index 4371d26..41c380d 100644 --- a/src/dirtyJtag.cpp +++ b/src/dirtyJtag.cpp @@ -113,7 +113,7 @@ bool DirtyJtag::getVersion() CMD_STOP}; uint8_t rx_buf[64]; ret = libusb_bulk_transfer(dev_handle, DIRTYJTAG_WRITE_EP, - buf, 2, &actual_length, DIRTYJTAG_TIMEOUT); + buf, 2, &actual_length, DIRTYJTAG_TIMEOUT); if (ret < 0) { cerr << "getVersion: usb bulk write failed " << ret << endl; return false; @@ -162,7 +162,7 @@ int DirtyJtag::setClkFreq(uint32_t clkHZ) static_cast(0xff & ((clkHZ / 1000) )), CMD_STOP}; ret = libusb_bulk_transfer(dev_handle, DIRTYJTAG_WRITE_EP, - buf, 4, &actual_length, DIRTYJTAG_TIMEOUT); + buf, 4, &actual_length, DIRTYJTAG_TIMEOUT); if (ret < 0) { cerr << "setClkFreq: usb bulk write failed " << ret << endl; return -EXIT_FAILURE; @@ -171,7 +171,7 @@ int DirtyJtag::setClkFreq(uint32_t clkHZ) return clkHZ; } -int DirtyJtag::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int DirtyJtag::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { (void) flush_buffer; int actual_length; @@ -241,7 +241,7 @@ int DirtyJtag::flush() return 0; } -int DirtyJtag::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) +int DirtyJtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { int actual_length; uint32_t real_bit_len = len - (end ? 1 : 0); @@ -286,7 +286,7 @@ int DirtyJtag::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) actual_length = 0; int ret = libusb_bulk_transfer(dev_handle, DIRTYJTAG_WRITE_EP, - (unsigned char *)tx_buf, (byte_to_send + header_offset), + (unsigned char *)tx_buf, (byte_to_send + header_offset), &actual_length, DIRTYJTAG_TIMEOUT); if ((ret < 0) || (actual_length != (int)(byte_to_send + header_offset))) { cerr << "writeTDI: fill: usb bulk write failed " << ret << diff --git a/src/dirtyJtag.hpp b/src/dirtyJtag.hpp index 573c2e1..1c7fcaf 100644 --- a/src/dirtyJtag.hpp +++ b/src/dirtyJtag.hpp @@ -25,9 +25,9 @@ class DirtyJtag : public JtagInterface { int setClkFreq(uint32_t clkHZ) override; /* TMS */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /* TDI */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /* clk */ int toggleClk(uint8_t tms, uint8_t tdo, uint32_t clk_len) override; diff --git a/src/efinix.cpp b/src/efinix.cpp index f3384f2..63cfbc0 100644 --- a/src/efinix.cpp +++ b/src/efinix.cpp @@ -415,7 +415,7 @@ bool Efinix::prepare_flash_access() * so to send only a cmd set len to 0 (or omit this param) */ int Efinix::spi_put(uint8_t cmd, - uint8_t *tx, uint8_t *rx, uint32_t len) + const uint8_t *tx, uint8_t *rx, uint32_t len) { int kXferLen = len + 1 + ((rx == NULL) ? 0 : 1); uint8_t jtx[kXferLen]; @@ -440,7 +440,7 @@ int Efinix::spi_put(uint8_t cmd, return 0; } -int Efinix::spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) +int Efinix::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) { int kXferLen = len + ((rx == NULL) ? 0 : 1); uint8_t jtx[kXferLen]; diff --git a/src/efinix.hpp b/src/efinix.hpp index 0854bbe..8236257 100644 --- a/src/efinix.hpp +++ b/src/efinix.hpp @@ -41,9 +41,9 @@ class Efinix: public Device, SPIInterface { void reset() override; /* spi interface */ - int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) override; - int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override; + int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override; int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose = false) override; diff --git a/src/efinixHexParser.cpp b/src/efinixHexParser.cpp index 46893da..c6d4639 100644 --- a/src/efinixHexParser.cpp +++ b/src/efinixHexParser.cpp @@ -23,7 +23,7 @@ int EfinixHexParser::parse() istringstream lineStream(_raw_data); while (std::getline(lineStream, buffer, '\n')) { - _bit_data += std::stol(buffer, nullptr, 16); + _bit_data.push_back(std::stol(buffer, nullptr, 16)); } _bit_length = _bit_data.size() * 8; diff --git a/src/fsparser.cpp b/src/fsparser.cpp index 67ee9b3..092a9ad 100644 --- a/src/fsparser.cpp +++ b/src/fsparser.cpp @@ -136,9 +136,9 @@ int FsParser::parse() */ for (auto &&line : _lstRawData) { - for (size_t i = 0; i < line.size(); i+=8) { + for (size_t i = 0; i < line.size(); i += 8) { uint8_t data = bitToVal(&line[i], 8); - _bit_data += (_reverseByte) ? reverseByte(data) : data; + _bit_data.push_back((_reverseByte) ? reverseByte(data) : data); } } diff --git a/src/ftdiJtagBitbang.cpp b/src/ftdiJtagBitbang.cpp index 2967baa..96e7315 100644 --- a/src/ftdiJtagBitbang.cpp +++ b/src/ftdiJtagBitbang.cpp @@ -116,7 +116,7 @@ int FtdiJtagBitBang::setBitmode(uint8_t mode) return ret; } -int FtdiJtagBitBang::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int FtdiJtagBitBang::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { int ret; @@ -162,7 +162,7 @@ int FtdiJtagBitBang::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) return len; } -int FtdiJtagBitBang::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) +int FtdiJtagBitBang::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { uint32_t iter; uint32_t xfer_size = (rx) ? _rx_size : _buffer_size; diff --git a/src/ftdiJtagBitbang.hpp b/src/ftdiJtagBitbang.hpp index 8c910b7..44dc88a 100644 --- a/src/ftdiJtagBitbang.hpp +++ b/src/ftdiJtagBitbang.hpp @@ -31,10 +31,10 @@ class FtdiJtagBitBang : public JtagInterface, private FTDIpp_MPSSE { int setClkFreq(uint32_t clkHZ) override; /* TMS */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /* TDI */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; int toggleClk(uint8_t tms, uint8_t tdo, uint32_t clk_len) override; /*! diff --git a/src/ftdiJtagMPSSE.cpp b/src/ftdiJtagMPSSE.cpp index 91bd205..3bf73ec 100644 --- a/src/ftdiJtagMPSSE.cpp +++ b/src/ftdiJtagMPSSE.cpp @@ -107,7 +107,7 @@ void FtdiJtagMPSSE::config_edge() } } -int FtdiJtagMPSSE::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int FtdiJtagMPSSE::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { (void) flush_buffer; display("%s %d %d\n", __func__, len, (len/8)+1); @@ -208,7 +208,7 @@ int FtdiJtagMPSSE::flush() return mpsse_write(); } -int FtdiJtagMPSSE::writeTDI(uint8_t *tdi, uint8_t *tdo, uint32_t len, bool last) +int FtdiJtagMPSSE::writeTDI(const uint8_t *tdi, uint8_t *tdo, uint32_t len, bool last) { /* 3 possible case : * - n * 8bits to send -> use byte command diff --git a/src/ftdiJtagMPSSE.hpp b/src/ftdiJtagMPSSE.hpp index d1e3038..e81baab 100644 --- a/src/ftdiJtagMPSSE.hpp +++ b/src/ftdiJtagMPSSE.hpp @@ -33,11 +33,11 @@ class FtdiJtagMPSSE : public JtagInterface, public FTDIpp_MPSSE { uint32_t getClkFreq() override {return FTDIpp_MPSSE::getClkFreq();} /* TMS */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /* clock */ int toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len) override; /* TDI */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /*! * \brief send TMD and TDI and receive tdo bits; diff --git a/src/ftdispi.cpp b/src/ftdispi.cpp index 5dd2d2c..1bbbe40 100644 --- a/src/ftdispi.cpp +++ b/src/ftdispi.cpp @@ -163,8 +163,8 @@ int FtdiSpi::ft2232_spi_wr_then_rd( /* Returns 0 upon success, a negative number upon errors. */ int FtdiSpi::ft2232_spi_wr_and_rd(//struct ftdi_spi *spi, - uint32_t writecnt, - const uint8_t * writearr, uint8_t * readarr) + uint32_t writecnt, + const uint8_t * writearr, uint8_t * readarr) { uint32_t max_xfer = (readarr) ? _buffer_size : 4096; uint8_t buf[max_xfer]; @@ -229,7 +229,7 @@ int FtdiSpi::ft2232_spi_wr_and_rd(//struct ftdi_spi *spi, } /* method spiInterface::spi_put */ -int FtdiSpi::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) +int FtdiSpi::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) { uint32_t xfer_len = len + 1; uint8_t jtx[xfer_len]; @@ -252,7 +252,7 @@ int FtdiSpi::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) } /* method spiInterface::spi_put */ -int FtdiSpi::spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) +int FtdiSpi::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) { return ft2232_spi_wr_and_rd(len, tx, rx); } diff --git a/src/ftdispi.hpp b/src/ftdispi.hpp index 02c2f77..99aae1e 100644 --- a/src/ftdispi.hpp +++ b/src/ftdispi.hpp @@ -51,9 +51,9 @@ class FtdiSpi : public FTDIpp_MPSSE, SPIInterface { const uint8_t *writearr, uint8_t *readarr); /* spi interface */ - int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) override; - int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override; + int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override; int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose=false) override; diff --git a/src/gowin.cpp b/src/gowin.cpp index 69c6dce..1706d15 100644 --- a/src/gowin.cpp +++ b/src/gowin.cpp @@ -175,7 +175,7 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, std::st if (mcufw.size() > 0) { if (idcode != 0x0100981b) throw std::runtime_error("Microcontroller firmware flashing only supported on GW1NSR-4C"); - + _mcufw = new RawParser(mcufw, false); if (_mcufw->parse() == EXIT_FAILURE) { @@ -204,12 +204,12 @@ void Gowin::reset() void Gowin::programFlash() { - uint8_t *data = _fs->getData(); + const uint8_t *data = _fs->getData(); int length = _fs->getLength(); - - uint8_t *mcu_data = nullptr; + + const uint8_t *mcu_data = nullptr; int mcu_length = 0; - + if (_mcufw) { mcu_data = _mcufw->getData(); mcu_length = _mcufw->getLength(); @@ -256,7 +256,7 @@ void Gowin::programFlash() void Gowin::program(unsigned int offset, bool unprotect_flash) { - uint8_t *data; + const uint8_t *data; int length; if (_mode == NONE_MODE || !_fs) @@ -456,7 +456,7 @@ bool Gowin::wr_rd(uint8_t cmd, printf("%02x ", xfer_rx[i]); printf("\n"); } - for (i = 0; i < rx_len; i++) + for (i = 0; i < rx_len; i++) rx[i] = (xfer_rx[i]); } return true; @@ -518,7 +518,7 @@ bool Gowin::pollFlag(uint32_t mask, uint32_t value) } /* TN653 p. 17-21 */ -bool Gowin::flashFLASH(uint32_t page, uint8_t *data, int length) +bool Gowin::flashFLASH(uint32_t page, const uint8_t *data, int length) { uint8_t tx[4] = {0x4E, 0x31, 0x57, 0x47}; uint8_t tmp[4]; @@ -630,7 +630,7 @@ bool Gowin::connectJtagToMCU() } /* TN653 p. 9 */ -bool Gowin::flashSRAM(uint8_t *data, int length) +bool Gowin::flashSRAM(const uint8_t *data, int length) { int tx_len, tx_end; int byte_length = length / 8; @@ -748,7 +748,7 @@ bool Gowin::eraseSRAM() _jtag->shiftDR(_wr, _rd, _len); \ _jtag->toggleClk(6); } while (0) -int Gowin::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) +int Gowin::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) { uint8_t jrx[len+1], jtx[len+1]; jtx[0] = cmd; @@ -762,7 +762,7 @@ int Gowin::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) return ret; } -int Gowin::spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) +int Gowin::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) { if (is_gw2a) { uint8_t jtx[len]; diff --git a/src/gowin.hpp b/src/gowin.hpp index 6cf1885..337910d 100644 --- a/src/gowin.hpp +++ b/src/gowin.hpp @@ -36,9 +36,9 @@ class Gowin: public Device, SPIInterface { printError("unprotect flash not supported"); return false;} virtual bool bulk_erase_flash() override { printError("bulk erase flash not supported"); return false;} - int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) override; - int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override; + int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override; int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose) override; @@ -50,8 +50,8 @@ class Gowin: public Device, SPIInterface { bool pollFlag(uint32_t mask, uint32_t value); bool eraseSRAM(); bool eraseFLASH(); - bool flashSRAM(uint8_t *data, int length); - bool flashFLASH(uint32_t page, uint8_t *data, int length); + bool flashSRAM(const uint8_t *data, int length); + bool flashFLASH(uint32_t page, const uint8_t *data, int length); void displayReadReg(uint32_t dev); uint32_t readStatusReg(); uint32_t readUserCode(); diff --git a/src/ice40.cpp b/src/ice40.cpp index 9cda2a8..f482f0f 100644 --- a/src/ice40.cpp +++ b/src/ice40.cpp @@ -60,7 +60,7 @@ void Ice40::reset() /* cf. TN1248 (iCE40 Programming and Configuration) * Appendix A. SPI Slave Configuration Procedure */ -bool Ice40::program_cram(uint8_t *data, uint32_t length) +bool Ice40::program_cram(const uint8_t *data, uint32_t length) { uint32_t timeout = 1000; @@ -78,7 +78,7 @@ bool Ice40::program_cram(uint8_t *data, uint32_t length) /* load configuration data MSB first */ ProgressBar progress("Loading to CRAM", length, 50, _verbose); - uint8_t *ptr = data; + const uint8_t *ptr = data; int size = 0; for (uint32_t addr = 0; addr < length; addr += size, ptr+=size) { size = (addr + 256 > length)?(length-addr) : 256; @@ -127,7 +127,7 @@ void Ice40::program(unsigned int offset, bool unprotect_flash) return; } - uint8_t *data = bit.getData(); + const uint8_t *data = bit.getData(); int length = bit.getLength() / 8; if (_mode == Device::MEM_MODE) { diff --git a/src/ice40.hpp b/src/ice40.hpp index 222791f..8602134 100644 --- a/src/ice40.hpp +++ b/src/ice40.hpp @@ -22,7 +22,7 @@ class Ice40: public Device, SPIInterface { ~Ice40(); void program(unsigned int offset, bool unprotect_flash) override; - bool program_cram(uint8_t *data, uint32_t length); + bool program_cram(const uint8_t *data, uint32_t length); bool dumpFlash(uint32_t base_addr, uint32_t len) override; bool protect_flash(uint32_t len) override; bool unprotect_flash() override; @@ -31,12 +31,12 @@ class Ice40: public Device, SPIInterface { int idCode() override {return 0;} void reset() override; - int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) override { (void)cmd; (void)tx; (void)rx; (void)len; return 0; } - int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override { + int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override { (void)tx; (void)rx; (void)len; return 0; } diff --git a/src/jlink.cpp b/src/jlink.cpp index 12b67a0..55d4616 100644 --- a/src/jlink.cpp +++ b/src/jlink.cpp @@ -26,12 +26,12 @@ using namespace std; // convert 2Byte to 1 short #define CONV_16B(_val) ((((uint16_t) _val[0]) << 0) | \ - (((uint16_t) _val[1]) << 8)) + (((uint16_t) _val[1]) << 8)) // convert 4Byte to 1 word #define CONV_32B(_val) ((((uint32_t) _val[0]) << 0) | \ - (((uint32_t) _val[1]) << 8) | \ - (((uint32_t) _val[2]) << 16) | \ - (((uint32_t) _val[3]) << 24)) + (((uint32_t) _val[1]) << 8) | \ + (((uint32_t) _val[2]) << 16) | \ + (((uint32_t) _val[3]) << 24)) // a 0-byte is introduce when reading a packet with // size multiple of 64 Byte but < 0x8000 #define HAS_0BYTE(_len) ((_len != 0) && (_len % 64 == 0) && (_len != 0x8000)) @@ -89,7 +89,7 @@ Jlink::~Jlink() libusb_exit(jlink_ctx); } -int Jlink::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int Jlink::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { // empty buffer // if asked flush @@ -123,7 +123,7 @@ int Jlink::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) return len; } -int Jlink::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) +int Jlink::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { if (len == 0) // nothing to do return 0; @@ -132,7 +132,8 @@ int Jlink::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) uint32_t xfer_len = BUF_SIZE * 8; // default to buffer capacity uint8_t tms = (_last_tms) ? 0xff : 0x00; // set tms byte - uint8_t *tx_ptr = tx, *rx_ptr = rx; // use pointer to simplify algo + const uint8_t *tx_ptr = tx; + uint8_t *rx_ptr = rx; // use pointer to simplify algo /* write by burst */ for (uint32_t rest = 0; rest < len; rest += xfer_len) { @@ -477,9 +478,9 @@ int Jlink::get_hw_version() return -1; _hw_type = (version / 1000000) % 100; - _major = (version / 10000) % 100; - _minor = (version / 100) % 100; - _revision = version % 100; + _major = (version / 10000) % 100; + _minor = (version / 100) % 100; + _revision = version % 100; if (_debug) printf("%08x ", version); diff --git a/src/jlink.hpp b/src/jlink.hpp index 99054f3..fce6c12 100644 --- a/src/jlink.hpp +++ b/src/jlink.hpp @@ -44,7 +44,7 @@ class Jlink: public JtagInterface { * \param[in] flush_buffer: force buffer to be send or not * \return <= 0 if something wrong, len otherwise */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /*! * \brief write and read len bits with optional tms set to 1 if end @@ -54,7 +54,7 @@ class Jlink: public JtagInterface { * \param[in] end: if true tms is set to one with the last tdi bit * \return <= 0 if something wrong, len otherwise */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /*! * \brief access ll_write outer this class / directly receives diff --git a/src/jtag.cpp b/src/jtag.cpp index ea359af..1bd8d7d 100644 --- a/src/jtag.cpp +++ b/src/jtag.cpp @@ -298,7 +298,7 @@ void Jtag::go_test_logic_reset() _state = TEST_LOGIC_RESET; } -int Jtag::read_write(unsigned char *tdi, unsigned char *tdo, int len, char last) +int Jtag::read_write(const uint8_t *tdi, unsigned char *tdo, int len, char last) { flushTMS(false); _jtag->writeTDI(tdi, tdo, len, last); @@ -317,7 +317,7 @@ void Jtag::toggleClk(int nb) return; } -int Jtag::shiftDR(unsigned char *tdi, unsigned char *tdo, int drlen, int end_state) +int Jtag::shiftDR(const uint8_t *tdi, unsigned char *tdo, int drlen, int end_state) { /* get number of devices in the JTAG chain * after the selected one @@ -361,7 +361,7 @@ int Jtag::shiftDR(unsigned char *tdi, unsigned char *tdo, int drlen, int end_sta uint8_t tx[n]; memset(tx, 0xff, n); read_write(tx, NULL, bits_after, 1); // its the last force - // tms high with last bit + // tms high with last bit } /* move to end_state */ diff --git a/src/jtag.hpp b/src/jtag.hpp index e2ef671..aaddedd 100644 --- a/src/jtag.hpp +++ b/src/jtag.hpp @@ -72,9 +72,9 @@ class Jtag { int end_state = RUN_TEST_IDLE); int shiftIR(unsigned char tdi, int irlen, int end_state = RUN_TEST_IDLE); - int shiftDR(unsigned char *tdi, unsigned char *tdo, int drlen, + int shiftDR(const uint8_t *tdi, unsigned char *tdo, int drlen, int end_state = RUN_TEST_IDLE); - int read_write(unsigned char *tdi, unsigned char *tdo, int len, char last); + int read_write(const uint8_t *tdi, unsigned char *tdo, int len, char last); void toggleClk(int nb); void go_test_logic_reset(); diff --git a/src/jtagInterface.hpp b/src/jtagInterface.hpp index 77b3572..a0a9cd1 100644 --- a/src/jtagInterface.hpp +++ b/src/jtagInterface.hpp @@ -30,7 +30,7 @@ class JtagInterface { * \param len: number of bit to send * \return number of bit send/received */ - virtual int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) = 0; + virtual int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) = 0; /*! * \brief send TDI bits (mainly in shift DR/IR state) @@ -41,7 +41,7 @@ class JtagInterface { * but only in shift[i|d]r, if end is false tms remain the same. * \return number of bit written and/or read */ - virtual int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) = 0; + virtual int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) = 0; /*! * \brief send TMD and TDI and receive tdo bits; * \param tms: array of TMS values (used to write) diff --git a/src/lattice.cpp b/src/lattice.cpp index 2a21a95..8ddf7b5 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -232,25 +232,25 @@ void displayFeabits(uint16_t _featbits) printf(" Error!\n"); } printf("\tMaster Mode SPI : %s\n", - (((_featbits>>11)&0x01)?"enable":"disable")); + (((_featbits>>11)&0x01)?"enable":"disable")); printf("\tI2c port : %s\n", - (((_featbits>>10)&0x01)?"disable":"enable")); + (((_featbits>>10)&0x01)?"disable":"enable")); printf("\tSlave SPI port : %s\n", - (((_featbits>>9)&0x01)?"disable":"enable")); + (((_featbits>>9)&0x01)?"disable":"enable")); printf("\tJTAG port : %s\n", - (((_featbits>>8)&0x01)?"disable":"enable")); + (((_featbits>>8)&0x01)?"disable":"enable")); printf("\tDONE : %s\n", - (((_featbits>>7)&0x01)?"enable":"disable")); + (((_featbits>>7)&0x01)?"enable":"disable")); printf("\tINITN : %s\n", - (((_featbits>>6)&0x01)?"enable":"disable")); + (((_featbits>>6)&0x01)?"enable":"disable")); printf("\tPROGRAMN : %s\n", - (((_featbits>>5)&0x01)?"disable":"enable")); + (((_featbits>>5)&0x01)?"disable":"enable")); printf("\tMy_ASSP : %s\n", - (((_featbits>>4)&0x01)?"enable":"disable")); + (((_featbits>>4)&0x01)?"enable":"disable")); printf("\tPassword (Flash Protect Key) Protect All : %s\n", - (((_featbits>>3)&0x01)?"Enabled" : "Disabled")); + (((_featbits>>3)&0x01)?"Enabled" : "Disabled")); printf("\tPassword (Flash Protect Key) Protect : %s\n", - (((_featbits>>2)&0x01)?"Enabled" : "Disabled")); + (((_featbits>>2)&0x01)?"Enabled" : "Disabled")); } bool Lattice::checkStatus(uint32_t val, uint32_t mask) @@ -330,7 +330,7 @@ bool Lattice::program_mem() _jtag->set_state(Jtag::RUN_TEST_IDLE); _jtag->toggleClk(1000); - uint8_t *data = _bit.getData(); + const uint8_t *data = _bit.getData(); int length = _bit.getLength()/8; wr_rd(0x7A, NULL, 0, NULL, 0); _jtag->set_state(Jtag::RUN_TEST_IDLE); @@ -1296,11 +1296,11 @@ uint16_t Lattice::getUFMStartPageFromJEDEC(JedParser *_jed, int id) uint32_t bit_offset = _jed->offset_for_section(id); /* Convert to starting page, relative to Configuration Flash's page 0. For 7000 parts only, first UFM page starts 16 bytes (1 page) after - the last Configuration Flash page, based on looking at - Diamond-generated JEDECs. + the last Configuration Flash page, based on looking at + Diamond-generated JEDECs. - For all other parts, the first UFM page immediately follows the last - Configuration Flash page. */ + For all other parts, the first UFM page immediately follows the last + Configuration Flash page. */ uint16_t raw_page_offset = bit_offset / 128; /* Raw page offsets won't overlap- see Lattice TN-02155, page 49. So we @@ -1329,7 +1329,7 @@ uint16_t Lattice::getUFMStartPageFromJEDEC(JedParser *_jed, int id) /* SPI implementation */ /* ------------------ */ -int Lattice::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) +int Lattice::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) { int xfer_len = len + 1; uint8_t jtx[xfer_len]; @@ -1355,7 +1355,7 @@ int Lattice::spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, uint32_t len) return 0; } -int Lattice::spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) +int Lattice::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) { int xfer_len = len; uint8_t jtx[xfer_len]; @@ -2009,7 +2009,7 @@ bool Lattice::program_pubkey_MachXO3D() printSuccess("DONE"); } - uint8_t* data = _pk.getData(); + const uint8_t* data = _pk.getData(); len = _pk.getLength()/8; if (data[0] == 0x0f && data[1] == 0xf0) { diff --git a/src/lattice.hpp b/src/lattice.hpp index 2d357aa..0b9b124 100644 --- a/src/lattice.hpp +++ b/src/lattice.hpp @@ -55,9 +55,9 @@ class Lattice: public Device, SPIInterface { } /* spi interface */ - int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) override; - int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override; + int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override; int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose = false) override; diff --git a/src/libgpiodJtagBitbang.cpp b/src/libgpiodJtagBitbang.cpp index b0aa0b4..5b40b80 100644 --- a/src/libgpiodJtagBitbang.cpp +++ b/src/libgpiodJtagBitbang.cpp @@ -272,8 +272,8 @@ int LibgpiodJtagBitbang::read_tdo() #ifdef GPIOD_APIV2 gpiod_line_value req = gpiod_line_request_get_value( _tdo_request, _tdo_pin); - if (req == GPIOD_LINE_VALUE_ERROR) - { + if (req == GPIOD_LINE_VALUE_ERROR) + { display("Error reading TDO line\n"); throw std::runtime_error("Error reading TDO line\n"); } @@ -291,7 +291,7 @@ int LibgpiodJtagBitbang::setClkFreq(__attribute__((unused)) uint32_t clkHZ) return 0; } -int LibgpiodJtagBitbang::writeTMS(uint8_t *tms_buf, uint32_t len, +int LibgpiodJtagBitbang::writeTMS(const uint8_t *tms_buf, uint32_t len, __attribute__((unused)) bool flush_buffer) { int tms; @@ -311,7 +311,7 @@ int LibgpiodJtagBitbang::writeTMS(uint8_t *tms_buf, uint32_t len, return len; } -int LibgpiodJtagBitbang::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) +int LibgpiodJtagBitbang::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { int tms = _curr_tms; int tdi = _curr_tdi; diff --git a/src/libgpiodJtagBitbang.hpp b/src/libgpiodJtagBitbang.hpp index 1dc7086..cf239d5 100644 --- a/src/libgpiodJtagBitbang.hpp +++ b/src/libgpiodJtagBitbang.hpp @@ -33,8 +33,8 @@ class LibgpiodJtagBitbang : public JtagInterface { virtual ~LibgpiodJtagBitbang(); int setClkFreq(uint32_t clkHZ) override; - int writeTMS(uint8_t *tms_buf, uint32_t len, bool flush_buffer) override; - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTMS(const uint8_t *tms_buf, uint32_t len, bool flush_buffer) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; int toggleClk(uint8_t tms, uint8_t tdo, uint32_t clk_len) override; int get_buffer_size() override { return 0; } diff --git a/src/remoteBitbang_client.cpp b/src/remoteBitbang_client.cpp index 40d6357..8c73297 100644 --- a/src/remoteBitbang_client.cpp +++ b/src/remoteBitbang_client.cpp @@ -76,7 +76,7 @@ RemoteBitbang_client::~RemoteBitbang_client() close(_sock); } -int RemoteBitbang_client::writeTMS(uint8_t *tms, uint32_t len, +int RemoteBitbang_client::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { // empty buffer @@ -100,7 +100,7 @@ int RemoteBitbang_client::writeTMS(uint8_t *tms, uint32_t len, return len; } -int RemoteBitbang_client::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, +int RemoteBitbang_client::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { if (len == 0) // nothing to do @@ -190,7 +190,7 @@ bool RemoteBitbang_client::open_connection(const string &ip_addr) } int one = 1; - setsockopt(_sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&one, + setsockopt(_sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&one, sizeof(one)); return true; diff --git a/src/remoteBitbang_client.hpp b/src/remoteBitbang_client.hpp index 499ded4..5405b4e 100644 --- a/src/remoteBitbang_client.hpp +++ b/src/remoteBitbang_client.hpp @@ -43,7 +43,7 @@ class RemoteBitbang_client: public JtagInterface { * \param[in] flush_buffer: force buffer to be send or not * \return <= 0 if something wrong, len otherwise */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /*! * \brief write and read len bits with optional tms set to 1 if end @@ -53,7 +53,7 @@ class RemoteBitbang_client: public JtagInterface { * \param[in] end: if true tms is set to one with the last tdi bit * \return <= 0 if something wrong, len otherwise */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /*! * \brief send a serie of clock cycle with constant TMS and TDI diff --git a/src/spiFlash.cpp b/src/spiFlash.cpp index 616348a..2ebed49 100644 --- a/src/spiFlash.cpp +++ b/src/spiFlash.cpp @@ -233,7 +233,7 @@ int SPIFlash::sectors_erase(int base_addr, int size) return ret; } -int SPIFlash::write_page(int addr, uint8_t *data, int len) +int SPIFlash::write_page(int addr, const uint8_t *data, int len) { uint32_t addr_len; uint8_t write_cmd; @@ -340,7 +340,7 @@ bool SPIFlash::dump(const std::string &filename, const int &base_addr, return true; } -int SPIFlash::erase_and_prog(int base_addr, uint8_t *data, int len) +int SPIFlash::erase_and_prog(int base_addr, const uint8_t *data, int len) { if (_jedec_id == 0) { try { @@ -435,7 +435,7 @@ int SPIFlash::erase_and_prog(int base_addr, uint8_t *data, int len) if (sectors_erase(base_addr, len) == -1) return -1; - uint8_t *ptr = data; + const uint8_t *ptr = data; int size = 0; for (int addr = 0; addr < len; addr += size, ptr+=size) { size = (addr + 256 > len)?(len-addr) : 256; diff --git a/src/spiFlash.hpp b/src/spiFlash.hpp index 34a0673..2ef040b 100644 --- a/src/spiFlash.hpp +++ b/src/spiFlash.hpp @@ -64,7 +64,7 @@ class SPIFlash { */ int sectors_erase(int base_addr, int len); /* write */ - int write_page(int addr, uint8_t *data, int len); + int write_page(int addr, const uint8_t *data, int len); /* read */ int read(int base_addr, uint8_t *data, int len); /*! @@ -79,7 +79,7 @@ class SPIFlash { bool dump(const std::string &filename, const int &base_addr, const int &len, int rd_burst = 0); /* combo flash + erase */ - int erase_and_prog(int base_addr, uint8_t *data, int len); + int erase_and_prog(int base_addr, const uint8_t *data, int len); /*! * \brief check if area base_addr to base_addr + len match * data content diff --git a/src/spiInterface.cpp b/src/spiInterface.cpp index b2a54fb..87423cc 100644 --- a/src/spiInterface.cpp +++ b/src/spiInterface.cpp @@ -116,7 +116,7 @@ bool SPIInterface::bulk_erase_flash() return post_flash_access() && ret; } -bool SPIInterface::write(uint32_t offset, uint8_t *data, uint32_t len, +bool SPIInterface::write(uint32_t offset, const uint8_t *data, uint32_t len, bool unprotect_flash) { bool ret = true; diff --git a/src/spiInterface.hpp b/src/spiInterface.hpp index 99a42b5..24dd069 100644 --- a/src/spiInterface.hpp +++ b/src/spiInterface.hpp @@ -44,7 +44,7 @@ class SPIInterface { * \param[in] verbose: verbose level * \return false when something fails */ - bool write(uint32_t offset, uint8_t *data, uint32_t len, + bool write(uint32_t offset, const uint8_t *data, uint32_t len, bool unprotect_flash); /*! @@ -78,7 +78,7 @@ class SPIInterface { * to send only a cmd set len to 0 * \return 0 when success */ - virtual int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + virtual int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) = 0; /*! @@ -88,7 +88,7 @@ class SPIInterface { * \param[in] len: number of byte to send/receive * \return 0 when success */ - virtual int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) = 0; + virtual int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) = 0; /*! * \brief wait until register content and mask match cond, or timeout diff --git a/src/usbBlaster.cpp b/src/usbBlaster.cpp index 4721101..1fd0263 100644 --- a/src/usbBlaster.cpp +++ b/src/usbBlaster.cpp @@ -89,7 +89,7 @@ uint32_t UsbBlaster::getClkFreq() return ll_driver->getClkFreq(); } -int UsbBlaster::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int UsbBlaster::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { int ret; @@ -138,14 +138,14 @@ int UsbBlaster::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) #include "configBitstreamParser.hpp" -int UsbBlaster::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) +int UsbBlaster::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { uint32_t real_len = (end) ? len -1 : len; uint32_t nb_byte = real_len >> 3; uint32_t nb_bit = (real_len & 0x07); uint8_t mode = (rx != NULL)? DO_RDWR : DO_WRITE; - uint8_t *tx_ptr = tx; + const uint8_t *tx_ptr = tx; uint8_t *rx_ptr = rx; /* security: send residual @@ -349,8 +349,8 @@ UsbBlasterI::UsbBlasterI() throw std::exception(); } - ret = ftdi_usb_open(_ftdi, 0x09fb, 0x6001); - if (ret < 0) { + ret = ftdi_usb_open(_ftdi, 0x09fb, 0x6001); + if (ret < 0) { fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(_ftdi)); ftdi_free(_ftdi); diff --git a/src/usbBlaster.hpp b/src/usbBlaster.hpp index a3b2b52..277119e 100644 --- a/src/usbBlaster.hpp +++ b/src/usbBlaster.hpp @@ -54,10 +54,10 @@ class UsbBlaster : public JtagInterface { * \param flush_buffer force flushing the buffer * \return number of state written * */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /* TDI */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /*! * \brief toggle clock with static tms and tdi * \param tms TMS state diff --git a/src/xilinx.cpp b/src/xilinx.cpp index 7785682..7d2c473 100644 --- a/src/xilinx.cpp +++ b/src/xilinx.cpp @@ -508,7 +508,7 @@ bool Xilinx::load_bridge() void Xilinx::program_spi(ConfigBitstreamParser * bit, unsigned int offset, bool unprotect_flash) { - uint8_t *data = bit->getData(); + const uint8_t *data = bit->getData(); int length = bit->getLength() / 8; SPIInterface::write(offset, data, length, unprotect_flash); } @@ -570,7 +570,7 @@ void Xilinx::program_mem(ConfigBitstreamParser *bitfile) */ /* GGM: TODO */ int byte_length = bitfile->getLength() / 8; - uint8_t *data = bitfile->getData(); + const uint8_t *data = bitfile->getData(); int tx_len, tx_end; int burst_len = byte_length / 100; @@ -585,9 +585,9 @@ void Xilinx::program_mem(ConfigBitstreamParser *bitfile) tx_end = Jtag::UPDATE_DR; } else { tx_len = burst_len * 8; - /* - * 12: Enter the SHIFT-DR state. X 0 2 - */ + /* + * 12: Enter the SHIFT-DR state. X 0 2 + */ tx_end = Jtag::SHIFT_DR; } _jtag->shiftDR(data+i, NULL, tx_len, tx_end); @@ -727,7 +727,7 @@ bool Xilinx::xc3s_flow_program(ConfigBitstreamParser *bit) { int byte_length = bit->getLength() / 8; int burst_len = byte_length / 100; - uint8_t *data = bit->getData(); + const uint8_t *data = bit->getData(); int tx_len = burst_len * 8, tx_end = Jtag::SHIFT_DR; ProgressBar progress("Flash SRAM", byte_length, 50, _quiet); @@ -769,8 +769,9 @@ bool Xilinx::xc3s_flow_program(ConfigBitstreamParser *bit) _jtag->toggleClk(32); if (_jtag->shiftIR(BYPASS, _irlen) < 0) return false; - data[0] = 0x00; - if (_jtag->shiftDR(data, NULL, 1) < 0) + //data[0] = 0x00; + uint8_t d = 0; + if (_jtag->shiftDR(&d, NULL, 1) < 0) return false; _jtag->toggleClk(1); @@ -1076,7 +1077,7 @@ bool Xilinx::xcf_program(ConfigBitstreamParser *bitfile) uint8_t tx_buf[4096 / 8]; uint16_t pkt_len = ((_jtag->get_target_device_id() == 0x05044093) ? 2048 : 4096) / 8; - uint8_t *data = bitfile->getData(); + const uint8_t *data = bitfile->getData(); uint32_t data_len = bitfile->getLength() / 8; uint32_t xfer_len, offset = 0; uint32_t addr = 0; @@ -1520,7 +1521,7 @@ bool Xilinx::xc2c_flow_program(JedParser *jed) * so to send only a cmd set len to 0 (or omit this param) */ int Xilinx::spi_put(uint8_t cmd, - uint8_t *tx, uint8_t *rx, uint32_t len) + const uint8_t *tx, uint8_t *rx, uint32_t len) { int xfer_len = len + 1 + ((rx == NULL) ? 0 : 1); uint8_t jtx[xfer_len]; @@ -1546,7 +1547,7 @@ int Xilinx::spi_put(uint8_t cmd, return 0; } -int Xilinx::spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) +int Xilinx::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) { int xfer_len = len + ((rx == NULL) ? 0 : 1); uint8_t jtx[xfer_len]; diff --git a/src/xilinx.hpp b/src/xilinx.hpp index 4df75af..2064487 100644 --- a/src/xilinx.hpp +++ b/src/xilinx.hpp @@ -134,9 +134,9 @@ class Xilinx: public Device, SPIInterface { bool xc2c_flow_program(JedParser *jed); /* spi interface */ - int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx, + int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len) override; - int spi_put(uint8_t *tx, uint8_t *rx, uint32_t len) override; + int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override; int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond, uint32_t timeout, bool verbose = false) override; diff --git a/src/xilinxMapParser.cpp b/src/xilinxMapParser.cpp index 2d14477..7b05988 100644 --- a/src/xilinxMapParser.cpp +++ b/src/xilinxMapParser.cpp @@ -42,7 +42,7 @@ int XilinxMapParser::parse() while(std::getline(ss, line, '\n')) { bool empty = true; // to said if line contains only '\t' (empty) - // or one or more blank in a non empty line + // or one or more blank in a non empty line size_t prev_pos = 0, next_pos; int row = 0; /* suppress potential '\r' (thanks windows) */ diff --git a/src/xvc_client.cpp b/src/xvc_client.cpp index 5572f23..2c0aa9c 100644 --- a/src/xvc_client.cpp +++ b/src/xvc_client.cpp @@ -43,8 +43,8 @@ XVC_client::XVC_client(const std::string &ip_addr, int port, std::regex r("[_:]"); string rep((const char *)buffer); - std::sregex_token_iterator start{ rep.begin(), rep.end(), r, -1 }, end; - std::vector toto(start, end); + std::sregex_token_iterator start{ rep.begin(), rep.end(), r, -1 }, end; + std::vector toto(start, end); if (toto.size() != 3) throw std::runtime_error("wrong getinfo: answer"); @@ -87,7 +87,7 @@ XVC_client::~XVC_client() close(_sock); } -int XVC_client::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) +int XVC_client::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) { // empty buffer // if asked flush @@ -121,7 +121,7 @@ int XVC_client::writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) return len; } -int XVC_client::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) +int XVC_client::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) { if (len == 0) // nothing to do return 0; @@ -130,7 +130,8 @@ int XVC_client::writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) uint32_t xfer_len = _buffer_size * 8; // default to buffer capacity uint8_t tms = (_last_tms) ? 0xff : 0x00; // set tms byte - uint8_t *tx_ptr = tx, *rx_ptr = rx; // use pointer to simplify algo + const uint8_t *tx_ptr = tx; + uint8_t *rx_ptr = rx; // use pointer to simplify algo /* write by burst */ for (uint32_t rest = 0; rest < len; rest += xfer_len) { diff --git a/src/xvc_client.hpp b/src/xvc_client.hpp index 87034c3..6f363ba 100644 --- a/src/xvc_client.hpp +++ b/src/xvc_client.hpp @@ -43,7 +43,7 @@ class XVC_client: public JtagInterface { * \param[in] flush_buffer: force buffer to be send or not * \return <= 0 if something wrong, len otherwise */ - int writeTMS(uint8_t *tms, uint32_t len, bool flush_buffer) override; + int writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer) override; /*! * \brief write and read len bits with optional tms set to 1 if end @@ -53,7 +53,7 @@ class XVC_client: public JtagInterface { * \param[in] end: if true tms is set to one with the last tdi bit * \return <= 0 if something wrong, len otherwise */ - int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; + int writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; /*! * \brief send a serie of clock cycle with constant TMS and TDI