Skip to content

Commit

Permalink
PackChk reports INFO messages when generate STM32L5xx_DFP and STM32L0…
Browse files Browse the repository at this point in the history
…xx_DFP (#479)

added:
- iteration over possible TrustZone variants, if available
- skipping Test for system_ and startup_ if generator is involved

Arm-Debug/devtools-external#479
  • Loading branch information
thorstendb-ARM authored Feb 21, 2023
1 parent e762d40 commit b020bd1
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 123 deletions.
2 changes: 1 addition & 1 deletion tools/packchk/include/ValidateSemantic.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ValidateSemantic : public Validate
bool ExcludeSysHeaderDirectories(const std::string& systemHeader, const std::string& rteFolder);
bool FindFileFromList(const std::string& systemHeader, const std::set<RteFile*>& targFiles);
bool CheckDeviceDependencies(RteDeviceItem* device, RteProject* rteProject);

bool HasExternalGenerator(RteComponentAggregate* aggregate);

const std::map<std::string, compiler_s>& GetCompilers() {
return m_compilers;
Expand Down
297 changes: 175 additions & 122 deletions tools/packchk/src/ValidateSemantic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ bool ValidateSemantic::GatherCompilers(RtePackage* pKg)
return true;
}


/**
* @brief RTE Model messages
*/
Expand Down Expand Up @@ -361,7 +362,7 @@ bool ValidateSemantic::UpdateRte(RteTarget* target, RteProject* rteProject, RteC
target->ClearSelectedComponents();
RteComponentAggregate* cmsisComp = target->GetComponentAggregate("ARM::CMSIS.CORE");
target->SelectComponent(cmsisComp, 1, true);
target->SelectComponent(component, 1, true);
target->SelectComponent(component, 1, true, true);
rteProject->CollectSettings();
target->CollectFilteredFiles();
target->EvaluateComponentDependencies();
Expand Down Expand Up @@ -485,169 +486,221 @@ bool ValidateSemantic::CheckDeviceDependencies(RteDeviceItem *device, RteProject
mcuDispName += Pname;
}

RteItem filter;
device->GetEffectiveFilterAttributes(processorName, filter);
filter.AddAttribute("Dname", mcuName);

for(auto &[compilerKey, compiler] : m_compilers) {
filter.AddAttribute("Tcompiler", compiler.tcompiler);
filter.AddAttribute("Toptions", compiler.toptions);

rteProject->Clear();
rteProject->AddTarget("Test", filter.GetAttributes(), true, true);
rteProject->SetActiveTarget("Test");
RteTarget* target = rteProject->GetActiveTarget();
rteProject->FilterComponents();

set<RteComponentAggregate*> startupComponents;
target->GetComponentAggregates(deviceStartup, startupComponents);
if(startupComponents.empty()) {
LogMsg("M350", COMP("Startup"), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
continue; // error: no startup component found
}

for(auto aggregate : startupComponents) {
ErrLog::Get()->SetFileName(aggregate->GetPackage()->GetPackageFileName());
list<string> trustZoneList;
auto trustZone = processor->GetAttribute("Dtz");
if(trustZone.empty()) {
trustZoneList.push_back("");
}
else {
trustZoneList.push_back("TZ-disabled");
trustZoneList.push_back("Secure");
trustZoneList.push_back("Non-secure");
}

for(auto &[componentKey, componentMap] : aggregate->GetAllComponents()) {
int foundSystemC = 0, foundStartup = 0;
bool bFoundSystemH = false;
int lineSystem = 0, lineStartup = 0;
for(auto trustZoneMode : trustZoneList) {
RteItem filter;
device->GetEffectiveFilterAttributes(processorName, filter);
filter.AddAttribute("Dname", mcuName);

for(auto& [key, component] : componentMap) {
string compId = component->GetComponentID(true);
LogMsg("M091", COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
for(auto &[compilerKey, compiler] : m_compilers) {
filter.AddAttribute("Tcompiler", compiler.tcompiler);
filter.AddAttribute("Toptions", compiler.toptions);

UpdateRte(target, rteProject, component);
int lineNo = component->GetLineNumber();
if(!trustZoneMode.empty()) {
filter.AddAttribute("Dsecure", trustZoneMode);
}

CheckDependencyResult(target, component, mcuVendor, mcuDispName, compiler);
rteProject->Clear();
rteProject->AddTarget("Test", filter.GetAttributes(), true, true);
rteProject->SetActiveTarget("Test");
RteTarget* target = rteProject->GetActiveTarget();
rteProject->FilterComponents();

set<RteComponentAggregate*> startupComponents;
target->GetComponentAggregates(deviceStartup, startupComponents);
if(startupComponents.empty()) {
LogMsg("M350", COMP("Startup"), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
continue; // error: no startup component found
}

const set<RteFile*>& targFiles = target->GetFilteredFiles(component);
if(targFiles.empty()) {
LogMsg("M352", COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
continue;
}
for(auto aggregate : startupComponents) {
ErrLog::Get()->SetFileName(aggregate->GetPackage()->GetPackageFileName());

const string& deviceHeaderfile = target->GetDeviceHeader();
if(deviceHeaderfile.empty()) {
LogMsg("M353", VAL("FILECAT", "Device Header-file"), COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
bOk = false;
}
for(auto &[componentKey, componentMap] : aggregate->GetAllComponents()) {
int foundSystemC = 0, foundStartup = 0;
bool bFoundSystemH = false;
int lineSystem = 0, lineStartup = 0;

const set<string>& incPaths = target->GetIncludePaths();
if(incPaths.empty()) {
LogMsg("M355", VAL("FILECAT", "Include"), COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
bOk = false;
}
for(auto& [key, component] : componentMap) {
string compId = component->GetComponentID(true);
LogMsg("M091", COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);

for(auto file : targFiles) {
const string& category = file->GetAttribute("category");
UpdateRte(target, rteProject, component);
int lineNo = component->GetLineNumber();

if(category == "source" || category == "sourceAsm" || category == "sourceC") {
string fileName = RteUtils::BackSlashesToSlashes(RteUtils::ExtractFileName(file->GetName()));
if(fileName.empty()) {
continue;
}
const string& attribute = file->GetAttribute("attr");
CheckDependencyResult(target, component, mcuVendor, mcuDispName, compiler);

if(FindName(fileName, "system_", ".c")) {
foundSystemC++;
lineSystem = file->GetLineNumber();
if(attribute != "config") {
LogMsg("M377", NAME(fileName), TYP(category), lineNo);
}
const set<RteFile*>& targFiles = target->GetFilteredFiles(component);
if(targFiles.empty()) {
LogMsg("M352", COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
continue;
}

string systemHeader = RteUtils::ExtractFileBaseName(fileName);
systemHeader += ".h";

bFoundSystemH = FindFileFromList(systemHeader, targFiles);
if(!bFoundSystemH) {
string incPathsMsg;
int incPathsCnt = 0;
for(auto& incPath : incPaths) {
systemHeader = RteUtils::BackSlashesToSlashes(incPath);
if(ExcludeSysHeaderDirectories(systemHeader, rteProject->GetRteFolder())) {
continue;
}
const string& deviceHeaderfile = target->GetDeviceHeader();
if(deviceHeaderfile.empty()) {
LogMsg("M353", VAL("FILECAT", "Device Header-file"), COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
bOk = false;
}

incPathsMsg += "\n ";
incPathsMsg += to_string((unsigned long long) ++incPathsCnt);
incPathsMsg += ": ";
incPathsMsg += systemHeader;
const set<string>& incPaths = target->GetIncludePaths();
if(incPaths.empty()) {
LogMsg("M355", VAL("FILECAT", "Include"), COMP("Startup"), VAL("COMPID", compId), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), lineNo);
bOk = false;
}

systemHeader += "/";
systemHeader += RteUtils::ExtractFileBaseName(fileName);
systemHeader += ".h";
for(auto file : targFiles) {
const string& category = file->GetAttribute("category");

string sysHeader = RteUtils::ExtractFileName(systemHeader);
for (auto f : targFiles) {
if(RteUtils::ExtractFileName(f->GetName()) == sysHeader) {
systemHeader = f->GetOriginalAbsolutePath();
break;
}
}
if(category == "source" || category == "sourceAsm" || category == "sourceC") {
string fileName = RteUtils::BackSlashesToSlashes(RteUtils::ExtractFileName(file->GetName()));
if(fileName.empty()) {
continue;
}
const string& attribute = file->GetAttribute("attr");

if(RteFsUtils::Exists(systemHeader)) {
bFoundSystemH = true;
}
if(FindName(fileName, "system_", ".c")) {
foundSystemC++;
lineSystem = file->GetLineNumber();
if(attribute != "config") {
LogMsg("M377", NAME(fileName), TYP(category), lineNo);
}

string systemHeader = RteUtils::ExtractFileBaseName(fileName);
systemHeader += ".h";

bFoundSystemH = FindFileFromList(systemHeader, targFiles);
if(!bFoundSystemH) {
systemHeader = RteUtils::ExtractFileBaseName(fileName);
systemHeader += ".h";
if(incPathsMsg.empty()) {
incPathsMsg = "\n ";
string incPathsMsg;
int incPathsCnt = 0;
for(auto& incPath : incPaths) {
systemHeader = RteUtils::BackSlashesToSlashes(incPath);
if(ExcludeSysHeaderDirectories(systemHeader, rteProject->GetRteFolder())) {
continue;
}

incPathsMsg += "\n ";
incPathsMsg += to_string((unsigned long long) ++incPathsCnt);
incPathsMsg += ": ";
incPathsMsg += "<not found any include path>";
incPathsMsg += systemHeader;

systemHeader += "/";
systemHeader += RteUtils::ExtractFileBaseName(fileName);
systemHeader += ".h";

string sysHeader = RteUtils::ExtractFileName(systemHeader);
for (auto f : targFiles) {
if(RteUtils::ExtractFileName(f->GetName()) == sysHeader) {
systemHeader = f->GetOriginalAbsolutePath();
break;
}
}

if(RteFsUtils::Exists(systemHeader)) {
bFoundSystemH = true;
}
}

if(!bFoundSystemH) {
systemHeader = RteUtils::ExtractFileBaseName(fileName);
systemHeader += ".h";
if(incPathsMsg.empty()) {
incPathsMsg = "\n ";
incPathsMsg += to_string((unsigned long long) ++incPathsCnt);
incPathsMsg += ": ";
incPathsMsg += "<not found any include path>";
}
LogMsg("M358", VAL("HFILE", RteUtils::ExtractFileName(systemHeader)), VAL("CFILE", fileName), COMP("Startup"), VAL("COMPID", compId),
VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), PATH(incPathsMsg), lineNo);
bOk = false;
}
LogMsg("M358", VAL("HFILE", RteUtils::ExtractFileName(systemHeader)), VAL("CFILE", fileName), COMP("Startup"), VAL("COMPID", compId),
VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions), PATH(incPathsMsg), lineNo);
bOk = false;
}
}
}

if(fileName.find("startup_", 0) != string::npos) {
foundStartup++;
lineStartup = file->GetLineNumber();
if(fileName.find("startup_", 0) != string::npos) {
foundStartup++;
lineStartup = file->GetLineNumber();

if(attribute != "config") {
LogMsg("M377", NAME(fileName), TYP(category), lineNo);
if(attribute != "config") {
LogMsg("M377", NAME(fileName), TYP(category), lineNo);
}
}
}
}
}
}

if(foundSystemC != 1) {
LogMsg(foundSystemC ? "M354" : "M353",
VAL("FILECAT", "system_*"), COMP("Startup"), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions),
foundSystemC ? lineSystem : lineNo);
bOk = false;
}
if(foundSystemC != 1 || foundStartup != 1) { // ignore if generator="..."
if(HasExternalGenerator(aggregate)) {
continue;
}
}

if(foundSystemC != 1) {
LogMsg(foundSystemC ? "M354" : "M353",
VAL("FILECAT", "system_*"), COMP("Startup"), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions),
foundSystemC ? lineSystem : lineNo);
bOk = false;
}

if(foundStartup != 1) {
LogMsg(foundStartup ? "M354" : "M353",
VAL("FILECAT", "startup_*"), COMP("Startup"), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions),
foundStartup ? lineStartup : lineNo);
bOk = false;
if(foundStartup != 1) {
LogMsg(foundStartup ? "M354" : "M353",
VAL("FILECAT", "startup_*"), COMP("Startup"), VENDOR(mcuVendor), MCU(mcuDispName), COMPILER(compiler.tcompiler), OPTION(compiler.toptions),
foundStartup ? lineStartup : lineNo);
bOk = false;
}
}
}

}
filter.RemoveAttribute("Tcompiler");

if(bOk) {
LogMsg("M010");
}
}
filter.RemoveAttribute("Tcompiler");
}

if(bOk) {
LogMsg("M010");
return bOk;
}


/**
* @brief check for MCU dependencies
* @param pKg package under test
* @return passed / failed
*/
bool ValidateSemantic::HasExternalGenerator(RteComponentAggregate* aggregate)
{
auto bundleName = aggregate->GetCbundleName();
if(!bundleName.empty()) {
for(auto &[componentKey, componentMap] : aggregate->GetAllComponents()) {
for(auto& [key, component] : componentMap) {
auto parentBundle = component->GetParentBundle();
if(parentBundle) {
for(auto bundleComponent : parentBundle->GetChildren()) {
auto generatorAttrName = bundleComponent->GetAttribute("generator");
if(!generatorAttrName.empty()) {
return true;
}
}
}
}
}
}

return bOk;
return false;
}


/**
* @brief check for MCU dependencies
* @param pKg package under test
Expand Down

0 comments on commit b020bd1

Please sign in to comment.