Enforce flash page alignment for UPDI targets, when accessing flash

This commit is contained in:
Nav
2022-09-17 19:55:55 +01:00
parent 9f9a67688e
commit 65bdcd62d3

View File

@@ -1469,33 +1469,14 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
) {
std::uint16_t alignTo = 1;
// We don't have to align to the page size in all cases. We may only need to align to the word size (2 bytes).
switch (memoryType) {
case Avr8MemoryType::FLASH_PAGE: {
alignTo = (this->configVariant == Avr8ConfigVariant::UPDI)
? 2
: this->targetParameters.flashPageSize.value();
break;
}
case Avr8MemoryType::SPM: {
// Memory access via the SPM type must be word aligned.
alignTo = 2;
}
case Avr8MemoryType::APPL_FLASH:
case Avr8MemoryType::BOOT_FLASH: {
if (this->configVariant == Avr8ConfigVariant::UPDI) {
// For UPDI sessions, memory access via the APPL_FLASH must be word aligned.
alignTo = 2;
} else {
if (
memoryType == Avr8MemoryType::FLASH_PAGE
|| memoryType == Avr8MemoryType::SPM
|| memoryType == Avr8MemoryType::APPL_FLASH
|| memoryType == Avr8MemoryType::BOOT_FLASH
) {
alignTo = this->targetParameters.flashPageSize.value();
}
break;
}
default: {
break;
}
}
if (this->maximumMemoryAccessSizePerRequest.has_value() && alignTo > this->maximumMemoryAccessSizePerRequest) {
throw Exception(
@@ -1518,33 +1499,14 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
) {
std::uint16_t alignTo = 1;
// We don't have to align to the page size in all cases. We may only need to align to the word size (2 bytes).
switch (memoryType) {
case Avr8MemoryType::FLASH_PAGE: {
alignTo = (this->configVariant == Avr8ConfigVariant::UPDI)
? 2
: this->targetParameters.flashPageSize.value();
break;
}
case Avr8MemoryType::SPM: {
// Memory access via the SPM type must be word aligned.
alignTo = 2;
}
case Avr8MemoryType::APPL_FLASH:
case Avr8MemoryType::BOOT_FLASH: {
if (this->configVariant == Avr8ConfigVariant::UPDI) {
// For UPDI sessions, memory access via the APPL_FLASH must be word aligned.
alignTo = 2;
} else {
if (
memoryType == Avr8MemoryType::FLASH_PAGE
|| memoryType == Avr8MemoryType::SPM
|| memoryType == Avr8MemoryType::APPL_FLASH
|| memoryType == Avr8MemoryType::BOOT_FLASH
) {
alignTo = this->targetParameters.flashPageSize.value();
}
break;
}
default: {
break;
}
}
if ((bytes % alignTo) != 0) {
return static_cast<TargetMemorySize>(std::ceil(
@@ -1718,8 +1680,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
for (float i = 1; i <= totalReadsRequired; i++) {
auto bytesToRead = static_cast<TargetMemorySize>(
(bytes - output.size()) > (singlePacketSize * 2) ? (singlePacketSize * 2)
: bytes - output.size()
(bytes - output.size()) > (singlePacketSize * 2)
? (singlePacketSize * 2) : bytes - output.size()
);
auto data = this->readMemory(
type,