@@ -73,10 +73,10 @@ int LatticeBitParser::parseHeader()
7373 printError (" Wrong preamble key" );
7474 return EXIT_FAILURE;
7575 }
76- _endHeader = pos - 3 ; // align to 2 Dummy bits + preamble (ie. Header start offset).
76+ _endHeader = pos - 4 ; // align to 3 Dummy Bytes + preamble (ie. Header start offset).
7777
7878 /* parse header */
79- istringstream lineStream (_raw_data.substr (currPos, _endHeader - currPos - 1 ));
79+ istringstream lineStream (_raw_data.substr (currPos, _endHeader - currPos));
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]);
101+ uint32_t preamble = (*(uint32_t *)&_raw_data[_endHeader + 1 ]);
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 " );
@@ -138,18 +138,19 @@ int LatticeBitParser::parse()
138138 /* According to FPGA-TN-02192-3.4
139139 * the Lattice ECP3 must trasnmit at least 128 clock pulses before
140140 * receiving the preamble.
141- * Here the header contains 16 Dummy bit + preamble so only
142- * 14bits 8x14 = 112bits must be added as padding.
141+ * Here the header contains 3x8 Dummy bit + preamble so only
142+ * 13bits 8x13 = 112bits must be added as padding.
143143 */
144144 const uint32_t offset = (_is_ecp3) ? 14 : 0 ;
145145 _bit_data.resize (_raw_data.size () - _endHeader + offset);
146146 if (_is_ecp3) {
147- std::string tmp (14 , 0xff );
147+ std::string tmp (13 , 0xff );
148148 std::move (tmp.begin (), tmp.end (), _bit_data.begin ());
149149 }
150150 std::move (_raw_data.begin () + _endHeader, _raw_data.end (), _bit_data.begin () + offset);
151151 _bit_length = _bit_data.size () * 8 ;
152152 } else {
153+ _endHeader++;
153154 const uint32_t len = _raw_data.size () - _endHeader;
154155 uint32_t max_len = 16 ;
155156 for (uint32_t i = 0 ; i < len; i+=max_len) {
@@ -183,7 +184,7 @@ int LatticeBitParser::parse()
183184bool LatticeBitParser::parseCfgData ()
184185{
185186 uint8_t *ptr;
186- size_t pos = _endHeader + 4 ; // drop 16 Dummy bits and preamble
187+ size_t pos = _endHeader + 5 ; // drop 16 Dummy bits and preamble
187188 uint32_t idcode;
188189 char __buf[10 ];
189190 int __buf_valid_bytes;
0 commit comments