Merge pull request #370 from aystarik/master

Generic refactoring of the code
This commit is contained in:
Gwenhael Goavec-Merou 2023-08-31 09:46:44 +02:00 committed by GitHub
commit fbb8341323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 300 additions and 291 deletions

View File

@ -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<float>(_jtag->getClkFreq());
@ -101,7 +101,7 @@ void Altera::programMem(RawParser &_bit)
int xfer_len = 512;
int tx_len;
int tx_end;
Jtag::tapState_t tx_end;
for (int i=0; i < byte_length; i+=xfer_len) {
if (i + xfer_len > byte_length) { // last packet with some size
@ -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);
@ -250,7 +250,7 @@ void Altera::program(unsigned int offset, bool unprotect_flash)
}
}
int Altera::idCode()
uint32_t Altera::idCode()
{
unsigned char tx_data[4] = {IDCODE};
unsigned char rx_data[4];
@ -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);
}
@ -352,7 +352,7 @@ void Altera::shiftVIR(uint32_t reg)
}
void Altera::shiftVDR(uint8_t * tx, uint8_t * rx, uint32_t len,
int end_state, bool debug)
Jtag::tapState_t end_state, bool debug)
{
(void) debug;
uint8_t tx_ir[2] = {USER0, 0};

View File

@ -39,7 +39,7 @@ class Altera: public Device, SPIInterface {
return SPIInterface::dump(base_addr, len);
}
int idCode() override;
uint32_t idCode() override;
void reset() override;
/*************************/
@ -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;
@ -98,7 +98,7 @@ class Altera: public Device, SPIInterface {
* \param[in] end_state: next state at the end of xfer
*/
void shiftVDR(uint8_t * tx, uint8_t * rx, uint32_t len,
int end_state = Jtag::UPDATE_DR, bool debug = false);
Jtag::tapState_t end_state = Jtag::UPDATE_DR, bool debug = false);
std::string _device_package;
std::string _spiOverJtagPath; /**< spiOverJtag explicit path */

View File

@ -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,14 +110,10 @@ 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;
if (len - xfer_len == 0)
tx_end = Jtag::RUN_TEST_IDLE;
else
tx_end = Jtag::SHIFT_DR;
Jtag::tapState_t tx_end = (len - xfer_len) ? Jtag::SHIFT_DR : Jtag::RUN_TEST_IDLE;
_jtag->shiftDR(ptr, NULL, xfer_len * 8, tx_end);
len -= xfer_len;
progress.display(pos);
@ -143,7 +139,7 @@ void Anlogic::program(unsigned int offset, bool unprotect_flash)
}
}
int Anlogic::idCode()
uint32_t Anlogic::idCode()
{
unsigned char tx_data[4];
unsigned char rx_data[4];
@ -184,7 +180,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 +206,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)

View File

@ -22,7 +22,7 @@ class Anlogic: public Device, SPIInterface {
~Anlogic();
void program(unsigned int offset, bool unprotect_flash) override;
int idCode() override;
uint32_t idCode() override;
void reset() override;
/* spi interface */
@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 :

View File

@ -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).

View File

@ -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,12 +349,13 @@ 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
int byte_to_read = 0; // for rd operation number of read in one xfer
@ -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);
}

View File

@ -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 */

View File

@ -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];

View File

@ -44,21 +44,21 @@ class CologneChip: public Device, SPIInterface {
printError("bulk erase flash not supported"); return false;}
void program(unsigned int offset, bool unprotect_flash) override;
int idCode() override {return 0;}
uint32_t idCode() override {return 0;}
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;

View File

@ -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;

View File

@ -11,6 +11,7 @@
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
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<uint8_t> _bit_data;
std::string _raw_data; /**< unprocessed file content */
std::map<std::string, std::string> _hdr;
};

View File

