Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/altera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,16 +1303,17 @@ int Altera::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len)
* one bit
*/
int xfer_len = len + 1 + ((rx == NULL) ? 0 : 1);
uint8_t jtx[xfer_len];
uint8_t jrx[xfer_len];
std::vector<uint8_t> jtx, jrx;
jtx.resize(xfer_len);
jrx.resize(xfer_len);

if (tx != NULL) {
for (uint32_t i = 0; i < len; i++)
jtx[i] = RawParser::reverseByte(tx[i]);
}

shiftVIR(RawParser::reverseByte(cmd));
shiftVDR(jtx, (rx) ? jrx : NULL, 8 * xfer_len);
shiftVDR(jtx.data(), (rx) ? jrx.data() : NULL, 8 * xfer_len);

if (rx) {
for (uint32_t i = 0; i < len; i++) {
Expand Down
14 changes: 8 additions & 6 deletions src/anlogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ int Anlogic::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len)
int xfer_len = len + 1;
if (rx)
xfer_len++;
uint8_t jtx[xfer_len];
uint8_t jrx[xfer_len];
std::vector<uint8_t> jtx, jrx;
jtx.resize(xfer_len);
jrx.resize(xfer_len);

jtx[0] = AnlogicBitParser::reverseByte(cmd);
if (tx != NULL) {
Expand All @@ -210,7 +211,7 @@ int Anlogic::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t len)
uint8_t op = 0x60;
_jtag->shiftDR(&op, NULL, 8);

_jtag->shiftDR(jtx, (rx == NULL)? NULL: jrx, 8*xfer_len);
_jtag->shiftDR(jtx.data(), (rx == NULL)? NULL: jrx.data(), 8*xfer_len);
if (rx != NULL) {
for (uint32_t i=0; i < len; i++)
rx[i] = AnlogicBitParser::reverseByte(jrx[i+1]>>1)
Expand All @@ -223,8 +224,9 @@ int Anlogic::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len)
int xfer_len = len;
if (rx)
xfer_len++;
uint8_t jtx[xfer_len];
uint8_t jrx[xfer_len];
std::vector<uint8_t> jtx, jrx;
jtx.resize(xfer_len);
jrx.resize(xfer_len);

if (tx != NULL) {
for (uint32_t i = 0; i < len; i++)
Expand All @@ -235,7 +237,7 @@ int Anlogic::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len)
uint8_t op = 0x60;
_jtag->shiftDR(&op, NULL, 8);

_jtag->shiftDR(jtx, (rx == NULL)? NULL: jrx, 8*xfer_len);
_jtag->shiftDR(jtx.data(), (rx == NULL)? NULL: jrx.data(), 8*xfer_len);
if (rx != NULL) {
for (uint32_t i=0; i < len; i++)
rx[i] = AnlogicBitParser::reverseByte(jrx[i]>>1) |
Expand Down
27 changes: 16 additions & 11 deletions src/ch552_jtag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ int CH552_jtag::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer,

mpsse_store(buf, 3);
if (pos >= iter) {
uint8_t tmp[_to_read];
std::vector<uint8_t> tmp;
tmp.resize(_to_read);
pos = 0;
if (-1 == mpsse_read(tmp, _to_read))
if (-1 == mpsse_read(tmp.data(), _to_read))
printError("writeTMS: Fail to read/write");
_to_read = 0;
}
Expand All @@ -131,8 +132,9 @@ int CH552_jtag::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer,

if (flush_buffer) {
if (_to_read > 0) {
uint8_t tmp[_to_read];
if (mpsse_read(tmp, _to_read) == -1)
std::vector<uint8_t> tmp;
tmp.resize(_to_read);
if (mpsse_read(tmp.data(), _to_read) == -1)
printError("writeTMS: fail to flush");
_to_read = 0;
}
Expand All @@ -149,10 +151,11 @@ int CH552_jtag::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len)
(void) tdi;

int byteLen = (clk_len+7)/8;
uint8_t buf_tms[byteLen];
std::vector<uint8_t> buf_tms;
buf_tms.resize(byteLen);

memset(buf_tms, (tms) ? 0xff : 0x00, byteLen);
return writeTMS(buf_tms, clk_len, false);
memset(buf_tms.data(), (tms) ? 0xff : 0x00, byteLen);
return writeTMS(buf_tms.data(), clk_len, false);
}

int CH552_jtag::flush()
Expand All @@ -163,8 +166,9 @@ int CH552_jtag::flush()
if (ret == -1)
printError("flush: fails to write");
} else {
uint8_t tmp[_to_read];
ret = mpsse_read(tmp, _to_read);
std::vector<uint8_t> tmp;
tmp.resize(_to_read);
ret = mpsse_read(tmp.data(), _to_read);
if (ret == -1)
printError("flush: fails to read/write");
_to_read = 0;
Expand Down Expand Up @@ -199,8 +203,9 @@ int CH552_jtag::writeTDI(const uint8_t *tdi, uint8_t *tdo, uint32_t len, bool la
uint8_t oneshot_buf[3] = {rd_cmd, 0, 0};

if (_to_read != 0) {
uint8_t tmp_[_to_read];
if (mpsse_read(tmp_, _to_read) == -1)
std::vector<uint8_t> tmp_;
tmp_.resize(_to_read);
if (mpsse_read(tmp_.data(), _to_read) == -1)
printError("writeTDI: fails to flush read");
_to_read = 0;
}
Expand Down
14 changes: 8 additions & 6 deletions src/colognechip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,9 @@ void CologneChip::programJTAG_flash(unsigned int offset, const uint8_t *data,
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];
uint8_t jrx[xfer_len+2];
std::vector<uint8_t> jtx, jrx;
jtx.resize(xfer_len+2, 0);
jrx.resize(xfer_len+2, 0);

jtx[0] = ConfigBitstreamParser::reverseByte(cmd);

Expand All @@ -428,7 +429,7 @@ int CologneChip::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t l
_jtag->shiftIR(JTAG_SPI_BYPASS, 6, Jtag::SHIFT_DR);

int drlen = (rx == NULL) ? 8*xfer_len : 8*xfer_len+1;
_jtag->read_write(jtx, (rx == NULL) ? NULL : jrx, drlen, false);
_jtag->read_write(jtx.data(), (rx == NULL) ? NULL : jrx.data(), drlen, false);

int shift = _jtag->get_devices_list().size();

Expand All @@ -448,16 +449,17 @@ int CologneChip::spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx, uint32_t l
int CologneChip::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len)
{
int xfer_len = len;
uint8_t jtx[xfer_len+2];
uint8_t jrx[xfer_len+2];
std::vector<uint8_t> jtx, jrx;
jtx.resize(xfer_len+2, 0);
jrx.resize(xfer_len+2, 0);

if (tx != NULL) {
for (uint32_t i=0; i < len; i++)
jtx[i] = ConfigBitstreamParser::reverseByte(tx[i]);
}

_jtag->shiftIR(JTAG_SPI_BYPASS, 6, Jtag::SELECT_DR_SCAN);
_jtag->shiftDR(jtx, (rx == NULL)? NULL: jrx, 8*xfer_len+1, Jtag::SELECT_DR_SCAN);
_jtag->shiftDR(jtx.data(), (rx == NULL)? NULL: jrx.data(), 8*xfer_len+1, Jtag::SELECT_DR_SCAN);

if (rx != NULL) {
for (uint32_t i=0; i < len; i++) {
Expand Down
9 changes: 5 additions & 4 deletions src/dirtyJtag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,16 @@ int DirtyJtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
uint32_t real_bit_len = len - (end ? 1 : 0);
const uint32_t kRealByteLen = (len + 7) / 8;

uint8_t tx_cpy[kRealByteLen];
std::vector<uint8_t> tx_cpy;
tx_cpy.resize(kRealByteLen);
uint8_t tx_buf[512], rx_buf[512];
uint8_t *tx_ptr, *rx_ptr = rx;

tx_ptr = tx_cpy.data();
if (tx)
memcpy(tx_cpy, tx, kRealByteLen);
memcpy(tx_ptr, tx, kRealByteLen);
else
memset(tx_cpy, 0, kRealByteLen);
tx_ptr = tx_cpy;
memset(tx_ptr, 0, kRealByteLen);

tx_buf[0] = CMD_XFER | (rx ? 0 : v_options[_version].no_read);
uint16_t max_bit_transfer_length = v_options[_version].max_bits;
Expand Down
14 changes: 8 additions & 6 deletions src/efinix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,10 @@ int Efinix::spi_put(uint8_t cmd,
const uint8_t *tx, uint8_t *rx, uint32_t len)
{
int kXferLen = len + 1 + ((rx == NULL) ? 0 : 1);
uint8_t jtx[kXferLen];
std::vector<uint8_t> jtx, jrx;
jtx.resize(kXferLen, 0);
jrx.resize(kXferLen, 0);
jtx[0] = EfinixHexParser::reverseByte(cmd);
uint8_t jrx[kXferLen];
if (tx != NULL) {
for (uint32_t i=0; i < len; i++)
jtx[i+1] = EfinixHexParser::reverseByte(tx[i]);
Expand All @@ -496,7 +497,7 @@ int Efinix::spi_put(uint8_t cmd,
* in the same time store each byte
* to next
*/
_jtag->shiftDR(jtx, (rx == NULL)? NULL: jrx, 8*kXferLen);
_jtag->shiftDR(jtx.data(), (rx == NULL)? NULL: jrx.data(), 8*kXferLen);

if (rx != NULL) {
for (uint32_t i=0; i < len; i++)
Expand All @@ -508,8 +509,9 @@ int Efinix::spi_put(uint8_t cmd,
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];
uint8_t jrx[kXferLen];
std::vector<uint8_t> jtx, jrx;
jtx.resize(kXferLen, 0);
jrx.resize(kXferLen, 0);
if (tx != NULL) {
for (uint32_t i=0; i < len; i++)
jtx[i] = EfinixHexParser::reverseByte(tx[i]);
Expand All @@ -520,7 +522,7 @@ int Efinix::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len)
* in the same time store each byte
* to next
*/
_jtag->shiftDR(jtx, (rx == NULL)? NULL: jrx, 8*kXferLen);
_jtag->shiftDR(jtx.data(), (rx == NULL)? NULL: jrx.data(), 8*kXferLen);

if (rx != NULL) {
for (uint32_t i=0; i < len; i++)
Expand Down
7 changes: 4 additions & 3 deletions src/esp_usb_jtag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ int esp_usb_jtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool en
}
int ret;
const uint32_t kTdiLen = (len+7) >> 3; // TDI/RX len in byte
uint8_t tdi[kTdiLen]; // TDI buffer (required when tx is NULL)
std::vector<uint8_t> tdi; // TDI buffer (required when tx is NULL)
tdi.resize(kTdiLen);
uint8_t tx_buf[OUT_EP_SZ];
const uint8_t tdo = !(rx == NULL); // only set cap/tdo when something to read
uint8_t *rx_ptr = NULL;
Expand All @@ -687,9 +688,9 @@ int esp_usb_jtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool en

/* Copy RX or fill the buffer with TDI current level */
if (tx)
memcpy(tdi, tx, kTdiLen);
memcpy(tdi.data(), tx, kTdiLen);
else
memset(tdi, _tdi ? 0xff : 0x00, kTdiLen);
memset(tdi.data(), _tdi ? 0xff : 0x00, kTdiLen);

if (_verbose) {
snprintf(mess, 256, "len=0x%08x\n", len);
Expand Down
56 changes: 31 additions & 25 deletions src/ftdiJtagMPSSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ int FtdiJtagMPSSE::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer,
printf("writeTMS: error\n");

if (_ch552WA) {
uint8_t c[len/8+1];
int ret = ftdi_read_data(_ftdi, c, len/8+1);
std::vector<uint8_t> c;
c.resize(len/8+1);
int ret = ftdi_read_data(_ftdi, c.data(), len/8+1);
if (ret != 0) {
printf("ret : %d\n", ret);
}
Expand All @@ -167,8 +168,9 @@ int FtdiJtagMPSSE::writeTMS(const uint8_t *tms, uint32_t len, bool flush_buffer,
if (flush_buffer)
mpsse_write();
if (_ch552WA) {
uint8_t c[len/8+1];
ftdi_read_data(_ftdi, c, len/8+1);
std::vector<uint8_t> c;
c.resize(len/8+1);
ftdi_read_data(_ftdi, c.data(), len/8+1);
}

return len;
Expand Down Expand Up @@ -210,9 +212,10 @@ int FtdiJtagMPSSE::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len)
ret = clk_len;
} else {
int byteLen = (len+7)/8;
uint8_t buf_tms[byteLen];
memset(buf_tms, (tms) ? 0xff : 0x00, byteLen);
ret = writeTMS(buf_tms, len, false);
std::vector<uint8_t> buf_tms;
buf_tms.resize(byteLen);
memset(buf_tms.data(), (tms) ? 0xff : 0x00, byteLen);
ret = writeTMS(buf_tms.data(), len, false);
}

return ret;
Expand Down Expand Up @@ -243,8 +246,9 @@ int FtdiJtagMPSSE::writeTDI(const uint8_t *tdi, uint8_t *tdo, uint32_t len, bool
int nb_byte = real_len >> 3; // number of byte to send
int nb_bit = (real_len & 0x07); // residual bits
int xfer = tx_buff_size - 3;
unsigned char c[xfer];
unsigned char rev[xfer];
std::vector<unsigned char> c, rev;
c.resize(xfer);
rev.resize(xfer);
unsigned char *rx_ptr = (unsigned char *)tdo;
unsigned char *tx_ptr = (unsigned char *)tdi;
bool use_msb_first = _msb_first && !tdo;
Expand Down Expand Up @@ -284,15 +288,15 @@ int FtdiJtagMPSSE::writeTDI(const uint8_t *tdi, uint8_t *tdo, uint32_t len, bool
rev[i] = bit_reverse(tx_ptr[i]);
}
}
mpsse_store(use_msb_first ? rev : tx_ptr, xfer_len);
mpsse_store(use_msb_first ? rev.data() : tx_ptr, xfer_len);
tx_ptr += xfer_len;
}
if (tdo) {
mpsse_read(rx_ptr, xfer_len);
rx_ptr += xfer_len;
} else if (_ch552WA) {
mpsse_write();
ftdi_read_data(_ftdi, c, xfer_len);
ftdi_read_data(_ftdi, c.data(), xfer_len);
} else if (!last) {
mpsse_write();
}
Expand Down Expand Up @@ -329,7 +333,7 @@ int FtdiJtagMPSSE::writeTDI(const uint8_t *tdi, uint8_t *tdo, uint32_t len, bool
*rx_ptr >>= (8 - nb_bit);
} else {
mpsse_write();
ftdi_read_data(_ftdi, c, nb_bit);
ftdi_read_data(_ftdi, c.data(), nb_bit);
}
} else if (!last) {
mpsse_write();
Expand Down Expand Up @@ -367,7 +371,7 @@ int FtdiJtagMPSSE::writeTDI(const uint8_t *tdi, uint8_t *tdo, uint32_t len, bool
*rx_ptr |= (((c[index]) & 0x80) >> (7 - nb_bit));
} else if (_ch552WA) {
mpsse_write();
ftdi_read_data(_ftdi, c, 1);
ftdi_read_data(_ftdi, c.data(), 1);
} else {
mpsse_write();
}
Expand Down Expand Up @@ -444,12 +448,14 @@ bool FtdiJtagMPSSE::writeTMSTDI(const uint8_t *tms, const uint8_t *tdi,
int32_t ret;
uint32_t max_len = 1024;
uint8_t mode = 0; // current state: 0 none, 1 TDI, 2 TMS
uint8_t tdi_buf[max_len]; // buffer to store TDI sequence
uint8_t tms_tmp = 0; // buffer to store TMS sequence (limited to 6bits per cmd)
uint8_t tdo_tmp[max_len]; // local TDO sequence
std::vector<uint8_t> tdi_buf; // buffer to store TDI sequence
std::vector<uint8_t> tdo_tmp; // local TDO sequence
tdi_buf.resize(max_len);
tdo_tmp.resize(max_len);
uint32_t buff_len = 0; // current bits stored
memset(tdi_buf, 0, max_len);
memset(tdo_tmp, 0, max_len);
memset(tdi_buf.data(), 0, max_len);
memset(tdo_tmp.data(), 0, max_len);
_tdo_pos = 0; // current bits read

if (_verbose)
Expand Down Expand Up @@ -525,9 +531,9 @@ bool FtdiJtagMPSSE::writeTMSTDI(const uint8_t *tms, const uint8_t *tdi,
buff_len++;
is_end = true;
}
writeTDI(tdi_buf, tdo_tmp, buff_len, is_end);
update_tdo_buff(tdo_tmp, tdo, buff_len);
memset(tdi_buf, 0, max_len);
writeTDI(tdi_buf.data(), tdo_tmp.data(), buff_len, is_end);
update_tdo_buff(tdo_tmp.data(), tdo, buff_len);
memset(tdi_buf.data(), 0, max_len);
buff_len = 0;
if (is_end) {
_curr_tdi = tdi_bit;
Expand All @@ -554,9 +560,9 @@ bool FtdiJtagMPSSE::writeTMSTDI(const uint8_t *tms, const uint8_t *tdi,

/* buffer full? */
if (buff_len == 8*max_len && mode == 1) {
writeTDI(tdi_buf, tdo_tmp, buff_len, false);
update_tdo_buff(tdo_tmp, tdo, buff_len);
memset(tdi_buf, 0, max_len);
writeTDI(tdi_buf.data(), tdo_tmp.data(), buff_len, false);
update_tdo_buff(tdo_tmp.data(), tdo, buff_len);
memset(tdi_buf.data(), 0, max_len);
buff_len = 0;
} else if (buff_len == 6 && mode == 2) {
ret = update_tms_buff(&tms_tmp, 0, buff_len, _curr_tdi, tdo, true);
Expand All @@ -574,8 +580,8 @@ bool FtdiJtagMPSSE::writeTMSTDI(const uint8_t *tms, const uint8_t *tdi,
if (buff_len > 0) {
switch (mode) {
case 1:
writeTDI(tdi_buf, tdo_tmp, buff_len, false);
update_tdo_buff(tdo_tmp, tdo, buff_len);
writeTDI(tdi_buf.data(), tdo_tmp.data(), buff_len, false);
update_tdo_buff(tdo_tmp.data(), tdo, buff_len);
break;
case 2:
if (update_tms_buff(&tms_tmp, 0, buff_len, _curr_tdi,
Expand Down
Loading