Skip to content

Commit

Permalink
Fixes for PVS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aystarik committed Sep 1, 2023
1 parent d89f2fd commit b69d6e0
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 85 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/ch347jtag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int CH347Jtag::usb_xfer(unsigned wlen, unsigned rlen, unsigned *ract, bool defer
return 0;
}

wcomplete = 0;
int wcomplete = 0, rcomplete = 0;
libusb_fill_bulk_transfer(wtrans, dev_handle, CH347JTAG_WRITE_EP, obuf,
wlen, sync_cb, &wcomplete, CH347JTAG_TIMEOUT);
int r = libusb_submit_transfer(wtrans);
Expand Down
1 change: 0 additions & 1 deletion src/ch347jtag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class CH347Jtag : public JtagInterface {
libusb_device_handle *dev_handle;
libusb_context *usb_ctx;
struct libusb_transfer *wtrans, *rtrans;
int rcomplete, wcomplete;
uint8_t ibuf[512];
uint8_t _obuf[512];
uint8_t *obuf;
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
42 changes: 21 additions & 21 deletions src/gowin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,23 +679,23 @@ int Gowin::spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len)
_jtag->flush();

/* send bit/bit full tx content (or set di to 0 when NULL) */
for (uint32_t i = 0; i < len * 8; i++) {
uint8_t r;
t = _spi_msk | _spi_do;
if (tx != NULL && tx[i>>3] & (1 << (7-(i&0x07))))
t |= _spi_di;
_jtag->shiftDR(&t, NULL, 8);
_jtag->toggleClk(6);
t |= _spi_sck;
_jtag->shiftDR(&t, (rx) ? &r : NULL, 8);
_jtag->toggleClk(6);
_jtag->flush();
/* if read reconstruct bytes */
if (rx) {
if (r & _spi_do)
rx[i >> 3] |= 1 << (7-(i & 0x07));
else
rx[i >> 3] &= ~(1 << (7-(i & 0x07)));
for (unsigned l = 0; l < len; ++l) {
if (rx)
rx[l] = 0;
for (uint8_t b = 0, bm = 0x80; b < 8; ++b, bm >>= 1) {
uint8_t r;
t = _spi_msk | _spi_do;
if (tx != NULL && tx[l] & bm)
t |= _spi_di;
_jtag->shiftDR(&t, NULL, 8);
_jtag->toggleClk(6);
t |= _spi_sck;
_jtag->shiftDR(&t, (rx) ? &r : NULL, 8);
_jtag->toggleClk(6);
_jtag->flush();
/* if read reconstruct bytes */
if (rx && (r & _spi_do))
rx[l] |= bm;
}
}
/* set CS and unset SCK (next xfer) */
Expand Down Expand Up @@ -745,9 +745,9 @@ int Gowin::spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
_jtag->toggleClk(6);

/* send command bit/bit */
for (int i = 0; i < 8; i++) {
for (uint8_t i = 0, bm = 0x80; i < 8; ++i, bm >>= 1) {
t = _spi_msk | _spi_do;
if ((cmd & (1 << (7-i))) != 0)
if ((cmd & bm) != 0)
t |= _spi_di;
_jtag->shiftDR(&t, NULL, 8);
_jtag->toggleClk(6);
Expand All @@ -761,7 +761,7 @@ int Gowin::spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
do {
tmp = 0;
/* read status register bit/bit with di == 0 */
for (int i = 0; i < 8; i++) {
for (uint8_t i = 0, bm = 0x80; i < 8; ++i, bm >>= 1) {
uint8_t r;
t &= ~_spi_sck;
_jtag->shiftDR(&t, NULL, 8);
Expand All @@ -771,7 +771,7 @@ int Gowin::spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
_jtag->toggleClk(6);
_jtag->flush();
if ((r & _spi_do) != 0)
tmp |= 1 << (7-i);
tmp |= bm;
}

count++;
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
Loading

0 comments on commit b69d6e0

Please sign in to comment.