Deepak Kodihalli | 6568217 | 2017-03-02 02:32:45 -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 | # paths |
Deepak Kodihalli | fff3da4 | 2017-08-16 03:15:51 -0500 | [diff] [blame] | 39 | my $i2cPath = "/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c\@1e78a000/1e78a100.i2c-bus/i2c-<port>/<port>-00<address>"; |
| 40 | my $fsiMasterPath = "/sys/devices/platform/gpio-fsi/fsi0/slave\@00:00/raw"; |
| 41 | my $fsiSlavePath = "/sys/devices/platform/gpio-fsi/fsi0/slave\@00:00/00:00:00:0a/fsi1/slave\@<link>:00/raw"; |
Deepak Kodihalli | 6568217 | 2017-03-02 02:32:45 -0600 | [diff] [blame] | 42 | |
| 43 | |
| 44 | open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!"; |
| 45 | |
| 46 | genI2CCallouts(); |
| 47 | genProcFSICallouts(); |
| 48 | |
| 49 | close $fh; |
| 50 | |
| 51 | |
| 52 | sub genI2CCallouts |
| 53 | { |
| 54 | my $bmc = Util::getBMCTarget($targets); |
| 55 | my $connections = $targets->findConnections($bmc, "I2C"); |
| 56 | # hash of arrays - {I2C master port : list of connected slave Targets} |
| 57 | my %masters; |
| 58 | |
| 59 | for my $i2c (@{$connections->{CONN}}) |
| 60 | { |
| 61 | my $master = $i2c->{SOURCE}; |
| 62 | my $port = $targets->getAttribute($master,"I2C_PORT"); |
| 63 | $port = Util::adjustI2CPort($port); |
| 64 | my $slave = $i2c->{DEST}; |
| 65 | push(@{$masters{$port}}, $slave); |
| 66 | } |
| 67 | |
| 68 | for my $m (keys %masters) |
| 69 | { |
| 70 | for my $s(@{$masters{$m}}) |
| 71 | { |
| 72 | my $addr = $targets->getAttribute($s,"I2C_ADDRESS"); |
| 73 | $addr = Util::adjustI2CAddress(hex($addr)); |
| 74 | $addr = substr $addr, 2; # strip 0x |
| 75 | my $path = $i2cPath; |
| 76 | $path =~ s/<port>/$m/g; |
| 77 | $path =~ s/<address>/$addr/g; |
| 78 | print $fh $path.": "; |
| 79 | my $fru = Util::getEnclosingFru($targets, $s); |
| 80 | print $fh Util::getObmcName(\@inventory, $fru)."\n"; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
| 86 | sub genProcFSICallouts |
| 87 | { |
| 88 | my @procs; |
| 89 | for my $target (keys %{$targets->getAllTargets()}) |
| 90 | { |
| 91 | if ($targets->getType($target) eq "PROC") |
| 92 | { |
| 93 | push @procs, $target; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | for my $proc (@procs) |
| 98 | { |
| 99 | my $connections = $targets->findConnections($proc, "FSIM"); |
| 100 | if ("" ne $connections) |
| 101 | { |
| 102 | # This is a master processor |
| 103 | my $path = $fsiMasterPath; # revisit on a multinode system |
| 104 | my $fru = Util::getEnclosingFru($targets, $proc); |
| 105 | print $fh $path.": ".Util::getObmcName(\@inventory, $fru); |
| 106 | for my $fsi (@{$connections->{CONN}}) |
| 107 | { |
| 108 | my $master = $fsi->{SOURCE}; |
| 109 | my $slave = $fsi->{DEST}; |
| 110 | my $link = $targets->getAttribute($master, "FSI_LINK"); |
| 111 | $link = substr $link, 2; # strip 0x |
| 112 | my $fru = Util::getEnclosingFru($targets, $slave); |
| 113 | $path = $fsiSlavePath; |
| 114 | $path =~ s/<link>/$link/g; |
| 115 | print $fh "\n".$path.": ".Util::getObmcName(\@inventory, $fru); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | |
| 122 | sub printUsage |
| 123 | { |
| 124 | print " |
| 125 | $0 -m [MRW file] -o [Output filename]\n"; |
| 126 | exit(1); |
| 127 | } |