From c9fb3f406562cbf35d14a1bf20f7e381bee9a392 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Sat, 14 May 2022 19:00:21 +0200 Subject: [PATCH] latticeBitParser: fix end header position with MACHOX3D .bit file --- src/latticeBitParser.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/latticeBitParser.cpp b/src/latticeBitParser.cpp index 8321b05..55d546c 100644 --- a/src/latticeBitParser.cpp +++ b/src/latticeBitParser.cpp @@ -60,6 +60,18 @@ int LatticeBitParser::parseHeader() return EXIT_FAILURE; } + /* .bit for MACHXO3D seems to have more 0xff before preamble key */ + size_t pos = _raw_data.find(0xb3, _endHeader); + if (pos == string::npos) { + printError("Preamble key not found"); + return EXIT_FAILURE; + } + if ((uint8_t)_raw_data[pos-1] != 0xbd && (uint8_t)_raw_data[pos-1] != 0xbf) { + printError("Wrong preamble key"); + return EXIT_FAILURE; + } + _endHeader = pos - 4; + /* parse header */ istringstream lineStream(_raw_data.substr(currPos, _endHeader-currPos)); string buff;