blob: 5398aa51fcb36ca85b0a218a988e3f7abd95e4a2 [file] [log] [blame]
Deepak Kodihalli65682172017-03-02 02:32:45 -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
38# paths
Deepak Kodihallifff3da42017-08-16 03:15:51 -050039my $i2cPath = "/sys/devices/platform/ahb/ahb:apb/ahb:apb:i2c\@1e78a000/1e78a100.i2c-bus/i2c-<port>/<port>-00<address>";
40my $fsiMasterPath = "/sys/devices/platform/gpio-fsi/fsi0/slave\@00:00/raw";
41my $fsiSlavePath = "/sys/devices/platform/gpio-fsi/fsi0/slave\@00:00/00:00:00:0a/fsi1/slave\@<link>:00/raw";
Deepak Kodihalli65682172017-03-02 02:32:45 -060042
43
44open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!";
45
46genI2CCallouts();
47genProcFSICallouts();
48
49close $fh;
50
51
52sub 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
86sub 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
122sub printUsage
123{
124 print "
125 $0 -m [MRW file] -o [Output filename]\n";
126 exit(1);
127}