gen_devtree: Add two wrapper functions
Added statusOK() and addRegProp().
Change-Id: I64bd7c666b6b7f79774e0839af365e46bf2ce198
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/gen_devtree.pl b/gen_devtree.pl
index 2b58203..d4f27e8 100755
--- a/gen_devtree.pl
+++ b/gen_devtree.pl
@@ -205,8 +205,9 @@
#Future: could do more validation on the actual values
- $memory{reg} = "<$g_configuration{memory}{base} " .
- "$g_configuration{memory}{size}>";
+ addRegProp(\%memory,
+ $g_configuration{memory}{base},
+ $g_configuration{memory}{size});
return %memory;
}
@@ -284,7 +285,7 @@
"$size is invalid\n";
}
- $node{"reg"} = "<$base $size>";
+ addRegProp(\%node, $base, $size);
my $name = makeNodeName("region", $node{reg});
return ($name, \%node);
@@ -337,7 +338,7 @@
die "ERROR: No BMC SPI flashes found connected to the BMC\n";
}
- $bmcFlash{fmc}{status} = "okay";
+ statusOK(\%{$bmcFlash{fmc}});
foreach my $spi (@{$connections->{CONN}}) {
@@ -353,7 +354,7 @@
$bmcFlash{fmc}{$flashName}{COMMENT} = connectionComment($spi);
- $bmcFlash{fmc}{$flashName}{status} = "okay";
+ statusOK(\%{$bmcFlash{fmc}{$flashName}});
#Add in anything specified in the config file for this chip.
addBMCFlashConfigProperties(\%{$bmcFlash{fmc}{$flashName}},
@@ -490,7 +491,7 @@
my $unitNum = $g_targetObj->getAttribute($spi->{SOURCE},
"CHIP_UNIT");
if ($unitNum == $spiNum) {
- $spiMaster{status} = "okay";
+ statusOK(\%spiMaster);
#Add in any pinctrl properties. These would come from the parent
#of $spi{SOURCE}, which would be a unit-pingroup-bmc if the
@@ -502,7 +503,7 @@
$spiMaster{$flashName}{COMMENT} = connectionComment($spi);
- $spiMaster{$flashName}{status} = "okay";
+ statusOK(\%{$spiMaster{$flashName}});
#AST2500 PNORs need a label
my $function = $g_targetObj->getAttribute($spi->{SOURCE},
@@ -531,7 +532,7 @@
{
my %node;
if (exists $g_configuration{"lpc-host-spi-flash-mailbox"}) {
- $node{status} = "okay";
+ statusOK(\%node);
}
return %node;
@@ -551,7 +552,7 @@
my %node;
if (exists $g_configuration{"lpc-host-spi-flash-mailbox"}) {
- $node{status} = "okay";
+ statusOK(\%node);
#Point to the reserved-memory region label
$node{"memory-region"} = "<(ref)" .
@@ -696,7 +697,7 @@
my $num = $g_targetObj->getAttribute($uart->{SOURCE}, "CHIP_UNIT");
my $name = "uart$num";
- $node{$name}{status} = "okay";
+ statusOK(\%{$node{$name}});
$node{$name}{COMMENT} = connectionComment($uart);
#Add in any pinctrl properties. These would come from the parent
@@ -738,7 +739,7 @@
"USE_HW_CHECKSUM");
my $name = "mac$num";
- $node{$name}{status} = "okay";
+ statusOK(\%{$node{$name}});
if ($ncsi == 1) {
$node{$name}{"use-ncsi"} = ZERO_LENGTH_PROPERTY;
@@ -774,7 +775,7 @@
#For now, enable 1 node all the time.
#TBD if this needs to be fixed
- $node{vuart}{status} = "okay";
+ statusOK(\%{$node{vuart}});
push @nodes, { %node };
@@ -832,7 +833,7 @@
#Put it in the format we want to print it in
$i2cAddress = adjustI2CAddress($i2cAddress);
- $deviceNode{reg} = "<$i2cAddress>";
+ addRegProp(\%deviceNode, $i2cAddress);
$deviceName = makeNodeName($deviceName, $deviceNode{reg});
@@ -872,7 +873,7 @@
#busNodeName is the hash twice so when we loop
#below it doesn't get lost
my $busNodeName = "i2c$busNum";
- $busNodes{$busNodeName}{$busNodeName}{status} = "okay";
+ statusOK(\%{$busNodes{$busNodeName}{$busNodeName}});
$busNodes{$busNodeName}{$busNodeName}{$deviceName} = { %deviceNode };
#Add in any pinctrl properties. These would come from the parent
@@ -1355,6 +1356,36 @@
}
+#Adds a {status} = "okay" element to the hash passed in.
+# $node = reference to the hash to add element to
+sub statusOK
+{
+ my $node = shift;
+ $node->{status} = "okay";
+}
+
+
+#Adds the {reg} element to the hash passed in using the values
+#passed in. Resulting value looks like: "<val1 val2 etc>"
+# $node = reference to the hash to add element to
+# @values = the values for the property. May be passed in one at
+# a time and not as an array.
+sub addRegProp
+{
+ my $node = shift;
+ my @values = @_;
+
+ $node->{reg} = "<";
+ for (my $i = 0; $i < scalar @values; $i++) {
+ $node->{reg} .= $values[$i];
+ if ($i < (scalar @values) - 1) {
+ $node->{reg} .= " ";
+ }
+ }
+ $node->{reg} .= ">";
+}
+
+
sub printUsage
{
print "gen_devtree.pl -x [XML filename] -y [yaml config file] " .