Added EraseTargetMemory TC command

This commit is contained in:
Nav
2022-12-11 23:25:15 +00:00
parent 83c273a22b
commit 76a0207701
7 changed files with 77 additions and 17 deletions

View File

@@ -27,7 +27,7 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
* The flash erase ('vFlashErase') packet consists of two segments, an address and a length, separated by a * The flash erase ('vFlashErase') packet consists of two segments, an address and a length, separated by a
* comma. * comma.
*/ */
auto packetSegments = packetString.split(","); const auto packetSegments = packetString.split(",");
if (packetSegments.size() != 2) { if (packetSegments.size() != 2) {
throw Exception( throw Exception(
"Unexpected number of segments in packet data: " + std::to_string(packetSegments.size()) "Unexpected number of segments in packet data: " + std::to_string(packetSegments.size())
@@ -52,24 +52,12 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
Logger::debug("Handling FlashErase packet"); Logger::debug("Handling FlashErase packet");
try { 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.enableProgrammingMode();
targetControllerConsole.writeMemory( Logger::warning("Erasing entire chip, in preparation for programming");
Targets::TargetMemoryType::FLASH,
this->startAddress, // We don't erase a specific address range - we just erase the entire program memory.
Targets::TargetMemoryBuffer(this->bytes, 0xFF) targetControllerConsole.eraseMemory(Targets::TargetMemoryType::FLASH);
);
debugSession.connection.writePacket(OkResponsePacket()); debugSession.connection.writePacket(OkResponsePacket());

View File

@@ -18,6 +18,7 @@ namespace Bloom::TargetController::Commands
WRITE_TARGET_REGISTERS, WRITE_TARGET_REGISTERS,
READ_TARGET_MEMORY, READ_TARGET_MEMORY,
WRITE_TARGET_MEMORY, WRITE_TARGET_MEMORY,
ERASE_TARGET_MEMORY,
GET_TARGET_STATE, GET_TARGET_STATE,
STEP_TARGET_EXECUTION, STEP_TARGET_EXECUTION,
SET_BREAKPOINT, SET_BREAKPOINT,

View File

@@ -0,0 +1,33 @@
#pragma once
#include "Command.hpp"
#include "src/Targets/TargetMemory.hpp"
namespace Bloom::TargetController::Commands
{
class EraseTargetMemory: public Command
{
public:
static constexpr CommandType type = CommandType::ERASE_TARGET_MEMORY;
static const inline std::string name = "EraseTargetMemory";
Targets::TargetMemoryType memoryType;
EraseTargetMemory(Targets::TargetMemoryType memoryType)
: memoryType(memoryType)
{};
[[nodiscard]] CommandType getType() const override {
return EraseTargetMemory::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
[[nodiscard]] bool requiresDebugMode() const override {
return this->memoryType == Targets::TargetMemoryType::RAM;
}
};
}

View File

@@ -37,6 +37,7 @@ namespace Bloom::TargetController
using Commands::WriteTargetRegisters; using Commands::WriteTargetRegisters;
using Commands::ReadTargetMemory; using Commands::ReadTargetMemory;
using Commands::WriteTargetMemory; using Commands::WriteTargetMemory;
using Commands::EraseTargetMemory;
using Commands::StepTargetExecution; using Commands::StepTargetExecution;
using Commands::SetBreakpoint; using Commands::SetBreakpoint;
using Commands::RemoveBreakpoint; using Commands::RemoveBreakpoint;
@@ -220,6 +221,10 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::handleWriteTargetMemory, this, std::placeholders::_1) std::bind(&TargetControllerComponent::handleWriteTargetMemory, this, std::placeholders::_1)
); );
this->registerCommandHandler<EraseTargetMemory>(
std::bind(&TargetControllerComponent::handleEraseTargetMemory, this, std::placeholders::_1)
);
this->registerCommandHandler<StepTargetExecution>( this->registerCommandHandler<StepTargetExecution>(
std::bind(&TargetControllerComponent::handleStepTargetExecution, this, std::placeholders::_1) std::bind(&TargetControllerComponent::handleStepTargetExecution, this, std::placeholders::_1)
); );
@@ -930,6 +935,21 @@ namespace Bloom::TargetController
return std::make_unique<Response>(); return std::make_unique<Response>();
} }
std::unique_ptr<Response> TargetControllerComponent::handleEraseTargetMemory(EraseTargetMemory& command) {
const auto& targetDescriptor = this->getTargetDescriptor();
if (
command.memoryType == this->getTargetDescriptor().programMemoryType
&& !this->target->programmingModeEnabled()
) {
throw Exception("Cannot erase program memory - programming mode not enabled.");
}
this->target->eraseMemory(command.memoryType);
return std::make_unique<Response>();
}
std::unique_ptr<Response> TargetControllerComponent::handleStepTargetExecution(StepTargetExecution& command) { std::unique_ptr<Response> TargetControllerComponent::handleStepTargetExecution(StepTargetExecution& command) {
if (command.fromProgramCounter.has_value()) { if (command.fromProgramCounter.has_value()) {
this->target->setProgramCounter(command.fromProgramCounter.value()); this->target->setProgramCounter(command.fromProgramCounter.value());

View File

@@ -32,6 +32,7 @@
#include "Commands/WriteTargetRegisters.hpp" #include "Commands/WriteTargetRegisters.hpp"
#include "Commands/ReadTargetMemory.hpp" #include "Commands/ReadTargetMemory.hpp"
#include "Commands/WriteTargetMemory.hpp" #include "Commands/WriteTargetMemory.hpp"
#include "Commands/EraseTargetMemory.hpp"
#include "Commands/StepTargetExecution.hpp" #include "Commands/StepTargetExecution.hpp"
#include "Commands/SetBreakpoint.hpp" #include "Commands/SetBreakpoint.hpp"
#include "Commands/RemoveBreakpoint.hpp" #include "Commands/RemoveBreakpoint.hpp"
@@ -350,6 +351,7 @@ namespace Bloom::TargetController
std::unique_ptr<Responses::Response> handleWriteTargetRegisters(Commands::WriteTargetRegisters& command); std::unique_ptr<Responses::Response> handleWriteTargetRegisters(Commands::WriteTargetRegisters& command);
std::unique_ptr<Responses::TargetMemoryRead> handleReadTargetMemory(Commands::ReadTargetMemory& command); std::unique_ptr<Responses::TargetMemoryRead> handleReadTargetMemory(Commands::ReadTargetMemory& command);
std::unique_ptr<Responses::Response> handleWriteTargetMemory(Commands::WriteTargetMemory& command); std::unique_ptr<Responses::Response> handleWriteTargetMemory(Commands::WriteTargetMemory& command);
std::unique_ptr<Responses::Response> handleEraseTargetMemory(Commands::EraseTargetMemory& command);
std::unique_ptr<Responses::Response> handleStepTargetExecution(Commands::StepTargetExecution& command); std::unique_ptr<Responses::Response> handleStepTargetExecution(Commands::StepTargetExecution& command);
std::unique_ptr<Responses::Response> handleSetBreakpoint(Commands::SetBreakpoint& command); std::unique_ptr<Responses::Response> handleSetBreakpoint(Commands::SetBreakpoint& command);
std::unique_ptr<Responses::Response> handleRemoveBreakpoint(Commands::RemoveBreakpoint& command); std::unique_ptr<Responses::Response> handleRemoveBreakpoint(Commands::RemoveBreakpoint& command);

View File

@@ -13,6 +13,7 @@
#include "Commands/WriteTargetRegisters.hpp" #include "Commands/WriteTargetRegisters.hpp"
#include "Commands/ReadTargetMemory.hpp" #include "Commands/ReadTargetMemory.hpp"
#include "Commands/WriteTargetMemory.hpp" #include "Commands/WriteTargetMemory.hpp"
#include "Commands/EraseTargetMemory.hpp"
#include "Commands/StepTargetExecution.hpp" #include "Commands/StepTargetExecution.hpp"
#include "Commands/SetBreakpoint.hpp" #include "Commands/SetBreakpoint.hpp"
#include "Commands/RemoveBreakpoint.hpp" #include "Commands/RemoveBreakpoint.hpp"
@@ -38,6 +39,7 @@ namespace Bloom::TargetController
using Commands::WriteTargetRegisters; using Commands::WriteTargetRegisters;
using Commands::ReadTargetMemory; using Commands::ReadTargetMemory;
using Commands::WriteTargetMemory; using Commands::WriteTargetMemory;
using Commands::EraseTargetMemory;
using Commands::StepTargetExecution; using Commands::StepTargetExecution;
using Commands::SetBreakpoint; using Commands::SetBreakpoint;
using Commands::RemoveBreakpoint; using Commands::RemoveBreakpoint;
@@ -190,6 +192,13 @@ namespace Bloom::TargetController
); );
} }
void TargetControllerConsole::eraseMemory(Targets::TargetMemoryType memoryType) {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<EraseTargetMemory>(memoryType),
this->defaultTimeout
);
}
void TargetControllerConsole::setBreakpoint(TargetBreakpoint breakpoint) { void TargetControllerConsole::setBreakpoint(TargetBreakpoint breakpoint) {
this->commandManager.sendCommandAndWaitForResponse( this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<SetBreakpoint>(breakpoint), std::make_unique<SetBreakpoint>(breakpoint),

View File

@@ -138,6 +138,13 @@ namespace Bloom::TargetController
const Targets::TargetMemoryBuffer& buffer const Targets::TargetMemoryBuffer& buffer
); );
/**
* Requests the TargetController to erase the given target memory type.
*
* @param memoryType
*/
void eraseMemory(Targets::TargetMemoryType memoryType);
/** /**
* Requests the TargetController to set a breakpoint on the target. * Requests the TargetController to set a breakpoint on the target.
* *