blob: c371658eaeb7a9627504e29911fc9a445cc20a88 [file] [log] [blame]
Deepak Kodihalli9f3e1c12017-02-19 23:39:15 -06001#! /usr/bin/perl
2use strict;
3use warnings;
4
5
6use mrw::Targets;
7use mrw::Inventory;
8use mrw::Util;
9use Getopt::Long;
10use YAML::Tiny qw(LoadFile);
11
12
13my $mrwFile = "";
14my $outFile = "";
15my $configFile = "";
Santosh Puranik51041fc2019-10-08 09:45:15 -050016my $skipBrokenMrw = 0;
Deepak Kodihalli9f3e1c12017-02-19 23:39:15 -060017
18
19GetOptions(
20"m=s" => \$mrwFile,
21"c=s" => \$configFile,
22"o=s" => \$outFile,
Santosh Puranik51041fc2019-10-08 09:45:15 -050023"skip-broken-mrw" => \$skipBrokenMrw
Deepak Kodihalli9f3e1c12017-02-19 23:39:15 -060024)
25or printUsage();
26
27
28if (($mrwFile eq "") or ($configFile eq "") or ($outFile eq ""))
29{
30 printUsage();
31}
32
33
34# Load system MRW
35my $targets = Targets->new;
36$targets->loadXML($mrwFile);
37my @inventory = Inventory::getInventory($targets);
38
39
40# Parse config YAML
41my $targetItems = LoadFile($configFile);
42
43
44# Targets we're interested in, from the config YAML
45my @targetNames = keys %{$targetItems};
46my %targetHash;
47@targetHash{@targetNames} = ();
48
49
50# Target Type : Target inventory path
51my %defaultPaths = (
52 "ETHERNET",
53 Util::getObmcName(
54 \@inventory,
55 Util::getBMCTarget($targets))."/ethernet"
56);
57
58
59open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!";
60# Retrieve OBMC path of targets we're interested in
61for my $item (@inventory) {
62 my $targetType = "";
63 my $path = "";
64
65 if (!$targets->isBadAttribute($item->{TARGET}, "TYPE")) {
66 $targetType = $targets->getAttribute($item->{TARGET}, "TYPE");
67 }
68 next if (not exists $targetItems->{$targetType});
69
70 writeOutput($targetType,
71 $item,
72 $targetItems);
73 delete($targetHash{$targetType});
74}
75writeRemaining($targetItems);
76close $fh;
77
78
79sub writeRemaining
80{
81 my ($yamlDict) = @_;
82 for my $type (keys %targetHash)
83 {
Santosh Puranik51041fc2019-10-08 09:45:15 -050084 if($skipBrokenMrw and !exists $defaultPaths{$type})
85 {
86 next;
87 }
Deepak Kodihalli9f3e1c12017-02-19 23:39:15 -060088 print $fh $defaultPaths{$type}.":";
89 print $fh "\n";
90 while (my ($interface,$propertyMap) = each %{$yamlDict->{$type}})
91 {
92 print $fh " ".$interface.":";
93 print $fh "\n";
94 while (my ($property,$value) = each %{$propertyMap})
95 {
96 $value = "'".$value."'";
97 print $fh " ".$property.": ".$value;
98 print $fh "\n";
99 }
100 }
101 }
102}
103
104
105sub writeOutput
106{
107 my ($type, $item, $yamlDict) = @_;
108 print $fh $item->{OBMC_NAME}.":";
109 print $fh "\n";
110 while (my ($interface,$propertyMap) = each %{$yamlDict->{$type}})
111 {
112 print $fh " ".$interface.":";
113 print $fh "\n";
114 while (my ($property,$value) = each %{$propertyMap})
115 {
116 $value = getValue($item, $property, $value);
117 print $fh " ".$property.": ".$value;
118 print $fh "\n";
119 }
120 }
121}
122
123
124sub getValue
125{
126 my ($item, $property, $value) = @_;
127 $value = "'".$value."'";
128
129 if ($property eq "FieldReplaceable")
130 {
131 $value = "'false'";
132 if (!$targets->isBadAttribute($item->{TARGET}, "RU_TYPE"))
133 {
134 my $ruType = $targets->getAttribute($item->{TARGET}, "RU_TYPE");
135 if (($ruType eq "FRU") || ($ruType eq "CRU"))
136 {
137 $value = "'true'";
138 }
139 }
140 }
141
142 return $value;
143}
144
145
146sub printUsage
147{
148 print "
Santosh Puranik51041fc2019-10-08 09:45:15 -0500149 $0 -m [MRW file] -c [Config yaml] -o [Output filename] [OPTIONS]
150Options:
151 --skip-broken-mrw = Skip broken MRW targets
152 \n";
Deepak Kodihalli9f3e1c12017-02-19 23:39:15 -0600153 exit(1);
154}