@ -50,7 +50,7 @@ class Device {
virtual bool unprotect_flash() = 0;
virtual bool bulk_erase_flash() = 0;
virtual int idCode() = 0;
virtual uint32_t idCode() = 0;
virtual void reset();
virtual bool connectJtagToMCU() {return false;}

View File

@ -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<uint8_t *>(data), length, 5000);
if (ret < 0) {
if (checkDevicePresent()) {
/* close device ? */
@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -291,7 +291,8 @@ void Efinix::programSPI(unsigned int offset, const uint8_t *data,
void Efinix::programJTAG(const uint8_t *data, const int length)
{
int xfer_len = 512, tx_end;
int xfer_len = 512;
Jtag::tapState_t tx_end;
uint8_t tx[512];
if (_fpga_family == TITANIUM_FAMILY)
@ -415,7 +416,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 +441,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];

View File

@ -37,13 +37,13 @@ class Efinix: public Device, SPIInterface {
bool bulk_erase_flash() override {
printError("bulk erase flash not supported"); return false;}
/* not supported in SPI Active mode */
int idCode() override {return 0;}
uint32_t idCode() override {return 0;}
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;

View File

@ -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;

View File

@ -138,7 +138,7 @@ int FsParser::parse()
for (auto &&line : _lstRawData) {
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);
}
}

View File

@ -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;

View File

@ -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;
/*!

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -204,10 +204,10 @@ 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) {
@ -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)
@ -400,7 +400,7 @@ bool Gowin::DisableCfg()
return pollFlag(STATUS_SYSTEM_EDIT_MODE, 0);
}
int Gowin::idCode()
uint32_t Gowin::idCode()
{
uint8_t device_id[4];
wr_rd(READ_IDCODE, NULL, 0, device_id, 4);
@ -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,9 +630,10 @@ 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 tx_len;
Jtag::tapState_t tx_end;
int byte_length = length / 8;
ProgressBar progress("Flash SRAM", byte_length, 50, _quiet);
@ -748,7 +749,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 +763,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];

View File

@ -22,7 +22,7 @@ class Gowin: public Device, SPIInterface {
Device::prog_type_t prg_type, bool external_flash,
bool verify, int8_t verbose);
~Gowin();
int idCode() override;
uint32_t idCode() override;
void reset() override;
void program(unsigned int offset, bool unprotect_flash) override;
void programFlash();
@ -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();

View File

@ -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) {

View File

@ -22,21 +22,21 @@ 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;
bool bulk_erase_flash() override;
/* not supported in SPI Active mode */
int idCode() override {return 0;}
uint32_t 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;
}

View File

@ -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) {

View File

@ -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

View File

@ -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, tapState_t end_state)
{
/* get number of devices in the JTAG chain
* after the selected one
@ -370,7 +370,7 @@ int Jtag::shiftDR(unsigned char *tdi, unsigned char *tdo, int drlen, int end_sta
return 0;
}
int Jtag::shiftIR(unsigned char tdi, int irlen, int end_state)
int Jtag::shiftIR(unsigned char tdi, int irlen, tapState_t end_state)
{
if (irlen > 8) {
cerr << "Error: this method this direct char don't support more than 1 byte" << endl;
@ -379,7 +379,7 @@ int Jtag::shiftIR(unsigned char tdi, int irlen, int end_state)
return shiftIR(&tdi, NULL, irlen, end_state);
}
int Jtag::shiftIR(unsigned char *tdi, unsigned char *tdo, int irlen, int end_state)
int Jtag::shiftIR(unsigned char *tdi, unsigned char *tdo, int irlen, tapState_t end_state)
{
display("%s: avant shiftIR\n", __func__);
int bypass_after = 0;
@ -440,7 +440,7 @@ int Jtag::shiftIR(unsigned char *tdi, unsigned char *tdo, int irlen, int end_sta
return 0;
}
void Jtag::set_state(int newState)
void Jtag::set_state(tapState_t newState)
{
unsigned char tms = 0;
while (newState != _state) {
@ -621,6 +621,9 @@ void Jtag::set_state(int newState)
_state = SELECT_DR_SCAN;
}
break;
case UNKNOWN:;
// UNKNOWN should not be valid...
throw std::exception();
}
setTMS(tms);

View File

@ -68,21 +68,6 @@ class Jtag {
*/
JtagInterface *get_ll_class() {return _jtag;}
int shiftIR(unsigned char *tdi, unsigned char *tdo, int irlen,
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 end_state = RUN_TEST_IDLE);
int read_write(unsigned char *tdi, unsigned char *tdo, int len, char last);
void toggleClk(int nb);
void go_test_logic_reset();
void set_state(int newState);
int flushTMS(bool flush_buffer = false);
void flush() {flushTMS(); _jtag->flush();}
void setTMS(unsigned char tms);
enum tapState_t {
TEST_LOGIC_RESET = 0,
RUN_TEST_IDLE = 1,
@ -102,6 +87,22 @@ class Jtag {
UPDATE_IR = 15,
UNKNOWN = 999
};
int shiftIR(unsigned char *tdi, unsigned char *tdo, int irlen,
tapState_t end_state = RUN_TEST_IDLE);
int shiftIR(unsigned char tdi, int irlen,
tapState_t end_state = RUN_TEST_IDLE);
int shiftDR(const uint8_t *tdi, unsigned char *tdo, int drlen,
tapState_t end_state = RUN_TEST_IDLE);
int read_write(const uint8_t *tdi, unsigned char *tdo, int len, char last);
void toggleClk(int nb);
void go_test_logic_reset();
void set_state(tapState_t newState);
int flushTMS(bool flush_buffer = false);
void flush() {flushTMS(); _jtag->flush();}
void setTMS(unsigned char tms);
const char *getStateName(tapState_t s);
/* utilities */
@ -119,7 +120,7 @@ class Jtag {
*/
bool search_and_insert_device_with_idcode(uint32_t idcode);
bool _verbose;
int _state;
tapState_t _state;
int _tms_buffer_size;
int _num_tms;
unsigned char *_tms_buffer;

View File

@ -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)

View File

@ -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);
@ -338,7 +338,7 @@ bool Lattice::program_mem()
uint8_t tmp[1024];
int size = 1024;
int next_state = Jtag::SHIFT_DR;
Jtag::tapState_t next_state = Jtag::SHIFT_DR;
ProgressBar progress("Loading", length, 50, _quiet);
@ -843,7 +843,7 @@ bool Lattice::DisableCfg()
return true;
}
int Lattice::idCode()
uint32_t Lattice::idCode()
{
uint8_t device_id[4];
wr_rd(READ_DEVICE_ID_CODE, NULL, 0, device_id, 4);
@ -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) {

View File

@ -23,7 +23,7 @@ class Lattice: public Device, SPIInterface {
Lattice(Jtag *jtag, std::string filename, const std::string &file_type,
Device::prog_type_t prg_type, std::string flash_sector, bool verify,
int8_t verbose);
int idCode() override;
uint32_t idCode() override;
int userCode();
void reset() override {}
void program(unsigned int offset, bool unprotect_flash) override;
@ -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;

View File

@ -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;

View File

@ -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; }

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -217,12 +217,12 @@ void SVF_jtag::parse_runtest(vector<string> const &vstr)
end_state = fsm_state[*res];
}
if (run_state != -1) {
_run_state = run_state;
_run_state = (Jtag::tapState_t)run_state;
}
if (end_state != -1) {
_end_state = end_state;
_end_state = (Jtag::tapState_t)end_state;
} else if (run_state != -1) {
_end_state = run_state;
_end_state = (Jtag::tapState_t)run_state;
}
_jtag->set_state(_run_state);
_jtag->toggleClk(nb_iter);
@ -245,13 +245,13 @@ void SVF_jtag::handle_instruction(vector<string> const &vstr)
if (_verbose) cout << "trst value : " << vstr[1] << endl;
} else if (!vstr[0].compare("ENDDR")) {
if (_verbose) cout << "enddr value : " << vstr[1] << endl;
_enddr = fsm_state[vstr[1]];
_enddr = (Jtag::tapState_t)fsm_state[vstr[1]];
} else if (!vstr[0].compare("ENDIR")) {
if (_verbose) cout << "endir value : " << vstr[1] << endl;
_endir = fsm_state[vstr[1]];
_endir = (Jtag::tapState_t)fsm_state[vstr[1]];
} else if (!vstr[0].compare("STATE")) {
if (_verbose) cout << "state value : " << vstr[1] << endl;
_jtag->set_state(fsm_state[vstr[1]]);
_jtag->set_state((Jtag::tapState_t)fsm_state[vstr[1]]);
} else if (!vstr[0].compare("RUNTEST")) {
parse_runtest(vstr);
} else if (!vstr[0].compare("HIR")) {
@ -335,8 +335,8 @@ void SVF_jtag::handle_instruction(vector<string> const &vstr)
}
SVF_jtag::SVF_jtag(Jtag *jtag, bool verbose):_verbose(verbose), _freq_hz(0),
_enddr(fsm_state["IDLE"]), _endir(fsm_state["IDLE"]),
_run_state(fsm_state["IDLE"]), _end_state(fsm_state["IDLE"])
_enddr((Jtag::tapState_t)fsm_state["IDLE"]), _endir((Jtag::tapState_t)fsm_state["IDLE"]),
_run_state((Jtag::tapState_t)fsm_state["IDLE"]), _end_state((Jtag::tapState_t)fsm_state["IDLE"])
{
_jtag = jtag;

View File

@ -58,10 +58,10 @@ class SVF_jtag {
bool _verbose;
uint32_t _freq_hz;
int _enddr;
int _endir;
int _run_state;
int _end_state;
Jtag::tapState_t _enddr;
Jtag::tapState_t _endir;
Jtag::tapState_t _run_state;
Jtag::tapState_t _end_state;
svf_XYR hdr;
svf_XYR hir;
svf_XYR sdr;

View File

@ -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

View File

@ -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

View File

@ -330,7 +330,7 @@ void Xilinx::reset()
_jtag->toggleClk(2000);
}
int Xilinx::idCode()
uint32_t Xilinx::idCode()
{
int id = 0;
unsigned char tx_data[4]= {0x00, 0x00, 0x00, 0x00};
@ -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,8 +570,9 @@ void Xilinx::program_mem(ConfigBitstreamParser *bitfile)
*/
/* GGM: TODO */
int byte_length = bitfile->getLength() / 8;
uint8_t *data = bitfile->getData();
int tx_len, tx_end;
const uint8_t *data = bitfile->getData();
int tx_len;
Jtag::tapState_t tx_end;
int burst_len = byte_length / 100;
ProgressBar progress("Flash SRAM", byte_length, 50, _quiet);
@ -727,8 +728,9 @@ bool Xilinx::xc3s_flow_program(ConfigBitstreamParser *bit)
{
int byte_length = bit->getLength() / 8;
int burst_len = byte_length / 100;
uint8_t *data = bit->getData();
int tx_len = burst_len * 8, tx_end = Jtag::SHIFT_DR;
const uint8_t *data = bit->getData();
int tx_len = burst_len * 8;
Jtag::tapState_t tx_end = Jtag::SHIFT_DR;
ProgressBar progress("Flash SRAM", byte_length, 50, _quiet);
flow_enable();
@ -769,8 +771,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,11 +1079,11 @@ 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;
int xfer_end;
Jtag::tapState_t xfer_end;
/* limit JTAG clock frequency to 15MHz */
if (_jtag->getClkFreq() > 15e6)
@ -1520,7 +1523,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 +1549,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];

View File

@ -46,7 +46,7 @@ class Xilinx: public Device, SPIInterface {
*/
bool bulk_erase_flash() override;
int idCode() override;
uint32_t idCode() override;
void reset() override;
/* -------------- */
@ -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;

View File

@ -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) {

View File

@ -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