1#! /usr/bin/perl 2use strict; 3use warnings; 4 5use mrw::Targets; 6use mrw::Inventory; 7use mrw::Util; 8use Getopt::Long; 9use YAML::Tiny qw(LoadFile); 10 11my $mrwFile = ""; 12my $outFile = ""; 13my $configFile = ""; 14 15GetOptions( 16"m=s" => \$mrwFile, 17"c=s" => \$configFile, 18"o=s" => \$outFile, 19) 20or printUsage(); 21 22if (($mrwFile eq "") or ($configFile eq "") or ($outFile eq "")) 23{ 24 printUsage(); 25} 26 27# Load system MRW 28my $targets = Targets->new; 29$targets->loadXML($mrwFile); 30my @inventory = Inventory::getInventory($targets); 31 32# Target Type : Target inventory path 33my %defaultPaths = ( 34 "ETHERNET", 35 Util::getObmcName( 36 \@inventory, 37 Util::getBMCTarget($targets))."/ethernet" 38); 39 40# Parse config YAML 41my $targetItems = LoadFile($configFile); 42 43# Targets we're interested in, from the config YAML 44my @targetNames = keys %{$targetItems}; 45my %targetHash; 46@targetHash{@targetNames} = (); 47my @targetTypes; 48my @paths; 49 50# Retrieve OBMC path of targets we're interested in 51for my $item (@inventory) { 52 my $targetType = ""; 53 my $path = ""; 54 55 if (!$targets->isBadAttribute($item->{TARGET}, "TYPE")) { 56 $targetType = $targets->getAttribute($item->{TARGET}, "TYPE"); 57 } 58 59 my @types = grep(/$targetType$/, @targetTypes); 60 61 next if (length($targetType) == 0 || 62 ((not exists $targetHash{$targetType}) && (scalar @types == 0))); 63 64 push @targetTypes, $targetType; 65 push @paths, $item->{OBMC_NAME}; 66 delete($targetHash{$targetType}); 67} 68 69for my $type (keys %targetHash) 70{ 71 if(defined $defaultPaths{$type}) 72 { 73 # One or more targets wasn't present in the inventory 74 push @targetTypes, $type; 75 push @paths, $defaultPaths{$type}; 76 } 77} 78 79open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!"; 80print $fh "FRUS=".join ',',@targetTypes; 81print $fh "\n"; 82print $fh "PATHS=".join ',',@paths; 83close $fh; 84 85sub printUsage 86{ 87 print " 88 $0 -m [MRW file] -c [Config yaml] -o [Output filename]\n"; 89 exit(1); 90} 91