blob: 587c86fa42baf2bc3ac4a4b17b322994ffd9691d [file] [log] [blame]
Deepak Kodihallic54679c2017-02-22 04:21:09 -06001#! /usr/bin/perl
2use strict;
3use warnings;
4
5
6use mrw::Targets;
7use mrw::Inventory;
8use mrw::Util;
9use Getopt::Long;
10
11
12my $mrwFile = "";
13my $outFile = "";
14
15
16GetOptions(
17"m=s" => \$mrwFile,
18"o=s" => \$outFile,
19)
20or printUsage();
21
22
23if (($mrwFile eq "") or ($outFile eq ""))
24{
25 printUsage();
26}
27
28
29# Load system MRW
30my $targets = Targets->new;
31$targets->loadXML($mrwFile);
32
33
34# Load inventory
35my @inventory = Inventory::getInventory($targets);
36
37
38open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!";
39
40
41my $bmc = Util::getBMCTarget($targets);
42my $connections = $targets->findConnections($bmc, "I2C");
43# hash of arrays - {I2C master port : list of connected slave Targets}
44my %masters;
45
46for my $i2c (@{$connections->{CONN}})
47{
48 my $master = $i2c->{SOURCE};
49 my $port = $targets->getAttribute($master,"I2C_PORT");
50 $port = Util::adjustI2CPort($port);
51 my $slave = $i2c->{DEST};
52 push(@{$masters{$port}}, $slave);
53}
54
55for my $m (keys %masters)
56{
57 print $fh $m.":\n";
58 for my $s(@{$masters{$m}})
59 {
60 my $addr = $targets->getAttribute($s,"I2C_ADDRESS");
61 $addr = Util::adjustI2CAddress(hex($addr));
62 print $fh " ".$addr.": ";
63 my $fru = Util::getEnclosingFru($targets, $s);
64 print $fh Util::getObmcName(\@inventory, $fru)."\n";
65 }
66}
67
68
69close $fh;
70
71
72sub printUsage
73{
74 print "
75 $0 -m [MRW file] -o [Output filename]\n";
76 exit(1);
77}