From 0f3afbcaea9a86bd16a48418d6b00932525336cf Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Thu, 10 Aug 2023 13:50:26 +0300 Subject: [PATCH] Make IDCODE unsigned --- src/altera.cpp | 2 +- src/altera.hpp | 2 +- src/anlogic.cpp | 8 ++------ src/anlogic.hpp | 2 +- src/colognechip.hpp | 2 +- src/device.hpp | 2 +- src/efinix.hpp | 2 +- src/gowin.cpp | 2 +- src/gowin.hpp | 2 +- src/ice40.hpp | 2 +- src/jtag.cpp | 5 ++++- src/jtag.hpp | 11 ++++++----- src/lattice.cpp | 4 ++-- src/lattice.hpp | 2 +- src/main.cpp | 4 ++-- src/svf_jtag.cpp | 8 ++++---- src/svf_jtag.hpp | 4 ++-- src/xilinx.cpp | 2 +- src/xilinx.hpp | 2 +- 19 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/altera.cpp b/src/altera.cpp index 51d7ec2..a94bc4c 100644 --- a/src/altera.cpp +++ b/src/altera.cpp @@ -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]; diff --git a/src/altera.hpp b/src/altera.hpp index 1e40aa9..f63ccf6 100644 --- a/src/altera.hpp +++ b/src/altera.hpp @@ -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; /*************************/ diff --git a/src/anlogic.cpp b/src/anlogic.cpp index f70314b..45e233f 100644 --- a/src/anlogic.cpp +++ b/src/anlogic.cpp @@ -113,11 +113,7 @@ void Anlogic::program(unsigned int offset, bool unprotect_flash) const uint8_t *ptr = data; while (len > 0) { int xfer_len = (len > 512)?512:len; - Jtag::tapState_t 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]; diff --git a/src/anlogic.hpp b/src/anlogic.hpp index 8864e3c..366812d 100644 --- a/src/anlogic.hpp +++ b/src/anlogic.hpp @@ -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 */ diff --git a/src/colognechip.hpp b/src/colognechip.hpp index 35ae837..7aef8ca 100644 --- a/src/colognechip.hpp +++ b/src/colognechip.hpp @@ -44,7 +44,7 @@ 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: diff --git a/src/device.hpp b/src/device.hpp index d5b254e..78aa935 100644 --- a/src/device.hpp +++ b/src/device.hpp @@ -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;} diff --git a/src/efinix.hpp b/src/efinix.hpp index 8236257..3bd2afe 100644 --- a/src/efinix.hpp +++ b/src/efinix.hpp @@ -37,7 +37,7 @@ 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 */ diff --git a/src/gowin.cpp b/src/gowin.cpp index 7568927..b435e5c 100644 --- a/src/gowin.cpp +++ b/src/gowin.cpp @@ -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); diff --git a/src/gowin.hpp b/src/gowin.hpp index 337910d..24b701a 100644 --- a/src/gowin.hpp +++ b/src/gowin.hpp @@ -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(); diff --git a/src/ice40.hpp b/src/ice40.hpp index 8602134..ddf23fb 100644 --- a/src/ice40.hpp +++ b/src/ice40.hpp @@ -28,7 +28,7 @@ class Ice40: public Device, SPIInterface { 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, const uint8_t *tx, uint8_t *rx, diff --git a/src/jtag.cpp b/src/jtag.cpp index 65c9145..4432a8c 100644 --- a/src/jtag.cpp +++ b/src/jtag.cpp @@ -440,7 +440,7 @@ int Jtag::shiftIR(unsigned char *tdi, unsigned char *tdo, int irlen, tapState_t 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); diff --git a/src/jtag.hpp b/src/jtag.hpp index 91190ce..8ac77a2 100644 --- a/src/jtag.hpp +++ b/src/jtag.hpp @@ -67,6 +67,7 @@ class Jtag { * \return a pointer instance of JtagInterface */ JtagInterface *get_ll_class() {return _jtag;} + enum tapState_t { TEST_LOGIC_RESET = 0, RUN_TEST_IDLE = 1, @@ -88,16 +89,16 @@ class Jtag { }; int shiftIR(unsigned char *tdi, unsigned char *tdo, int irlen, - Jtag::tapState_t end_state = RUN_TEST_IDLE); + tapState_t end_state = RUN_TEST_IDLE); int shiftIR(unsigned char tdi, int irlen, - Jtag::tapState_t end_state = RUN_TEST_IDLE); + tapState_t end_state = RUN_TEST_IDLE); int shiftDR(const uint8_t *tdi, unsigned char *tdo, int drlen, - Jtag::tapState_t end_state = RUN_TEST_IDLE); + 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(int newState); + void set_state(tapState_t newState); int flushTMS(bool flush_buffer = false); void flush() {flushTMS(); _jtag->flush();} void setTMS(unsigned char tms); @@ -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; diff --git a/src/lattice.cpp b/src/lattice.cpp index 01ea945..739e785 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -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); @@ -1308,7 +1308,7 @@ uint16_t Lattice::getUFMStartPageFromJEDEC(JedParser *_jed, int id) addres. TODO: In any case, JEDEC files don't carry part information. Verify against IDCODE read previously? */ - + if(raw_page_offset > 9211) { return raw_page_offset - 9211 - 1; // 7000 } else if(raw_page_offset > 5758) { diff --git a/src/lattice.hpp b/src/lattice.hpp index 0b9b124..fe2104e 100644 --- a/src/lattice.hpp +++ b/src/lattice.hpp @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 2071b1a..ddfdb4b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,7 +115,7 @@ int main(int argc, char **argv) /* index_chain file_size target_flash external_flash altsetting */ -1, 0, "primary", false, -1, /* vid, pid, index bus_addr, device_addr */ - 0, 0, -1, 0, 0, + 0, 0, -1, 0, 0, "127.0.0.1", 0, false, false, "", false, false, /* xvc server */ false, 3721, "-", @@ -533,7 +533,7 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } - /* check if selected device is supported + /* check if selected device is supported * mainly used in conjunction with --index-chain */ if (fpga_list.find(idcode) == fpga_list.end()) { diff --git a/src/svf_jtag.cpp b/src/svf_jtag.cpp index a971b75..6b7ac22 100644 --- a/src/svf_jtag.cpp +++ b/src/svf_jtag.cpp @@ -217,12 +217,12 @@ void SVF_jtag::parse_runtest(vector 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); @@ -336,7 +336,7 @@ void SVF_jtag::handle_instruction(vector const &vstr) SVF_jtag::SVF_jtag(Jtag *jtag, bool verbose):_verbose(verbose), _freq_hz(0), _enddr((Jtag::tapState_t)fsm_state["IDLE"]), _endir((Jtag::tapState_t)fsm_state["IDLE"]), - _run_state(fsm_state["IDLE"]), _end_state(fsm_state["IDLE"]) + _run_state((Jtag::tapState_t)fsm_state["IDLE"]), _end_state((Jtag::tapState_t)fsm_state["IDLE"]) { _jtag = jtag; diff --git a/src/svf_jtag.hpp b/src/svf_jtag.hpp index b5164ab..d727707 100644 --- a/src/svf_jtag.hpp +++ b/src/svf_jtag.hpp @@ -60,8 +60,8 @@ class SVF_jtag { uint32_t _freq_hz; Jtag::tapState_t _enddr; Jtag::tapState_t _endir; - int _run_state; - int _end_state; + Jtag::tapState_t _run_state; + Jtag::tapState_t _end_state; svf_XYR hdr; svf_XYR hir; svf_XYR sdr; diff --git a/src/xilinx.cpp b/src/xilinx.cpp index e2ac32a..bcf9428 100644 --- a/src/xilinx.cpp +++ b/src/xilinx.cpp @@ -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}; diff --git a/src/xilinx.hpp b/src/xilinx.hpp index 2064487..c8cf142 100644 --- a/src/xilinx.hpp +++ b/src/xilinx.hpp @@ -46,7 +46,7 @@ class Xilinx: public Device, SPIInterface { */ bool bulk_erase_flash() override; - int idCode() override; + uint32_t idCode() override; void reset() override; /* -------------- */