From 2e2e325a9b0b0fa8abe358e5e0257a244b5e46a1 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Sat, 20 Nov 2021 17:01:40 +0100 Subject: [PATCH] lattice: check matching idcode between bitstream and FPGA --- src/lattice.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lattice.cpp b/src/lattice.cpp index 0a0244b..f7269d8 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -271,9 +271,14 @@ bool Lattice::program_mem() if (_verbose) _bit.displayHeader(); - /* read ID Code 0xE0 */ + /* read ID Code 0xE0 and compare to bitstream */ + uint32_t bit_idcode = std::stoul(_bit.getHeaderVal("idcode").c_str(), NULL, 16); + uint32_t idcode = idCode(); + if (idcode != bit_idcode) + throw std::runtime_error("mismatch between target's idcode and bitstream idcode"); + if (_verbose) { - printf("IDCode : %x\n", idCode()); + printf("IDCode : %x\n", idcode); displayReadReg(readStatusReg()); } @@ -521,6 +526,13 @@ bool Lattice::program_extFlash(unsigned int offset) if (_verbose) _bit->displayHeader(); + if (_file_extension == "bit") { + uint32_t bit_idcode = std::stoul(_bit->getHeaderVal("idcode").c_str(), NULL, 16); + uint32_t idcode = idCode(); + if (idcode != bit_idcode) + throw std::runtime_error("mismatch between target's idcode and bitstream idcode"); + } + /*IR = 0h3A, DR=0hFE,0h68. Enter RUNTESTIDLE. * thank @GregDavill * https://twitter.com/GregDavill/status/1251786406441086977