xilinx: fail write-flash on SPI access errors; improve open-file errors

This commit is contained in:
Nicholas Dietz 2026-06-15 17:22:43 -05:00 committed by Gwenhael Goavec-Merou
parent ed82b6de3b
commit 09e250b856
2 changed files with 19 additions and 14 deletions

View File

@ -804,14 +804,14 @@ int spi_comm(struct arguments args, const cable_t &cable,
bit = new RawParser(args.bit_file, false); bit = new RawParser(args.bit_file, false);
printSuccess("DONE"); printSuccess("DONE");
} catch (std::exception &e) { } catch (std::exception &e) {
printError("FAIL"); printError("FAIL: unable to open '" + args.bit_file + "': " + std::string(e.what()));
delete spi; delete spi;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printInfo("Parse file ", false); printInfo("Parse file ", false);
if (bit->parse() == EXIT_FAILURE) { if (bit->parse() == EXIT_FAILURE) {
printError("FAIL"); printError("FAIL: unable to parse '" + args.bit_file + "'");
delete bit; delete bit;
delete spi; delete spi;
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -207,20 +207,24 @@ static void open_bitfile(
const std::string &filename, const std::string &extension, const std::string &filename, const std::string &extension,
ConfigBitstreamParser **parser, bool reverse, bool verbose) ConfigBitstreamParser **parser, bool reverse, bool verbose)
{ {
printInfo("Open file ", false); printInfo("Open file " + filename + " ", false);
if (extension == "bit") { try {
*parser = new BitParser(filename, reverse, verbose); if (extension == "bit") {
} else if (extension == "mcs") { *parser = new BitParser(filename, reverse, verbose);
*parser = new McsParser(filename, reverse, verbose); } else if (extension == "mcs") {
} else { *parser = new McsParser(filename, reverse, verbose);
*parser = new RawParser(filename, reverse); } else {
*parser = new RawParser(filename, reverse);
}
} catch (const std::exception &e) {
throw std::runtime_error("Unable to open '" + filename + "': " + e.what());
} }
printSuccess("DONE"); printSuccess("DONE");
printInfo("Parse file ", false); printInfo("Parse file ", false);
if ((*parser)->parse() == EXIT_FAILURE) { if ((*parser)->parse() == EXIT_FAILURE) {
throw std::runtime_error("Failed to parse bitstream"); throw std::runtime_error("Failed to parse bitstream '" + filename + "'");
} }
printSuccess("DONE"); printSuccess("DONE");
@ -662,12 +666,11 @@ void Xilinx::program(unsigned int offset, bool unprotect_flash)
&secondary_bit, reverse, _verbose); &secondary_bit, reverse, _verbose);
} }
} catch (std::exception &e) { } catch (std::exception &e) {
printError("FAIL");
if (bit) if (bit)
delete bit; delete bit;
if (secondary_bit) if (secondary_bit)
delete secondary_bit; delete secondary_bit;
return; throw std::runtime_error(e.what());
} }
if (_verbose) { if (_verbose) {
@ -870,11 +873,13 @@ void Xilinx::program_spi(ConfigBitstreamParser * bit, std::string extention,
throw std::runtime_error("called with null bitstream"); throw std::runtime_error("called with null bitstream");
if (extention == "mcs") { if (extention == "mcs") {
McsParser *parser = (McsParser *)bit; McsParser *parser = (McsParser *)bit;
FlashInterface::write(parser->getRecords(), unprotect_flash, true); if (!FlashInterface::write(parser->getRecords(), unprotect_flash, true))
throw std::runtime_error("SPI flash write failed");
} else { } else {
const uint8_t *data = bit->getData(); const uint8_t *data = bit->getData();
int length = bit->getLength() / 8; int length = bit->getLength() / 8;
FlashInterface::write(offset, data, length, unprotect_flash); if (!FlashInterface::write(offset, data, length, unprotect_flash))
throw std::runtime_error("SPI flash write failed");
} }
} }