2022-06-05 16:15:12 +01:00
|
|
|
#include "FlashDone.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"
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
namespace DebugServer::Gdb::AvrGdb::CommandPackets
|
2022-06-05 16:15:12 +01:00
|
|
|
{
|
2022-12-26 21:27:19 +00:00
|
|
|
using Services::TargetControllerService;
|
2022-06-05 16:15:12 +01:00
|
|
|
|
|
|
|
|
using ResponsePackets::ErrorResponsePacket;
|
|
|
|
|
using ResponsePackets::OkResponsePacket;
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
using namespace Exceptions;
|
2022-06-05 16:15:12 +01:00
|
|
|
|
2024-10-25 22:22:25 +01:00
|
|
|
FlashDone::FlashDone(const RawPacket& rawPacket)
|
2022-08-30 02:04:35 +01:00
|
|
|
: CommandPacket(rawPacket)
|
2022-06-05 16:15:12 +01:00
|
|
|
{}
|
|
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
void FlashDone::handle(
|
2024-10-25 22:22:25 +01:00
|
|
|
DebugSession& debugSession,
|
|
|
|
|
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
|
2024-07-23 21:14:22 +01:00
|
|
|
const Targets::TargetDescriptor& targetDescriptor,
|
|
|
|
|
TargetControllerService& targetControllerService
|
|
|
|
|
) {
|
2023-05-07 20:17:33 +01:00
|
|
|
Logger::info("Handling FlashDone packet");
|
2022-06-05 16:15:12 +01:00
|
|
|
|
|
|
|
|
try {
|
2024-07-23 21:14:22 +01:00
|
|
|
if (!debugSession.programmingSession.has_value()) {
|
|
|
|
|
throw Exception{"No active programming session"};
|
|
|
|
|
}
|
2022-09-17 20:12:26 +01:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
Logger::info(
|
|
|
|
|
"Flushing " + std::to_string(debugSession.programmingSession->buffer.size())
|
|
|
|
|
+ " bytes to target's program memory"
|
|
|
|
|
);
|
2022-09-17 20:12:26 +01:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
targetControllerService.enableProgrammingMode();
|
2022-09-17 20:12:26 +01:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
targetControllerService.writeMemory(
|
2024-10-25 22:22:25 +01:00
|
|
|
gdbTargetDescriptor.programAddressSpaceDescriptor,
|
|
|
|
|
gdbTargetDescriptor.programMemorySegmentDescriptor,
|
2024-07-23 21:14:22 +01:00
|
|
|
debugSession.programmingSession->startAddress,
|
|
|
|
|
std::move(debugSession.programmingSession->buffer)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
debugSession.programmingSession.reset();
|
2022-09-17 20:12:26 +01:00
|
|
|
|
2022-09-17 20:22:39 +01:00
|
|
|
Logger::warning("Program memory updated");
|
2022-12-26 21:27:19 +00:00
|
|
|
targetControllerService.disableProgrammingMode();
|
2022-09-17 20:22:39 +01:00
|
|
|
|
2022-09-24 18:35:58 +01:00
|
|
|
Logger::warning("Resetting target");
|
2022-12-26 21:27:19 +00:00
|
|
|
targetControllerService.resetTarget();
|
2022-09-24 18:35:58 +01:00
|
|
|
Logger::info("Target reset complete");
|
2022-06-05 16:15:12 +01:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
debugSession.connection.writePacket(OkResponsePacket{});
|
2022-06-05 16:15:12 +01:00
|
|
|
|
|
|
|
|
} catch (const Exception& exception) {
|
2022-09-17 20:12:26 +01:00
|
|
|
Logger::error("Failed to handle FlashDone packet - " + exception.getMessage());
|
|
|
|
|
debugSession.programmingSession.reset();
|
|
|
|
|
|
|
|
|
|
try {
|
2022-12-26 21:27:19 +00:00
|
|
|
targetControllerService.disableProgrammingMode();
|
2022-09-17 20:12:26 +01:00
|
|
|
|
|
|
|
|
} catch (const Exception& exception) {
|
|
|
|
|
Logger::error("Failed to disable programming mode - " + exception.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
debugSession.connection.writePacket(ErrorResponsePacket{});
|
2022-06-05 16:15:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|