diff options
-rw-r--r-- | Util.pm | 23 | ||||
-rwxr-xr-x | gen_ipmi_fru.pl | 19 | ||||
-rwxr-xr-x | gen_openpower_fru.pl | 83 |
3 files changed, 108 insertions, 17 deletions
@@ -43,6 +43,24 @@ sub getChildUnitsWithTargetType return @units; } +# Returns OBMC name corresponding to a Target name +# param[in] \@inventory = reference to array of inventory items +# param[in] $targetName = A Target name +sub getObmcName +{ + my ($inventory_ref, $targetName) = @_; + my @inventory = @{ $inventory_ref }; + + for my $item (@inventory) + { + if($item->{TARGET} eq $targetName) + { + return $item->{OBMC_NAME}; + } + } + return undef; +} + 1; =head1 NAME @@ -67,6 +85,11 @@ it will die. Currently supports single BMC systems. Returns an array of targets that have target-type C<TargetType> and are children (any level) of target C<ChipTarget>. +=item getObmcName(C<InventoryItems>, C<TargetName>) + +Returns an OBMC name corresponding to a Target name. Returns +undef if the Target name is not found. + =back =cut diff --git a/gen_ipmi_fru.pl b/gen_ipmi_fru.pl index 99884d9..5465d84 100755 --- a/gen_ipmi_fru.pl +++ b/gen_ipmi_fru.pl @@ -4,6 +4,7 @@ use warnings; use mrw::Targets; use mrw::Inventory; +use mrw::Util; use Getopt::Long; # For parsing command line arguments use YAML::Tiny qw(LoadFile); @@ -106,7 +107,7 @@ for my $item (@inventory) { printDebug(" ".$child); printDebug(" Type:".$fruType ); - my $childObmcName = getObmcName(\@inventory, $child); + my $childObmcName = Util::getObmcName(\@inventory, $child); writeToFile($fruType, $childObmcName, $fruTypeConfig, $fh); } } @@ -114,22 +115,6 @@ close $fh; #------------------------------------END OF MAIN----------------------- -# Map an MRW name to corresponding OBMC name -sub getObmcName -{ - my $inventory = $_[0]; # Inventory items - my $target = $_[1]; # MRW Target name - for my $item (@inventory) - { - if($item->{TARGET} eq $target) - { - return $item->{OBMC_NAME}; - } - } - return undef; -} - - #Get the metdata for the incoming frutype from the loaded config file. #Write the FRU data into the output file diff --git a/gen_openpower_fru.pl b/gen_openpower_fru.pl new file mode 100755 index 0000000..066c949 --- /dev/null +++ b/gen_openpower_fru.pl @@ -0,0 +1,83 @@ +#! /usr/bin/perl +use strict; +use warnings; + +use mrw::Targets; +use mrw::Inventory; +use mrw::Util; +use Getopt::Long; +use YAML::Tiny qw(LoadFile); + +my $mrwFile = ""; +my $outFile = ""; +my $configFile = ""; + +GetOptions( +"m=s" => \$mrwFile, +"c=s" => \$configFile, +"o=s" => \$outFile, +) +or printUsage(); + +if (($mrwFile eq "") or ($configFile eq "") or ($outFile eq "")) +{ + printUsage(); +} + +# Load system MRW +my $targets = Targets->new; +$targets->loadXML($mrwFile); +my @inventory = Inventory::getInventory($targets); + +# Target Type : Target inventory path +my %defaultPaths = ( + "ETHERNET", + Util::getObmcName( + \@inventory, + Util::getBMCTarget($targets))."/ethernet" +); + +# Parse config YAML +my $targetItems = LoadFile($configFile); + +# Targets we're interested in, from the config YAML +my @targetNames = keys %{$targetItems}; +my %targetHash; +@targetHash{@targetNames} = (); +my @targetTypes; +my @paths; + +# Retrieve OBMC path of targets we're interested in +for my $item (@inventory) { + my $targetType = ""; + my $path = ""; + + if (!$targets->isBadAttribute($item->{TARGET}, "TYPE")) { + $targetType = $targets->getAttribute($item->{TARGET}, "TYPE"); + } + next if (not exists $targetHash{$targetType}); + + push @targetTypes, $targetType; + push @paths, $item->{OBMC_NAME}; + delete($targetHash{$targetType}); +} + +for my $type (keys %targetHash) +{ + # One or more targets wasn't present in the inventory + push @targetTypes, $type; + push @paths, $defaultPaths{$type}; +} + +open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!"; +print $fh "FRUS=".join ',',@targetTypes; +print $fh "\n"; +print $fh "PATHS=".join ',',@paths; +close $fh; + +sub printUsage +{ + print " + $0 -m [MRW file] -c [Config yaml] -o [Output filename]\n"; + exit(1); +} |