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 next if (not exists $targetHash{$targetType}); 59 60 push @targetTypes, $targetType; 61 push @paths, $item->{OBMC_NAME}; 62 delete($targetHash{$targetType}); 63} 64 65for my $type (keys %targetHash) 66{ 67 if(defined $defaultPaths{$type}) 68 { 69 # One or more targets wasn't present in the inventory 70 push @targetTypes, $type; 71 push @paths, $defaultPaths{$type}; 72 } 73} 74 75open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!"; 76print $fh "FRUS=".join ',',@targetTypes; 77print $fh "\n"; 78print $fh "PATHS=".join ',',@paths; 79close $fh; 80 81sub printUsage 82{ 83 print " 84 $0 -m [MRW file] -c [Config yaml] -o [Output filename]\n"; 85 exit(1); 86} 87