Deepak Kodihalli | c54679c | 2017-02-22 04:21:09 -0600 | [diff] [blame] | 1 | #! /usr/bin/perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | |
| 5 | |
| 6 | use mrw::Targets; |
| 7 | use mrw::Inventory; |
| 8 | use mrw::Util; |
| 9 | use Getopt::Long; |
| 10 | |
| 11 | |
| 12 | my $mrwFile = ""; |
| 13 | my $outFile = ""; |
| 14 | |
| 15 | |
| 16 | GetOptions( |
| 17 | "m=s" => \$mrwFile, |
| 18 | "o=s" => \$outFile, |
| 19 | ) |
| 20 | or printUsage(); |
| 21 | |
| 22 | |
| 23 | if (($mrwFile eq "") or ($outFile eq "")) |
| 24 | { |
| 25 | printUsage(); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | # Load system MRW |
| 30 | my $targets = Targets->new; |
| 31 | $targets->loadXML($mrwFile); |
| 32 | |
| 33 | |
| 34 | # Load inventory |
| 35 | my @inventory = Inventory::getInventory($targets); |
| 36 | |
| 37 | |
| 38 | open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!"; |
| 39 | |
| 40 | |
| 41 | my $bmc = Util::getBMCTarget($targets); |
| 42 | my $connections = $targets->findConnections($bmc, "I2C"); |
| 43 | # hash of arrays - {I2C master port : list of connected slave Targets} |
| 44 | my %masters; |
| 45 | |
| 46 | for 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 | |
| 55 | for 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 | |
| 69 | close $fh; |
| 70 | |
| 71 | |
| 72 | sub printUsage |
| 73 | { |
| 74 | print " |
| 75 | $0 -m [MRW file] -o [Output filename]\n"; |
| 76 | exit(1); |
| 77 | } |