blob: 066c9496c08957a24a3f1fcc4212115573e239a7 [file] [log] [blame]
Deepak Kodihalli6225e932017-02-07 12:14:55 -06001#! /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 # One or more targets wasn't present in the inventory
68 push @targetTypes, $type;
69 push @paths, $defaultPaths{$type};
70}
71
72open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!";
73print $fh "FRUS=".join ',',@targetTypes;
74print $fh "\n";
75print $fh "PATHS=".join ',',@paths;
76close $fh;
77
78sub printUsage
79{
80 print "
81 $0 -m [MRW file] -c [Config yaml] -o [Output filename]\n";
82 exit(1);
83}