| 1 | #!/usr/bin/perl -w |
|---|
| 2 | # |
|---|
| 3 | # Copyright 2002 Jean Delvare <khali@linux-fr.org> |
|---|
| 4 | # |
|---|
| 5 | # This program is free software; you can redistribute it and/or modify |
|---|
| 6 | # it under the terms of the GNU General Public License as published by |
|---|
| 7 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | # (at your option) any later version. |
|---|
| 9 | # |
|---|
| 10 | # This program is distributed in the hope that it will be useful, |
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | # GNU General Public License for more details. |
|---|
| 14 | # |
|---|
| 15 | # You should have received a copy of the GNU General Public License |
|---|
| 16 | # along with this program; if not, write to the Free Software |
|---|
| 17 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 18 | # |
|---|
| 19 | # Version 0.1 2002-02-06 Jean Delvare <khali@linux-fr.org> |
|---|
| 20 | # Version 0.2 2002-02-16 Jean Delvare <khali@linux-fr.org> |
|---|
| 21 | # Fixed to work with the new, simplified /proc interface names of the eeprom |
|---|
| 22 | # driver (lm_sensors 2.6.3 and greater). |
|---|
| 23 | # Shifted data display by 4 columns left. |
|---|
| 24 | # Version 0.3 2002-02-17 Jean Delvare <khali@linux-fr.org> |
|---|
| 25 | # Added UUID field at 0x10 (added decode_uuid). |
|---|
| 26 | # Merged decode_string and decode_string32. |
|---|
| 27 | # Added unknown field at 0x20. |
|---|
| 28 | # Moved header and footer to BEGIN and END, respectively. |
|---|
| 29 | # Reformated history to match those of the other decode scripts. |
|---|
| 30 | # Deleted decode_char (made useless by decode_string). |
|---|
| 31 | # Reordered field display, changed some labels. |
|---|
| 32 | # Added old /proc interface check. |
|---|
| 33 | # Version 1.0 2002-11-15 Jean Delvare <khali@linux-fr.org> |
|---|
| 34 | # Gave the label "OEM Data" to the field at 0x20. |
|---|
| 35 | # Gave the label "Timestamp" to the field at 0xE0. |
|---|
| 36 | # Renamed "Model Number" to "Model Name". |
|---|
| 37 | # Added some Documentation. |
|---|
| 38 | # |
|---|
| 39 | # EEPROM data decoding for Sony Vaio laptops. |
|---|
| 40 | # |
|---|
| 41 | # Two assumptions: lm_sensors-2.6.3 or greater installed, |
|---|
| 42 | # and Perl is at /usr/bin/perl |
|---|
| 43 | # |
|---|
| 44 | # Please note that this is a guess-only work. Sony support refused to help |
|---|
| 45 | # me, so if someone can provide information, please contact me. |
|---|
| 46 | # |
|---|
| 47 | # It seems that if present, the EEPROM is always at 0x57. |
|---|
| 48 | # |
|---|
| 49 | # Models tested so far: |
|---|
| 50 | # PCG-F403 : No EEPROM |
|---|
| 51 | # PCG-F707 : No EEPROM |
|---|
| 52 | # PCG-GR114EK : OK |
|---|
| 53 | # PCG-GR114SK : OK |
|---|
| 54 | # PCG-GR214EP : OK |
|---|
| 55 | # PCG-GRX316G : OK |
|---|
| 56 | # PCG-GRX570 : OK |
|---|
| 57 | # PCG-GRX600K : OK |
|---|
| 58 | # PCG-U1 : OK |
|---|
| 59 | # PCG-Z600LEK : No EEPROM |
|---|
| 60 | # PCG-Z600NE : No EEPROM |
|---|
| 61 | # Any feedback appreciated anyway. |
|---|
| 62 | # |
|---|
| 63 | # Thanks to Werner Heuser, Carsten Blume, Christian Gennerat, Joe Wreschnig, |
|---|
| 64 | # Xavier Roche, Sebastien Lefevre, Lars Heer and Steve Dobson and others |
|---|
| 65 | # for their precious help. |
|---|
| 66 | # |
|---|
| 67 | |
|---|
| 68 | use strict; |
|---|
| 69 | |
|---|
| 70 | sub print_item |
|---|
| 71 | { |
|---|
| 72 | my ($label,$value) = @_; |
|---|
| 73 | |
|---|
| 74 | printf("\%16s : \%s\n",$label,$value); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | sub decode_string |
|---|
| 78 | { |
|---|
| 79 | my ($bus,$addr,$base,$offset,$length) = @_; |
|---|
| 80 | |
|---|
| 81 | my $line=''; |
|---|
| 82 | my $remains=$length+$offset; |
|---|
| 83 | while($remains>0) |
|---|
| 84 | { |
|---|
| 85 | my $filename="/proc/sys/dev/sensors/eeprom-i2c-$bus-$addr/".sprintf('%02x',$base); |
|---|
| 86 | open(FH,$filename) || die "Can't open $filename"; |
|---|
| 87 | $line.=<FH>; |
|---|
| 88 | close(FH); |
|---|
| 89 | $remains-=16; |
|---|
| 90 | $base+=16; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | my @bytes=split(/[ \n]/,$line); |
|---|
| 94 | @bytes=@bytes[$offset..$offset+$length-1]; |
|---|
| 95 | my $string=''; |
|---|
| 96 | my $item; |
|---|
| 97 | while(defined($item=shift(@bytes)) && ($item!=0)) |
|---|
| 98 | { |
|---|
| 99 | $string.=chr($item); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | return($string); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | sub decode_uuid |
|---|
| 106 | { |
|---|
| 107 | my ($bus,$addr,$base) = @_; |
|---|
| 108 | |
|---|
| 109 | my $filename="/proc/sys/dev/sensors/eeprom-i2c-$bus-$addr/".sprintf('%02x',$base); |
|---|
| 110 | open(FH,$filename) || die "Can't open $filename"; |
|---|
| 111 | my $line=<FH>; |
|---|
| 112 | close(FH); |
|---|
| 113 | |
|---|
| 114 | my @bytes=split(/[ \n]/,$line); |
|---|
| 115 | my $string=''; |
|---|
| 116 | my $item; |
|---|
| 117 | |
|---|
| 118 | for(my $i=0;$i<16;$i++) |
|---|
| 119 | { |
|---|
| 120 | $string.=sprintf('%02x',shift(@bytes)); |
|---|
| 121 | if(($i==3)||($i==5)||($i==7)||($i==9)) |
|---|
| 122 | { |
|---|
| 123 | $string.='-'; |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | return($string); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | sub vaio_decode |
|---|
| 131 | { |
|---|
| 132 | my ($bus,$addr) = @_; |
|---|
| 133 | |
|---|
| 134 | print_item('Machine Name',decode_string($bus,$addr,128,0,32)); |
|---|
| 135 | print_item('Serial Number',decode_string($bus,$addr,192,0,32)); |
|---|
| 136 | print_item('UUID',decode_uuid($bus,$addr,16)); |
|---|
| 137 | print_item('Revision',decode_string($bus,$addr,160,0,10)); |
|---|
| 138 | print_item('Model Name','PCG-'.decode_string($bus,$addr,160,10,4)); |
|---|
| 139 | print_item('OEM Data',decode_string($bus,$addr,32,0,16)); |
|---|
| 140 | print_item('Timestamp',decode_string($bus,$addr,224,0,32)); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | BEGIN |
|---|
| 144 | { |
|---|
| 145 | print("Sony Vaio EEPROM Decoder\n"); |
|---|
| 146 | print("Written by Jean Delvare. Copyright 2002.\n"); |
|---|
| 147 | print("Version 1.0\n\n"); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | END |
|---|
| 151 | { |
|---|
| 152 | print("\n"); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | if ( -r '/proc/sys/dev/sensors/eeprom-i2c-0-57') |
|---|
| 156 | { |
|---|
| 157 | if ( -r '/proc/sys/dev/sensors/eeprom-i2c-0-57/data0-15') |
|---|
| 158 | { |
|---|
| 159 | print("Deprecated old interface found. Please upgrade to lm_sensors 2.6.3 or greater."); |
|---|
| 160 | } |
|---|
| 161 | else |
|---|
| 162 | { |
|---|
| 163 | vaio_decode('0','57'); |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | else |
|---|
| 167 | { |
|---|
| 168 | print("Vaio EEPROM not found. Please make sure that the eeprom module is loaded.\n"); |
|---|
| 169 | print("If you believe this is an error, please contact me <khali\@linux-fr.org>\n"); |
|---|
| 170 | print("so that we may see how to fix the problem.\n"); |
|---|
| 171 | } |
|---|