forked from Open-CMSIS-Pack/devtools
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathProjMgrCbuildRun.cpp
More file actions
374 lines (350 loc) · 15.3 KB
/
Copy pathProjMgrCbuildRun.cpp
File metadata and controls
374 lines (350 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "ProductInfo.h"
#include "ProjMgrCbuildBase.h"
#include "ProjMgrUtils.h"
#include "ProjMgrYamlEmitter.h"
#include "ProjMgrYamlParser.h"
#include "RteFsUtils.h"
using namespace std;
// cbuild-run
class ProjMgrCbuildRun : public ProjMgrCbuildBase {
public:
ProjMgrCbuildRun(YAML::Node node, const RunDebugType& debugRun, const std::string& directory);
protected:
std::string m_directory;
void SetProgrammingNode(YAML::Node node, const std::vector<AlgorithmType>& algorithms);
void SetFlashInfoNode(YAML::Node node, const std::vector<FlashInfoType>& flashInfo);
void SetFilesNode(YAML::Node node, const std::vector<FilesType>& outputs);
void SetResourcesNode(YAML::Node node, const SystemResourcesType& systemResources);
void SetDebuggerNode(YAML::Node node, const DebuggerType& debugger);
void SetDebugVarsNode(YAML::Node node, const DebugVarsType& debugVars);
void SetDebugSequencesNode(YAML::Node node, const std::vector<DebugSequencesType>& algorithms);
void SetDebugSequencesBlockNode(YAML::Node node, const std::vector<DebugSequencesBlockType>& blocks);
void SetDebugTopologyNode(YAML::Node node, const DebugTopologyType& topology);
void SetProcessorsNode(YAML::Node node, const std::vector<ProcessorType>& processors);
void SetDebugPortsNode(YAML::Node node, const std::vector<DebugPortType>& debugPorts);
void SetAccessPortsNode(YAML::Node node, const std::vector<AccessPortType>& accessPorts);
void SetDatapatchNode(YAML::Node node, const std::vector<DatapatchType>& datapatch);
void SetGdbServerNode(YAML::Node node, const std::vector<GdbServerItem>& gdbserver);
void SetTelnetNode(YAML::Node node, const std::map<std::string, TelnetOptionsItem>& telnet);
void SetCustomNodes(YAML::Node node, const CustomItem& debugger);
YAML::Node GetCustomNode(const CustomItem& value);
};
ProjMgrCbuildRun::ProjMgrCbuildRun(YAML::Node node,
const RunDebugType& debugRun, const std::string& directory) : m_directory(directory) {
SetNodeValue(node[YAML_GENERATED_BY], ORIGINAL_FILENAME + string(" version ") + VERSION_STRING);
SetNodeValue(node[YAML_SOLUTION], FormatPath(debugRun.solution, directory));
SetNodeValue(node[YAML_TARGETTYPE], debugRun.targetType);
SetNodeValue(node[YAML_TARGET_SET], debugRun.targetSet);
SetNodeValue(node[YAML_COMPILER], debugRun.compiler);
SetNodeValue(node[YAML_BOARD], debugRun.board);
SetNodeValue(node[YAML_BOARD_PACK], debugRun.boardPack);
SetNodeValue(node[YAML_DEVICE], debugRun.device);
SetNodeValue(node[YAML_DEVICE_PACK], debugRun.devicePack);
SetFilesNode(node[YAML_OUTPUT], debugRun.outputs);
SetResourcesNode(node[YAML_SYSTEM_RESOURCES], debugRun.systemResources);
SetFilesNode(node[YAML_SYSTEM_DESCRIPTIONS], debugRun.systemDescriptions);
SetDebuggerNode(node[YAML_DEBUGGER], debugRun.debugger);
SetDebugVarsNode(node[YAML_DEBUG_VARS], debugRun.debugVars);
SetDebugSequencesNode(node[YAML_DEBUG_SEQUENCES], debugRun.debugSequences);
SetProgrammingNode(node[YAML_PROGRAMMING], debugRun.algorithms);
SetFlashInfoNode(node[YAML_FLASH_INFO], debugRun.flashInfo);
SetDebugTopologyNode(node[YAML_DEBUG_TOPOLOGY], debugRun.debugTopology);
};
void ProjMgrCbuildRun::SetProgrammingNode(YAML::Node node, const std::vector<AlgorithmType>& algorithms) {
for (const auto& item : algorithms) {
YAML::Node algorithmNode;
SetNodeValue(algorithmNode[YAML_ALGORITHM], FormatPath(item.algorithm, m_directory));
SetNodeValue(algorithmNode[YAML_START], ProjMgrUtils::ULLToHex(item.start));
SetNodeValue(algorithmNode[YAML_SIZE], ProjMgrUtils::ULLToHex(item.size));
SetNodeValue(algorithmNode[YAML_RAM_START], ProjMgrUtils::ULLToHex(item.ram.start));
SetNodeValue(algorithmNode[YAML_RAM_SIZE], ProjMgrUtils::ULLToHex(item.ram.size));
SetNodeValue(algorithmNode[YAML_PNAME], item.ram.pname);
node.push_back(algorithmNode);
}
}
void ProjMgrCbuildRun::SetFlashInfoNode(YAML::Node node, const std::vector<FlashInfoType>& flashInfo) {
for (const auto& item : flashInfo) {
YAML::Node flashInfoNode;
SetNodeValue(flashInfoNode[YAML_NAME], item.name);
SetNodeValue(flashInfoNode[YAML_START], ProjMgrUtils::ULLToHex(item.start));
SetNodeValue(flashInfoNode[YAML_PAGE_SIZE], ProjMgrUtils::ULLToHex(item.pageSize));
if (!item.blocks.empty()) {
for (const auto& block : item.blocks) {
YAML::Node blockNode;
blockNode[YAML_COUNT] = block.count;
SetNodeValue(blockNode[YAML_SIZE], ProjMgrUtils::ULLToHex(block.size));
if (block.arg.has_value()) {
blockNode[YAML_ARG] = block.arg.value();
}
flashInfoNode[YAML_BLOCKS].push_back(blockNode);
}
}
if (item.blankVal.has_value()) {
SetNodeValue(flashInfoNode[YAML_BLANK_VAL], ProjMgrUtils::ULLToHex(item.blankVal.value(), 16));
}
if (item.fillVal.has_value()) {
SetNodeValue(flashInfoNode[YAML_FILL_VAL], ProjMgrUtils::ULLToHex(item.fillVal.value(), 16));
}
if (item.ptime.has_value()) {
flashInfoNode[YAML_PTIME] = item.ptime.value();
}
if (item.etime.has_value()) {
flashInfoNode[YAML_ETIME] = item.etime.value();
}
SetNodeValue(flashInfoNode[YAML_PNAME], item.pname);
node.push_back(flashInfoNode);
}
}
void ProjMgrCbuildRun::SetFilesNode(YAML::Node node, const std::vector<FilesType>& files) {
for (const auto& item : files) {
YAML::Node fileNode;
SetNodeValue(fileNode[YAML_FILE], FormatPath(item.file, m_directory));
SetNodeValue(fileNode[YAML_INFO], item.info);
SetNodeValue(fileNode[YAML_TYPE], item.type);
SetNodeValue(fileNode[YAML_LOAD], item.load);
if (!item.offset.empty()) {
fileNode[YAML_LOAD_OFFSET] = ProjMgrUtils::ULLToHex(RteUtils::StringToULL(item.offset));
}
SetNodeValue(fileNode[YAML_PNAME], item.pname);
node.push_back(fileNode);
}
}
void ProjMgrCbuildRun::SetResourcesNode(YAML::Node node, const SystemResourcesType& systemResources) {
for (const auto& item : systemResources.memories) {
YAML::Node memoryNode;
SetNodeValue(memoryNode[YAML_NAME], item.name);
SetNodeValue(memoryNode[YAML_ACCESS], item.access);
SetNodeValue(memoryNode[YAML_START], ProjMgrUtils::ULLToHex(item.start));
SetNodeValue(memoryNode[YAML_SIZE], ProjMgrUtils::ULLToHex(item.size));
SetNodeValue(memoryNode[YAML_PNAME], item.pname);
SetNodeValue(memoryNode[YAML_ALIAS], item.alias);
SetNodeValue(memoryNode[YAML_FROM_PACK], item.fromPack);
node[YAML_MEMORY].push_back(memoryNode);
}
for (const auto& item : systemResources.processors) {
YAML::Node processorNode;
const vector<pair<const string, const string&>> attrMap = {
{ YAML_CORE , item.core },
{ YAML_REVISION , item.revision },
{ YAML_PNAME , item.pname },
{ YAML_ENDIAN , item.endian },
{ YAML_FPU , item.fpu },
{ YAML_MPU , item.mpu },
{ YAML_DSP , item.dsp },
{ YAML_TRUSTZONE , item.trustzone },
{ YAML_MVE , item.mve },
{ YAML_PACBTI , item.pacbti },
};
for (const auto& [key, attr] : attrMap) {
SetNodeValue(processorNode[key], attr);
}
processorNode[YAML_MAX_CLOCK] = item.maxClock;
if (item.punits.has_value()) {
processorNode[YAML_PUNITS] = item.punits.value();
}
if (item.cdecp.has_value()) {
processorNode[YAML_CDECP] = ProjMgrUtils::ULLToHex(item.cdecp.value(), 2);
}
node[YAML_PROCESSORS].push_back(processorNode);
}
}
void ProjMgrCbuildRun::SetDebuggerNode(YAML::Node node, const DebuggerType& debugger) {
if (!debugger.name.empty()) {
SetNodeValue(node[YAML_NAME], debugger.name);
SetNodeValue(node[YAML_INFO], debugger.info);
SetNodeValue(node[YAML_PROTOCOL], debugger.protocol);
if (debugger.clock.has_value()) {
node[YAML_CLOCK] = debugger.clock.value();
}
if (!debugger.dbgconf.empty()) {
SetNodeValue(node[YAML_DBGCONF], FormatPath(debugger.dbgconf, m_directory));
}
SetNodeValue(node[YAML_START_PNAME], debugger.startPname);
SetGdbServerNode(node[YAML_GDBSERVER], debugger.gdbserver);
SetTelnetNode(node[YAML_TELNET], debugger.telnet);
SetCustomNodes(node, debugger.custom);
}
}
YAML::Node ProjMgrCbuildRun::GetCustomNode(const CustomItem& value) {
YAML::Node node;
if (!value.scalar.empty()) {
node = value.scalar;
}
else if (!value.vec.empty()) {
for (const auto& item : value.vec) {
node.push_back(GetCustomNode(item));
}
}
else if (!value.map.empty()) {
for (const auto& [k, v] : value.map) {
node[k] = GetCustomNode(v);
}
}
return node;
}
void ProjMgrCbuildRun::SetCustomNodes(YAML::Node node, const CustomItem& custom) {
for (const auto& [key, value] : custom.map) {
node[key] = GetCustomNode(value);
}
}
void ProjMgrCbuildRun::SetGdbServerNode(YAML::Node node, const std::vector<GdbServerItem>& gdbserver) {
for (const auto& item : gdbserver) {
YAML::Node gdbserverNode;
gdbserverNode[YAML_PORT] = item.port;
SetNodeValue(gdbserverNode[YAML_PNAME], item.pname);
node.push_back(gdbserverNode);
}
}
void ProjMgrCbuildRun::SetTelnetNode(YAML::Node node, const std::map<std::string, TelnetOptionsItem>& telnet) {
for (const auto& [pname, item] : telnet) {
YAML::Node telnetNode;
SetNodeValue(telnetNode[YAML_MODE], item.mode);
SetNodeValue(telnetNode[YAML_PNAME], pname);
telnetNode[YAML_PORT] = item.ullPort;
if (!item.file.empty()) {
SetNodeValue(telnetNode[YAML_FILE], FormatPath(item.file, m_directory));
}
node.push_back(telnetNode);
}
}
void ProjMgrCbuildRun::SetDebugVarsNode(YAML::Node node, const DebugVarsType& debugVars) {
if (!debugVars.vars.empty()) {
SetNodeValue(node[YAML_VARS], "|\n" + debugVars.vars);
}
}
void ProjMgrCbuildRun::SetDebugSequencesNode(YAML::Node node, const std::vector<DebugSequencesType>& sequences) {
for (const auto& sequence : sequences) {
YAML::Node sequenceNode;
SetNodeValue(sequenceNode[YAML_NAME], sequence.name);
SetNodeValue(sequenceNode[YAML_INFO], sequence.info);
SetDebugSequencesBlockNode(sequenceNode[YAML_BLOCKS], sequence.blocks);
SetNodeValue(sequenceNode[YAML_PNAME], sequence.pname);
node.push_back(sequenceNode);
}
}
void ProjMgrCbuildRun::SetDebugSequencesBlockNode(YAML::Node node, const std::vector<DebugSequencesBlockType>& blocks) {
for (const auto& block : blocks) {
if (block.execute.empty() && block.blocks.empty() && block.control_if.empty() && block.control_while.empty()) {
continue;
}
YAML::Node blockNode;
SetNodeValue(blockNode[YAML_INFO], block.info);
SetNodeValue(blockNode[YAML_IF], block.control_if);
SetNodeValue(blockNode[YAML_WHILE], block.control_while);
if (block.timeout.has_value()) {
blockNode[YAML_TIMEOUT] = block.timeout.value();
}
if (block.bAtomic) {
blockNode[YAML_ATOMIC] = YAML::Null;
}
if (!block.execute.empty()) {
SetNodeValue(blockNode[YAML_EXECUTE], "|\n" + block.execute);
}
SetDebugSequencesBlockNode(blockNode[YAML_BLOCKS], block.blocks);
node.push_back(blockNode);
}
}
void ProjMgrCbuildRun::SetDebugTopologyNode(YAML::Node node, const DebugTopologyType& topology) {
SetDebugPortsNode(node[YAML_DEBUGPORTS], topology.debugPorts);
SetProcessorsNode(node[YAML_PROCESSORS], topology.processors);
if (topology.swj.has_value()) {
node[YAML_SWJ] = topology.swj.value();
}
if (topology.dormant.has_value()) {
node[YAML_DORMANT] = topology.dormant.value();
}
if (!topology.sdf.empty()) {
SetNodeValue(node[YAML_SDF], FormatPath(topology.sdf, m_directory));
}
}
void ProjMgrCbuildRun::SetDebugPortsNode(YAML::Node node, const vector<DebugPortType>& debugPorts) {
for (const auto& dp : debugPorts) {
YAML::Node dpNode;
dpNode[YAML_DPID] = dp.dpid;
if (dp.jtagTapIndex.has_value()) {
dpNode[YAML_JTAG][YAML_TAPINDEX] = dp.jtagTapIndex.value();
}
if (dp.swdTargetSel.has_value()) {
dpNode[YAML_SWD][YAML_TARGETSEL] = dp.swdTargetSel.value();
}
SetAccessPortsNode(dpNode[YAML_ACCESSPORTS], dp.accessPorts);
node.push_back(dpNode);
}
}
void ProjMgrCbuildRun::SetAccessPortsNode(YAML::Node node, const vector<AccessPortType>& accessPorts) {
for (const auto& ap : accessPorts) {
YAML::Node apNode;
apNode[YAML_APID] = ap.apid;
if (ap.index.has_value()) {
apNode[YAML_INDEX] = ap.index.value();
}
if (ap.address.has_value()) {
SetNodeValue(apNode[YAML_ADDRESS], ProjMgrUtils::ULLToHex(ap.address.value()));
}
if (ap.hprot.has_value()) {
SetNodeValue(apNode[YAML_HPROT], ProjMgrUtils::ULLToHex(ap.hprot.value(), 1));
}
if (ap.sprot.has_value()) {
SetNodeValue(apNode[YAML_SPROT], ProjMgrUtils::ULLToHex(ap.sprot.value(), 1));
}
SetDatapatchNode(apNode[YAML_DATAPATCH], ap.datapatch);
SetAccessPortsNode(apNode[YAML_ACCESSPORTS], ap.accessPorts);
node.push_back(apNode);
}
}
void ProjMgrCbuildRun::SetDatapatchNode(YAML::Node node, const vector<DatapatchType>& datapatch) {
for (const auto& patch : datapatch) {
YAML::Node patchNode;
SetNodeValue(patchNode[YAML_ADDRESS], ProjMgrUtils::ULLToHex(patch.address));
SetNodeValue(patchNode[YAML_VALUE], ProjMgrUtils::ULLToHex(patch.value));
if (patch.mask.has_value()) {
SetNodeValue(patchNode[YAML_MASK], ProjMgrUtils::ULLToHex(patch.mask.value()));
}
SetNodeValue(patchNode[YAML_TYPE], patch.type);
SetNodeValue(patchNode[YAML_INFO], patch.info);
node.push_back(patchNode);
}
}
void ProjMgrCbuildRun::SetProcessorsNode(YAML::Node node, const vector<ProcessorType>& processors) {
for (const auto& processor : processors) {
if (processor.pname.empty() && processor.resetSequence.empty() && !processor.apid.has_value()) {
continue;
}
YAML::Node processorNode;
SetNodeValue(processorNode[YAML_PNAME], processor.pname);
if (processor.apid.has_value()) {
processorNode[YAML_APID] = processor.apid.value();
}
SetNodeValue(processorNode[YAML_RESET_SEQUENCE], processor.resetSequence);
node.push_back(processorNode);
}
}
//-- ProjMgrYamlEmitter::GenerateCbuildRun --------------------------------------------------------
bool ProjMgrYamlEmitter::GenerateCbuildRun(const RunDebugType& debugRun) {
// remove cbuild-run file if it was generated in the $SolutionDir()$ by csolution lower than 2.11.0
const string olderCbuildRun = RteFsUtils::ParentPath(debugRun.solution) + '/' +
debugRun.solutionName + '+' + debugRun.targetType + ".cbuild-run.yml";
if (RteFsUtils::Exists(olderCbuildRun)) {
try {
const YAML::Node& cbuildRun = YAML::LoadFile(olderCbuildRun);
const auto& generatedBy = cbuildRun["cbuild-run"]["generated-by"].as<string>();
const auto& tool = RteUtils::ExtractPrefix(generatedBy, " version");
const auto& version = RteUtils::ExtractSuffix(generatedBy, "version ");
if (tool == "csolution" && VersionCmp::Compare(version, "2.11.0") < 0) {
RteFsUtils::RemoveFile(olderCbuildRun);
}
} catch (YAML::Exception&) {}
}
// generate cbuild-run.yml
m_cbuildRun = debugRun.cbuildRun;
RteFsUtils::NormalizePath(m_cbuildRun, m_outputDir);
const auto& cbuildRunDir = RteFsUtils::ParentPath(m_cbuildRun);
YAML::Node rootNode;
ProjMgrCbuildRun cbuildRun(rootNode[YAML_CBUILD_RUN], debugRun, cbuildRunDir);
return WriteFile(rootNode, m_cbuildRun);
}