blob: d737fea7b07a129ffd5365f9a1d0ac3d2f1ba81a [file] [log] [blame]
Matt Spinler7d381e12016-09-27 14:27:24 -05001#!/usr/bin/env perl
2
3#Generates a BMC device tree syntax file from the machine
4#readable workbook.
5
6use strict;
7use XML::Simple;
8use mrw::Targets;
9use Getopt::Long;
Matt Spinler30b461c2016-10-10 16:50:07 -050010use YAML::Tiny qw(LoadFile);
11use Scalar::Util qw(looks_like_number);
Matt Spinler7d381e12016-09-27 14:27:24 -050012
Matt Spinler30b461c2016-10-10 16:50:07 -050013use constant {
14 VERSION => "/dts-v1/;",
15 ZERO_LENGTH_PROPERTY => "zero_length_property",
16 PRE_ROOT_INCLUDES => "pre-root-node",
17 ROOT_INCLUDES => "root-node",
18 POST_ROOT_INCLUDES => "post-root-node"
19};
Matt Spinler74909132016-10-07 13:52:19 -050020
Matt Spinler7d381e12016-09-27 14:27:24 -050021
22my $serverwizFile;
Matt Spinler30b461c2016-10-10 16:50:07 -050023my $configFile;
Matt Spinler7d381e12016-09-27 14:27:24 -050024my $outputFile;
25my $debug;
26
27GetOptions("x=s" => \$serverwizFile,
Matt Spinler30b461c2016-10-10 16:50:07 -050028 "y=s" => \$configFile,
Matt Spinler7d381e12016-09-27 14:27:24 -050029 "o=s" => \$outputFile,
30 "d" => \$debug)
31or printUsage();
32
Matt Spinler30b461c2016-10-10 16:50:07 -050033if ((not defined $serverwizFile) || (not defined $outputFile) ||
34 (not defined $configFile)) {
Matt Spinler7d381e12016-09-27 14:27:24 -050035 printUsage();
36}
37
Matt Spinler30b461c2016-10-10 16:50:07 -050038my %g_configuration = %{ LoadFile($configFile) };
39
Matt Spinler7d381e12016-09-27 14:27:24 -050040my $g_targetObj = Targets->new;
41$g_targetObj->loadXML($serverwizFile);
42
Matt Spinler74909132016-10-07 13:52:19 -050043my ($g_bmc, $g_bmcModel, $g_bmcMfgr, $g_systemName);
44setGlobalAttributes();
Matt Spinler7d381e12016-09-27 14:27:24 -050045
Matt Spinler30b461c2016-10-10 16:50:07 -050046my $g_i2cBusAdjust = 0;
47getI2CBusAdjust();
Matt Spinler7d381e12016-09-27 14:27:24 -050048
49open (my $f, ">$outputFile") or die "Could not open $outputFile\n";
50
51printVersion($f);
Matt Spinler30b461c2016-10-10 16:50:07 -050052printIncludes($f, PRE_ROOT_INCLUDES);
Matt Spinler7d381e12016-09-27 14:27:24 -050053printRootNodeStart($f);
54
55printPropertyList($f, 1, "model", getSystemBMCModel());
Matt Spinler7d381e12016-09-27 14:27:24 -050056printPropertyList($f, 1, "compatible", getBMCCompatibles());
Matt Spinler995f2a22016-09-30 13:07:31 -050057
Matt Spinler23d47c22016-10-04 12:31:21 -050058printNode($f, 1, "aliases", getAliases());
Matt Spinler7d381e12016-09-27 14:27:24 -050059printNode($f, 1, "chosen", getChosen());
Matt Spinler30b461c2016-10-10 16:50:07 -050060printNode($f, 1, "memory", getBmcMemory());
Matt Spinler7d381e12016-09-27 14:27:24 -050061
Matt Spinler995f2a22016-09-30 13:07:31 -050062printNode($f, 1, "leds", getLEDNode());
63
Matt Spinler30b461c2016-10-10 16:50:07 -050064printIncludes($f, ROOT_INCLUDES);
65
Matt Spinler7d381e12016-09-27 14:27:24 -050066printRootNodeEnd($f, 0);
67
Matt Spinler96f8f242016-11-28 16:26:57 -060068printNodes($f, 0, getBMCFlashNodes());
69
70printNodes($f, 0, getOtherFlashNodes());
71
Matt Spinler74909132016-10-07 13:52:19 -050072printNodes($f, 0, getI2CNodes());
Matt Spinler7d381e12016-09-27 14:27:24 -050073printNodes($f, 0, getMacNodes());
Matt Spinler995f2a22016-09-30 13:07:31 -050074printNodes($f, 0, getUARTNodes());
Matt Spinler7d381e12016-09-27 14:27:24 -050075printNodes($f, 0, getVuartNodes());
76
Matt Spinler30b461c2016-10-10 16:50:07 -050077printIncludes($f, POST_ROOT_INCLUDES);
78
Matt Spinler7d381e12016-09-27 14:27:24 -050079close $f;
80exit 0;
81
82
Matt Spinler74909132016-10-07 13:52:19 -050083#Finds the values for these globals:
84# $g_bmc, $g_bmcModel, $g_bmcMfgr, $g_systemName
85sub setGlobalAttributes()
86{
87 $g_bmc = getBMCTarget();
88 if (length($g_bmc) == 0) {
89 die "Unable to find a BMC in this system\n";
90 }
91
92 if ($g_targetObj->isBadAttribute($g_bmc, "MODEL")) {
93 die "The MODEL attribute on $g_bmc is missing or empty.\n";
94 }
95 $g_bmcModel = $g_targetObj->getAttribute($g_bmc, "MODEL");
96
97 if ($g_targetObj->isBadAttribute($g_bmc, "MANUFACTURER")) {
98 die "The MANUFACTURER attribute on $g_bmc is missing or empty.\n";
99 }
100 $g_bmcMfgr = $g_targetObj->getAttribute($g_bmc, "MANUFACTURER");
101
102 $g_systemName = $g_targetObj->getSystemName();
103 if (length($g_systemName) == 0) {
104 die "The SYSTEM_NAME attribute is not set on the system target.\n";
105 }
106}
107
108
Matt Spinler23d47c22016-10-04 12:31:21 -0500109#Returns a hash that represents the 'aliases' node.
110#Will look like:
111# aliases {
112# name1 = &val1;
113# name2 = &val2;
114# ...
115# }
116sub getAliases()
117{
118 my %aliases;
Matt Spinler23d47c22016-10-04 12:31:21 -0500119
Matt Spinler30b461c2016-10-10 16:50:07 -0500120 #Get the info from the config file
Matt Spinler23d47c22016-10-04 12:31:21 -0500121
Matt Spinler30b461c2016-10-10 16:50:07 -0500122 if ((not exists $g_configuration{aliases}) ||
123 (keys %{$g_configuration{aliases}} == 0)) {
124 print "WARNING: Missing or empty 'aliases' section in config file.\n";
125 return %aliases;
126 }
127 %aliases = %{ $g_configuration{aliases} };
128
129 #add a & reference if one is missing
130 foreach my $a (keys %aliases) {
131 if (($aliases{$a} !~ /^&/) && ($aliases{$a} !~ /^\(ref\)/)) {
132 $aliases{$a} = "(ref)$aliases{$a}";
Matt Spinler23d47c22016-10-04 12:31:21 -0500133 }
134 }
135
136 return %aliases;
137}
138
Matt Spinler7d381e12016-09-27 14:27:24 -0500139
140#Return a hash that represents the 'chosen' node
Matt Spinler995f2a22016-09-30 13:07:31 -0500141#Will look like:
142# chosen {
143# stdout-path = ...
144# bootargs = ...
145# }
Matt Spinler7d381e12016-09-27 14:27:24 -0500146sub getChosen()
147{
Matt Spinler7d381e12016-09-27 14:27:24 -0500148 my %chosen;
Matt Spinler30b461c2016-10-10 16:50:07 -0500149 my @allowed = qw(bootargs stdin-path stdout-path);
150
151 #Get the info from the config file
152
153 if (not exists $g_configuration{chosen}) {
154 die "ERROR: Missing 'chosen' section in config file.\n";
155 }
156 %chosen = %{ $g_configuration{chosen} };
157
158 #Check for allowed entries. Empty is OK.
159 foreach my $key (keys %chosen) {
160 my $found = 0;
161 foreach my $good (@allowed) {
162 if ($key eq $good) {
163 $found = 1;
164 }
165 }
166
167 if ($found == 0) {
168 die "Invalid entry $key in 'chosen' section in config file\n";
169 }
170 }
171
Matt Spinler7d381e12016-09-27 14:27:24 -0500172 return %chosen;
173}
174
175
Matt Spinler30b461c2016-10-10 16:50:07 -0500176#Return a hash that represents the 'memory' node.
Matt Spinler995f2a22016-09-30 13:07:31 -0500177#Will look like:
Matt Spinler30b461c2016-10-10 16:50:07 -0500178# memory {
179# reg = < base size >
180# }
181sub getBmcMemory()
182{
183 my %memory;
184
185 #Get the info from the config file
186
187 if (not exists $g_configuration{memory}) {
188 die "ERROR: Missing 'memory' section in config file.\n";
189 }
190
191 if ((not exists $g_configuration{memory}{base}) ||
192 ($g_configuration{memory}{base} !~ /0x/)) {
193 die "ERROR: The base entry in the memory section in the config " .
194 "file is either missing or invalid.\n";
195 }
196
197 if ((not exists $g_configuration{memory}{size}) ||
198 ($g_configuration{memory}{size} !~ /0x/)) {
199 die "ERROR: The size entry in the memory section in the config " .
200 "file is either missing or invalid.\n";
201 }
202
203 #Future: could do more validation on the actual values
204
205 $memory{reg} = "<$g_configuration{memory}{base} " .
206 "$g_configuration{memory}{size}>";
207
208 return %memory;
209}
210
211
Matt Spinler25d60bb2016-10-31 15:16:03 -0500212#Returns an array of hashes representing the device tree nodes for
213#the BMC flash. These nodes are BMC model specific because different
214#models can have different device drivers.
215sub getBMCFlashNodes()
Matt Spinler7d381e12016-09-27 14:27:24 -0500216{
Matt Spinler25d60bb2016-10-31 15:16:03 -0500217 my @nodes;
218
219 if ($g_bmcModel eq "AST2500") {
220 my %node = getAST2500BMCSPIFlashNode();
221 push @nodes, { %node };
222 }
223 else {
224 die "ERROR: No BMC SPI flash support yet for BMC model $g_bmcModel\n";
225 }
226
227 return @nodes;
228}
229
230
231#Returns a hash that represents the BMC SPI flash(es) by finding the SPI
232#connections that come from the unit tagged as BMC_CODE. The code also
233#looks in the config file for any additional properties to add. Supports
234#the hardware where the same SPI master unit can be wired to more than 1
235#flash (a chip select line is used to switch between them.) This is
236#specific to the ASPEED AST2500 hardware and device driver.
237#Will look like:
238# fmc {
239# status = "okay"
240# flash@0 {
241# ...
242# };
243# flash@1 {
244# ...
245# };
246sub getAST2500BMCSPIFlashNode()
247{
248 my %bmcFlash;
249 my $chipSelect = 0;
250 my $lastUnit = "";
251
Matt Spinler18d5f572016-11-15 15:25:45 -0600252 my $connections = $g_targetObj->findConnections($g_bmc, "SPI", "FLASH");
Matt Spinler25d60bb2016-10-31 15:16:03 -0500253
254 if ($connections eq "") {
255 die "ERROR: No BMC SPI flashes found connected to the BMC\n";
256 }
257
258 $bmcFlash{fmc}{status} = "okay";
259
260 foreach my $spi (@{$connections->{CONN}}) {
261
262 #Looking for spi-masters with a function of 'BMC_CODE'.
263 #It's possible there are multiple flash chips here.
264 if (!$g_targetObj->isBadAttribute($spi->{SOURCE}, "SPI_FUNCTION")) {
265
266 my $function = $g_targetObj->getAttribute($spi->{SOURCE},
267 "SPI_FUNCTION");
268 if ($function eq "BMC_CODE") {
269
270 my $flashName = "flash@".$chipSelect;
271
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500272 $bmcFlash{fmc}{$flashName}{COMMENT} = connectionComment($spi);
Matt Spinler25d60bb2016-10-31 15:16:03 -0500273
274 $bmcFlash{fmc}{$flashName}{status} = "okay";
275
276 #Add in anything specified in the config file for this chip.
277 addBMCFlashConfigProperties(\%{$bmcFlash{fmc}{$flashName}},
278 $chipSelect);
279
280 #The code currently only supports the config where a chip
281 #select line is used to select between possibly multiple
282 #flash chips attached to the same SPI pins/unit. So we
283 #need to make sure if there are multiple chips found, that
284 #they are off of the same master unit.
285 if ($lastUnit eq "") {
286 $lastUnit = $spi->{SOURCE};
287 }
288 else {
289 if ($lastUnit ne $spi->{SOURCE}) {
290 die "ERROR: Currently only 1 spi-master unit is " .
291 "supported for BMC flash connections."
292 }
293 }
294
295 #Since we don't need anything chip select specific from the
296 #XML, we can just assign our own chip selects.
297 $chipSelect++;
298 }
299 }
300 }
301
302 if ($chipSelect == 0) {
303 die "ERROR: Didn't find any BMC flash chips connected";
304 }
305
306 return %bmcFlash;
307}
308
309
310#Looks in the bmc-flash-config section in the config file for the
311#chip select passed in to add any additional properties to the BMC
312#flash node.
313# $node = hash reference to the flash node
314# $cs = the flash chip select value
315sub addBMCFlashConfigProperties()
316{
317 my ($node, $cs) = @_;
318 my $section = "chip-select-$cs";
319
320 if (exists $g_configuration{"bmc-flash-config"}{$section}) {
321 foreach my $key (sort keys $g_configuration{"bmc-flash-config"}{$section}) {
322 $node->{$key} = $g_configuration{"bmc-flash-config"}{$section}{$key};
323 }
324 }
Matt Spinler995f2a22016-09-30 13:07:31 -0500325}
326
327
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500328#Returns an array of hashes representing the other flashes used by the
329#BMC besides the ones that hold the BMC code. This is BMC model specific
330#as different models can have different interfaces.
331#Typically, these are SPI flashes.
332sub getOtherFlashNodes()
333{
334 my @nodes;
335
336 if ($g_bmcModel eq "AST2500") {
337 @nodes = getAST2500SpiFlashNodes();
338 }
339 else {
340 die "ERROR: No SPI flash support yet for BMC model $g_bmcModel\n";
341 }
342
343 return @nodes;
344}
345
346
347#Returns an array of hashes representing the SPI flashes in an
348#AST2500. These are for the SPI1 and SPI2 interfaces in the chip.
349#Each SPI master interface can support multiple flash chips. If
350#no hardware is connected to the interface, the node won't be present.
351sub getAST2500SpiFlashNodes()
352{
353 my @nodes;
354
355 #The AST2500 has 2 SPI master units, 1 and 2.
356 my @units = (1, 2);
357
358 foreach my $unit (@units) {
359
360 my %node = getAST2500SpiMasterNode($unit);
361
362 if (keys %node) {
363 my %spiNode;
364 my $nodeName = "spi$unit";
365 $spiNode{$nodeName} = { %node };
366 push @nodes, { %spiNode };
367 }
368 }
369
370 return @nodes;
371}
372
373
374#Returns a hash that represents the device tree node for the SPI1
375#or SPI2 master interface on the AST2500. Each master can support
376#multiple chips by use of a chip select.
377#Will look like:
378# spi1 {
379# status = "okay";
380# flash@0 {
381# ...
382# };
383# };
384#
385# $spiNum = The SPI master unit number to use
386sub getAST2500SpiMasterNode()
387{
388 my $spiNum = shift;
389 my %spiMaster;
390 my $chipSelect = 0;
391
Matt Spinler18d5f572016-11-15 15:25:45 -0600392 my $connections = $g_targetObj->findConnections($g_bmc, "SPI", "FLASH");
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500393
394 if ($connections eq "") {
395 return %spiMaster;
396 }
397
398 #Looking for spi-masters with a chip-unit of $spiNum
399 #It's possible there are multiple flash chips off the master
400 foreach my $spi (@{$connections->{CONN}}) {
401
402 my $unitNum = $g_targetObj->getAttribute($spi->{SOURCE},
403 "CHIP_UNIT");
404 if ($unitNum == $spiNum) {
405 $spiMaster{status} = "okay";
Matt Spinler2efdcba2016-11-08 15:37:20 -0600406
407 #Add in any pinctrl properties. These would come from the parent
408 #of $spi{SOURCE}, which would be a unit-pingroup-bmc if the
409 #pins for this connection are multi-function.
410 addPinCtrlProps($g_targetObj->getTargetParent($spi->{SOURCE}),
411 \%spiMaster);
412
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500413 my $flashName = "flash@".$chipSelect;
414
415 $spiMaster{$flashName}{COMMENT} = connectionComment($spi);
416
417 $spiMaster{$flashName}{status} = "okay";
418
Matt Spinler0eda4882016-11-30 15:20:11 -0600419 #AST2500 PNORs need a label
420 my $function = $g_targetObj->getAttribute($spi->{SOURCE},
421 "SPI_FUNCTION");
422 if ($function eq "PNOR") {
423 $spiMaster{$flashName}{label} = "pnor";
424 }
425
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500426 $chipSelect++;
427 }
428 }
429
430 return %spiMaster;
431}
432
433
Matt Spinler995f2a22016-09-30 13:07:31 -0500434#Returns a hash that represents the leds node by finding all of the
435#GPIO connections to LEDs.
436#Node will look like:
437# leds {
438# <ledname> {
439# gpios = &gpio ASPEED_GPIO(x, y) GPIO_ACTIVE_xxx>
440# };
441# <another ledname> {
442# ...
443# }
444sub getLEDNode()
445{
446 my %leds;
447
Matt Spinlereca7f062016-11-07 09:59:23 -0600448 $leds{compatible} = "gpio-leds";
Matt Spinler995f2a22016-09-30 13:07:31 -0500449
Matt Spinler18d5f572016-11-15 15:25:45 -0600450 my $connections = $g_targetObj->findConnections($g_bmc, "GPIO", "LED");
Matt Spinler995f2a22016-09-30 13:07:31 -0500451
452 if ($connections eq "") {
453 print "WARNING: No LEDs found connected to the BMC\n";
454 return %leds;
455 }
456
457 foreach my $gpio (@{$connections->{CONN}}) {
458 my %ledNode;
459
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500460 $ledNode{COMMENT} = connectionComment($gpio);
Matt Spinler995f2a22016-09-30 13:07:31 -0500461
462 #The node name will be the simplified LED name
463 my $name = $gpio->{DEST_PARENT};
464 $name =~ s/(-\d+$)//; #remove trailing position
465 $name =~ s/.*\///; #remove the front of the path
466
467 #For now only supports ASPEED.
468 if (uc($g_bmcMfgr) ne "ASPEED") {
469 die "ERROR: Unsupported BMC manufacturer $g_bmcMfgr\n";
470 }
471 my $num = $g_targetObj->getAttribute($gpio->{SOURCE}, "PIN_NUM");
472 my $macro = getAspeedGpioMacro($num);
473
474 #If it's active high or low
475 my $state = $g_targetObj->getAttribute($gpio->{DEST_PARENT}, "ON_STATE");
476 my $activeString = getGpioActiveString($state);
477
478 $ledNode{gpios} = "<&gpio $macro $activeString>";
479
480 $leds{$name} = { %ledNode };
481 }
482
483 return %leds;
484}
485
486
487#Returns a either GPIO_ACTIVE_HIGH or GPIO_ACTIVE_LOW
488# $val = either a 1 or a 0 for active high or low
489sub getGpioActiveString() {
490 my $val = shift;
491
492 if ($val == 0) {
493 return "GPIO_ACTIVE_LOW";
494 }
495
496 return "GPIO_ACTIVE_HIGH";
497}
498
499
500#Turns a GPIO number into something like ASPEED_GPIO(A, 0) for the
501#ASPEED GPIO numbering scheme A[0-7] -> Z[0-7] and then starts at
502#AA[0-7] after that.
503# $num = the GPIO number
504sub getAspeedGpioMacro() {
505 my $num = shift;
506 my $char;
507 my $offset = $num % 8;
508 my $block = int($num / 8);
509
510 #If past Z, wraps to AA, AB, etc
511 if ((ord('A') + $block) > ord('Z')) {
512 #how far past Z?
513 $char = $block - (ord('Z') - ord('A'));
514
515 #Don't let it wrap twice
516 if ($char > (ord('Z') - ord('A') + 1)) {
517 die "ERROR: Invalid PIN_NUM value $num found for GPIO\n";
518 }
519
520 #start back at 'A' again, and convert to a character
521 $char = chr($char + ord('A') - 1);
522
523 #Add in a bonus 'A', to get something like AB
524 $char = "A".$char;
525 }
526 else {
527 $char = ord('A') + $block;
528 $char = chr($char);
529 }
530
531 return "ASPEED_GPIO($char, $offset)";
532}
533
534
535#Returns a list of hashes that represent the UART nodes on the BMC by
536#finding the UART connections.
537#Nodes will look like:
538# &uartX {
539# status = "okay"
540# }
541sub getUARTNodes()
542{
543 my @nodes;
544
Matt Spinler23d47c22016-10-04 12:31:21 -0500545 #Using U750 for legacy MRW reasons
Matt Spinler18d5f572016-11-15 15:25:45 -0600546 my $connections = $g_targetObj->findConnections($g_bmc, "U750");
Matt Spinler995f2a22016-09-30 13:07:31 -0500547
548 if ($connections eq "") {
549 print "WARNING: No UART buses found connected to the BMC\n";
550 return @nodes;
551 }
552
553 foreach my $uart (@{$connections->{CONN}}) {
554 my %node;
555
556 my $num = $g_targetObj->getAttribute($uart->{SOURCE}, "CHIP_UNIT");
557 my $name = "uart$num";
558
559 $node{$name}{status} = "okay";
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500560 $node{$name}{COMMENT} = connectionComment($uart);
Matt Spinler995f2a22016-09-30 13:07:31 -0500561
Matt Spinler2efdcba2016-11-08 15:37:20 -0600562 #Add in any pinctrl properties. These would come from the parent
563 #of $uart{SOURCE}, which would be a unit-pingroup-bmc if the
564 #pins for this connection are multi-function.
565 addPinCtrlProps($g_targetObj->getTargetParent($uart->{SOURCE}),
566 \%{$node{$name}});
567
Matt Spinler995f2a22016-09-30 13:07:31 -0500568 push @nodes, { %node };
569 }
570
Matt Spinler7d381e12016-09-27 14:27:24 -0500571 return @nodes;
572}
573
574
Matt Spinler995f2a22016-09-30 13:07:31 -0500575#Returns a list of hashes that represent the MAC (ethernet) nodes on the BMC
576#by finding the connections of type ETHERNET.
577#Nodes will look like:
578# &macX {
579# ...
580# }
581sub getMacNodes()
582{
583 my @nodes;
584
Matt Spinler18d5f572016-11-15 15:25:45 -0600585 my $connections = $g_targetObj->findConnections($g_bmc, "ETHERNET");
Matt Spinler995f2a22016-09-30 13:07:31 -0500586
587 if ($connections eq "") {
588 print "WARNING: No ethernet buses found connected to the BMC\n";
589 return @nodes;
590 }
591
592 foreach my $eth (@{$connections->{CONN}}) {
593 my %node;
594
595 my $num = $g_targetObj->getAttribute($eth->{SOURCE}, "CHIP_UNIT");
596 my $ncsi = $g_targetObj->getAttribute($eth->{SOURCE}, "NCSI_MODE");
597 my $hwChecksum = $g_targetObj->getAttribute($eth->{SOURCE},
598 "USE_HW_CHECKSUM");
599
600 my $name = "mac$num";
601 $node{$name}{status} = "okay";
602
603 if ($ncsi == 1) {
Matt Spinler74909132016-10-07 13:52:19 -0500604 $node{$name}{"use-ncsi"} = ZERO_LENGTH_PROPERTY;
Matt Spinler995f2a22016-09-30 13:07:31 -0500605 }
606 if ($hwChecksum == 0) {
Matt Spinler74909132016-10-07 13:52:19 -0500607 $node{$name}{"no-hw-checksum"} = ZERO_LENGTH_PROPERTY;
Matt Spinler995f2a22016-09-30 13:07:31 -0500608 }
609
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500610 $node{$name}{COMMENT} = connectionComment($eth);
Matt Spinler995f2a22016-09-30 13:07:31 -0500611
Matt Spinler2efdcba2016-11-08 15:37:20 -0600612 #Add in any pinctrl properties. These would come from the parent
613 #of $eth{SOURCE}, which would be a unit-pingroup-bmc if the
614 #pins for this connection are multi-function.
615 addPinCtrlProps($g_targetObj->getTargetParent($eth->{SOURCE}),
616 \%{$node{$name}});
617
Matt Spinler995f2a22016-09-30 13:07:31 -0500618 push @nodes, { %node };
619 }
620
621 return @nodes;
622}
623
624
625#Returns a list of hashes that represent the virtual UART nodes
626#Node will look like:
627# &vuart {
628# status = "okay"
629# }
Matt Spinler7d381e12016-09-27 14:27:24 -0500630sub getVuartNodes()
631{
632 my @nodes;
633 my %node;
634
635 #For now, enable 1 node all the time.
Matt Spinler995f2a22016-09-30 13:07:31 -0500636 #TBD if this needs to be fixed
Matt Spinler7d381e12016-09-27 14:27:24 -0500637 $node{vuart}{status} = "okay";
638
639 push @nodes, { %node };
640
641 return @nodes;
642}
643
Matt Spinler74909132016-10-07 13:52:19 -0500644#Returns a list of hashes that represent the I2C device nodes.
645#There is 1 parent node for each bus, which then have subnodes
646#for each device on that bus. If a bus doesn't have any
647#attached devices, it doesn't need to show up.
648#The nodes will look like:
649# &i2c0 {
650# status = "okay"
651# device1@addr { (addr = 7 bit I2C address)
652# reg = <addr>
653# compatible = ...
654# ...
655# }
656# device2@addr {
657# reg = <addr>
658# ...
659# }
660# }
661# &i2c1 {
662# ...
663# }
664sub getI2CNodes()
665{
666 my @nodes;
667 my %busNodes;
668
Matt Spinler18d5f572016-11-15 15:25:45 -0600669 my $connections = $g_targetObj->findConnections($g_bmc, "I2C");
Matt Spinler74909132016-10-07 13:52:19 -0500670
671 if ($connections eq "") {
672 print "WARNING: No I2C buses found connected to the BMC\n";
673 return @nodes;
674 }
675
676 foreach my $i2c (@{$connections->{CONN}}) {
677
678 my %deviceNode, my $deviceName;
679
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500680 $deviceNode{COMMENT} = connectionComment($i2c);
Matt Spinler74909132016-10-07 13:52:19 -0500681
682 $deviceName = lc $i2c->{DEST_PARENT};
683 $deviceName =~ s/-\d+$//; #remove trailing position
684 $deviceName =~ s/.*\///; #remove the front of the path
685
686 #Get the I2C address
687 my $i2cAddress = $g_targetObj->getAttribute($i2c->{DEST}, "I2C_ADDRESS");
688 $i2cAddress = hex($i2cAddress);
689 if ($i2cAddress == 0) {
690 die "ERROR: Missing I2C address on $i2c->{DEST}\n";
691 }
692
693 #Put it in the format we want to print it in
694 $i2cAddress = adjustI2CAddress($i2cAddress);
695 $deviceNode{reg} = "<$i2cAddress>";
696
697 $deviceName = makeNodeName($deviceName, $deviceNode{reg});
698
699 #Get the I2C bus number
700 if ($g_targetObj->isBadAttribute($i2c->{SOURCE},
701 "I2C_PORT")) {
702 die "ERROR: I2C_PORT attribute in $i2c->{DEST_PARENT} " .
703 "is either missing or empty.\n";
704 }
705
706 my $busNum = $g_targetObj->getAttribute($i2c->{SOURCE}, "I2C_PORT");
707 if ($busNum =~ /0x/i) {
708 $busNum = hex($busNum);
709 }
710
711 #Convert the number to the Linux numbering scheme.
Matt Spinler30b461c2016-10-10 16:50:07 -0500712 $busNum += $g_i2cBusAdjust;
Matt Spinler74909132016-10-07 13:52:19 -0500713
714 #Get the compatible property
715 if ($g_targetObj->isBadAttribute($i2c->{DEST_PARENT},
716 "BMC_DT_COMPATIBLE")) {
717 die "ERROR: BMC_DT_COMPATIBLE attribute in $i2c->{DEST_PARENT} " .
718 "is either missing or empty.\n";
719 }
720
721 $deviceNode{compatible} = $g_targetObj->getAttribute(
722 $i2c->{DEST_PARENT},
723 "BMC_DT_COMPATIBLE");
724
725 #Get any other part specific properties, where the property
726 #names are actually defined in the XML.
727 my %props = getPartDefinedDTProperties($i2c->{DEST_PARENT});
728 foreach my $prop (sort keys %props) {
729 $deviceNode{$prop} = $props{$prop};
730 }
731
732 #busNodeName is the hash twice so when we loop
733 #below it doesn't get lost
734 my $busNodeName = "i2c$busNum";
735 $busNodes{$busNodeName}{$busNodeName}{status} = "okay";
736 $busNodes{$busNodeName}{$busNodeName}{$deviceName} = { %deviceNode };
Matt Spinler2efdcba2016-11-08 15:37:20 -0600737
738 #Add in any pinctrl properties. These would come from the parent
739 #of $i2c{SOURCE}, which would be a unit-pingroup-bmc if the
740 #pins for this connection are multi-function.
741 addPinCtrlProps($g_targetObj->getTargetParent($i2c->{SOURCE}),
742 \%{$busNodes{$busNodeName}{$busNodeName}});
Matt Spinler74909132016-10-07 13:52:19 -0500743 }
744
745 #Each bus gets its own hash entry in the array
746 for my $b (sort keys %busNodes) {
747 push @nodes, { %{$busNodes{$b}} };
748 }
749
750 return @nodes;
751}
752
753
754#Returns a hash of property names and values that should be stored in
755#the device tree node for this device. The names of the properties and
756#the attributes to find their values in are stored in the
757#BMC_DT_ATTR_NAMES attribute in the chip.
758# $chip = the chip target
759sub getPartDefinedDTProperties()
760{
761 my $chip = shift;
762 my %props;
763
764 if ($g_targetObj->isBadAttribute($chip, "BMC_DT_ATTR_NAMES")) {
765 return %props;
766 }
767
768 my $attr = $g_targetObj->getAttribute($chip, "BMC_DT_ATTR_NAMES");
769 $attr =~ s/\s//g;
770 my @names = split(',', $attr);
771
772 #There can be up to 4 entries in this attribute
773 for (my $i = 0; $i < scalar @names; $i += 2) {
774
775 #$names[$i] holds the name of the attribute.
776 #$names[$i+1] holds the name of the property to store its value in.
777 if (($names[$i] ne "NA") && ($names[$i] ne "")) {
778
779 my $val = $g_targetObj->getAttribute($chip, $names[$i]);
780
781 #if the value is empty, assume it's for a standalone property,
782 #which gets turned into: some-property;
783 if ($val eq "") {
784 $props{$names[$i+1]} = ZERO_LENGTH_PROPERTY;
785 }
786 else {
787 $props{$names[$i+1]} = "<$val>";
788 }
789 }
790 }
791
792 return %props;
793}
794
795
796#Convert the MRW I2C address into the format the dts needs
797# $addr = the I2C Address
798sub adjustI2CAddress()
799{
800 my $addr = shift;
801
802 #MRW holds the 8 bit value. We need the 7 bit one.
Matt Spinler96f8f242016-11-28 16:26:57 -0600803 $addr = $addr >> 1;
Matt Spinler74909132016-10-07 13:52:19 -0500804 $addr = sprintf("0x%X", $addr);
805 $addr = lc $addr;
806
807 return $addr;
808}
809
810
Matt Spinler30b461c2016-10-10 16:50:07 -0500811#Sets the global $g_i2cBusAdjust from the configuration file.
812sub getI2CBusAdjust()
Matt Spinler74909132016-10-07 13:52:19 -0500813{
Matt Spinler30b461c2016-10-10 16:50:07 -0500814 if (exists $g_configuration{"i2c-bus-adjust"}) {
Matt Spinler74909132016-10-07 13:52:19 -0500815
Matt Spinler30b461c2016-10-10 16:50:07 -0500816 $g_i2cBusAdjust = $g_configuration{"i2c-bus-adjust"};
Matt Spinler74909132016-10-07 13:52:19 -0500817
Matt Spinler30b461c2016-10-10 16:50:07 -0500818 if (!looks_like_number($g_i2cBusAdjust)) {
819 die "ERROR: Invalid i2c-bus-adjust value $g_i2cBusAdjust " .
820 "found in config file.\n";
Matt Spinler7d381e12016-09-27 14:27:24 -0500821 }
822 }
Matt Spinler30b461c2016-10-10 16:50:07 -0500823 else {
824 $g_i2cBusAdjust = 0;
825 print "WARNING: No I2C Bus number adjustment done " .
826 "for this system.\n";
827 }
Matt Spinler7d381e12016-09-27 14:27:24 -0500828}
829
830
Matt Spinler2efdcba2016-11-08 15:37:20 -0600831
832#Adds two pinctrl properties to the device node hash passed in,
833#if specified in the MRW. Pin Control refers to a mechanism for
834#Linux to know which function of a multi-function pin to configure.
835#For example, a pin could either be configured to be a GPIO, or
836#an I2C clock line. The pin function depends on board wiring,
837#so is known by the MRW.
838# $target = the target to get the BMC_DT_PINCTRL_FUNCTS attribute from
839# $node = a hash reference to the device tree node to add the properties to
840sub addPinCtrlProps()
841{
842 my ($target, $node) = @_;
843
844 if (!$g_targetObj->isBadAttribute($target, "BMC_DT_PINCTRL_FUNCS")) {
845 my $attr = $g_targetObj->getAttribute($target,
846 "BMC_DT_PINCTRL_FUNCS");
847
848 my $pinCtrl0Prop = makePinCtrl0PropValue($attr);
849 if ($pinCtrl0Prop ne "") {
850 $node->{"pinctrl-names"} = "default";
851 $node->{"pinctrl-0"} = $pinCtrl0Prop;
852 }
853 }
854}
855
856
857#Constructs the pinctrl-0 property value based on the
858#BMC_DT_PINCTRL_FUNCS attribute passed in.
859# $attr = BMC_DT_PINCTRL_FUNCS attribute value, which is an array
860sub makePinCtrl0PropValue()
861{
862 my $attr = shift;
863 my @entries;
864 my $value = "";
865
866 $attr =~ s/\s//g;
867 my @funcs = split(',', $attr);
868 foreach my $func (@funcs) {
869 if (($func ne "NA") && ($func ne "")) {
870 push @entries, $func;
871 }
872 }
873
874 #<&pinctrl_funcA_default &pinctrl_funcB_default ...>
875 if (scalar @entries) {
876 $value = "<";
877 foreach my $entry (@entries) {
878 $value .= "&pinctrl_".$entry."_default ";
879 }
880 $value =~ s/\s$//; #Remove the trailing space
881 $value .= ">";
882 }
883
884 return $value;
885}
886
887
Matt Spinler7d381e12016-09-27 14:27:24 -0500888#Returns a list of compatible fields for the BMC itself.
889sub getBMCCompatibles()
890{
891 my @compats;
892
Matt Spinler23d47c22016-10-04 12:31:21 -0500893 #1st entry: <system mfgr>,<system name>-bmc
894 #2nd entry: <bmc mfgr>,<bmc model>
Matt Spinler7d381e12016-09-27 14:27:24 -0500895
Matt Spinler23d47c22016-10-04 12:31:21 -0500896 foreach my $target (sort keys %{ $g_targetObj->getAllTargets() }) {
897 if ($g_targetObj->getType($target) eq "SYS") {
898 my $mfgr = $g_targetObj->getAttribute($target, "MANUFACTURER");
899 push @compats, lc "$mfgr,$g_systemName-bmc";
900 last;
901 }
Matt Spinler7d381e12016-09-27 14:27:24 -0500902 }
903
904 push @compats, lc($g_bmcMfgr).",".lc($g_bmcModel);
905
906 return @compats;
907}
908
909
910#Returns a string for the system's BMC model property
911sub getSystemBMCModel()
912{
Matt Spinler995f2a22016-09-30 13:07:31 -0500913 #'<System> BMC'
Matt Spinler7d381e12016-09-27 14:27:24 -0500914 my $sys = lc $g_systemName;
915 $sys = uc(substr($sys, 0, 1)) . substr($sys, 1);
916
917 return $sys . " BMC";
918}
919
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500920#Create the comment that will show up in the device tree
921#for a connection. In the output, will look like:
922# // sourceUnit ->
923# // destChip
924#
925# $conn = The connection hash reference
926sub connectionComment()
927{
928 my $conn = shift;
929 my $comment = "$conn->{SOURCE} ->\n$conn->{DEST_PARENT}";
930 return $comment;
931}
932
Matt Spinler7d381e12016-09-27 14:27:24 -0500933
934#Prints a list of nodes at the same indent level
935# $f = file handle
936# $level = indent level (0,1,etc)
937# @nodes = array of node hashes to print, where the
938# key for the hash is the name of the node
939sub printNodes()
940{
941 my ($f, $level, @nodes) = @_;
942
943 foreach my $n (@nodes) {
944 my %node = %$n;
945
946 foreach my $name (sort keys %node) {
947 my %n = %{ $node{$name} };
948 printNode($f, $level, $name, %n);
949 }
950 }
951}
952
953
954#Print a single node and its children
955# $f = file handle
956# $level = indent level (0,1,etc)
957# $name = the name of the node - shows up as:
958# name { ...
959# %vals = The contents of the node, with the following options:
960# if the key is:
961# - 'DTSI_INCLUDE', then value gets turned into a #include
Matt Spinler995f2a22016-09-30 13:07:31 -0500962# - 'COMMENT', then value gets turned into a // comment
Matt Spinler74909132016-10-07 13:52:19 -0500963# - 'ZERO_LENGTH_PROPERTY' then value gets turned into: value;
Matt Spinler7d381e12016-09-27 14:27:24 -0500964#
965# If the value is:
966# - a hash - then that hash gets turned into a child node
967# where the key is the name of the child node
Matt Spinler995f2a22016-09-30 13:07:31 -0500968# - an array of hashes indicates an array of child nodes
Matt Spinler7d381e12016-09-27 14:27:24 -0500969sub printNode()
970{
971 my ($f, $level, $name, %vals) = @_;
972 my $include = "";
973
Matt Spinlerc0dff8a2016-11-02 15:47:30 -0500974 #No reason to print an empty node
975 if (!keys %vals) {
976 return;
977 }
978
Matt Spinler7d381e12016-09-27 14:27:24 -0500979 if ($level == 0) {
980 $name = "&".$name;
981 }
982
Matt Spinler995f2a22016-09-30 13:07:31 -0500983 print $f "\n";
984
985 if (exists $vals{COMMENT}) {
986 my @lines = split('\n', $vals{COMMENT});
987 foreach my $l (@lines) {
988 print $f indent($level) . "// $l\n";
989 }
990 }
991
992 print $f indent($level) . "$name {\n";
Matt Spinler7d381e12016-09-27 14:27:24 -0500993
Matt Spinler74909132016-10-07 13:52:19 -0500994 #First print properties, then includes, then subnodes
995
996 #Print Properties
Matt Spinler7d381e12016-09-27 14:27:24 -0500997 foreach my $v (sort keys %vals) {
998
Matt Spinler995f2a22016-09-30 13:07:31 -0500999 next if ($v eq "COMMENT");
Matt Spinler74909132016-10-07 13:52:19 -05001000 next if ($v eq "DTSI_INCLUDE");
1001 next if (ref($vals{$v}) eq "HASH");
1002 next if (ref($vals{$v}) eq "ARRAY");
Matt Spinler995f2a22016-09-30 13:07:31 -05001003
Matt Spinler74909132016-10-07 13:52:19 -05001004 if ($vals{$v} ne ZERO_LENGTH_PROPERTY) {
1005 printProperty($f, $level+1, $v, $vals{$v});
Matt Spinler7d381e12016-09-27 14:27:24 -05001006 }
Matt Spinler74909132016-10-07 13:52:19 -05001007 else {
1008 printZeroLengthProperty($f, $level+1, $v);
1009 }
1010 }
1011
1012 #Print Includes
1013 foreach my $v (sort keys %vals) {
1014
1015 if ($v eq "DTSI_INCLUDE") {
1016 #print 1 include per line
1017 my @incs = split(',', $vals{$v});
1018 foreach my $i (@incs) {
1019 print $f qq(#include "$i";\n);
1020 }
1021 }
1022 }
1023
1024 #Print Nodes
1025 foreach my $v (sort keys %vals) {
1026
1027 if (ref($vals{$v}) eq "HASH") {
Matt Spinler7d381e12016-09-27 14:27:24 -05001028 printNode($f, $level+1, $v, %{$vals{$v}});
1029 }
Matt Spinler995f2a22016-09-30 13:07:31 -05001030 #An array of nested nodes
1031 elsif (ref($vals{$v}) eq "ARRAY") {
1032 my @array = @{$vals{$v}};
1033 &printNodes($f, $level+1, @array);
1034 }
Matt Spinler7d381e12016-09-27 14:27:24 -05001035 }
1036
1037 print $f indent($level) . "};\n";
1038}
1039
1040
1041#Prints a comma separated list of properties.
1042#e.g. a = "b, c, d";
1043# $f = file handle
1044# $level = indent level (0,1,etc)
1045# $name = name of property
1046# @vals = list of property values
1047sub printPropertyList()
1048{
1049 my ($f, $level, $name, @vals) = @_;
1050
1051 print $f indent($level) . "$name = ";
1052
1053 for (my $i = 0;$i < scalar @vals; $i++) {
Matt Spinler30b461c2016-10-10 16:50:07 -05001054 print $f qq("$vals[$i]");
Matt Spinler7d381e12016-09-27 14:27:24 -05001055 if ($i < (scalar(@vals) - 1)) {
1056 print $f ", ";
1057 }
1058 }
1059 print $f ";\n"
1060}
1061
1062
1063#Prints a single property. e.g. a = "b";
1064# $f = file handle
1065# $level = indent level (0,1,etc)
1066# $name = name of property
1067# @vals = property values
1068sub printProperty()
1069{
1070 my ($f, $level, $name, $val) = @_;
Matt Spinler30b461c2016-10-10 16:50:07 -05001071 my $quoteChar = qq(");
Matt Spinler23d47c22016-10-04 12:31:21 -05001072
Matt Spinler30b461c2016-10-10 16:50:07 -05001073 $val = convertReference($val);
Matt Spinler23d47c22016-10-04 12:31:21 -05001074
1075 #properties with < > or single word aliases don't need quotes
1076 if (($val =~ /<.*>/) || ($val =~ /^&\w+$/)) {
Matt Spinler30b461c2016-10-10 16:50:07 -05001077 $quoteChar = "";
Matt Spinler23d47c22016-10-04 12:31:21 -05001078 }
1079
Matt Spinler30b461c2016-10-10 16:50:07 -05001080 print $f indent($level) . "$name = $quoteChar$val$quoteChar;\n";
Matt Spinler7d381e12016-09-27 14:27:24 -05001081}
1082
1083
Matt Spinler30b461c2016-10-10 16:50:07 -05001084#Prints a zero length property e.g. some-property;
Matt Spinler7d381e12016-09-27 14:27:24 -05001085# $f = file handle
1086# $level = indent level (0,1,etc)
1087# $name = name of property
Matt Spinler30b461c2016-10-10 16:50:07 -05001088sub printZeroLengthProperty()
Matt Spinler7d381e12016-09-27 14:27:24 -05001089{
1090 my ($f, $level, $name) = @_;
1091 print $f indent($level) . "$name;\n";
1092}
1093
1094
Matt Spinler30b461c2016-10-10 16:50:07 -05001095#Replace '(ref)' with '&'.
Matt Spinler7d381e12016-09-27 14:27:24 -05001096#Needed because Serverwiz doesn't properly escape '&'s in the XML,
Matt Spinler30b461c2016-10-10 16:50:07 -05001097#so the '(ref)' string is used to represent the reference
Matt Spinler7d381e12016-09-27 14:27:24 -05001098#specifier instead of '&'.
Matt Spinler30b461c2016-10-10 16:50:07 -05001099sub convertReference() {
Matt Spinler7d381e12016-09-27 14:27:24 -05001100 my $val = shift;
Matt Spinler30b461c2016-10-10 16:50:07 -05001101 $val =~ s/\(ref\)/&/g;
Matt Spinler7d381e12016-09-27 14:27:24 -05001102 return $val
1103}
1104
1105
1106#Returns the target for the BMC chip.
1107#Not worrying about multiple BMC systems for now.
1108sub getBMCTarget()
1109{
1110 foreach my $target (sort keys %{ $g_targetObj->getAllTargets() })
1111 {
1112 if ($g_targetObj->getType($target) eq "BMC") {
1113 return $target;
1114 }
1115 }
1116 return "";
1117}
1118
1119
1120#Prints the device tree version line.
1121# $f = file handle
1122sub printVersion()
1123{
1124 my $f = shift;
1125 print $f VERSION."\n"
1126}
1127
1128
1129#Prints the #include line for pulling in an include file.
Matt Spinler30b461c2016-10-10 16:50:07 -05001130#The files to include come from the configuration file.
Matt Spinler7d381e12016-09-27 14:27:24 -05001131# $f = file handle
Matt Spinler30b461c2016-10-10 16:50:07 -05001132# $type = include type
Matt Spinler7d381e12016-09-27 14:27:24 -05001133sub printIncludes()
1134{
Matt Spinler30b461c2016-10-10 16:50:07 -05001135 my ($f, $type) = @_;
1136 my @includes = getIncludes($type);
Matt Spinler7d381e12016-09-27 14:27:24 -05001137
1138 foreach my $i (@includes) {
1139 #if a .dtsi, gets " ", otherwise < >
1140 if ($i =~ /\.dtsi$/) {
Matt Spinler30b461c2016-10-10 16:50:07 -05001141 $i = qq("$i");
Matt Spinler7d381e12016-09-27 14:27:24 -05001142 }
1143 else {
Matt Spinler30b461c2016-10-10 16:50:07 -05001144 $i = "<$i>";
Matt Spinler7d381e12016-09-27 14:27:24 -05001145 }
Matt Spinler30b461c2016-10-10 16:50:07 -05001146 print $f "#include $i\n";
Matt Spinler7d381e12016-09-27 14:27:24 -05001147 }
1148}
1149
1150
Matt Spinler30b461c2016-10-10 16:50:07 -05001151#Returns an array of include files found in the config file
1152#for the type specified.
1153# $type = the include type, which is the section name in the
1154# YAML configuration file.
Matt Spinler7d381e12016-09-27 14:27:24 -05001155sub getIncludes()
1156{
Matt Spinler30b461c2016-10-10 16:50:07 -05001157 my $type = shift;
Matt Spinler7d381e12016-09-27 14:27:24 -05001158 my @includes;
1159
Matt Spinler30b461c2016-10-10 16:50:07 -05001160 #The config file may have a section but no includes
1161 #listed in it, which is OK.
1162 if ((exists $g_configuration{includes}{$type}) &&
1163 (ref($g_configuration{includes}{$type}) eq "ARRAY")) {
Matt Spinler7d381e12016-09-27 14:27:24 -05001164
Matt Spinler30b461c2016-10-10 16:50:07 -05001165 @includes = @{$g_configuration{includes}{$type}};
Matt Spinler7d381e12016-09-27 14:27:24 -05001166 }
1167
1168 return @includes;
1169}
1170
Matt Spinler30b461c2016-10-10 16:50:07 -05001171
Matt Spinler74909132016-10-07 13:52:19 -05001172#Appends the first value of the 'reg' property
1173#passed in to the name passed in to create the
1174#full name for the node
1175# $name = node name that will be appended to
1176# $reg = the reg property values
1177sub makeNodeName()
1178{
1179 my ($name, $reg) = @_;
1180
1181 $reg =~ s/<//g;
1182 $reg =~ s/>//g;
1183 my @vals = split(' ', $reg);
1184
1185 if (scalar @vals > 0) {
1186 $vals[0] =~ s/0x//;
1187 $name .= "@" . lc $vals[0];
1188 }
1189
1190 return $name;
1191}
1192
Matt Spinler7d381e12016-09-27 14:27:24 -05001193
1194#Prints the root node starting bracket.
1195# $f = file handle
1196sub printRootNodeStart() {
1197 my $f = shift;
Matt Spinler30b461c2016-10-10 16:50:07 -05001198 print $f qq(/ {\n);
Matt Spinler7d381e12016-09-27 14:27:24 -05001199}
1200
1201
1202#Prints the root node ending bracket.
1203# $f = file handle
1204# $level = indent level (0,1,etc)
1205sub printRootNodeEnd() {
1206 my ($f, $level) = @_;
Matt Spinler30b461c2016-10-10 16:50:07 -05001207 print $f indent($level).qq(};\n);
Matt Spinler7d381e12016-09-27 14:27:24 -05001208}
1209
1210
1211#Returns a string that can be used to indent based on the
1212#level passed in. Each level is an additional 4 spaces.
1213# $level = indent level (0,1,etc)
1214sub indent() {
1215 my $level = shift;
1216 return ' ' x ($level * 4);
1217}
1218
1219
Matt Spinler7d381e12016-09-27 14:27:24 -05001220sub printUsage
1221{
Matt Spinler30b461c2016-10-10 16:50:07 -05001222 print "gen_devtree.pl -x [XML filename] -y [yaml config file] " .
1223 "-o [output filename]\n";
Matt Spinler7d381e12016-09-27 14:27:24 -05001224 exit(1);
1225}