Skip to content

Commit

Permalink
efinix: program(): thow exception when something fails
Browse files Browse the repository at this point in the history
  • Loading branch information
trabucayre committed Jul 29, 2024
1 parent aed4f9a commit a7cb7ec
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/efinix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ void Efinix::reset()

void Efinix::program(unsigned int offset, bool unprotect_flash)
{
bool ret;
if (_file_extension.empty())
return;
if (_mode == Device::NONE_MODE)
Expand All @@ -184,7 +185,7 @@ void Efinix::program(unsigned int offset, bool unprotect_flash)
}
} catch (std::exception &e) {
printError("FAIL: " + std::string(e.what()));
return;
throw std::runtime_error(e.what());
}

printInfo("Parse file ", false);
Expand All @@ -193,7 +194,7 @@ void Efinix::program(unsigned int offset, bool unprotect_flash)
} else {
printError("FAIL");
delete bit;
return;
throw std::runtime_error("Efinix: Failed to parse file: " + _filename);
}

const uint8_t *data = bit->getData();
Expand All @@ -204,14 +205,21 @@ void Efinix::program(unsigned int offset, bool unprotect_flash)

switch (_mode) {
case MEM_MODE:
programJTAG(data, length);
if (!programJTAG(data, length)) {
delete bit;
throw std::runtime_error("Efinix: Failed to load bitstream");
}
break;
case FLASH_MODE:
if (_jtag)
SPIInterface::write(offset, const_cast<uint8_t *>(data),
ret = SPIInterface::write(offset, const_cast<uint8_t *>(data),
length, unprotect_flash);
else
programSPI(offset, data, length, unprotect_flash);
ret = programSPI(offset, data, length, unprotect_flash);
if (!ret) {
delete bit;
throw std::runtime_error("Efinix: Failed to write bitstream in flash");
}
break;
default:
return;
Expand Down Expand Up @@ -398,7 +406,8 @@ bool Efinix::prepare_flash_access()
bridge.parse();
const uint8_t *data = bridge.getData();
const int length = bridge.getLength() / 8;
programJTAG(data, length);
if (!programJTAG(data, length))
return false;
} catch (std::exception &e) {
printError(e.what());
return false;
Expand Down

0 comments on commit a7cb7ec

Please sign in to comment.