Changeset 5157
- Timestamp:
- 03/24/08 11:22:48 (8 months ago)
- Files:
-
- i2c-tools/trunk/CHANGES (modified) (1 diff)
- i2c-tools/trunk/eeprom/decode-dimms.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
i2c-tools/trunk/CHANGES
r5152 r5157 7 7 Don't print anything by default if checksum fails 8 8 Decode all DDR2 SDRAM timing information 9 Add support for reading SPD data from hexdumps 9 10 decode-vaio: Private data might not be readable by non-root users 10 11 Print the asset tag i2c-tools/trunk/eeprom/decode-dimms.pl
r5156 r5157 47 47 use POSIX; 48 48 use Fcntl qw(:DEFAULT :seek); 49 use vars qw($opt_html $opt_body $opt_bodyonly $opt_igncheck $use_sysfs 50 @vendors %decode_callback $revision );49 use vars qw($opt_html $opt_body $opt_bodyonly $opt_igncheck $use_sysfs $use_hexdump 50 @vendors %decode_callback $revision @dimm_list); 51 51 52 52 $revision = '$Revision$ ($Date$)'; … … 1101 1101 } 1102 1102 1103 # Read various hex dump style formats: hexdump, hexdump -C, i2cdump, eeprog 1104 # note that normal 'hexdump' format on a little-endian system byte-swaps 1105 # words, using hexdump -C is better. 1106 sub read_hexdump ($) 1107 { 1108 my $addr = 0; 1109 my $repstart = 0; 1110 my @bytes; 1111 my $header = 1; 1112 my $word = 0; 1113 1114 open F, '<', $_[0] or die "Unable to open: $_[0]"; 1115 while (<F>) { 1116 chomp; 1117 if (/^\*$/) { 1118 $repstart = $addr; 1119 next; 1120 } 1121 /^(?:0000 )?([a-f\d]{2,8}):?\s+((:?[a-f\d]{4}\s*){8}|(:?[a-f\d]{2}\s*){16})/i || 1122 /^(?:0000 )?([a-f\d]{2,8}):?\s*$/i; 1123 next if (!defined $1 && $header); # skip leading unparsed lines 1124 1125 defined $1 or die "Unable to parse input"; 1126 $header = 0; 1127 1128 $addr = hex $1; 1129 if ($repstart) { 1130 @bytes[$repstart .. ($addr-1)] = 1131 (@bytes[($repstart-16)..($repstart-1)]) x (($addr-$repstart)/16); 1132 $repstart = 0; 1133 } 1134 last unless defined $2; 1135 foreach (split(/\s+/, $2)) { 1136 if (/^(..)(..)$/) { 1137 $word |= 1; 1138 $bytes[$addr++] = hex($1); 1139 $bytes[$addr++] = hex($2); 1140 } else { 1141 $bytes[$addr++] = hex($_); 1142 } 1143 } 1144 } 1145 close F; 1146 $header and die "Unable to parse any data from hexdump '$_[0]'"; 1147 $word and printc "Warning: Assuming big-endian order 16-bit hex dump"; 1148 return @bytes; 1149 } 1150 1103 1151 sub readspd64 ($$) { # reads 64 bytes from SPD-EEPROM 1104 1152 my ($offset, $dimm_i) = @_; 1105 1153 my @bytes; 1106 if ($use_sysfs) { 1154 if ($use_hexdump) { 1155 @bytes = read_hexdump($dimm_i); 1156 return @bytes[$offset..($offset+63)]; 1157 } elsif ($use_sysfs) { 1107 1158 # Kernel 2.6 with sysfs 1108 1159 sysopen(HANDLE, "/sys/bus/i2c/drivers/eeprom/$dimm_i/eeprom", O_RDONLY) … … 1124 1175 1125 1176 for (@ARGV) { 1126 if (/ -h/) {1127 print "Usage: $0 [-c] [-f [-b]] \n",1177 if (/^-?-h/) { 1178 print "Usage: $0 [-c] [-f [-b]] [-x file [files..]]\n", 1128 1179 " $0 -h\n\n", 1129 1180 " -f, --format print nice html output\n", … … 1131 1182 " (useful for postprocessing the output)\n", 1132 1183 " -c, --checksum decode completely even if checksum fails\n", 1184 " -x, Read data from hexdump files\n", 1133 1185 " -h, --help display this usage summary\n"; 1186 print <<"EOF"; 1187 1188 Hexdumps can be the output from hexdump, hexdump -C, i2cdump, eeprog and 1189 likely many other progams producing hex dumps of one kind or another. Note 1190 that the default output of "hexdump" will be byte-swapped on little-endian 1191 systems and will therefore not be parsed correctly. It is better to use 1192 "hexdump -C", which is not ambiguous. 1193 EOF 1134 1194 exit; 1135 1195 } 1136 $opt_html = 1 if (/-f/); 1137 $opt_bodyonly = 1 if (/-b/); 1138 $opt_igncheck = 1 if (/-c/); 1196 $opt_html = 1 if (/^-?-f/); 1197 $opt_bodyonly = 1 if (/^-?-b/); 1198 $opt_igncheck = 1 if (/^-?-c/); 1199 $use_hexdump = 1 if (/^-x/); 1200 push @dimm_list, $_ if ($use_hexdump && !/^-/); 1139 1201 } 1140 1202 $opt_body = $opt_html && ! $opt_bodyonly; … … 1156 1218 1157 1219 my $dimm_count = 0; 1158 my @dimm_list;1159 1220 my $dir; 1160 if ($use_sysfs) { $dir = '/sys/bus/i2c/drivers/eeprom'; } 1161 else { $dir = '/proc/sys/dev/sensors'; } 1162 if (-d $dir) { 1163 @dimm_list = split(/\s+/, `ls $dir`); 1164 } elsif (! -d '/sys/module/eeprom') { 1165 print "No EEPROM found, are you sure the eeprom module is loaded?\n"; 1166 exit; 1221 if (!$use_hexdump) { 1222 if ($use_sysfs) { $dir = '/sys/bus/i2c/drivers/eeprom'; } 1223 else { $dir = '/proc/sys/dev/sensors'; } 1224 if (-d $dir) { 1225 @dimm_list = split(/\s+/, `ls $dir`); 1226 } elsif (! -d '/sys/module/eeprom') { 1227 print "No EEPROM found, are you sure the eeprom module is loaded?\n"; 1228 exit; 1229 } 1167 1230 } 1168 1231 … … 1170 1233 $_ = $dimm_list[$i]; 1171 1234 if (($use_sysfs && /^\d+-\d+$/) 1172 || (!$use_sysfs && /^eeprom-/)) { 1235 || (!$use_sysfs && /^eeprom-/) 1236 || $use_hexdump) { 1173 1237 my @bytes = readspd64(0, $dimm_list[$i]); 1174 1238 my $dimm_checksum = 0; … … 1180 1244 1181 1245 print "<b><u>" if $opt_html; 1182 printl2 "\n\nDecoding EEPROM", ($use_sysfs ? 1246 printl2 "\n\nDecoding EEPROM", 1247 $use_hexdump ? $dimm_list[$i] : ($use_sysfs ? 1183 1248 "/sys/bus/i2c/drivers/eeprom/$dimm_list[$i]" : 1184 1249 "/proc/sys/dev/sensors/$dimm_list[$i]"); 1185 1250 print "</u></b>" if $opt_html; 1186 1251 print "<table border=1>\n" if $opt_html; 1187 if (($use_sysfs && /^[^-]+-([^-]+)$/) 1188 || (!$use_sysfs && /^[^-]+-[^-]+-[^-]+-([^-]+)$/)) { 1189 my $dimm_num = $1 - 49; 1190 printl "Guessing DIMM is in", "bank $dimm_num"; 1252 if (!$use_hexdump) { 1253 if (($use_sysfs && /^[^-]+-([^-]+)$/) 1254 || (!$use_sysfs && /^[^-]+-[^-]+-[^-]+-([^-]+)$/)) { 1255 my $dimm_num = $1 - 49; 1256 printl "Guessing DIMM is in", "bank $dimm_num"; 1257 } 1191 1258 } 1192 1259
