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