mirror of
https://github.com/trabucayre/openFPGALoader.git
synced 2026-08-30 09:59:03 +02:00
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:
@@ -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')) {
|
||||
|
||||
Reference in New Issue
Block a user