efinix: Add header parsing and flash programming validation

Parse bitstream header to extract Mode, Width and Device fields.
Add validation for flash programming:
- Check device matches --fpga-part parameter
- Reject passive mode (only active mode supported for flash)

This prevents flashing incorrect bitstreams that would fail to boot.
This commit is contained in:
zhangyh
2025-12-12 02:55:31 +00:00
parent c16e6d0f65
commit ebf2f6fd80
3 changed files with 73 additions and 0 deletions
+46
View File
@@ -17,9 +17,55 @@ EfinixHexParser::EfinixHexParser(const string &filename):
false)
{}
int EfinixHexParser::parseHeader()
{
string buffer;
istringstream lineStream(_raw_data);
int bytesRead = 0;
string headerText;
bool foundPaddedBits = false;
while (std::getline(lineStream, buffer, '\n')) {
bytesRead += buffer.size() + 1;
if (buffer != "0A") {
try {
uint8_t byte = std::stol(buffer, nullptr, 16);
headerText += (char)byte;
} catch (...) {
}
} else {
headerText += '\n';
if (foundPaddedBits)
break;
}
if (headerText.find("PADDED_BITS") != string::npos)
foundPaddedBits = true;
}
size_t pos;
if ((pos = headerText.find("Mode: ")) != string::npos) {
size_t end = headerText.find('\n', pos);
_hdr["mode"] = headerText.substr(pos + 6, end - pos - 6);
}
if ((pos = headerText.find("Width: ")) != string::npos) {
size_t end = headerText.find('\n', pos);
_hdr["width"] = headerText.substr(pos + 7, end - pos - 7);
}
if ((pos = headerText.find("Device: ")) != string::npos) {
size_t end = headerText.find('\n', pos);
_hdr["device"] = headerText.substr(pos + 8, end - pos - 8);
}
return bytesRead;
}
int EfinixHexParser::parse()
{
string buffer;
parseHeader();
istringstream lineStream(_raw_data);
while (std::getline(lineStream, buffer, '\n')) {