Skip to content

Commit 0bc2594

Browse files
committed
latticeBitParser: align configuration Data start address to the bitstream header offset
1 parent 7ae6e2c commit 0bc2594

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/latticeBitParser.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ int LatticeBitParser::parseHeader()
7373
printError("Wrong preamble key");
7474
return EXIT_FAILURE;
7575
}
76-
_endHeader = pos - 4;
76+
_endHeader = pos - 3; // align to 2 Dummy bits + preamble (ie. Header start offset).
7777

7878
/* parse header */
79-
istringstream lineStream(_raw_data.substr(currPos, _endHeader-currPos));
79+
istringstream lineStream(_raw_data.substr(currPos, _endHeader - currPos - 1));
8080
string buff;
8181
while (std::getline(lineStream, buff, '\0')) {
8282
pos = buff.find_first_of(':', 0);
@@ -98,7 +98,7 @@ int LatticeBitParser::parse()
9898
return EXIT_FAILURE;
9999

100100
/* check preamble */
101-
uint32_t preamble = (*(uint32_t *)&_raw_data[_endHeader+1]);
101+
uint32_t preamble = (*(uint32_t *)&_raw_data[_endHeader]);
102102
//0xb3beffff is the preamble for encrypted bitstreams in Nexus fpgas
103103
if ((preamble != 0xb3bdffff) && (preamble != 0xb3bfffff) && (preamble != 0xb3beffff)) {
104104
printError("Error: missing preamble\n");
@@ -139,8 +139,7 @@ int LatticeBitParser::parse()
139139
std::move(_raw_data.begin()+_endHeader, _raw_data.end(), _bit_data.begin());
140140
_bit_length = _bit_data.size() * 8;
141141
} else {
142-
_endHeader += 1;
143-
uint32_t len = _raw_data.size() - _endHeader;
142+
const uint32_t len = _raw_data.size() - _endHeader;
144143
uint32_t max_len = 16;
145144
for (uint32_t i = 0; i < len; i+=max_len) {
146145
std::string tmp(16, 0xff);
@@ -173,7 +172,7 @@ int LatticeBitParser::parse()
173172
bool LatticeBitParser::parseCfgData()
174173
{
175174
uint8_t *ptr;
176-
size_t pos = _endHeader + 5; // drop preamble
175+
size_t pos = _endHeader + 4; // drop 16 Dummy bits and preamble
177176
uint32_t idcode;
178177
char __buf[10];
179178
int __buf_valid_bytes;

0 commit comments

Comments
 (0)