latticeBitParser: fix end header position with MACHOX3D .bit file

This commit is contained in:
Gwenhael Goavec-Merou 2022-05-14 19:00:21 +02:00
parent a4d5fd8448
commit c9fb3f4065
1 changed files with 12 additions and 0 deletions

View File

@ -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;