Refactored AVR8 TDF loading

Refactored EDBG AVR8 target parameter uploading
Implemented UPDI parameter extraction (from TDF) and uploading to debug tool
Introduced supported physical interfaces in AVR8 TDFs
This commit is contained in:
Nav
2021-06-27 20:09:15 +01:00
parent 0931bc649f
commit 1971f0a89e
8 changed files with 939 additions and 429 deletions

View File

@@ -51,7 +51,7 @@ TargetDescriptionFile::TargetDescriptionFile(
+ matchingDescriptionFiles.front().toObject().find("targetDescriptionFilePath")->toString();
Logger::debug("Loading AVR8 target description file: " + descriptionFilePath.toStdString());
this->init(descriptionFilePath);
Targets::TargetDescription::TargetDescriptionFile::init(descriptionFilePath);
} else if (matchingDescriptionFiles.size() > 1) {
/*
@@ -86,6 +86,27 @@ TargetDescriptionFile::TargetDescriptionFile(
}
}
void TargetDescriptionFile::init(const QDomDocument& xml) {
Targets::TargetDescription::TargetDescriptionFile::init(xml);
this->loadDebugPhysicalInterfaces();
}
void TargetDescriptionFile::loadDebugPhysicalInterfaces() {
auto interfaceNamesToInterfaces = std::map<std::string, PhysicalInterface>({
{"updi", PhysicalInterface::UPDI},
{"debugwire", PhysicalInterface::DEBUG_WIRE},
{"jtag", PhysicalInterface::DEBUG_WIRE},
{"pdi", PhysicalInterface::PDI},
});
for (const auto& [interfaceName, interface]: this->interfacesByName) {
if (interfaceNamesToInterfaces.contains(interfaceName)) {
this->supportedDebugPhysicalInterfaces.insert(interfaceNamesToInterfaces.at(interfaceName));
}
}
}
QJsonObject TargetDescriptionFile::getTargetDescriptionMapping() {
auto mappingFile = QFile(
QString::fromStdString(Paths::resourcesDirPath() + "/TargetDescriptionFiles/AVR/Mapping.json")
@@ -276,6 +297,63 @@ std::optional<MemorySegment> TargetDescriptionFile::getFirstBootSectionMemorySeg
return std::nullopt;
}
std::optional<MemorySegment> TargetDescriptionFile::getSignatureMemorySegment() const {
if (this->addressSpacesMappedById.contains("signatures")) {
auto& signaturesAddressSpace = this->addressSpacesMappedById.at("signatures");
auto& signaturesAddressSpaceSegments = signaturesAddressSpace.memorySegmentsByTypeAndName;
if (signaturesAddressSpaceSegments.contains(MemorySegmentType::SIGNATURES)) {
return signaturesAddressSpaceSegments.at(MemorySegmentType::SIGNATURES).begin()->second;
}
} else {
// The signatures memory segment may be part of the data address space
if (this->addressSpacesMappedById.contains("data")) {
auto dataAddressSpace = this->addressSpacesMappedById.at("data");
if (dataAddressSpace.memorySegmentsByTypeAndName.contains(MemorySegmentType::SIGNATURES)) {
auto& signatureSegmentsByName = dataAddressSpace.memorySegmentsByTypeAndName.at(
MemorySegmentType::SIGNATURES
);
if (signatureSegmentsByName.contains("signatures")) {
return signatureSegmentsByName.at("signatures");
}
}
}
}
return std::nullopt;
}
std::optional<MemorySegment> TargetDescriptionFile::getFuseMemorySegment() const {
if (this->addressSpacesMappedById.contains("data")) {
auto dataAddressSpace = this->addressSpacesMappedById.at("data");
if (dataAddressSpace.memorySegmentsByTypeAndName.contains(MemorySegmentType::FUSES)) {
return dataAddressSpace.memorySegmentsByTypeAndName.at(
MemorySegmentType::SIGNATURES
).begin()->second;
}
}
return std::nullopt;
}
std::optional<MemorySegment> TargetDescriptionFile::getLockbitsMemorySegment() const {
if (this->addressSpacesMappedById.contains("data")) {
auto dataAddressSpace = this->addressSpacesMappedById.at("data");
if (dataAddressSpace.memorySegmentsByTypeAndName.contains(MemorySegmentType::LOCKBITS)) {
return dataAddressSpace.memorySegmentsByTypeAndName.at(
MemorySegmentType::LOCKBITS
).begin()->second;
}
}
return std::nullopt;
}
std::optional<RegisterGroup> TargetDescriptionFile::getCpuRegisterGroup() const {
auto& modulesByName = this->modulesMappedByName;

View File

@@ -1,9 +1,12 @@
#pragma once
#include <set>
#include "src/Targets/TargetDescription/TargetDescriptionFile.hpp"
#include "src/Targets/Microchip/AVR/TargetSignature.hpp"
#include "src/Targets/Microchip/AVR/AVR8/Family.hpp"
#include "src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp"
namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription
{
@@ -44,6 +47,13 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription
};
};
std::set<PhysicalInterface> supportedDebugPhysicalInterfaces;
/**
* Populates this->supportedDebugPhysicalInterfaces with physical interfaces defined in the TDF.
*/
void loadDebugPhysicalInterfaces();
public:
/**
* Will resolve the target description file using the target description JSON mapping and a given target signature.
@@ -53,6 +63,14 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription
*/
TargetDescriptionFile(const TargetSignature& targetSignature, std::optional<std::string> targetName);
/**
* Extends TDF initialisation to include the loading of physical interfaces for debugging AVR8 targets, among
* other things.
*
* @param xml
*/
void init(const QDomDocument& xml) override;
/**
* Loads the AVR8 target description JSON mapping file.
*
@@ -79,6 +97,9 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription
[[nodiscard]] std::optional<Targets::TargetDescription::MemorySegment> getRegisterMemorySegment() const;
[[nodiscard]] std::optional<Targets::TargetDescription::MemorySegment> getEepromMemorySegment() const;
[[nodiscard]] std::optional<Targets::TargetDescription::MemorySegment> getFirstBootSectionMemorySegment() const;
[[nodiscard]] std::optional<Targets::TargetDescription::MemorySegment> getSignatureMemorySegment() const;
[[nodiscard]] std::optional<Targets::TargetDescription::MemorySegment> getFuseMemorySegment() const;
[[nodiscard]] std::optional<Targets::TargetDescription::MemorySegment> getLockbitsMemorySegment() const;
[[nodiscard]] std::optional<Targets::TargetDescription::RegisterGroup> getCpuRegisterGroup() const;
[[nodiscard]] std::optional<Targets::TargetDescription::RegisterGroup> getBootLoadRegisterGroup() const;
[[nodiscard]] std::optional<Targets::TargetDescription::RegisterGroup> getEepromRegisterGroup() const;
@@ -95,5 +116,14 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit::TargetDescription
[[nodiscard]] std::optional<Targets::TargetDescription::Register> getEepromAddressHighRegister() const;
[[nodiscard]] std::optional<Targets::TargetDescription::Register> getEepromDataRegister() const;
[[nodiscard]] std::optional<Targets::TargetDescription::Register> getEepromControlRegister() const;
/**
* Returns a set of all supported physical interfaces for debugging.
*
* @return
*/
const auto& getSupportedDebugPhysicalInterfaces() {
return this->supportedDebugPhysicalInterfaces;
};
};
}