Skip to content

Commit

Permalink
Merge pull request #372 from aystarik/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
trabucayre authored Sep 2, 2023
2 parents fbb8341 + 9e91c31 commit 8989ac9
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/altera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Altera::Altera(Jtag *jtag, const std::string &filename,
printError("\tplease use rbf or svf file");
printError("\tor use --write-flash with: ", false);
printError("-b board_name or --fpga_part xxxx");
std::runtime_error("Error: wrong file");
throw std::runtime_error("Error: wrong file");
} else {
_mode = Device::SPI_MODE;
}
Expand Down
1 change: 0 additions & 1 deletion src/anlogicCable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ int AnlogicCable::setClkFreq(uint32_t clkHZ)

if (clkHZ > 6000000) {
printWarn("Anlogic JTAG probe limited to 6MHz");
clkHZ = 6000000;
}

if (clkHZ >= 6000000) {
Expand Down
4 changes: 2 additions & 2 deletions src/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ static std::map <std::string, target_board_t> board_list = {
DFU_BOARD("icebreaker-bitsy", "", "dfu", 0x1d50, 0x6146, 0),
JTAG_BOARD("kc705", "", "digilent", 0, 0, CABLE_DEFAULT),
JTAG_BOARD("LD-SCHOKO", "LFE5U-45F-6CABGA256", "", 0, 0, CABLE_MHZ(6)),
DFU_BOARD("LD-SCHOKO", "", "dfu", 0x16d0, 0x116d, 0),
DFU_BOARD("LD-SCHOKO-DFU", "", "dfu", 0x16d0, 0x116d, 0),
JTAG_BOARD("LD-KONFEKT", "LFE5U-12F-6BG256C", "", 0, 0, CABLE_MHZ(6)),
DFU_BOARD("LD-KONFEKT", "", "dfu", 0x16d0, 0x116d, 0),
DFU_BOARD("LD-KONFEKT-DFU", "", "dfu", 0x16d0, 0x116d, 0),
JTAG_BOARD("licheeTang", "", "anlogicCable", 0, 0, CABLE_DEFAULT),
/* left for backward compatibility, use tec0117 instead */
JTAG_BOARD("littleBee", "", "ft2232", 0, 0, CABLE_DEFAULT),
Expand Down
2 changes: 1 addition & 1 deletion src/cmsisDAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ CmsisDAP::CmsisDAP(const cable_t &cable, int index, int8_t verbose):_verbose(ver
std::vector<struct hid_device_info *> dev_found;
_ll_buffer = (unsigned char *)malloc(sizeof(unsigned char) * 65);
if (!_ll_buffer)
std::runtime_error("internal buffer allocation failed");
throw std::runtime_error("internal buffer allocation failed");
_buffer = _ll_buffer+2;

/* only hid support */
Expand Down
34 changes: 15 additions & 19 deletions src/colognechip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "colognechip.hpp"

#include <memory>

#define JTAG_CONFIGURE 0x06
#define JTAG_SPI_BYPASS 0x05
#define SLEEP_US 500
Expand Down Expand Up @@ -125,7 +127,7 @@ bool CologneChip::dumpFlash(uint32_t base_addr, uint32_t len)
if (_spi) {
/* enable output and hold reset */
_spi->gpio_clear(_rstn_pin | _oen_pin);
} else {
} else if (_ftdi_jtag) {
/* enable output and disable reset */
_ftdi_jtag->gpio_clear(_oen_pin);
_ftdi_jtag->gpio_set(_rstn_pin);
Expand All @@ -134,13 +136,9 @@ bool CologneChip::dumpFlash(uint32_t base_addr, uint32_t len)
/* prepare SPI access */
printInfo("Read Flash ", false);
try {
SPIFlash *flash;
if (_spi) {
flash = new SPIFlash(reinterpret_cast<SPIInterface *>(_spi), false,
_verbose);
} else {
flash = new SPIFlash(this, false, _verbose);
}
std::unique_ptr<SPIFlash> flash(_spi ?
new SPIFlash(reinterpret_cast<SPIInterface *>(_spi), false, _verbose):
new SPIFlash(this, false, _verbose));
flash->reset();
flash->power_up();
flash->dump(_filename, base_addr, len);
Expand Down Expand Up @@ -172,14 +170,14 @@ void CologneChip::program(unsigned int offset, bool unprotect_flash)
if (_mode == Device::NONE_MODE || _mode == Device::READ_MODE)
return;

ConfigBitstreamParser *cfg;
std::unique_ptr<ConfigBitstreamParser> cfg;
if (_file_extension == "cfg") {
cfg = new CologneChipCfgParser(_filename);
cfg.reset(new CologneChipCfgParser(_filename));
} else if (_file_extension == "bit") {
cfg = new RawParser(_filename, false);
cfg.reset(new RawParser(_filename, false));
} else { /* unknown type: */
if (_mode == Device::FLASH_MODE) {
cfg = new RawParser(_filename, false);
cfg.reset(new RawParser(_filename, false));
} else {
throw std::runtime_error("incompatible file format");
}
Expand All @@ -192,18 +190,16 @@ void CologneChip::program(unsigned int offset, bool unprotect_flash)

switch (_mode) {
case Device::FLASH_MODE:
if (_jtag != NULL) {
if (_jtag != NULL)
programJTAG_flash(offset, data, length, unprotect_flash);
} else if (_jtag == NULL) {
else
programSPI_flash(offset, data, length, unprotect_flash);
}
break;
case Device::MEM_MODE:
if (_jtag != NULL) {
if (_jtag != NULL)
programJTAG_sram(data, length);
} else if (_jtag == NULL) {
else
programSPI_sram(data, length);
}
break;
default: /* avoid warning */
break;
Expand Down Expand Up @@ -389,7 +385,7 @@ int CologneChip::spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
uint32_t timeout, bool verbose)
{
uint8_t rx[2];
uint8_t dummy[2];
uint8_t dummy[2] = {0xff};
uint8_t tmp;
uint8_t tx = ConfigBitstreamParser::reverseByte(cmd);
uint32_t count = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/configBitstreamParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,6 @@ bool ConfigBitstreamParser::decompress_bitstream(string source, string *dest)

/* clean up and return */
(void)inflateEnd(&strm);
return ret == Z_STREAM_END;
return true;
#endif
}
4 changes: 2 additions & 2 deletions src/dfu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ int DFU::dfu_detach()

int DFU::get_status(struct dfu_status *status)
{
uint8_t buffer[6];
uint8_t buffer[6] = {0};
int res;

res = send(false, DFU_GETSTATUS, 0, buffer, 6);
Expand All @@ -586,7 +586,7 @@ int DFU::get_status(struct dfu_status *status)
*/
char DFU::get_state()
{
char c;
char c = 0;

int res = send(false, DFU_GETSTATE, 0, (unsigned char *)&c, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/ice40.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool Ice40::program_cram(const uint8_t *data, uint32_t length)
progress.done();

/* send 48 to 100 dummy bits */
uint8_t dummy[12];
uint8_t dummy[12] = {0xff};
_spi->spi_put(dummy, NULL, 12);

/* wait CDONE */
Expand Down
4 changes: 2 additions & 2 deletions src/jedParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ void JedParser::parseEField(const vector<string> &content)
{
_featuresRow = 0;
string featuresRow = content[0].substr(1);
for (size_t i = 0; i < featuresRow.size(); i++)
_featuresRow |= ((featuresRow[i] - '0') << i);
for (size_t i = 0; i < featuresRow.size(); ++i)
_featuresRow |= (uint64_t(featuresRow[i] - '0') << i);
string feabits = content[1];
_feabits = 0;
for (size_t i = 0; i < feabits.size(); i++) {
Expand Down
4 changes: 3 additions & 1 deletion src/jtag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Jtag::Jtag(const cable_t &cable, const jtag_pins_conf_t *pin_conf,
}

_tms_buffer = (unsigned char *)malloc(sizeof(unsigned char) * _tms_buffer_size);
if (_tms_buffer == nullptr)
throw std::runtime_error("Error: memory allocation failed");
memset(_tms_buffer, 0, _tms_buffer_size);

detectChain(5);
Expand Down Expand Up @@ -618,7 +620,7 @@ void Jtag::set_state(tapState_t newState)
_state = RUN_TEST_IDLE;
} else {
tms = 1;
_state = SELECT_DR_SCAN;
_state = SELECT_IR_SCAN;
}
break;
case UNKNOWN:;
Expand Down
27 changes: 12 additions & 15 deletions src/lattice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,10 @@ bool Lattice::program_flash(unsigned int offset, bool unprotect_flash)
} else if (_file_extension == "pub") {
/* clear current SRAM content */
clearSRAM();
retval = program_pubkey_MachXO3D();
program_pubkey_MachXO3D();
} else {
// machox2 + bit
if (_file_extension == "bit" && _fpga_family == MACHXO2_FAMILY) {
retval = true;
try {
LatticeBitParser _bit(_filename, true, _verbose);
_bit.parse();
Expand Down Expand Up @@ -1357,23 +1356,24 @@ int Lattice::spi_put(uint8_t cmd, const 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];
uint8_t jrx[xfer_len];
if (len == 0)
return 0;
uint8_t jtx[len];
uint8_t jrx[len];

if (tx) {
for (uint32_t i=0; i < len; i++)
jtx[i] = LatticeBitParser::reverseByte(tx[i]);
for (uint32_t i = 0; i < len; ++i) {
jtx[i] = (tx) ? LatticeBitParser::reverseByte(tx[i]) : 0;
jrx[i] = 0;
}

/* send first already stored cmd,
* in the same time store each byte
* to next
*/
_jtag->shiftDR(jtx, (rx == NULL)? NULL: jrx, 8*xfer_len);
_jtag->shiftDR(jtx, (rx) ? jrx : nullptr, 8 * len);

if (rx != NULL) {
for (uint32_t i=0; i < len; i++)
if (rx) {
for (uint32_t i = 0; i < len; ++i)
rx[i] = LatticeBitParser::reverseByte(jrx[i]);
}
return 0;
Expand All @@ -1383,7 +1383,7 @@ int Lattice::spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
uint32_t timeout, bool verbose)
{
uint8_t rx;
uint8_t dummy[2];
uint8_t dummy[2] = {0xff};
uint8_t tmp;
uint8_t tx = LatticeBitParser::reverseByte(cmd);
uint32_t count = 0;
Expand Down Expand Up @@ -2045,9 +2045,6 @@ bool Lattice::program_pubkey_MachXO3D()
printf("%02x", pubkey[j]);
}
printf("]\n");
}

if (_verbose) {
printf("Trailing bytes: [");
for (; i < len; i++) {
printf("%02x ", data[i]);
Expand Down
6 changes: 3 additions & 3 deletions src/part.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static std::map <uint32_t, fpga_model> fpga_list = {
/* Lattice MachXO3 */
{0x012BB043, {"lattice", "MachXO3LF", "LCMX03LF-1300C", 8}},
{0x012B2043, {"lattice", "MachXO3LF", "LCMX03LF-1300E", 8}},
{0x012BB043, {"lattice", "MachXO3LF", "LCMX03LF-2100C", 8}},
{0x612BB043, {"lattice", "MachXO3LF", "LCMX03LF-2100C", 8}},
{0x012B3043, {"lattice", "MachXO3LF", "LCMX03LF-2100E", 8}},
{0x012BC043, {"lattice", "MachXO3LF", "LCMX03LF-4300C", 8}},
{0x012B4043, {"lattice", "MachXO3LF", "LCMX03LF-4300E", 8}},
Expand Down Expand Up @@ -207,8 +207,8 @@ static std::map <uint32_t, fpga_model> fpga_list = {
{0x010F1043, {"lattice", "CrosslinkNX", "LIFCL-40", 8}},

/* Lattice Certus-NX */
{0x010F0043, {"lattice", "CertusNX", "LFD2NX-17", 8}},
{0x010F1043, {"lattice", "CertusNX", "LFD2NX-40", 8}},
{0x310F0043, {"lattice", "CertusNX", "LFD2NX-17", 8}},
{0x310F1043, {"lattice", "CertusNX", "LFD2NX-40", 8}},

/**************************************************************************/
/* Gowin */
Expand Down
4 changes: 4 additions & 0 deletions src/svf_jtag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void SVF_jtag::parse_XYR(vector<string> const &vstr, svf_XYR &t)
}
if (write_data != -1) {
size_t byte_len = (t.len + 7) / 8;
if (byte_len == 0)
return;
unsigned char *write_buffer = parse_hex(t.tdi, byte_len, 0);
if (!t.smask.empty()) {
unsigned char *smaskbuff = parse_hex(t.smask, byte_len, 0);
Expand Down Expand Up @@ -171,6 +173,8 @@ void SVF_jtag::parse_XYR(vector<string> const &vstr, svf_XYR &t)
cerr << uppercase << hex << int(read_buffer[j]);
}
cerr << " isn't the one expected: " << uppercase << t.tdo << endl;
delete[] tdobuf;
delete[] maskbuf;
throw exception();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/usbBlaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ UsbBlasterII::UsbBlasterII(const string &firmware_path)
{
std::string fpath;
uint8_t buf[5];
if (firmware_path.empty() && BLASTERII_DIR == "") {
if (firmware_path.empty() && strlen(BLASTERII_DIR) == 0) {
printError("missing FX2 firmware");
printError("use --probe-firmware with something");
printError("like /opt/intelFPGA/VERSION/quartus/linux64/blaster_6810.hex");
Expand Down
20 changes: 10 additions & 10 deletions src/xilinx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdexcept>
#include <string>
#include <vector>
#include <memory>

#include "jtag.hpp"
#include "bitparser.hpp"
Expand Down Expand Up @@ -371,22 +372,21 @@ void Xilinx::program(unsigned int offset, bool unprotect_flash)
return;

if (_mode == Device::FLASH_MODE && _file_extension == "jed") {
JedParser *jed;
if (_fpga_family != XC95_FAMILY && _fpga_family != XC2C_FAMILY)
throw std::runtime_error("Error: jed only supported for xc95 and xc2c");
printInfo("Open file ", false);

jed = new JedParser(_filename, _verbose);
std::unique_ptr<JedParser> jed(new JedParser(_filename, _verbose));
if (jed->parse() == EXIT_FAILURE) {
printError("FAIL");
return;
}
printSuccess("DONE");

if (_fpga_family == XC95_FAMILY)
flow_program(jed);
flow_program(jed.get());
else if (_fpga_family == XC2C_FAMILY)
xc2c_flow_program(jed);
else
throw std::runtime_error("Error: jed only supported for xc95 and xc2c");
xc2c_flow_program(jed.get());
return;
}

Expand Down Expand Up @@ -974,7 +974,7 @@ std::string Xilinx::flow_read()
std::string buffer;
uint8_t wr_buf[16+2]; // largest section length
uint8_t rd_buf[16+2];
memset(wr_buf, 0xff, 16);
memset(wr_buf, 0xff, sizeof(wr_buf));

/* limit JTAG clock frequency to 1MHz */
if (_jtag->getClkFreq() > 1e6)
Expand Down Expand Up @@ -1433,7 +1433,6 @@ std::string Xilinx::xc2c_flow_read()

bool Xilinx::xc2c_flow_program(JedParser *jed)
{
uint8_t wr_buf[249]; // largest section length
uint32_t delay_loop = (_jtag->getClkFreq() * 20) / 1000;
uint8_t shift_addr = 8 - _cpld_addr_size;

Expand Down Expand Up @@ -1472,6 +1471,7 @@ bool Xilinx::xc2c_flow_program(JedParser *jed)
for (auto row : listfuse) {
uint16_t pos = 0;
uint8_t addr = _gray_code[iter] >> shift_addr;
uint8_t wr_buf[249] = {0}; // largest section length
for (auto col : row) {
if (col)
wr_buf[pos >> 3] |= (1 << (pos & 0x07));
Expand Down Expand Up @@ -1577,7 +1577,7 @@ int Xilinx::spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
uint32_t timeout, bool verbose)
{
uint8_t rx[2];
uint8_t dummy[2];
uint8_t dummy[2] = {0xff};
uint8_t tmp;
uint8_t tx = McsParser::reverseByte(cmd);
uint32_t count = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/xvc_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class XVC_server {
int _sock; /*!< server socket descriptor */
struct sockaddr_in _sock_addr;
std::thread *_thread; /*!< connection thread */
bool _is_stopped; /*!< true when thread is stopped */
bool _must_stop; /*!< true to stop thread */
volatile bool _is_stopped; /*!< true when thread is stopped */
volatile bool _must_stop; /*!< true to stop thread */
uint32_t _buffer_size; /*!< buffer max capacity TDI+TMS */
uint8_t *_tmstdi; /*!< TDI/TMS from client */
uint8_t *_result; /*!< buffer for server -> client */
Expand Down

0 comments on commit 8989ac9

Please sign in to comment.