diff --git a/tools/svdconv/SVDGenerator/src/PartitionData.cpp b/tools/svdconv/SVDGenerator/src/PartitionData.cpp index 7d1b24654..d85608ffb 100644 --- a/tools/svdconv/SVDGenerator/src/PartitionData.cpp +++ b/tools/svdconv/SVDGenerator/src/PartitionData.cpp @@ -39,11 +39,11 @@ PartitionData::PartitionData(const FileHeaderInfo& fileHeaderInfo, const SvdOpti m_genH(nullptr), m_genSfd(nullptr), m_numOfItns(0) -{ +{ m_fileIo = new FileIo(); m_genH = new HeaderGenerator(m_fileIo); m_genSfd = new SfdGenerator(m_fileIo); - + m_fileIo->SetSvdFileName (fileHeaderInfo.svdFileName); m_fileIo->SetProgramDescription (fileHeaderInfo.descr); m_fileIo->SetCopyrightString (fileHeaderInfo.copyright); @@ -107,7 +107,7 @@ bool PartitionData::CreateHeadingBegin(const string& text) CreateCCommentBegin(); m_genSfd->Generate(text.c_str()); CreateCCommentEnd(); - + return true; } @@ -117,7 +117,7 @@ bool PartitionData::CreateHeadingEnd() m_genSfd->Generate(""); CreateCCommentEnd(); m_genH->Generate(""); - + return true; } @@ -126,12 +126,12 @@ bool PartitionData::CreateHeadingEnableBegin(const string& text) CreateCCommentBegin(); m_genSfd->Generate(text.c_str()); CreateCCommentEnd(); - + return true; } bool PartitionData::CreateHeadingEnableEnd() -{ +{ CreateCCommentBegin(); m_genSfd->Generate(""); CreateCCommentEnd(); @@ -177,7 +177,7 @@ bool PartitionData::CreatePartitionStart(SvdDevice *device) const auto& name = device->GetName(); const auto& vendor = device->GetVendor(); string headerDef = name; - + SvdUtils::ToUpper(headerDef); CreateConfWizStart(); @@ -205,7 +205,7 @@ bool PartitionData::CreatePartitionEnd(SvdDevice *device) m_genH->Generate("%s", name.c_str()); m_genH->Generate("%s", vendor.c_str()); m_genH->Generate(""); - + return true; } @@ -217,7 +217,7 @@ bool PartitionData::CreateSauRegionsConfig(SvdCpu *cpu) m_genH->Generate("SAU Regions Config"); - CreateHeadingBegin ("Initialize Secure Attribute Unit (SAU) Address Regions"); + CreateHeadingBegin ("Initialize Secure Attribute Unit (SAU) Address Regions"); CreateMaxNumSauRegions (cpu); CreateInitSauRegions (cpu); CreateHeadingEnd (); @@ -235,6 +235,11 @@ bool PartitionData::CreateMaxNumSauRegions(SvdCpu *cpu) const string name = "SAU_REGIONS_MAX"; const string descr = "Max. number of SAU regions"; + if(value == SvdItem::VALUE32_NOT_INIT) { + m_genH->Generate("SAU Regions Config: Number of SAU regions not set", cpu->GetLineNumber()); + value = 0; + } + m_genH->Generate("%s", value, 10, -1, descr.c_str(), name.c_str()); return true; @@ -252,7 +257,7 @@ bool PartitionData::CreateSauGlobalConfig(SvdCpu *cpu) CreateSauInitControlEnable (cpu); CreateSauAllNonSecure (cpu); CreateHeadingEnableEnd (); - + return true; } @@ -286,7 +291,7 @@ bool PartitionData::CreateSauInitControlEnable(SvdCpu *cpu) bool value = sauRegionsCfg->GetEnabled(); const string name = "SAU_INIT_CTRL_ENABLE"; const string descr = "SAU->CTRL register bit ENABLE"; - + CreateCCommentBegin(); m_genSfd->Generate("Enable SAU"); m_genSfd->Generate("%s", descr.c_str()); @@ -339,7 +344,7 @@ bool PartitionData::CreateInitSauRegions(SvdCpu *cpu) if(!sauRegionsCfg) { return true; } - + const auto& childs = sauRegionsCfg->GetChildren(); if(childs.empty()) { return true; @@ -469,7 +474,7 @@ bool PartitionData::CreateSleepAndExceptionBegin(SvdCpu *cpu) } bool PartitionData::CreateDeepSleep(SvdCpu *cpu) -{ +{ if(!cpu) { return false; } @@ -489,7 +494,7 @@ bool PartitionData::CreateDeepSleep(SvdCpu *cpu) } bool PartitionData::CreateSystemReset(SvdCpu *cpu) -{ +{ if(!cpu) { return false; } @@ -509,7 +514,7 @@ bool PartitionData::CreateSystemReset(SvdCpu *cpu) } bool PartitionData::CreatePriorityExceptions(SvdCpu *cpu) -{ +{ if(!cpu) { return false; } @@ -529,7 +534,7 @@ bool PartitionData::CreatePriorityExceptions(SvdCpu *cpu) } bool PartitionData::CreateFault(SvdCpu *cpu) -{ +{ if(!cpu) { return false; } @@ -653,7 +658,7 @@ bool PartitionData::CreateFloatingPointUnitNsacrCp10Cp11(SvdCpu *cpu) CreateCCommentBegin(); m_genSfd->Generate("Floating Point Unit usage"); m_genSfd->Generate("Secure state only", 0); - m_genSfd->Generate("Secure and Non-Secure state", 3); + m_genSfd->Generate("Secure and Non-Secure state", 3); m_genSfd->Generate("Value for SCB->NSACR register bits CP10, CP11"); CreateCCommentEnd(); m_genH->Generate("%s", value, 10, -1, descr.c_str(), name.c_str()); @@ -751,7 +756,7 @@ bool PartitionData::CreateSetupInterruptTarget(SvdDevice *device) CreateInterruptBlock(interrupt, num); m_numOfItns++; } - + CreateHeadingEnd(); return true; @@ -782,7 +787,7 @@ bool PartitionData::CreateInterruptBlock(const map& inte CreateInterruptBlockBegin(num); CreateCCommentBegin(); - + for(const auto& [key, interrupt] : interrupts) { if(!interrupt) { continue; @@ -819,7 +824,7 @@ bool PartitionData::CreateSetupInterruptTargetItem(SvdInterrupt *interrupt) m_genSfd->Generate("%s", num, name.c_str()); m_genSfd->Generate("%s", descr.c_str()); m_genSfd->Generate("", "Secure state", "Non-Secure state"); - + return true; } @@ -833,7 +838,7 @@ bool PartitionData::CreateSauRegions(SvdCpu *cpu) CreateSauRegionMacro (cpu); CreateSauSetup (cpu); - + return true; } @@ -875,11 +880,17 @@ bool PartitionData::CreateSauSetup(SvdCpu *cpu) m_genH->Generate(""); uint32_t numOfSauRegions = cpu->GetSauNumRegions(); - for(uint32_t i=0; iGenerate(" #if defined (SAU_INIT_REGION%i) && (SAU_INIT_REGION%i == 1U)", i, i); - m_genH->Generate(" SAU_INIT_REGION(%i);", i); - m_genH->Generate(" #endif"); + if(numOfSauRegions == SvdItem::VALUE32_NOT_INIT) { + m_genH->Generate("SAU Setup: Number of SAU regions not set", cpu->GetLineNumber()); + } + else { + for(uint32_t i=0; iGenerate(" #if defined (SAU_INIT_REGION%i) && (SAU_INIT_REGION%i == 1U)", i, i); + m_genH->Generate(" SAU_INIT_REGION(%i);", i); + m_genH->Generate(" #endif"); + } } + m_genH->Generate(""); m_genH->Generate(" #endif /* defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) */"); @@ -930,7 +941,7 @@ bool PartitionData::CreateSauSetup(SvdCpu *cpu) m_genH->Generate(" #endif"); m_genH->Generate(""); } - + m_genH->Generate("}"); return true; diff --git a/tools/svdconv/SVDModel/src/SvdCpu.cpp b/tools/svdconv/SVDModel/src/SvdCpu.cpp index 875f186ff..35493c5a1 100644 --- a/tools/svdconv/SVDModel/src/SvdCpu.cpp +++ b/tools/svdconv/SVDModel/src/SvdCpu.cpp @@ -336,9 +336,15 @@ bool SvdCpu::CheckItem() LogMsg("M363", lineNo); m_sauRegionsConfig->Invalidate(); } - else if(m_sauNumRegions > MAXNUM_SAU_REGIONS) { + } + + if(m_sauNumRegions != SvdItem::VALUE32_NOT_INIT) { + if(m_sauNumRegions == 0 || m_sauNumRegions > MAXNUM_SAU_REGIONS) { LogMsg("M364", NUM(m_sauNumRegions), NUM2(MAXNUM_SAU_REGIONS), lineNo); - m_sauRegionsConfig->Invalidate(); + m_sauNumRegions = SvdItem::VALUE32_NOT_INIT; + if(m_sauRegionsConfig) { + m_sauRegionsConfig->Invalidate(); + } } } diff --git a/tools/svdconv/Test/data/sauConfig/SSE300_errs.svd b/tools/svdconv/Test/data/sauConfig/SSE300_errs.svd new file mode 100644 index 000000000..597bea8c4 --- /dev/null +++ b/tools/svdconv/Test/data/sauConfig/SSE300_errs.svd @@ -0,0 +1,111 @@ + + + + + ARM Ltd. + ARM + SSE300_errs + ARMv8.1-M Mainline + 1.0 + ARM 32-bit v8.1-M Mainline based device + + ARM Limited (ARM) is supplying this software for use with Cortex-M\n + processor based microcontroller, but can be equally used for other\n + suitable processor architectures. This file can be freely distributed.\n + Modifications to this file shall be clearly marked.\n + \n + THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\n + OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\n + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\n + ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\n + CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. + + + CM55 + r0p0 + little + true + true + 3 + false + 256 + + 8 + 32 + 32 + read-write + 0x00000000 + 0xFFFFFFFF + + + SYSCOUNTER_CNTRL + System counter control + 0x58100000 + 32 + read-write + + 0 + 0x1000 + registers + + + System_Timestamp_Counter + System Timestamp Counter Interrupt + 1 + + + + CNTSR + Counter frequency status information + 0x4 + 32 + read-only + + + CNTCV + Current count value + 0x8 + 64 + read-write + + + CNTSCR + Stores the Counter Scaling value + 0x10 + 32 + read-write + 0x01000000 + + + + + diff --git a/tools/svdconv/Test/data/sauConfig/SSE300_ok.svd b/tools/svdconv/Test/data/sauConfig/SSE300_ok.svd new file mode 100644 index 000000000..e6c3781d6 --- /dev/null +++ b/tools/svdconv/Test/data/sauConfig/SSE300_ok.svd @@ -0,0 +1,111 @@ + + + + + ARM Ltd. + ARM + SSE300_ok + ARMv8.1-M Mainline + 1.0 + ARM 32-bit v8.1-M Mainline based device + + ARM Limited (ARM) is supplying this software for use with Cortex-M\n + processor based microcontroller, but can be equally used for other\n + suitable processor architectures. This file can be freely distributed.\n + Modifications to this file shall be clearly marked.\n + \n + THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED\n + OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\n + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\n + ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\n + CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. + + + CM55 + r0p0 + little + true + true + 3 + false + 8 + + 8 + 32 + 32 + read-write + 0x00000000 + 0xFFFFFFFF + + + SYSCOUNTER_CNTRL + System counter control + 0x58100000 + 32 + read-write + + 0 + 0x1000 + registers + + + System_Timestamp_Counter + System Timestamp Counter Interrupt + 1 + + + + CNTSR + Counter frequency status information + 0x4 + 32 + read-only + + + CNTCV + Current count value + 0x8 + 64 + read-write + + + CNTSCR + Stores the Counter Scaling value + 0x10 + 32 + read-write + 0x01000000 + + + + + diff --git a/tools/svdconv/Test/integtests/src/SvdConvIntegTests.cpp b/tools/svdconv/Test/integtests/src/SvdConvIntegTests.cpp index 9b7168dc4..981a61c42 100644 --- a/tools/svdconv/Test/integtests/src/SvdConvIntegTests.cpp +++ b/tools/svdconv/Test/integtests/src/SvdConvIntegTests.cpp @@ -113,3 +113,47 @@ TEST_F(SvdConvIntegTests, CheckOption_n) { ASSERT_TRUE(RteFsUtils::Exists(outNameTest)); } +TEST_F(SvdConvIntegTests, CheckSauNumRegions_Ok) { + const string& inFile = SvdConvIntegTestEnv::localtestdata_dir + "/sauConfig/SSE300_ok.svd"; + const string testOut = SvdConvIntegTestEnv::testoutput_dir + "/sauConfig"; + ASSERT_TRUE(RteFsUtils::Exists(inFile)); + + Arguments args("SVDConv.exe", inFile); + args.add({ "-o", testOut, "--generate=partition", "--create-folder" }); + + SvdConv svdConv; + EXPECT_FALSE(svdConv.Check(args, args, nullptr)); +} + +TEST_F(SvdConvIntegTests, CheckSauNumRegions_Errors) { + const string& inFile = SvdConvIntegTestEnv::localtestdata_dir + "/sauConfig/SSE300_errs.svd"; + const string testOut = SvdConvIntegTestEnv::testoutput_dir + "/sauConfig"; + ASSERT_TRUE(RteFsUtils::Exists(inFile)); + + Arguments args("SVDConv.exe", inFile); + args.add({ "-o", testOut, "--generate=partition", "--create-folder" }); + + SvdConv svdConv; + EXPECT_EQ(2, svdConv.Check(args, args, nullptr)); + + struct { + int M219 = 0; + int M364 = 0; + } cnt; + + auto errMsgs = ErrLog::Get()->GetLogMessages(); + for (const string& msg : errMsgs) { + size_t s; + + if ((s = msg.find("M219", 0)) != string::npos) { + cnt.M219++; + } + if ((s = msg.find("M364", 0)) != string::npos) { + cnt.M364++; + } + } + + if(cnt.M219 != 2 || cnt.M364 != 1) { + FAIL() << "Occurrences of M219, M364 are wrong."; + } +}