Skip to content

Commit 0d12cfb

Browse files
committed
Support old bitstreams
1 parent 838df4f commit 0d12cfb

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

libtang/src/Bitstream.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ enum class BitstreamCommand : uint8_t {
3636
CMD_AC = 0xac,
3737
CMD_B1 = 0xb1,
3838
CPLD_DATA = 0xaa,
39-
DUMMY_FF = 0xff,
40-
DUMMY_EE = 0xee,
41-
DUMMY_00 = 0x00
4239
};
4340

4441
class Crc16 {
@@ -110,12 +107,11 @@ class BlockReadWriter {
110107
}
111108

112109
// 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() {
114111
assert(iter < data.end());
115112
uint8_t val = *(iter++);
116-
BitstreamCommand cmd = BitstreamCommand(val);
117113
crc16.update_crc16(val);
118-
return cmd;
114+
return val;
119115
}
120116

121117
// Write a single byte and update CRC
@@ -419,17 +415,20 @@ Chip Bitstream::deserialise_chip()
419415
continue;
420416
}
421417

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:
429423
BITSTREAM_NOTE("padding block_size " << dec << it->size());
430424
continue;
431425
break;
426+
}
432427

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) {
433432
case BitstreamCommand::DEVICEID_CPLD:
434433
case BitstreamCommand::RESET_CRC_CPLD:
435434
case BitstreamCommand::CMD_A1:
@@ -714,7 +713,7 @@ void Bitstream::write_bmk(const Chip &chip, std::ostream &out) {
714713
out << meta << std::endl;
715714
}
716715
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;
718717
uint16_t size = it->size() << 3;
719718
out << uint8_t(size >> 8) << uint8_t(size & 0xff);
720719
for (size_t pos = 0; pos < it->size(); pos++) {
@@ -743,7 +742,7 @@ void Bitstream::write_bma(const Chip &chip, std::ostream &out) {
743742
out << meta << std::endl;
744743
}
745744
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;
747746
for (size_t pos = 0; pos < it->size(); pos++) {
748747
out << std::bitset<8>((*it)[pos]);
749748
}

0 commit comments

Comments
 (0)