Changeset 1589

Show
Ignore:
Timestamp:
11/08/02 16:21:21 (11 years ago)
Author:
khali
Message:

decode-dimms.pl pass -w and use strict

Valid HTML 3.2 output (--format mode)
Miscellaneous formatting enhancements and bug fixes
Clearer HTML output (original patch by Nick Kurshev

<nickols_k@…>)

Stop decoding on checksum error by default (--checksum option

forces)

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r1588 r1589  
    4444  Module w83781d: Fix in0/in1 initialization 
    4545  Module smartbatt: New 
     46  Program decode-dimms.pl: Code cleanup; valid HTML; better HTML output; 
     47                           stop decoding on checksum error 
    4648  Program dmidecode: Fix read bug; upgrade to version 1.8 
    4749  Program doc-insmod: Complete rewrite; fix author output 
  • lm-sensors/trunk/prog/eeprom/decode-dimms.pl

    r1322 r1589  
    1 #!/usr/bin/perl 
     1#!/usr/bin/perl -w 
    22# 
    33# Copyright 1998, 1999 Philip Edelbrock <phil@netroedge.com> 
     
    2323# Version 0.6  2000-09-16  Christian Zuckschwerdt <zany@triq.net> 
    2424#  updated according to SPD Spec Rev 1.2B 
    25 #  see http://developer.intel.com/ 
    26 #             technology/memory/pc133sdram/spec/Spdsd12b.htm 
     25#  see http://developer.intel.com/technology/memory/pc133sdram/spec/Spdsd12b.htm 
     26# Version 0.7  2002-11-08  Jean Delvare <khali@linux-fr.org> 
     27#  pass -w and use strict 
     28#  valid HTML 3.2 output (--format mode) 
     29#  miscellaneous formatting enhancements and bug fixes 
     30#  clearer HTML output (original patch by Nick Kurshev <nickols_k@mail.ru>) 
     31#  stop decoding on checksum error by default (--checksum option forces) 
     32# 
    2733# 
    2834# EEPROM data decoding for SDRAM DIMM modules.  
     
    4652# 
    4753 
     54use strict; 
     55use vars qw($opt_html $opt_body $opt_bodyonly $opt_igncheck); 
     56 
    4857sub printl ($$) # print a line w/ label and value 
    4958{ 
    5059   my ($label, $value) = @_; 
    5160   if ($opt_html) { 
    52        $value =~ s%\n%<br>%sg; 
     61       $label =~ s/</\&lt;/sg; 
     62       $label =~ s/>/\&gt;/sg; 
     63       $label =~ s/\n/<br>\n/sg; 
     64       $value =~ s/</\&lt;/sg; 
     65       $value =~ s/>/\&gt;/sg; 
     66       $value =~ s/\n/<br>\n/sg; 
    5367       print "<tr><td valign=top>$label</td><td>$value</td></tr>\n"; 
    5468   } else { 
     
    5872} 
    5973 
     74sub printl2 ($$) # print a line w/ label and value (outside a table) 
     75{ 
     76   my ($label, $value) = @_; 
     77   if ($opt_html) { 
     78       $label =~ s/</\&lt;/sg; 
     79       $label =~ s/>/\&gt;/sg; 
     80       $label =~ s/\n/<br>\n/sg; 
     81       $value =~ s/</\&lt;/sg; 
     82       $value =~ s/>/\&gt;/sg; 
     83       $value =~ s/\n/<br>\n/sg; 
     84       print "$label: $value\n"; 
     85   } else { 
     86       $value =~ s%\n%\n\t\t%sg; 
     87       print "$label\t$value\n"; 
     88   } 
     89} 
     90 
    6091sub prints ($) # print seperator w/ given text 
    6192{ 
    6293   my ($label) = @_; 
    6394   if ($opt_html) { 
     95       $label =~ s/</\&lt;/sg; 
     96       $label =~ s/>/\&gt;/sg; 
     97       $label =~ s/\n/<br>\n/sg; 
    6498       print "<tr><td align=center colspan=2><b>$label</b></td></tr>\n"; 
    6599   } else { 
     
    72106   my ($label) = @_; 
    73107   if ($opt_html) { 
    74        $label =~ s%\n%<br>%sg; 
     108       $label =~ s/</\&lt;/sg; 
     109       $label =~ s/>/\&gt;/sg; 
     110       $label =~ s/\n/<br>\n/sg; 
    75111       print "<h1>$label</h1>\n"; 
    76112   } else { 
     
    81117for (@ARGV) { 
    82118    if (/-h/) { 
    83         print "Usage: $0 [-f|-b|-h] 
    84  
    85   -f, --format            print nice html output 
    86   -b, --bodyonly          don't printhtml header 
    87                           (useful for postprocessing the output) 
    88   -h, --help              display this usage summary 
    89 "; 
    90         exit; 
     119                print "Usage: $0 [-f|-b|-h]\n\n", 
     120                        "  -f, --format            print nice html output\n", 
     121                        "  -b, --bodyonly          don't printhtml header\n", 
     122                        "                          (useful for postprocessing the output)\n", 
     123                        "  -c, --checksum          decode completely even if checksum fails\n", 
     124                        "  -h, --help              display this usage summary\n"; 
     125                exit; 
    91126    } 
    92127    $opt_html = 1 if (/-f/); 
    93128    $opt_bodyonly = 1 if (/-b/); 
    94 } 
    95 $opt_body = $opt_html and not $opt_bodyonly; 
    96  
    97 print "<html><head></head><body>\n" if $opt_body; 
     129    $opt_igncheck = 1 if (/-c/); 
     130} 
     131$opt_body = $opt_html && ! $opt_bodyonly; 
     132 
     133if ($opt_body) 
     134{ 
     135        print "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n", 
     136              "<html><head>\n", 
     137                  "\t<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">\n", 
     138                  "\t<title>PC DIMM Serial Presence Detect Tester/Decoder Output</title>\n", 
     139                  "</head><body>\n"; 
     140} 
    98141 
    99142printh ' 
    100143PC DIMM Serial Presence Detect Tester/Decoder 
    101 Written by Philip Edelbrock.  Copyright 1998, 1999. 
    102 Modified by Christian Zuckschwerdt <zany@triq.net> 
    103 Version 2.6.3 
     144By Philip Edelbrock, Christian Zuckschwerdt and others 
     145Version 2.6.6 
    104146'; 
    105147 
    106 print "<table border=1>\n" if $opt_html; 
    107  
    108 $dimm_count=0; 
     148 
     149my $dimm_count=0; 
    109150$_=`ls /proc/sys/dev/sensors/`; 
    110 @dimm_list=split(); 
    111  
    112 for $i ( 0 .. $#dimm_list ) { 
     151my @dimm_list=split(); 
     152 
     153for my $i ( 0 .. $#dimm_list ) { 
    113154        $_=$dimm_list[$i]; 
    114155        if (/^eeprom-/) { 
    115                 $dimm_checksum=0; 
    116                 $dimm_count=$dimm_count + 1; 
    117                  
    118                 printl "Decoding EEPROM", "/proc/sys/dev/sensors/$dimm_list[$i]"; 
     156                my $dimm_checksum=0; 
     157                $dimm_count += 1; 
     158                 
     159                print "<b><u><br><br>" if $opt_html; 
     160                printl2 "Decoding EEPROM" , " /proc/sys/dev/sensors/$dimm_list[$i]"; 
     161                print "</u></b>" if $opt_html; 
     162                print "<table border=1>\n" if $opt_html; 
    119163                if (/^[^-]+-[^-]+-[^-]+-([^-]+)$/) { 
    120                         $dimm_num=$1 - 49; 
     164                        my $dimm_num=$1 - 49; 
    121165                        printl "Guessing DIMM is in", "bank $dimm_num"; 
    122166                } 
     
    125169 
    126170                $_=`cat /proc/sys/dev/sensors/$dimm_list[$i]/00`; 
    127                 @bytes=split(" "); 
    128                 for $j ( 0 .. 15 ) { $dimm_checksum = $dimm_checksum + $bytes[$j];  } 
     171                my @bytes=split(" "); 
     172                for my $j ( 0 .. 15 ) { $dimm_checksum = $dimm_checksum + $bytes[$j];  } 
    129173                 
    130174                printl "# of bytes written to SDRAM EEPROM",$bytes[0]; 
    131175 
    132                 $l = "Total number of bytes in EEPROM"; 
     176                my $l = "Total number of bytes in EEPROM"; 
    133177                if ($bytes[1] <= 13) { 
    134178                        printl $l, 2**$bytes[1]; 
     
    162206                $l = "Data Width (SDRAM only)"; 
    163207                if ($bytes[7] > 1) { printl $l, "Undefined!" } else { 
    164                         $temp=($bytes[7]*256) + $bytes[6]; 
     208                        my $temp=($bytes[7]*256) + $bytes[6]; 
    165209                        printl $l, $temp; } 
    166210 
     
    175219                 
    176220                $l = "Cycle Time (SDRAM) highest CAS latency"; 
    177                 $temp=($bytes[9] >> 4) + ($bytes[9] & 0xf) * 0.1; 
     221                my $temp=($bytes[9] >> 4) + ($bytes[9] & 0xf) * 0.1; 
    178222                printl $l, "${temp}ns"; 
    179223                 
     
    229273                $_=`cat /proc/sys/dev/sensors/$dimm_list[$i]/10`; 
    230274                @bytes=split(" "); 
    231                 for $j ( 0 .. 15 ) { $dimm_checksum = $dimm_checksum + $bytes[$j]; } 
     275                for my $j ( 0 .. 15 ) { $dimm_checksum = $dimm_checksum + $bytes[$j]; } 
    232276                 
    233277                $l = "Burst lengths supported"; 
     
    380424                $_=`cat /proc/sys/dev/sensors/$dimm_list[$i]/20`; 
    381425                @bytes=split(" "); 
    382                 for $j ( 0 .. 15 ) { $dimm_checksum = $dimm_checksum + $bytes[$j];  } 
     426                for my $j ( 0 .. 15 ) { $dimm_checksum = $dimm_checksum + $bytes[$j];  } 
    383427                 
    384428                prints "The Following are Proposed and Apply to SDRAM DIMMs"; 
     
    404448                $_=`cat /proc/sys/dev/sensors/$dimm_list[$i]/30`; 
    405449                @bytes=split(" "); 
    406                 for $j ( 0 .. 14 ) { $dimm_checksum = $dimm_checksum + $bytes[$j];  } 
     450                for my $j ( 0 .. 14 ) { $dimm_checksum = $dimm_checksum + $bytes[$j];  } 
    407451 
    408452                printl "SPD Revision code ", sprintf("%x", $bytes[14]); 
    409453                $l = "EEPROM Checksum of bytes 0-62"; 
    410                 $temp = sprintf("0x%.2X (verses calculated: 0x%.2X)\n",$bytes[15],$dimm_checksum & 255); 
    411                 printl $l, $temp; 
    412  
     454                $dimm_checksum &= 0xff; 
     455                printl $l, ($bytes[15]==$dimm_checksum? 
     456                        sprintf("OK (0x%.2X)",$bytes[15]): 
     457                        sprintf("Bad (found 0x%.2X, calculated 0x%.2X)\n",$bytes[15],$dimm_checksum)); 
     458 
     459                if($bytes[15]==$dimm_checksum || $opt_igncheck) { 
    413460# Decode next 16 bytes (64-79) 
    414461                $_=`cat /proc/sys/dev/sensors/$dimm_list[$i]/40`; 
     
    418465                $temp = sprintf("0x%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X\n",$bytes[0],$bytes[1],$bytes[2],$bytes[3],$bytes[4],$bytes[5],$bytes[6],$bytes[7]); 
    419466                printl $l, $temp; 
    420                 $temp = pack("cccccccc", 
     467                $temp = pack("c8", 
    421468                        $bytes[0],$bytes[1],$bytes[2],$bytes[3],$bytes[4],$bytes[5],$bytes[6],$bytes[7]); 
    422469                printl $l, "(\"$temp\")"; 
     
    426473                printl $l, $temp; 
    427474                 
    428                 $l = "Manufacurer's Part Number:\""; 
     475                $l = "Manufacurer's Part Number"; 
    429476# Decode next 16 bytes (80-95) 
    430477                $_=`cat /proc/sys/dev/sensors/$dimm_list[$i]/50`; 
    431                 @bytes2=split(" "); 
    432                 $temp = pack("cccccccccccccccccc",$bytes[9],$bytes[10],$bytes[11],$bytes[12],$bytes[13],$bytes[14],$bytes[15], 
    433                         $bytes2[0],$bytes2[1],$bytes2[2],$bytes2[3],$bytes2[4],$bytes2[5],$bytes2[6],$bytes2[7],$bytes2[8],$bytes2[9]); 
     478                my @bytes2 = split ' '; 
     479                $temp = pack("c18",$bytes[9],$bytes[10],$bytes[11],$bytes[12],$bytes[13],$bytes[14],$bytes[15], 
     480                        $bytes2[0],$bytes2[1],$bytes2[2],$bytes2[3],$bytes2[4],$bytes2[5],$bytes2[6],$bytes2[7],$bytes2[8],$bytes2[9],$bytes2[10]); 
    434481                printl $l, $temp; 
    435482                 
    436483                $l = "Revision Code"; 
    437                 $temp = sprintf("0x%.2X%.2X\n",$bytes2[10],$bytes2[11]); 
     484                $temp = sprintf("0x%.2X%.2X\n",$bytes2[11],$bytes2[12]); 
    438485                printl $l, $temp; 
    439486                 
    440487                $l = "Manufacturing Date"; 
    441                 $temp = sprintf("0x%.2X%.2X\n",$bytes2[12],$bytes2[13]); 
     488                $temp = sprintf("0x%.2X%.2X\n",$bytes2[13],$bytes2[14]); 
    442489                printl $l, $temp; 
    443490                 
     
    471518                else { $temp .= "Single Sided DIMM\n";} 
    472519                printl $l, $temp; 
    473                  
    474                  
     520                } 
     521                 
     522                print "</table>\n" if $opt_html; 
    475523        } 
    476524} 
    477 printl "Number of SDRAM DIMMs detected and decoded", $dimm_count; 
    478  
    479 print "</table>\n" if $opt_html; 
     525print '<br><br>' if $opt_html; 
     526printl2 "Number of SDRAM DIMMs detected and decoded", $dimm_count; 
     527 
    480528print "</body></html>\n" if $opt_body; 
    481529print "\nTry '$0 --format' for html output.\n" unless $opt_html;