From 6a306c9c162144b4aa36bdf2e297a484815c421c Mon Sep 17 00:00:00 2001 From: khali Date: Thu, 4 Dec 2008 20:50:42 +0000 Subject: Gather DMI data and print it at start-up. We may use this data for various purposes later. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5519 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + prog/detect/sensors-detect | 80 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index eff2c9e7..7b47c028 100644 --- a/CHANGES +++ b/CHANGES @@ -40,6 +40,7 @@ SVN-HEAD Skip SMBus probing by default if a Super I/O was found (#2322) Display I2C address statictics with --stat Document the new detection order and rules + Gather DMI data and print it at start-up sensors-detect-stat.pl: Delete (functionality merged into sensors-detect) 3.0.3 (2008-09-28) diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index cca70640..f3fe4d26 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -2122,6 +2122,81 @@ sub unload_modules print "\n"; } +############ +# DMI DATA # +############ + +use vars qw(%dmi); + +sub initialize_dmi_data +{ + my %items = ( + # sysfs file name => dmidecode string name + sys_vendor => 'system-manufacturer', + product_name => 'system-product-name', + product_version => 'system-version', + board_vendor => 'baseboard-manufacturer', + board_name => 'baseboard-product-name', + board_version => 'baseboard-product-name', + chassis_type => 'chassis-type', + ); + # Many BIOS have broken DMI data, filter it out + my %fake = ( + 'System Manufacturer' => 1, + 'System Name' => 1, + ); + + # First try reading the strings from sysfs if available + if (-d '/sys/devices/virtual/dmi/id') { + foreach my $k (keys %items) { + $dmi{$k} = sysfs_device_attribute("/sys/devices/virtual/dmi/id", $k); + } + } else { + # Else fallback on calling dmidecode + return unless open(local *DMIDECODE, + "dmidecode --version 2>/dev/null |"); + my $version = ; + close(DMIDECODE); + return unless defined $version; + + # We need at least version 2.7 + chomp $version; + return unless $version =~ m/^(\d+).(\d+)$/; + return unless (($1 == 2 && $2 >= 7) || $1 > 2); + + foreach my $k (keys %items) { + next unless open(local *DMIDECODE, + "dmidecode -s $items{$k} 2>/dev/null |"); + $dmi{$k} = ; + close(DMIDECODE); + } + } + + # Strip trailing white-space, discard empty field + foreach my $k (keys %dmi) { + if (!defined $dmi{$k}) { + delete $dmi{$k}; + next; + } + $dmi{$k} =~ s/\s*$//; + delete $dmi{$k} if $dmi{$k} eq '' || exists $fake{$dmi{$k}}; + } +} + +sub print_dmi_summary +{ + my ($system, $board); + if (defined $dmi{sys_vendor} && defined $dmi{product_name}) { + $system = "$dmi{sys_vendor} $dmi{product_name}"; + } + if (defined $dmi{board_vendor} && defined $dmi{board_name}) { + $board = "$dmi{board_vendor} $dmi{board_name}"; + } + print "# System: $system\n" if defined $system; + print "# Board: $board\n" if defined $board + && (!defined $system || $system ne $board); +} + ################# # SYSFS HELPERS # ################# @@ -5047,8 +5122,11 @@ sub main chip_special_cases(); initialize_modules_supported(); initialize_cpu_list(); + initialize_dmi_data(); - print "# sensors-detect revision $revision\n\n"; + print "# sensors-detect revision $revision\n"; + print_dmi_summary(); + print "\n"; print "This program will help you determine which kernel modules you need\n", "to load to use lm_sensors most effectively. It is generally safe\n", "and recommended to accept the default answers to all questions,\n", -- cgit v1.2.1