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:
@@ -23,12 +23,35 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
|
||||
Logger::debug("Handling FlashDone packet");
|
||||
|
||||
try {
|
||||
if (debugSession.programmingSession.has_value()) {
|
||||
const auto& programmingSession = debugSession.programmingSession.value();
|
||||
|
||||
targetControllerConsole.enableProgrammingMode();
|
||||
|
||||
targetControllerConsole.writeMemory(
|
||||
Targets::TargetMemoryType::FLASH,
|
||||
programmingSession.startAddress,
|
||||
std::move(programmingSession.buffer)
|
||||
);
|
||||
|
||||
debugSession.programmingSession.reset();
|
||||
}
|
||||
|
||||
targetControllerConsole.disableProgrammingMode();
|
||||
|
||||
debugSession.connection.writePacket(OkResponsePacket());
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
Logger::error("Failed to disabling programming mode - " + exception.getMessage());
|
||||
Logger::error("Failed to handle FlashDone 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,17 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
|
||||
Logger::debug("Handling FlashErase packet");
|
||||
|
||||
try {
|
||||
const auto flashPageSize = debugSession.gdbTargetDescriptor.targetDescriptor.memoryDescriptorsByType.at(
|
||||
Targets::TargetMemoryType::FLASH
|
||||
).pageSize.value();
|
||||
|
||||
if ((this->bytes % flashPageSize) != 0) {
|
||||
throw Exception(
|
||||
"Invalid erase size (" + std::to_string(this->bytes) + " bytes) provided by GDB - must be a "
|
||||
"multiple of the target's flash page size (" + std::to_string(flashPageSize) + " bytes)"
|
||||
);
|
||||
}
|
||||
|
||||
targetControllerConsole.enableProgrammingMode();
|
||||
|
||||
targetControllerConsole.writeMemory(
|
||||
@@ -64,6 +75,15 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
Logger::error("Failed to erase flash memory - " + 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user