From 0309f4c60454471de9f79e173bdbe4d32d58db57 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 5 Jun 2021 23:52:00 +0100 Subject: [PATCH] Refactored EEPROM TDF memory segment lookup and included a fallback for cases where the eeprom segment is located in the data address space, as opposed to a dedicated address space for eeprom memory. --- .../AVR8/Avr8TargetDescriptionFile.php | 12 ++++++++-- .../TargetDescriptionFile.cpp | 22 ++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/build/scripts/TargetDescriptionFiles/AVR8/Avr8TargetDescriptionFile.php b/build/scripts/TargetDescriptionFiles/AVR8/Avr8TargetDescriptionFile.php index a81ddc75..299b6c31 100644 --- a/build/scripts/TargetDescriptionFiles/AVR8/Avr8TargetDescriptionFile.php +++ b/build/scripts/TargetDescriptionFiles/AVR8/Avr8TargetDescriptionFile.php @@ -131,10 +131,18 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile $this->gpRegisterSize = $registerMemorySegment->size; $this->gpRegisterStartAddress = $registerMemorySegment->startAddress; } + + if (isset($dataAddressSpace->memorySegmentsByTypeAndName['eeprom']['eeprom'])) { + $eepromMemorySegment = $dataAddressSpace->memorySegmentsByTypeAndName['eeprom']['eeprom']; + $this->eepromSize = $eepromMemorySegment->size; + $this->eepromPageSize = $eepromMemorySegment->pageSize; + } } - $eepromAddressSpace = $this->addressSpacesById['eeprom'] ?? null; - if (!empty($eepromAddressSpace)) { + if ((is_null($this->eepromSize) || is_null($this->eepromPageSize)) + && isset($this->addressSpacesById['eeprom']) + ) { + $eepromAddressSpace = $this->addressSpacesById['eeprom']; $eepromMemorySegments = $eepromAddressSpace->memorySegmentsByTypeAndName['eeprom'] ?? null; if (!empty($eepromMemorySegments)) { diff --git a/src/Targets/TargetDescription/TargetDescriptionFile.cpp b/src/Targets/TargetDescription/TargetDescriptionFile.cpp index 1d6d4a2a..427ac09d 100644 --- a/src/Targets/TargetDescription/TargetDescriptionFile.cpp +++ b/src/Targets/TargetDescription/TargetDescriptionFile.cpp @@ -434,19 +434,21 @@ std::optional TargetDescriptionFile::getRegisterMemorySegment() c std::optional TargetDescriptionFile::getEepromMemorySegment() const { auto addressMapping = this->getAddressSpacesMappedById(); - // EEPROM attributes are usually found in the data address space - auto eepromAddressSpaceIt = addressMapping.find("eeprom"); - - if (eepromAddressSpaceIt != addressMapping.end()) { - auto& eepromAddressSpace = eepromAddressSpaceIt->second; + if (addressMapping.contains("eeprom")) { + auto& eepromAddressSpace = addressMapping.at("eeprom"); auto& eepromAddressSpaceSegments = eepromAddressSpace.memorySegmentsByTypeAndName; - if (eepromAddressSpaceSegments.find(MemorySegmentType::EEPROM) != eepromAddressSpaceSegments.end()) { - auto& eepromMemorySegments = eepromAddressSpaceSegments.find(MemorySegmentType::EEPROM)->second; - auto eepromMemorySegmentIt = eepromMemorySegments.begin(); + if (eepromAddressSpaceSegments.contains(MemorySegmentType::EEPROM)) { + return eepromAddressSpaceSegments.at(MemorySegmentType::EEPROM).begin()->second; + } - if (eepromMemorySegmentIt != eepromMemorySegments.end()) { - return eepromMemorySegmentIt->second; + } else { + // The EEPROM memory segment may be part of the data address space + if (addressMapping.contains("data")) { + auto dataAddressSpace = addressMapping.at("data"); + + if (dataAddressSpace.memorySegmentsByTypeAndName.contains(MemorySegmentType::EEPROM)) { + return dataAddressSpace.memorySegmentsByTypeAndName.at(MemorySegmentType::EEPROM).begin()->second; } } }