Fix reading with gmunpack and clangformat
This commit is contained in:
parent
9148a1b81d
commit
542863a768
|
|
@ -59,17 +59,16 @@ static constexpr const uint8_t CFG_FILL_RAM = 0x20;
|
||||||
static constexpr const uint8_t CFG_SERDES = 0x40;
|
static constexpr const uint8_t CFG_SERDES = 0x40;
|
||||||
|
|
||||||
static const std::vector<std::pair<std::string, uint8_t>> crc_modes = {
|
static const std::vector<std::pair<std::string, uint8_t>> crc_modes = {
|
||||||
{"check", 0x00},
|
{"check", 0x00}, // Check CRC
|
||||||
{"ignore", 0x01},
|
{"ignore", 0x01}, // Ignore added CRC
|
||||||
{"unused", 0x02}
|
{"unused", 0x02} // CRC is unused
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::vector<std::pair<std::string, std::vector<uint8_t>>> spi_modes = {
|
static const std::vector<std::pair<std::string, std::vector<uint8_t>>> spi_modes = {
|
||||||
{"single", {}},
|
{"single", {}}, // Single SPI mode
|
||||||
{"dual", {0x50, 0x21, 0x18, 0x3B}},
|
{"dual", {0x50, 0x21, 0x18, 0x3B}}, // Dual SPI mode
|
||||||
{"quad", {0xF0, 0x23, 0x18, 0x6B}}
|
{"quad", {0xF0, 0x23, 0x18, 0x6B}} // Quad SPI mode
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t crc_table_x25[256] = {
|
static const uint16_t crc_table_x25[256] = {
|
||||||
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5,
|
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5,
|
||||||
0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52,
|
0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52,
|
||||||
|
|
@ -117,7 +116,6 @@ class BitstreamReadWriter
|
||||||
bool crc_unused = false;
|
bool crc_unused = false;
|
||||||
Crc16 crc16;
|
Crc16 crc16;
|
||||||
|
|
||||||
|
|
||||||
// Return a single byte and update CRC
|
// Return a single byte and update CRC
|
||||||
inline uint8_t get_byte()
|
inline uint8_t get_byte()
|
||||||
{
|
{
|
||||||
|
|
@ -222,22 +220,9 @@ class BitstreamReadWriter
|
||||||
// Get the offset into the bitstream
|
// Get the offset into the bitstream
|
||||||
size_t get_offset() { return size_t(distance(data.begin(), iter)); }
|
size_t get_offset() { return size_t(distance(data.begin(), iter)); }
|
||||||
|
|
||||||
// Check the calculated CRC16 against an actual CRC16, expected in the next 2
|
void set_crc_unused(bool val) { crc_unused = val; }
|
||||||
// bytes
|
|
||||||
void check_crc16()
|
bool get_crc_unused() { return crc_unused; }
|
||||||
{
|
|
||||||
uint8_t crc_bytes[2];
|
|
||||||
uint16_t actual_crc = crc16.get_crc16();
|
|
||||||
get_bytes(crc_bytes, 2);
|
|
||||||
// cerr << hex << int(crc_bytes[0]) << " " << int(crc_bytes[1]) << endl;
|
|
||||||
uint16_t exp_crc = (crc_bytes[0] << 8) | crc_bytes[1];
|
|
||||||
if (actual_crc != exp_crc) {
|
|
||||||
std::ostringstream err;
|
|
||||||
err << "crc fail, calculated 0x" << std::hex << actual_crc << " but expecting 0x" << exp_crc;
|
|
||||||
throw BitstreamParseError(err.str(), get_offset());
|
|
||||||
}
|
|
||||||
crc16.reset_crc16();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert the calculated CRC16 into the bitstream
|
// Insert the calculated CRC16 into the bitstream
|
||||||
void insert_crc16()
|
void insert_crc16()
|
||||||
|
|
@ -284,7 +269,7 @@ class BitstreamReadWriter
|
||||||
void write_cmd_cfgmode(uint8_t crcmode, std::vector<uint8_t> spimode)
|
void write_cmd_cfgmode(uint8_t crcmode, std::vector<uint8_t> spimode)
|
||||||
{
|
{
|
||||||
write_header(CMD_CFGMODE, spimode.size() > 0 ? 6 : 2);
|
write_header(CMD_CFGMODE, spimode.size() > 0 ? 6 : 2);
|
||||||
write_byte(0xFF); // crc retries
|
write_byte(0xFF); // crc retries
|
||||||
write_byte(crcmode); // crc error behaviour
|
write_byte(crcmode); // crc error behaviour
|
||||||
if (spimode.size() > 0) {
|
if (spimode.size() > 0) {
|
||||||
write_byte(spimode[0]); // spi io width
|
write_byte(spimode[0]); // spi io width
|
||||||
|
|
@ -396,6 +381,8 @@ class BitstreamReadWriter
|
||||||
|
|
||||||
void check_crc(BitstreamReadWriter &rd)
|
void check_crc(BitstreamReadWriter &rd)
|
||||||
{
|
{
|
||||||
|
if (rd.get_crc_unused())
|
||||||
|
return;
|
||||||
uint16_t actual_crc = rd.crc16.get_crc16();
|
uint16_t actual_crc = rd.crc16.get_crc16();
|
||||||
uint16_t exp_crc = rd.get_crc(); // crc
|
uint16_t exp_crc = rd.get_crc(); // crc
|
||||||
if (actual_crc != exp_crc) {
|
if (actual_crc != exp_crc) {
|
||||||
|
|
@ -461,11 +448,14 @@ int Bitstream::determine_size(int *max_die_x, int *max_die_y)
|
||||||
rd.get_vector(block, length);
|
rd.get_vector(block, length);
|
||||||
// Check data CRC
|
// Check data CRC
|
||||||
check_crc(rd);
|
check_crc(rd);
|
||||||
|
// Set CRC flag
|
||||||
|
if (cmd == CMD_CFGMODE)
|
||||||
|
rd.set_crc_unused(block[1] == 0x02);
|
||||||
// Skip bytes
|
// Skip bytes
|
||||||
if (cmd == CMD_SLAVE_MODE)
|
if (cmd == CMD_SLAVE_MODE)
|
||||||
rd.skip_bytes(3);
|
rd.skip_bytes(3);
|
||||||
if (cmd == CMD_CFGMODE)
|
if (cmd == CMD_CFGMODE)
|
||||||
rd.skip_bytes(3);
|
rd.skip_bytes(4);
|
||||||
if (cmd == CMD_PLL)
|
if (cmd == CMD_PLL)
|
||||||
rd.skip_bytes(6);
|
rd.skip_bytes(6);
|
||||||
if (cmd == CMD_CHG_STATUS)
|
if (cmd == CMD_CHG_STATUS)
|
||||||
|
|
@ -759,7 +749,7 @@ Chip Bitstream::deserialise_chip()
|
||||||
case CMD_CFGMODE:
|
case CMD_CFGMODE:
|
||||||
BITSTREAM_DEBUG("CMD_CFGMODE");
|
BITSTREAM_DEBUG("CMD_CFGMODE");
|
||||||
if (length > 20)
|
if (length > 20)
|
||||||
BITSTREAM_FATAL("PLL data longer than expected", rd.get_offset());
|
BITSTREAM_FATAL("CFGMODE data longer than expected", rd.get_offset());
|
||||||
// Check header CRC
|
// Check header CRC
|
||||||
check_crc(rd);
|
check_crc(rd);
|
||||||
|
|
||||||
|
|
@ -768,8 +758,10 @@ Chip Bitstream::deserialise_chip()
|
||||||
// Check data CRC
|
// Check data CRC
|
||||||
check_crc(rd);
|
check_crc(rd);
|
||||||
|
|
||||||
|
rd.set_crc_unused(block[1] == 0x02);
|
||||||
|
|
||||||
// Skip bytes
|
// Skip bytes
|
||||||
rd.skip_bytes(3);
|
rd.skip_bytes(4);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_SERDES:
|
case CMD_SERDES:
|
||||||
|
|
@ -844,7 +836,7 @@ Bitstream Bitstream::serialise_chip(const Chip &chip, const std::map<std::string
|
||||||
auto crcmode = crc_modes.begin();
|
auto crcmode = crc_modes.begin();
|
||||||
if (options.count("crcmode")) {
|
if (options.count("crcmode")) {
|
||||||
change_crc = true;
|
change_crc = true;
|
||||||
crcmode = find_if(crc_modes.begin(), crc_modes.end(), [&](const std::pair<std::string, uint8_t> &fp){
|
crcmode = find_if(crc_modes.begin(), crc_modes.end(), [&](const std::pair<std::string, uint8_t> &fp) {
|
||||||
return fp.first == options.at("crcmode");
|
return fp.first == options.at("crcmode");
|
||||||
});
|
});
|
||||||
if (crcmode == crc_modes.end()) {
|
if (crcmode == crc_modes.end()) {
|
||||||
|
|
@ -856,9 +848,10 @@ Bitstream Bitstream::serialise_chip(const Chip &chip, const std::map<std::string
|
||||||
auto spimode = spi_modes.begin();
|
auto spimode = spi_modes.begin();
|
||||||
if (options.count("spimode")) {
|
if (options.count("spimode")) {
|
||||||
change_spi = true;
|
change_spi = true;
|
||||||
spimode = find_if(spi_modes.begin(), spi_modes.end(), [&](const std::pair<std::string, std::vector<uint8_t>> &fp){
|
spimode = find_if(spi_modes.begin(), spi_modes.end(),
|
||||||
return fp.first == options.at("spimode");
|
[&](const std::pair<std::string, std::vector<uint8_t>> &fp) {
|
||||||
});
|
return fp.first == options.at("spimode");
|
||||||
|
});
|
||||||
if (spimode == spi_modes.end()) {
|
if (spimode == spi_modes.end()) {
|
||||||
throw std::runtime_error("bad spimode option " + options.at("spimode"));
|
throw std::runtime_error("bad spimode option " + options.at("spimode"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue