Support for vFlashErase GDB command packet
This commit is contained in:
68
src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashErase.cpp
Normal file
68
src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashErase.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "FlashErase.hpp"
|
||||
|
||||
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
||||
#include "src/DebugServer/Gdb/ResponsePackets/OkResponsePacket.hpp"
|
||||
|
||||
#include "src/Logger/Logger.hpp"
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
|
||||
namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
|
||||
{
|
||||
using TargetController::TargetControllerConsole;
|
||||
|
||||
using ResponsePackets::ErrorResponsePacket;
|
||||
using ResponsePackets::OkResponsePacket;
|
||||
|
||||
using namespace Bloom::Exceptions;
|
||||
|
||||
FlashErase::FlashErase(const RawPacketType& rawPacket)
|
||||
: MemoryAccessCommandPacket(rawPacket)
|
||||
{
|
||||
auto packetString = QString::fromLocal8Bit(
|
||||
reinterpret_cast<const char*>(this->data.data() + 12),
|
||||
static_cast<int>(this->data.size() - 12)
|
||||
);
|
||||
|
||||
/*
|
||||
* The flash erase ('vFlashErase') packet consists of two segments, an address and a length, separated by a
|
||||
* comma.
|
||||
*/
|
||||
auto packetSegments = packetString.split(",");
|
||||
if (packetSegments.size() != 2) {
|
||||
throw Exception(
|
||||
"Unexpected number of segments in packet data: " + std::to_string(packetSegments.size())
|
||||
);
|
||||
}
|
||||
|
||||
bool conversionStatus = false;
|
||||
this->startAddress = packetSegments.at(0).toUInt(&conversionStatus, 16);
|
||||
|
||||
if (!conversionStatus) {
|
||||
throw Exception("Failed to parse start address from flash erase packet data");
|
||||
}
|
||||
|
||||
this->bytes = packetSegments.at(1).toUInt(&conversionStatus, 16);
|
||||
|
||||
if (!conversionStatus) {
|
||||
throw Exception("Failed to parse length from flash erase packet data");
|
||||
}
|
||||
}
|
||||
|
||||
void FlashErase::handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) {
|
||||
Logger::debug("Handling FlashErase packet");
|
||||
|
||||
try {
|
||||
targetControllerConsole.writeMemory(
|
||||
Targets::TargetMemoryType::FLASH,
|
||||
this->startAddress,
|
||||
Targets::TargetMemoryBuffer(this->bytes, 0xFF)
|
||||
);
|
||||
|
||||
debugSession.connection.writePacket(OkResponsePacket());
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
Logger::error("Failed to erase flash memory - " + exception.getMessage());
|
||||
debugSession.connection.writePacket(ErrorResponsePacket());
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashErase.hpp
Normal file
27
src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashErase.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
|
||||
#include "MemoryAccessCommandPacket.hpp"
|
||||
|
||||
namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
|
||||
{
|
||||
/**
|
||||
* The FlashErase class implements the structure for the "vFlashErase" packet. Upon receiving this packet, the
|
||||
* server is expected to erase a particular region of the target's flash memory.
|
||||
*/
|
||||
class FlashErase: public MemoryAccessCommandPacket
|
||||
{
|
||||
public:
|
||||
std::uint32_t startAddress = 0;
|
||||
std::uint32_t bytes = 0;
|
||||
|
||||
explicit FlashErase(const RawPacketType& rawPacket);
|
||||
|
||||
void handle(
|
||||
DebugSession& debugSession,
|
||||
TargetController::TargetControllerConsole& targetControllerConsole
|
||||
) override;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user