Grouped the buffers from GDB's flash write packets so that we only flush once we have the full buffer.

This fixes an issue with GDB programming, where it was sending misaligned buffers and program memory
wasn't being properly updated.
This commit is contained in:
Nav
2022-09-17 20:12:26 +01:00
parent 65bdcd62d3
commit 18fb3b56ce
5 changed files with 130 additions and 8 deletions

View File

@@ -52,18 +52,51 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
Logger::debug("Handling FlashWrite packet");
try {
targetControllerConsole.enableProgrammingMode();
if (this->buffer.empty()) {
throw Exception("Received empty buffer from GDB");
}
targetControllerConsole.writeMemory(
Targets::TargetMemoryType::FLASH,
this->startAddress,
this->buffer
);
if (!debugSession.programmingSession.has_value()) {
debugSession.programmingSession = ProgrammingSession(this->startAddress, this->buffer);
} else {
auto& programmingSession = debugSession.programmingSession.value();
const auto currentEndAddress = programmingSession.startAddress + programmingSession.buffer.size() - 1;
const auto expectedStartAddress = (currentEndAddress + 1);
if (this->startAddress < expectedStartAddress) {
throw Exception("Invalid start address from GDB - the buffer would overlap a previous buffer");
}
if (this->startAddress > expectedStartAddress) {
// There is a gap in the buffer sent by GDB. Fill it with 0xFF
programmingSession.buffer.insert(
programmingSession.buffer.end(),
this->startAddress - expectedStartAddress,
0xFF
);
}
programmingSession.buffer.insert(
programmingSession.buffer.end(),
this->buffer.begin(),
this->buffer.end()
);
}
debugSession.connection.writePacket(OkResponsePacket());
} catch (const Exception& exception) {
Logger::error("Failed to write to flash memory - " + exception.getMessage());
Logger::error("Failed to handle FlashWrite packet - " + exception.getMessage());
debugSession.programmingSession.reset();
try {
targetControllerConsole.disableProgrammingMode();
} catch (const Exception& exception) {
Logger::error("Failed to disable programming mode - " + exception.getMessage());
}
debugSession.connection.writePacket(ErrorResponsePacket());
}
}