@@ -36,9 +36,6 @@ enum class BitstreamCommand : uint8_t {
36
36
CMD_AC = 0xac ,
37
37
CMD_B1 = 0xb1 ,
38
38
CPLD_DATA = 0xaa ,
39
- DUMMY_FF = 0xff ,
40
- DUMMY_EE = 0xee ,
41
- DUMMY_00 = 0x00
42
39
};
43
40
44
41
class Crc16 {
@@ -110,12 +107,11 @@ class BlockReadWriter {
110
107
}
111
108
112
109
// The command opcode is a byte so this works like get_byte
113
- inline BitstreamCommand get_command_opcode () {
110
+ inline uint8_t get_command_opcode () {
114
111
assert (iter < data.end ());
115
112
uint8_t val = *(iter++);
116
- BitstreamCommand cmd = BitstreamCommand (val);
117
113
crc16.update_crc16 (val);
118
- return cmd ;
114
+ return val ;
119
115
}
120
116
121
117
// Write a single byte and update CRC
@@ -419,17 +415,20 @@ Chip Bitstream::deserialise_chip()
419
415
continue ;
420
416
}
421
417
422
- BitstreamCommand cmd = rd.get_command_opcode ();
423
-
424
- bool is_cpld_command = false ;
425
- switch (cmd) {
426
- case BitstreamCommand::DUMMY_FF:
427
- case BitstreamCommand::DUMMY_EE:
428
- case BitstreamCommand::DUMMY_00:
418
+ uint8_t cmd_byte = rd.get_command_opcode ();
419
+ switch (cmd_byte) {
420
+ case 0xff :
421
+ case 0xee :
422
+ case 0x00 :
429
423
BITSTREAM_NOTE (" padding block_size " << dec << it->size ());
430
424
continue ;
431
425
break ;
426
+ }
432
427
428
+ // Add highest bit since old tools generate bitstreams with that bit low
429
+ BitstreamCommand cmd = BitstreamCommand (cmd_byte | 0x80 );
430
+ bool is_cpld_command = false ;
431
+ switch (cmd) {
433
432
case BitstreamCommand::DEVICEID_CPLD:
434
433
case BitstreamCommand::RESET_CRC_CPLD:
435
434
case BitstreamCommand::CMD_A1:
@@ -714,7 +713,7 @@ void Bitstream::write_bmk(const Chip &chip, std::ostream &out) {
714
713
out << meta << std::endl;
715
714
}
716
715
for (auto it = blocks.begin (); it != blocks.end (); ++it) {
717
- if (it->at (0 ) == ( uint8_t )BitstreamCommand::DUMMY_00 ) continue ;
716
+ if (it->at (0 ) == 0x00 ) continue ;
718
717
uint16_t size = it->size () << 3 ;
719
718
out << uint8_t (size >> 8 ) << uint8_t (size & 0xff );
720
719
for (size_t pos = 0 ; pos < it->size (); pos++) {
@@ -743,7 +742,7 @@ void Bitstream::write_bma(const Chip &chip, std::ostream &out) {
743
742
out << meta << std::endl;
744
743
}
745
744
for (auto it = blocks.begin (); it != blocks.end (); ++it) {
746
- if (it->at (0 ) == ( uint8_t )BitstreamCommand::DUMMY_00 ) continue ;
745
+ if (it->at (0 ) == 0x00 ) continue ;
747
746
for (size_t pos = 0 ; pos < it->size (); pos++) {
748
747
out << std::bitset<8 >((*it)[pos]);
749
748
}
0 commit comments