From b150bbdd237df7e17ba89365d96c40323aae993b Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Thu, 24 Jun 2021 08:57:18 +0200 Subject: [PATCH] gowin: checks if fs is targeted for connected device --- src/gowin.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gowin.cpp b/src/gowin.cpp index db5acbd..4e76e00 100644 --- a/src/gowin.cpp +++ b/src/gowin.cpp @@ -75,6 +75,8 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, is_gw1n1(false) { _fs = NULL; + uint32_t idcode = idCode(); + if (!_file_extension.empty()) { if (_file_extension == "fs") { if (prg_type == Device::WR_FLASH) @@ -98,6 +100,11 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, if (_verbose) _fs->displayHeader(); + string idcode_str = _fs->getHeaderVal("idcode"); + uint32_t fs_idcode = std::stoul(idcode_str.c_str(), NULL, 16); + if (fs_idcode != idcode) { + throw std::runtime_error("mismatch between target's idcode and fs idcode"); + } } else { throw std::runtime_error("incompatible file format"); } @@ -105,7 +112,7 @@ Gowin::Gowin(Jtag *jtag, const string filename, const string &file_type, _jtag->setClkFreq(2500000); /* erase and program flash differ for GW1N1 */ - if (idCode() == 0x0900281B) + if (idcode == 0x0900281B) is_gw1n1 = true; }