Skip to content

Commit 14ac1a7

Browse files
[cbuild-run] Initial debug sequences output (single core)
1 parent 06b391e commit 14ac1a7

File tree

7 files changed

+236
-1
lines changed

7 files changed

+236
-1
lines changed

external/yaml-cpp.patch

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ diff --git a/src/emitter.cpp b/src/emitter.cpp
6969
index 4d48307..d4485be 100644
7070
--- a/src/emitter.cpp
7171
+++ b/src/emitter.cpp
72+
@@ -721,7 +721,7 @@ Emitter& Emitter::Write(const std::string& str) {
73+
74+
StringEscaping::value stringEscaping = GetStringEscapingStyle(m_pState->GetOutputCharset());
75+
76+
- const StringFormat::value strFormat =
77+
+ const StringFormat::value strFormat = str.compare(0, 2, "|\n") == 0 ? StringFormat::Literal :
78+
Utils::ComputeStringFormat(str, m_pState->GetStringFormat(),
79+
m_pState->CurGroupFlowType(), stringEscaping == StringEscaping::NonAscii);
80+
7281
@@ -816,6 +816,8 @@ const char* Emitter::ComputeNullName() const {
7382
return "NULL";
7483
case CamelNull:
@@ -90,6 +99,19 @@ index 3dbe401..0dd0b17 100644
9099
case TildeNull:
91100
_Set(m_nullFmt, value, scope);
92101
return true;
102+
diff --git a/src/emitterutils.cpp b/src/emitterutils.cpp
103+
index 6cdf6de..b48b7c0 100644
104+
--- a/src/emitterutils.cpp
105+
+++ b/src/emitterutils.cpp
106+
@@ -365,7 +365,7 @@ bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str,
107+
108+
bool WriteLiteralString(ostream_wrapper& out, const std::string& str,
109+
std::size_t indent) {
110+
- out << "|\n";
111+
+ out << (str.compare(0, 2, "|\n") == 0 ? "" : "|\n");
112+
int codePoint;
113+
for (std::string::const_iterator i = str.begin();
114+
GetNextCodePointAndAdvance(codePoint, i, str.end());) {
93115
diff --git a/src/exceptions.cpp b/src/exceptions.cpp
94116
index 43a7976..af99fd6 100644
95117
--- a/src/exceptions.cpp

tools/projmgr/include/ProjMgrRunDebug.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ struct FilesType {
2929
std::string type;
3030
};
3131

32+
/**
33+
* @brief debug sequences block type
34+
*/
35+
struct DebugSequencesBlockType {
36+
std::string info;
37+
std::string execute;
38+
std::string control_if;
39+
std::string control_while;
40+
std::string timeout;
41+
bool atomic;
42+
std::vector<DebugSequencesBlockType> blocks;
43+
};
44+
45+
/**
46+
* @brief debug sequences type
47+
*/
48+
struct DebugSequencesType {
49+
std::string name;
50+
std::string info;
51+
std::vector<DebugSequencesBlockType> blocks;
52+
};
53+
3254
/**
3355
* @brief debug run manager types
3456
*/
@@ -43,6 +65,7 @@ struct RunDebugType {
4365
std::vector<AlgorithmType> algorithms;
4466
std::vector<FilesType> outputs;
4567
std::vector<FilesType> systemDescriptions;
68+
std::vector<DebugSequencesType> debugSequences;
4669
};
4770

4871
/**
@@ -75,6 +98,7 @@ class ProjMgrRunDebug {
7598

7699
protected:
77100
RunDebugType m_runDebug;
101+
void GetDebugSequenceBlock(const RteItem* item, DebugSequencesBlockType& block);
78102
};
79103

80104
#endif // PROJMGRRUNDEBUG_H

tools/projmgr/include/ProjMgrYamlParser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ static constexpr const char* YAML_ADDPATH_ASM = "add-path-asm";
2222
static constexpr const char* YAML_ALWAYS = "always";
2323
static constexpr const char* YAML_ARGUMENT = "argument";
2424
static constexpr const char* YAML_ARGUMENTS = "arguments";
25+
static constexpr const char* YAML_ATOMIC = "atomic";
2526
static constexpr const char* YAML_ATTR = "attr";
2627
static constexpr const char* YAML_AUTO = "auto";
2728
static constexpr const char* YAML_BASE = "base";
2829
static constexpr const char* YAML_BASE_DIR = "base-dir";
2930
static constexpr const char* YAML_BASE_NAME = "base-name";
31+
static constexpr const char* YAML_BLOCKS = "blocks";
3032
static constexpr const char* YAML_BOARD = "board";
3133
static constexpr const char* YAML_BOARD_BOOKS = "board-books";
3234
static constexpr const char* YAML_BOARD_PACK = "board-pack";
@@ -103,6 +105,7 @@ static constexpr const char* YAML_GROUP = "group";
103105
static constexpr const char* YAML_GROUPS = "groups";
104106
static constexpr const char* YAML_HOST = "host";
105107
static constexpr const char* YAML_ID = "id";
108+
static constexpr const char* YAML_IF = "if";
106109
static constexpr const char* YAML_IMPLEMENTED_BY = "implemented-by";
107110
static constexpr const char* YAML_IMPLEMENTS = "implements";
108111
static constexpr const char* YAML_INFO = "info";
@@ -168,6 +171,7 @@ static constexpr const char* YAML_SOLUTION = "solution";
168171
static constexpr const char* YAML_SELECT = "select";
169172
static constexpr const char* YAML_SELECTED_BY = "selected-by";
170173
static constexpr const char* YAML_SELECTED_BY_PACK = "selected-by-pack";
174+
static constexpr const char* YAML_SEQUENCES = "sequences";
171175
static constexpr const char* YAML_SETUPS = "setups";
172176
static constexpr const char* YAML_SETUP = "setup";
173177
static constexpr const char* YAML_SET = "set";
@@ -181,6 +185,7 @@ static constexpr const char* YAML_SYSTEM_DESCRIPTIONS = "system-descriptions";
181185
static constexpr const char* YAML_TARGET_CONFIGURATIONS = "target-configurations";
182186
static constexpr const char* YAML_TARGETTYPE = "target-type";
183187
static constexpr const char* YAML_TARGETTYPES = "target-types";
188+
static constexpr const char* YAML_TIMEOUT = "timeout";
184189
static constexpr const char* YAML_TRUSTZONE = "trustzone";
185190
static constexpr const char* YAML_CORE = "core";
186191
static constexpr const char* YAML_TITLE = "title";
@@ -190,6 +195,7 @@ static constexpr const char* YAML_UPDATE = "update";
190195
static constexpr const char* YAML_VARIABLES = "variables";
191196
static constexpr const char* YAML_VERSION = "version";
192197
static constexpr const char* YAML_WARNINGS = "warnings";
198+
static constexpr const char* YAML_WHILE = "while";
193199
static constexpr const char* YAML_WORKING_DIR = "working-dir";
194200

195201
/**

tools/projmgr/schemas/common.schema.json

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,41 @@
19701970
},
19711971
"additionalProperties": false
19721972
},
1973+
"DebugSequencesType": {
1974+
"type": "array",
1975+
"uniqueItems": true,
1976+
"items": { "$ref": "#/definitions/DebugSequenceType" }
1977+
},
1978+
"DebugSequenceType": {
1979+
"description": "A list of command blocks in order of execution.",
1980+
"type": "object",
1981+
"properties": {
1982+
"name": { "type": "string", "description": "Name of the sequence." },
1983+
"info": { "type": "string", "description": "Descriptive text to display for example for error diagnostics." },
1984+
"blocks": { "$ref": "#/definitions/DebugBlocksType" }
1985+
},
1986+
"additionalProperties": false,
1987+
"required": ["name"]
1988+
},
1989+
"DebugBlocksType": {
1990+
"type": "array",
1991+
"uniqueItems": true,
1992+
"items": { "$ref": "#/definitions/DebugBlockType" }
1993+
},
1994+
"DebugBlockType": {
1995+
"description": "A list of command blocks in order of execution.",
1996+
"type": "object",
1997+
"properties": {
1998+
"info": { "type": "string", "description": "Descriptive text to display for example for error diagnostics." },
1999+
"blocks": { "$ref": "#/definitions/DebugBlocksType" },
2000+
"execute": { "type": "string", "description": "Commands for execution." },
2001+
"atomic": { "type": "null", "description": "Atomic execution of commands; cannot be used with 'blocks'" },
2002+
"if": { "anyOf": [{"type": "string"}, {"type": "number"}], "description": "Only executed when expression is true." },
2003+
"while": { "anyOf": [{"type": "string"}, {"type": "number"}], "description": "Executed in loop until while expression is true." },
2004+
"timeout": { "type": "number", "description": "Timeout in milliseconds for while loop." }
2005+
},
2006+
"additionalProperties": false
2007+
},
19732008
"RunDebugDescType": {
19742009
"description": "This section describes generated contents",
19752010
"type": "object",
@@ -1984,7 +2019,8 @@
19842019
"device-pack": { "$ref": "#/definitions/PackID" },
19852020
"programming": { "$ref": "#/definitions/ProgrammingType" },
19862021
"system-descriptions": { "$ref": "#/definitions/RunFilesType", "description": "System description files." },
1987-
"output": { "$ref": "#/definitions/RunFilesType", "description": "Application image files." }
2022+
"output": { "$ref": "#/definitions/RunFilesType", "description": "Application image files." },
2023+
"sequences": { "$ref": "#/definitions/DebugSequencesType", "description": "Debug sequences for the target." }
19882024
},
19892025
"additionalProperties": false
19902026
}

tools/projmgr/src/ProjMgrCbuildRun.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class ProjMgrCbuildRun : public ProjMgrCbuildBase {
2121
std::string m_directory;
2222
void SetProgrammingNode(YAML::Node node, const std::vector<AlgorithmType>& algorithms);
2323
void SetFilesNode(YAML::Node node, const std::vector<FilesType>& outputs);
24+
void SetDebugSequencesNode(YAML::Node node, const std::vector<DebugSequencesType>& algorithms);
25+
void SetDebugSequencesBlockNode(YAML::Node node, const std::vector<DebugSequencesBlockType>& blocks);
2426
};
2527

2628
ProjMgrCbuildRun::ProjMgrCbuildRun(YAML::Node node,
@@ -36,6 +38,7 @@ ProjMgrCbuildRun::ProjMgrCbuildRun(YAML::Node node,
3638
SetProgrammingNode(node[YAML_PROGRAMMING], debugRun.algorithms);
3739
SetFilesNode(node[YAML_SYSTEM_DESCRIPTIONS], debugRun.systemDescriptions);
3840
SetFilesNode(node[YAML_OUTPUT], debugRun.outputs);
41+
SetDebugSequencesNode(node[YAML_SEQUENCES], debugRun.debugSequences);
3942
};
4043

4144
void ProjMgrCbuildRun::SetProgrammingNode(YAML::Node node, const std::vector<AlgorithmType>& algorithms) {
@@ -66,6 +69,36 @@ void ProjMgrCbuildRun::SetFilesNode(YAML::Node node, const std::vector<FilesType
6669
}
6770
}
6871

72+
void ProjMgrCbuildRun::SetDebugSequencesNode(YAML::Node node, const std::vector<DebugSequencesType>& sequences) {
73+
for (const auto& sequence : sequences) {
74+
YAML::Node sequenceNode;
75+
SetNodeValue(sequenceNode[YAML_NAME], sequence.name);
76+
SetNodeValue(sequenceNode[YAML_INFO], sequence.info);
77+
SetDebugSequencesBlockNode(sequenceNode[YAML_BLOCKS], sequence.blocks);
78+
node.push_back(sequenceNode);
79+
}
80+
}
81+
82+
void ProjMgrCbuildRun::SetDebugSequencesBlockNode(YAML::Node node, const std::vector<DebugSequencesBlockType>& blocks) {
83+
for (const auto& block : blocks) {
84+
YAML::Node blockNode;
85+
SetNodeValue(blockNode[YAML_INFO], block.info);
86+
SetNodeValue(blockNode[YAML_IF], block.control_if);
87+
SetNodeValue(blockNode[YAML_WHILE], block.control_while);
88+
if (!block.timeout.empty()) {
89+
blockNode[YAML_TIMEOUT] = RteUtils::StringToULL(block.timeout);
90+
}
91+
if (block.atomic) {
92+
blockNode[YAML_ATOMIC] = YAML::Null;
93+
}
94+
if (!block.execute.empty()) {
95+
SetNodeValue(blockNode[YAML_EXECUTE], "|\n" + block.execute);
96+
}
97+
SetDebugSequencesBlockNode(blockNode[YAML_BLOCKS], block.blocks);
98+
node.push_back(blockNode);
99+
}
100+
}
101+
69102
//-- ProjMgrYamlEmitter::GenerateCbuildRun --------------------------------------------------------
70103
bool ProjMgrYamlEmitter::GenerateCbuildRun(const RunDebugType& debugRun) {
71104
// generate cbuild-run.yml

tools/projmgr/src/ProjMgrRunDebug.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "ProjMgrYamlEmitter.h"
1010
#include "RteFsUtils.h"
1111

12+
#include <regex>
13+
1214
using namespace std;
1315

1416
ProjMgrRunDebug::ProjMgrRunDebug(void) {
@@ -39,6 +41,8 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts) {
3941
Collection<RteItem*> algorithms;
4042
// debug infos
4143
Collection<RteItem*> debugs;
44+
// debug sequences
45+
Collection<RteItem*> debugSequences;
4246

4347
// device collections
4448
if (context->devicePack) {
@@ -51,6 +55,10 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts) {
5155
for (const auto& deviceDebug : deviceDebugs) {
5256
debugs.push_back(deviceDebug);
5357
}
58+
const auto& deviceDebugSequences = context->rteDevice->GetEffectiveProperties("sequence", context->deviceItem.pname);
59+
for (const auto& deviceDebugSequence : deviceDebugSequences) {
60+
debugSequences.push_back(deviceDebugSequence);
61+
}
5462
}
5563

5664
// board collections
@@ -103,5 +111,53 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts) {
103111
m_runDebug.outputs.push_back({ output.hex.filename, RteConstants::OUTPUT_TYPE_HEX });
104112
}
105113
}
114+
115+
// debug sequences
116+
for (const auto& debugSequence : debugSequences) {
117+
DebugSequencesType sequence;
118+
sequence.name = debugSequence->GetName();
119+
sequence.info = debugSequence->GetAttribute("info");
120+
for (const auto& debugSequenceBlock : debugSequence->GetChildren()) {
121+
DebugSequencesBlockType block;
122+
GetDebugSequenceBlock(debugSequenceBlock, block);
123+
sequence.blocks.push_back(block);
124+
}
125+
m_runDebug.debugSequences.push_back(sequence);
126+
}
127+
106128
return true;
107129
}
130+
131+
void ProjMgrRunDebug::GetDebugSequenceBlock(const RteItem* item, DebugSequencesBlockType& block) {
132+
// get 'block' attributes
133+
if (item->GetTag() == "block") {
134+
block.info = block.info.empty() ? item->GetAttribute("info") : block.info;
135+
block.atomic = item->GetAttributeAsBool("atomic");
136+
const string execute = RteUtils::EnsureLf(item->GetText());
137+
block.execute = regex_replace(execute, regex("\n +"), "\n");
138+
// 'block' doesn't have children, stop here
139+
return;
140+
}
141+
142+
// get 'control' attributes
143+
if (item->GetTag() == "control") {
144+
block.info = item->GetAttribute("info");
145+
block.control_if = item->GetAttribute("if");
146+
block.control_while = item->GetAttribute("while");
147+
block.timeout = item->GetAttribute("timeout");
148+
}
149+
150+
const auto& children = item->GetChildren();
151+
if ((children.size() == 1) && (children.front()->GetTag() == "block")) {
152+
// last child block
153+
GetDebugSequenceBlock(children.front(), block);
154+
return;
155+
}
156+
157+
for (const auto& child : children) {
158+
// get children blocks recursively
159+
DebugSequencesBlockType childBlock;
160+
GetDebugSequenceBlock(child, childBlock);
161+
block.blocks.push_back(childBlock);
162+
}
163+
}

tools/projmgr/test/data/TestRunDebug/ref/TestHW.cbuild-run.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,61 @@ cbuild-run:
3232
output:
3333
- file: out/run-debug/TestHW/run-debug.axf
3434
type: elf
35+
sequences:
36+
- name: DebugDeviceUnlock
37+
blocks:
38+
- execute: |
39+
Sequence("CheckID");
40+
- name: DebugCoreStart
41+
blocks:
42+
- execute: |
43+
// Replication of Standard Functionality
44+
Write32(0xE000EDF0, 0xA05F0001); // Enable Core Debug via DHCSR
45+
- info: DbgMCU registers
46+
execute: |
47+
// Device Specific Debug Setup
48+
Write32(0x40021018, Read32(0x40021018) | 0x00400000); // Set RCC_APB2ENR.DBGMCUEN
49+
- name: CheckID
50+
blocks:
51+
- execute: |
52+
__var pidr1 = 0;
53+
__var pidr2 = 0;
54+
__var jep106id = 0;
55+
__var ROMTableBase = 0;
56+
57+
__ap = 0; // AHB-AP
58+
59+
ROMTableBase = ReadAP(0xF8) & ~0x3;
60+
61+
pidr1 = Read32(ROMTableBase + 0x0FE4);
62+
pidr2 = Read32(ROMTableBase + 0x0FE8);
63+
jep106id = ((pidr2 & 0x7) << 4 ) | ((pidr1 >> 4) & 0xF);
64+
- if: jep106id != 0x20
65+
execute: |
66+
Query(0, "Incorrect ID! Abort connection", 1);
67+
Message(2, "Incorrect ID! Abort connection.");
68+
- name: DebugPortStop
69+
blocks:
70+
- execute: |
71+
__var connectionFlash = ( __connection & 0xF ) == 2 ;
72+
__var FLASH_BASE = 0x40022000 ;
73+
__var FLASH_CR = FLASH_BASE + 0x10 ;
74+
__var OBL_LAUNCH_BIT = ( 1 << 13 ) ;
75+
__var FLASH_CR_Value = 0 ;
76+
__var DoDebugPortStop = 1 ;
77+
__var DP_CTRL_STAT = 0x4 ;
78+
__var DP_SELECT = 0x8 ;
79+
- if: connectionFlash && DoDebugPortStop
80+
execute: |
81+
DoDebugPortStop = 0 ;
82+
FLASH_CR_Value = Read32( FLASH_CR ) ;
83+
__errorcontrol = 1 ;
84+
// write OBL_LAUNCH bit (causes a reset)
85+
Write32( FLASH_CR, FLASH_CR_Value | ( OBL_LAUNCH_BIT ) ) ;
86+
__errorcontrol = 0 ;
87+
- if: DoDebugPortStop
88+
execute: |
89+
// Switch to DP Register Bank 0
90+
WriteDP(DP_SELECT, 0x00000000);
91+
// Power Down Debug port
92+
WriteDP(DP_CTRL_STAT, 0x00000000);

0 commit comments

Comments
 (0)