summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Joseph <tomjoseph@in.ibm.com>2017-05-05 11:53:54 +0530
committerPatrick Williams <patrick@stwcx.xyz>2017-05-19 14:43:47 +0000
commit5882591626c1f094cf4617c8d50c327cf4672d72 (patch)
tree01a4101c14dc736e49f7f66c480cc515bc81ca1e
parentc5e127d6122f2c8ba9d2b65edf2db10518ac4639 (diff)
downloadphosphor-mrw-tools-5882591626c1f094cf4617c8d50c327cf4672d72.tar.gz
phosphor-mrw-tools-5882591626c1f094cf4617c8d50c327cf4672d72.zip
Fetch inventory path and sensor information from MRW.
Generate output yaml containing inventory to sensor information mapping by processing MRW and the config file. Sample entry in the output yaml. /xyz/openbmc_project/inventory/system/chassis/motherboard/cpu1/core16: sensorID: 0x8c sensorType: 0x07 eventReadingType: 0x6F offset: 0x08 Change-Id: I34a42b8d81c08fc14849b7d29162433319474cf8 Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
-rw-r--r--Build.PL1
-rwxr-xr-xgen_ipmi_sel.pl120
2 files changed, 121 insertions, 0 deletions
diff --git a/Build.PL b/Build.PL
index 9782d09..13c73c4 100644
--- a/Build.PL
+++ b/Build.PL
@@ -9,6 +9,7 @@ Module::Build->new(
'gen_fan_zone_yaml.pl',
'gen_fru_properties.pl',
'gen_ipmi_fru.pl',
+ 'gen_ipmi_sel.pl',
'gen_ipmi_sensor.pl',
'gen_led_groups.pl',
'gen_openpower_fru.pl',
diff --git a/gen_ipmi_sel.pl b/gen_ipmi_sel.pl
new file mode 100755
index 0000000..dd1fcbd
--- /dev/null
+++ b/gen_ipmi_sel.pl
@@ -0,0 +1,120 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+
+use mrw::Targets;
+use mrw::Inventory;
+use mrw::Util;
+use Getopt::Long; # For parsing command line arguments
+use YAML::Tiny qw(LoadFile);
+
+# Globals
+my $serverwizFile = "";
+my $debug = 0;
+my $outputFile = "";
+my $metaDataFile = "";
+
+# Command line argument parsing
+GetOptions(
+"i=s" => \$serverwizFile, # string
+"m=s" => \$metaDataFile, # string
+"o=s" => \$outputFile, # string
+"d" => \$debug,
+)
+or printUsage();
+
+if (($serverwizFile eq "") or ($outputFile eq "") or ($metaDataFile eq ""))
+{
+ printUsage();
+}
+
+my $targetObj = Targets->new;
+$targetObj->loadXML($serverwizFile);
+
+# Open the MRW xml and the Metadata file for the sensor.
+# Get the IPMI sensor information based on the Entity ID and Sensor Type.
+# Fetch the Sensor ID, Event/Reading Type and Object Path from MRW.
+# Get the Sensor Type and Offset from the metadata file.
+# Merge and generate an output YAML with inventory object path as the key.
+
+open(my $fh, '>', $outputFile) or die "Could not open file '$outputFile' $!";
+my $metaDataConfig = LoadFile($metaDataFile);
+
+my @interestedTypes = keys %{$metaDataConfig};
+my %types;
+
+@types{@interestedTypes} = ();
+
+my @inventory = Inventory::getInventory($targetObj);
+#Process all the targets in the XML
+foreach my $target (sort keys %{$targetObj->getAllTargets()})
+{
+ my $sensorID = '';
+ my $sensorType = '';
+ my $eventReadingType = '';
+ my $path = '';
+ my $obmcPath = '';
+ my $entityID = '';
+ my $base = "/xyz/openbmc_project/inventory";
+
+ if ($targetObj->getTargetType($target) eq "unit-ipmi-sensor") {
+
+ $sensorID = $targetObj->getAttribute($target, "IPMI_SENSOR_ID");
+ $sensorType = $targetObj->getAttribute($target, "IPMI_SENSOR_TYPE");
+ $eventReadingType = $targetObj->getAttribute($target,
+ "IPMI_SENSOR_READING_TYPE");
+ $path = $targetObj->getAttribute($target, "INSTANCE_PATH");
+ $entityID = $targetObj->getAttribute($target, "IPMI_ENTITY_ID");
+
+ # Look only for the interested Entity ID & Sensor Type
+ next if (not exists $types{$entityID});
+ next if ($sensorType ne $metaDataConfig->{$entityID}->{SensorType});
+
+ #if there is ipmi sensor without sensorid or sensorReadingType or
+ #Instance path then die
+
+ if ($sensorID eq '' or $eventReadingType eq '' or $path eq '') {
+ close $fh;
+ die("sensor without info for target=$target");
+ }
+
+ # Removing the string "instance:" from path
+ $path =~ s/^instance:/\//;
+ $obmcPath = Util::getObmcName(\@inventory, $path);
+
+ # If unable to get the obmc path then die
+ if (not defined $obmcPath) {
+ close $fh;
+ die("Unable to get the obmc path for path=$path");
+ }
+
+ $base .= $obmcPath;
+
+ print $fh $base.":"."\n";
+ print $fh " sensorID: ".$sensorID."\n";
+ print $fh " sensorType: ".$sensorType."\n";
+ print $fh " eventReadingType: ".$eventReadingType."\n";
+ print $fh " offset: ".$metaDataConfig->{$entityID}->{Offset}."\n";
+
+ printDebug("$sensorID : $sensorType : $eventReadingType : $entityID : $metaDataConfig->{$entityID}->{Offset}")
+ }
+}
+close $fh;
+
+# Usage
+sub printUsage
+{
+ print "
+ $0 -i [MRW filename] -m [SensorMetaData filename] -o [Output filename] [OPTIONS]
+Options:
+ -d = debug mode
+ \n";
+ exit(1);
+}
+
+# Helper function to put debug statements.
+sub printDebug
+{
+ my $str = shift;
+ print "DEBUG: ", $str, "\n" if $debug;
+}
OpenPOWER on IntegriCloud