blob: b23a8bbf48fc5acbb2e66220d2830cf393448c1e [file] [log] [blame]
Andrew Geissler65ca8e12022-07-16 11:36:14 -04001#!/usr/bin/perl
2
Deepak Kodihalli65682172017-03-02 02:32:45 -06003use strict;
4use warnings;
5
6
7use mrw::Targets;
8use mrw::Inventory;
9use mrw::Util;
10use Getopt::Long;
11
12
13my $mrwFile = "";
14my $outFile = "";
15
16
17GetOptions(
18"m=s" => \$mrwFile,
19"o=s" => \$outFile,
20)
21or printUsage();
22
23
24if (($mrwFile eq "") or ($outFile eq ""))
25{
26 printUsage();
27}
28
29
30# Load system MRW
31my $targets = Targets->new;
32$targets->loadXML($mrwFile);
33
34
35# Load inventory
36my @inventory = Inventory::getInventory($targets);
37
38
39# paths
Matt Spinler605b2e92019-03-21 14:33:51 -050040my $i2cPath = "/sys/devices/platform/ahb/ahb:apb/ahb:apb:bus\@1e78a000/1e78a100.i2c-bus/i2c-<port>/<port>-00<address>";
Deepak Kodihallifff3da42017-08-16 03:15:51 -050041my $fsiMasterPath = "/sys/devices/platform/gpio-fsi/fsi0/slave\@00:00/raw";
42my $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 -060043
44
45open(my $fh, '>', $outFile) or die "Could not open file '$outFile' $!";
46
47genI2CCallouts();
48genProcFSICallouts();
49
50close $fh;
51
52
53sub genI2CCallouts
54{
55 my $bmc = Util::getBMCTarget($targets);
56 my $connections = $targets->findConnections($bmc, "I2C");
57 # hash of arrays - {I2C master port : list of connected slave Targets}
58 my %masters;
59
60 for my $i2c (@{$connections->{CONN}})
61 {
62 my $master = $i2c->{SOURCE};
63 my $port = $targets->getAttribute($master,"I2C_PORT");
64 $port = Util::adjustI2CPort($port);
65 my $slave = $i2c->{DEST};
66 push(@{$masters{$port}}, $slave);
67 }
68
69 for my $m (keys %masters)
70 {
71 for my $s(@{$masters{$m}})
72 {
73 my $addr = $targets->getAttribute($s,"I2C_ADDRESS");
74 $addr = Util::adjustI2CAddress(hex($addr));
75 $addr = substr $addr, 2; # strip 0x
76 my $path = $i2cPath;
77 $path =~ s/<port>/$m/g;
78 $path =~ s/<address>/$addr/g;
79 print $fh $path.": ";
80 my $fru = Util::getEnclosingFru($targets, $s);
81 print $fh Util::getObmcName(\@inventory, $fru)."\n";
82 }
83 }
84}
85
86
87sub genProcFSICallouts
88{
89 my @procs;
90 for my $target (keys %{$targets->getAllTargets()})
91 {
92 if ($targets->getType($target) eq "PROC")
93 {
94 push @procs, $target;
95 }
96 }
97
98 for my $proc (@procs)
99 {
100 my $connections = $targets->findConnections($proc, "FSIM");
101 if ("" ne $connections)
102 {
103 # This is a master processor
104 my $path = $fsiMasterPath; # revisit on a multinode system
105 my $fru = Util::getEnclosingFru($targets, $proc);
106 print $fh $path.": ".Util::getObmcName(\@inventory, $fru);
107 for my $fsi (@{$connections->{CONN}})
108 {
109 my $master = $fsi->{SOURCE};
110 my $slave = $fsi->{DEST};
111 my $link = $targets->getAttribute($master, "FSI_LINK");
112 $link = substr $link, 2; # strip 0x
113 my $fru = Util::getEnclosingFru($targets, $slave);
114 $path = $fsiSlavePath;
115 $path =~ s/<link>/$link/g;
116 print $fh "\n".$path.": ".Util::getObmcName(\@inventory, $fru);
117 }
118 }
119 }
120}
121
122
123sub printUsage
124{
125 print "
126 $0 -m [MRW file] -o [Output filename]\n";
127 exit(1);
128}