root/i2c-tools/trunk/eeprom/decode-dimms

Revision 5388, 48.8 kB (checked in by khali, 2 weeks ago)

Only export the ceil function from POSIX. By default, POSIX exports
everything, and this happens to generate warnings when using perl 5.10.0.
That's a perl bug, but we can still work around it and avoid potential
future issues of the same kind.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/perl -w
2 #
3 # EEPROM data decoder for SDRAM DIMM modules
4 #
5 # Copyright 1998, 1999 Philip Edelbrock <phil@netroedge.com>
6 # modified by Christian Zuckschwerdt <zany@triq.net>
7 # modified by Burkart Lingner <burkart@bollchen.de>
8 # Copyright (C) 2005-2008  Jean Delvare <khali@linux-fr.org>
9 #
10 #    This program is free software; you can redistribute it and/or modify
11 #    it under the terms of the GNU General Public License as published by
12 #    the Free Software Foundation; either version 2 of the License, or
13 #    (at your option) any later version.
14 #
15 #    This program is distributed in the hope that it will be useful,
16 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 #    GNU General Public License for more details.
19 #
20 #    You should have received a copy of the GNU General Public License
21 #    along with this program; if not, write to the Free Software
22 #    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 #    MA 02110-1301 USA.
24 #
25 #
26 # The eeprom driver must be loaded (unless option -x is used). For kernels
27 # older than 2.6.0, the eeprom driver can be found in the lm-sensors package.
28 #
29 # References:
30 # PC SDRAM Serial Presence
31 # Detect (SPD) Specification, Intel,
32 # 1997,1999, Rev 1.2B
33 #
34 # Jedec Standards 4.1.x & 4.5.x
35 # http://www.jedec.org
36 #
37
38 require 5.004;
39
40 use strict;
41 use POSIX qw(ceil);
42 use Fcntl qw(:DEFAULT :seek);
43 use vars qw($opt_html $opt_bodyonly $opt_igncheck $use_sysfs $use_hexdump
44             @vendors %decode_callback $revision @dimm_list %hexdump_cache);
45
46 use constant LITTLEENDIAN       => "little-endian";
47 use constant BIGENDIAN          => "big-endian";
48
49 $revision = '$Revision$ ($Date$)';
50 $revision =~ s/\$\w+: (.*?) \$/$1/g;
51 $revision =~ s/ \([^()]*\)//;
52
53 @vendors = (
54 ["AMD", "AMI", "Fairchild", "Fujitsu",
55  "GTE", "Harris", "Hitachi", "Inmos",
56  "Intel", "I.T.T.", "Intersil", "Monolithic Memories",
57  "Mostek", "Freescale (former Motorola)", "National", "NEC",
58  "RCA", "Raytheon", "Conexant (Rockwell)", "Seeq",
59  "NXP (former Signetics, Philips Semi.)", "Synertek", "Texas Instruments", "Toshiba",
60  "Xicor", "Zilog", "Eurotechnique", "Mitsubishi",
61  "Lucent (AT&T)", "Exel", "Atmel", "SGS/Thomson",
62  "Lattice Semi.", "NCR", "Wafer Scale Integration", "IBM",
63  "Tristar", "Visic", "Intl. CMOS Technology", "SSSI",
64  "MicrochipTechnology", "Ricoh Ltd.", "VLSI", "Micron Technology",
65  "Hyundai Electronics", "OKI Semiconductor", "ACTEL", "Sharp",
66  "Catalyst", "Panasonic", "IDT", "Cypress",
67  "DEC", "LSI Logic", "Zarlink (former Plessey)", "UTMC",
68  "Thinking Machine", "Thomson CSF", "Integrated CMOS (Vertex)", "Honeywell",
69  "Tektronix", "Sun Microsystems", "SST", "ProMos/Mosel Vitelic",
70  "Infineon (former Siemens)", "Macronix", "Xerox", "Plus Logic",
71  "SunDisk", "Elan Circuit Tech.", "European Silicon Str.", "Apple Computer",
72  "Xilinx", "Compaq", "Protocol Engines", "SCI",
73  "Seiko Instruments", "Samsung", "I3 Design System", "Klic",
74  "Crosspoint Solutions", "Alliance Semiconductor", "Tandem", "Hewlett-Packard",
75  "Intg. Silicon Solutions", "Brooktree", "New Media", "MHS Electronic",
76  "Performance Semi.", "Winbond Electronic", "Kawasaki Steel", "Bright Micro",
77  "TECMAR", "Exar", "PCMCIA", "LG Semi (former Goldstar)",
78  "Northern Telecom", "Sanyo", "Array Microsystems", "Crystal Semiconductor",
79  "Analog Devices", "PMC-Sierra", "Asparix", "Convex Computer",
80  "Quality Semiconductor", "Nimbus Technology", "Transwitch", "Micronas (ITT Intermetall)",
81  "Cannon", "Altera", "NEXCOM", "QUALCOMM",
82  "Sony", "Cray Research", "AMS(Austria Micro)", "Vitesse",
83  "Aster Electronics", "Bay Networks (Synoptic)", "Zentrum or ZMD", "TRW",
84  "Thesys", "Solbourne Computer", "Allied-Signal", "Dialog",
85  "Media Vision", "Level One Communication"],
86 ["Cirrus Logic", "National Instruments", "ILC Data Device", "Alcatel Mietec",
87  "Micro Linear", "Univ. of NC", "JTAG Technologies", "BAE Systems",
88  "Nchip", "Galileo Tech", "Bestlink Systems", "Graychip",
89  "GENNUM", "VideoLogic", "Robert Bosch", "Chip Express",
90  "DATARAM", "United Microelec Corp.", "TCSI", "Smart Modular",
91  "Hughes Aircraft", "Lanstar Semiconductor", "Qlogic", "Kingston",
92  "Music Semi", "Ericsson Components", "SpaSE", "Eon Silicon Devices",
93  "Programmable Micro Corp", "DoD", "Integ. Memories Tech.", "Corollary Inc.",
94  "Dallas Semiconductor", "Omnivision", "EIV(Switzerland)", "Novatel Wireless",
95  "Zarlink (former Mitel)", "Clearpoint", "Cabletron", "STEC (former Silicon Technology)",
96  "Vanguard", "Hagiwara Sys-Com", "Vantis", "Celestica",
97  "Century", "Hal Computers", "Rohm Company Ltd.", "Juniper Networks",
98  "Libit Signal Processing", "Mushkin Enhanced Memory", "Tundra Semiconductor", "Adaptec Inc.",
99  "LightSpeed Semi.", "ZSP Corp.", "AMIC Technology", "Adobe Systems",
100  "Dynachip", "PNY Electronics", "Newport Digital", "MMC Networks",
101  "T Square", "Seiko Epson", "Broadcom", "Viking Components",
102  "V3 Semiconductor", "Flextronics (former Orbit)", "Suwa Electronics", "Transmeta",
103  "Micron CMS", "American Computer & Digital Components Inc", "Enhance 3000 Inc", "Tower Semiconductor",
104  "CPU Design", "Price Point", "Maxim Integrated Product", "Tellabs",
105  "Centaur Technology", "Unigen Corporation", "Transcend Information", "Memory Card Technology",
106  "CKD Corporation Ltd.", "Capital Instruments, Inc.", "Aica Kogyo, Ltd.", "Linvex Technology",
107  "MSC Vertriebs GmbH", "AKM Company, Ltd.", "Dynamem, Inc.", "NERA ASA",
108  "GSI Technology", "Dane-Elec (C Memory)", "Acorn Computers", "Lara Technology",
109  "Oak Technology, Inc.", "Itec Memory", "Tanisys Technology", "Truevision",
110  "Wintec Industries", "Super PC Memory", "MGV Memory", "Galvantech",
111  "Gadzoox Nteworks", "Multi Dimensional Cons.", "GateField", "Integrated Memory System",
112  "Triscend", "XaQti", "Goldenram", "Clear Logic",
113  "Cimaron Communications", "Nippon Steel Semi. Corp.", "Advantage Memory", "AMCC",
114  "LeCroy", "Yamaha Corporation", "Digital Microwave", "NetLogic Microsystems",
115  "MIMOS Semiconductor", "Advanced Fibre", "BF Goodrich Data.", "Epigram",
116  "Acbel Polytech Inc.", "Apacer Technology", "Admor Memory", "FOXCONN",
117  "Quadratics Superconductor", "3COM"],
118 ["Camintonn Corporation", "ISOA Incorporated", "Agate Semiconductor", "ADMtek Incorporated",
119  "HYPERTEC", "Adhoc Technologies", "MOSAID Technologies", "Ardent Technologies",
120  "Switchcore", "Cisco Systems, Inc.", "Allayer Technologies", "WorkX AG",
121  "Oasis Semiconductor", "Novanet Semiconductor", "E-M Solutions", "Power General",
122  "Advanced Hardware Arch.", "Inova Semiconductors GmbH", "Telocity", "Delkin Devices",
123  "Symagery Microsystems", "C-Port Corporation", "SiberCore Technologies", "Southland Microsystems",
124  "Malleable Technologies", "Kendin Communications", "Great Technology Microcomputer", "Sanmina Corporation",
125  "HADCO Corporation", "Corsair", "Actrans System Inc.", "ALPHA Technologies",
126  "Silicon Laboratories, Inc. (Cygnal)", "Artesyn Technologies", "Align Manufacturing", "Peregrine Semiconductor",
127  "Chameleon Systems", "Aplus Flash Technology", "MIPS Technologies", "Chrysalis ITS",
128  "ADTEC Corporation", "Kentron Technologies", "Win Technologies", "Tachyon Semiconductor (former ASIC Designs Inc.)",
129  "Extreme Packet Devices", "RF Micro Devices", "Siemens AG", "Sarnoff Corporation",
130  "Itautec Philco SA", "Radiata Inc.", "Benchmark Elect. (AVEX)", "Legend",
131  "SpecTek Incorporated", "Hi/fn", "Enikia Incorporated", "SwitchOn Networks",
132  "AANetcom Incorporated", "Micro Memory Bank", "ESS Technology", "Virata Corporation",
133  "Excess Bandwidth", "West Bay Semiconductor", "DSP Group", "Newport Communications",
134  "Chip2Chip Incorporated", "Phobos Corporation", "Intellitech Corporation", "Nordic VLSI ASA",
135  "Ishoni Networks", "Silicon Spice", "Alchemy Semiconductor", "Agilent Technologies",
136  "Centillium Communications", "W.L. Gore", "HanBit Electronics", "GlobeSpan",
137  "Element 14", "Pycon", "Saifun Semiconductors", "Sibyte, Incorporated",
138  "MetaLink Technologies", "Feiya Technology", "I & C Technology", "Shikatronics",
139  "Elektrobit", "Megic", "Com-Tier", "Malaysia Micro Solutions",
140  "Hyperchip", "Gemstone Communications", "Anadigm (former Anadyne)", "3ParData",
141  "Mellanox Technologies", "Tenx Technologies", "Helix AG", "Domosys",
142  "Skyup Technology", "HiNT Corporation", "Chiaro", "MDT Technologies GmbH (former MCI Computer GMBH)",
143  "Exbit Technology A/S", "Integrated Technology Express", "AVED Memory", "Legerity",
144  "Jasmine Networks", "Caspian Networks", "nCUBE", "Silicon Access Networks",
145  "FDK Corporation", "High Bandwidth Access", "MultiLink Technology", "BRECIS",
146  "World Wide Packets", "APW", "Chicory Systems", "Xstream Logic",
147  "Fast-Chip", "Zucotto Wireless", "Realchip", "Galaxy Power",
148  "eSilicon", "Morphics Technology", "Accelerant Networks", "Silicon Wave",
149  "SandCraft", "Elpida"],
150 ["Solectron", "Optosys Technologies", "Buffalo (former Melco)", "TriMedia Technologies",
151  "Cyan Technologies", "Global Locate", "Optillion", "Terago Communications",
152  "Ikanos Communications", "Princeton Technology", "Nanya Technology", "Elite Flash Storage",
153  "Mysticom", "LightSand Communications", "ATI Technologies", "Agere Systems",
154  "NeoMagic", "AuroraNetics", "Golden Empire", "Mushkin",
155  "Tioga Technologies", "Netlist", "TeraLogic", "Cicada Semiconductor",
156  "Centon Electronics", "Tyco Electronics", "Magis Works", "Zettacom",
157  "Cogency Semiconductor", "Chipcon AS", "Aspex Technology", "F5 Networks",
158  "Programmable Silicon Solutions", "ChipWrights", "Acorn Networks", "Quicklogic",
159  "Kingmax Semiconductor", "BOPS", "Flasys", "BitBlitz Communications",
160  "eMemory Technology", "Procket Networks", "Purple Ray", "Trebia Networks",
161  "Delta Electronics", "Onex Communications", "Ample Communications", "Memory Experts Intl",
162  "Astute Networks", "Azanda Network Devices", "Dibcom", "Tekmos",
163  "API NetWorks", "Bay Microsystems", "Firecron Ltd", "Resonext Communications",
164  "Tachys Technologies", "Equator Technology", "Concept Computer", "SILCOM",
165  "3Dlabs", "c't Magazine", "Sanera Systems", "Silicon Packets",
166  "Viasystems Group", "Simtek", "Semicon Devices Singapore", "Satron Handelsges",
167  "Improv Systems", "INDUSYS GmbH", "Corrent", "Infrant Technologies",
168  "Ritek Corp", "empowerTel Networks", "Hypertec", "Cavium Networks",
169  "PLX Technology", "Massana Design", "Intrinsity", "Valence Semiconductor",
170  "Terawave Communications", "IceFyre Semiconductor", "Primarion", "Picochip Designs Ltd",
171  "Silverback Systems", "Jade Star Technologies", "Pijnenburg Securealink",
172  "TakeMS International AG", "Cambridge Silicon Radio",
173  "Swissbit", "Nazomi Communications", "eWave System",
174  "Rockwell Collins", "Picocel Co., Ltd.", "Alphamosaic Ltd", "Sandburst",
175  "SiCon Video", "NanoAmp Solutions", "Ericsson Technology", "PrairieComm",
176  "Mitac International", "Layer N Networks", "MtekVision", "Allegro Networks",
177  "Marvell Semiconductors", "Netergy Microelectronic", "NVIDIA", "Internet Machines",
178  "Peak Electronics", "Litchfield Communication", "Accton Technology", "Teradiant Networks",
179  "Europe Technologies", "Cortina Systems", "RAM Components", "Raqia Networks",
180  "ClearSpeed", "Matsushita Battery", "Xelerated", "SimpleTech",
181  "Utron Technology", "Astec International", "AVM gmbH", "Redux Communications",
182  "Dot Hill Systems", "TeraChip"],
183 ["T-RAM Incorporated", "Innovics Wireless", "Teknovus", "KeyEye Communications",
184  "Runcom Technologies", "RedSwitch", "Dotcast", "Silicon Mountain Memory",
185  "Signia Technologies", "Pixim", "Galazar Networks", "White Electronic Designs",
186  "Patriot Scientific", "Neoaxiom Corporation", "3Y Power Technology", "Europe Technologies",
187  "Potentia Power Systems", "C-guys Incorporated", "Digital Communications Technology Incorporated", "Silicon-Based Technology",
188  "Fulcrum Microsystems", "Positivo Informatica Ltd", "XIOtech Corporation", "PortalPlayer",
189  "Zhiying Software", "Direct2Data", "Phonex Broadband", "Skyworks Solutions",
190  "Entropic Communications", "Pacific Force Technology", "Zensys A/S", "Legend Silicon Corp.",
191  "sci-worx GmbH", "SMSC (former Oasis Silicon Systems)", "Renesas Technology", "Raza Microelectronics",
192  "Phyworks", "MediaTek", "Non-cents Productions", "US Modular",
193  "Wintegra Ltd", "Mathstar", "StarCore", "Oplus Technologies",
194  "Mindspeed", "Just Young Computer", "Radia Communications", "OCZ",
195  "Emuzed", "LOGIC Devices", "Inphi Corporation", "Quake Technologies",
196  "Vixel", "SolusTek", "Kongsberg Maritime", "Faraday Technology",
197  "Altium Ltd.", "Insyte", "ARM Ltd.", "DigiVision",
198  "Vativ Technologies", "Endicott Interconnect Technologies", "Pericom", "Bandspeed",
199  "LeWiz Communications", "CPU Technology", "Ramaxel Technology", "DSP Group",
200  "Axis Communications", "Legacy Electronics", "Chrontel", "Powerchip Semiconductor",
201  "MobilEye Technologies", "Excel Semiconductor", "A-DATA Technology", "VirtualDigm",
202  "G Skill Intl", "Quanta Computer", "Yield Microelectronics", "Afa Technologies",
203  "KINGBOX Technology Co. Ltd.", "Ceva", "iStor Networks", "Advance Modules",
204  "Microsoft", "Open-Silicon", "Goal Semiconductor", "ARC International",
205  "Simmtec", "Metanoia", "Key Stream", "Lowrance Electronics",
206  "Adimos", "SiGe Semiconductor", "Fodus Communications", "Credence Systems Corp.",
207  "Genesis Microchip Inc.", "Vihana, Inc.", "WIS Technologies", "GateChange Technologies",
208  "High Density Devices AS", "Synopsys", "Gigaram", "Enigma Semiconductor Inc.",
209  "Century Micro Inc.", "Icera Semiconductor", "Mediaworks Integrated Systems", "O'Neil Product Development",
210  "Supreme Top Technology Ltd.", "MicroDisplay Corporation", "Team Group Inc.", "Sinett Corporation",
211  "Toshiba Corporation", "Tensilica", "SiRF Technology", "Bacoc Inc.",
212  "SMaL Camera Technologies", "Thomson SC", "Airgo Networks", "Wisair Ltd.",
213  "SigmaTel", "Arkados", "Compete IT gmbH Co. KG", "Eudar Technology Inc.",
214  "Focus Enhancements", "Xyratex"],
215 ["Specular Networks", "Patriot Memory", "U-Chip Technology Corp.", "Silicon Optix",
216  "Greenfield Networks", "CompuRAM GmbH", "Stargen, Inc.", "NetCell Corporation",
217  "Excalibrus Technologies Ltd", "SCM Microsystems", "Xsigo Systems, Inc.", "CHIPS & Systems Inc",
218  "Tier 1 Multichip Solutions", "CWRL Labs", "Teradici", "Gigaram, Inc.",
219  "g2 Microsystems", "PowerFlash Semiconductor", "P.A. Semi, Inc.", "NovaTech Solutions, S.A.",
220  "c2 Microsystems, Inc.", "Level5 Networks", "COS Memory AG", "Innovasic Semiconductor",
221  "02IC Co. Ltd", "Tabula, Inc.", "Crucial Technology", "Chelsio Communications",
222  "Solarflare Communications", "Xambala Inc.", "EADS Astrium", "ATO Semicon Co. Ltd.",
223  "Imaging Works, Inc.", "Astute Networks, Inc.", "Tzero", "Emulex",
224  "Power-One", "Pulse~LINK Inc.", "Hon Hai Precision Industry", "White Rock Networks Inc.",
225  "Telegent Systems USA, Inc.", "Atrua Technologies, Inc.", "Acbel Polytech Inc.",
226  "eRide Inc.","ULi Electronics Inc.", "Magnum Semiconductor Inc.", "neoOne Technology, Inc.",
227  "Connex Technology, Inc.", "Stream Processors, Inc.", "Focus Enhancements", "Telecis Wireless, Inc.",
228  "uNav Microelectronics", "Tarari, Inc.", "Ambric, Inc.", "Newport Media, Inc.", "VMTS",
229  "Enuclia Semiconductor, Inc.", "Virtium Technology Inc.", "Solid State System Co., Ltd.", "Kian Tech LLC",
230  "Artimi", "Power Quotient International", "Avago Technologies", "ADTechnology", "Sigma Designs",
231  "SiCortex, Inc.", "Ventura Technology Group", "eASIC", "M.H.S. SAS", "Micro Star International",
232  "Rapport Inc.", "Makway International", "Broad Reach Engineering Co.",
233  "Semiconductor Mfg Intl Corp", "SiConnect", "FCI USA Inc.", "Validity Sensors",
234  "Coney Technology Co. Ltd.", "Spans Logic", "Neterion Inc.", "Qimonda",
235  "New Japan Radio Co. Ltd.", "Velogix", "Montalvo Systems", "iVivity Inc.", "Walton Chaintech",
236  "AENEON", "Lorom Industrial Co. Ltd.", "Radiospire Networks", "Sensio Technologies, Inc.",
237  "Nethra Imaging", "Hexon Technology Pte Ltd", "CompuStocx (CSX)", "Methode Electronics, Inc.",
238  "Connect One Ltd.", "Opulan Technologies", "Septentrio NV", "Goldenmars Technology Inc.",
239  "Kreton Corporation", "Cochlear Ltd.", "Altair Semiconductor", "NetEffect, Inc.",
240  "Spansion, Inc.", "Taiwan Semiconductor Mfg", "Emphany Systems Inc.",
241  "ApaceWave Technologies", "Mobilygen Corporation", "Tego", "Cswitch Corporation",
242  "Haier (Beijing) IC Design Co.", "MetaRAM", "Axel Electronics Co. Ltd.", "Tilera Corporation",
243  "Aquantia", "Vivace Semiconductor", "Redpine Signals", "Octalica", "InterDigital Communications",
244  "Avant Technology", "Asrock, Inc.", "Availink", "Quartics, Inc.", "Element CXI",
245  "Innovaciones Microelectronicas", "VeriSilicon Microelectronics", "W5 Networks"],
246 ["MOVEKING", "Mavrix Technology, Inc.", "CellGuide Ltd.", "Faraday Technology",
247  "Diablo Technologies, Inc.", "Jennic", "Octasic", "Molex Incorporated", "3Leaf Networks",
248  "Bright Micron Technology", "Netxen", "NextWave Broadband Inc.", "DisplayLink", "ZMOS Technology",
249  "Tec-Hill", "Multigig, Inc.", "Amimon", "Euphonic Technologies, Inc.", "BRN Phoenix",
250  "InSilica", "Ember Corporation", "Avexir Technologies Corporation", "Echelon Corporation",
251  "Edgewater Computer Systems", "XMOS Semiconductor Ltd.", "GENUSION, Inc.", "Memory Corp NV",
252  "SiliconBlue Technologies", "Rambus Inc."]);
253
254 $use_sysfs = -d '/sys/bus';
255
256 # We consider that no data was written to this area of the SPD EEPROM if
257 # all bytes read 0x00 or all bytes read 0xff
258 sub spd_written(@)
259 {
260         my $all_00 = 1;
261         my $all_ff = 1;
262
263         foreach my $b (@_) {
264                 $all_00 = 0 unless $b == 0x00;
265                 $all_ff = 0 unless $b == 0xff;
266                 return 1 unless $all_00 or $all_ff;
267         }
268
269         return 0;
270 }
271
272 sub parity($)
273 {
274         my $n = shift;
275         my $parity = 0;
276
277         while ($n) {
278                 $parity++ if ($n & 1);
279                 $n >>= 1;
280         }
281
282         return ($parity & 1);
283 }
284
285 sub manufacturer(@)
286 {
287         my @bytes = @_;
288         my $ai = 0;
289         my $first;
290
291         return ("Undefined", []) unless spd_written(@bytes);
292
293         while (defined($first = shift(@bytes)) && $first == 0x7F) {
294                 $ai++;
295         }
296
297         return ("Invalid", []) unless defined $first;
298         return ("Invalid", [$first, @bytes]) if parity($first) != 1;
299         return ("Unknown", \@bytes) unless (($first & 0x7F) - 1 <= $vendors[$ai]);
300
301         return ($vendors[$ai][($first & 0x7F) - 1], \@bytes);
302 }
303
304 sub manufacturer_data(@)
305 {
306         my $hex = "";
307         my $asc = "";
308
309         return unless spd_written(@_);
310
311         foreach my $byte (@_) {
312                 $hex .= sprintf("\%02X ", $byte);
313                 $asc .= ($byte >= 32 && $byte < 127) ? chr($byte) : '?';
314         }
315
316         return "$hex(\"$asc\")";
317 }
318
319 sub part_number(@)
320 {
321         my $asc = "";
322         my $byte;
323
324         while (defined ($byte = shift) && $byte >= 32 && $byte < 127) {
325                 $asc .= chr($byte);
326         }
327
328         return ($asc eq "") ? "Undefined" : $asc;
329 }
330
331 sub cas_latencies(@)
332 {
333         return "None" unless @_;
334         return join ', ', map("${_}T", sort { $b <=> $a } @_);
335 }
336
337 sub printl($$) # print a line w/ label and value
338 {
339         my ($label, $value) = @_;
340         if ($opt_html) {
341                 $label =~ s/</\&lt;/sg;
342                 $label =~ s/>/\&gt;/sg;
343                 $label =~ s/\n/<br>\n/sg;
344                 $value =~ s/</\&lt;/sg;
345                 $value =~ s/>/\&gt;/sg;
346                 $value =~ s/\n/<br>\n/sg;
347                 print "<tr><td valign=top>$label</td><td>$value</td></tr>\n";
348         } else {
349                 my @values = split /\n/, $value;
350                 printf "%-47s %s\n", $label, shift @values;
351                 printf "%-47s %s\n", "", $_ foreach (@values);
352         }
353 }
354
355 sub printl2($$) # print a line w/ label and value (outside a table)
356 {
357         my ($label, $value) = @_;
358         if ($opt_html) {
359                 $label =~ s/</\&lt;/sg;
360                 $label =~ s/>/\&gt;/sg;
361                 $label =~ s/\n/<br>\n/sg;
362                 $value =~ s/</\&lt;/sg;
363                 $value =~ s/>/\&gt;/sg;
364                 $value =~ s/\n/<br>\n/sg;
365         }
366         print "$label: $value\n";
367 }
368
369 sub prints($) # print seperator w/ given text
370 {
371         my ($label) = @_;
372         if ($opt_html) {
373                 $label =~ s/</\&lt;/sg;
374                 $label =~ s/>/\&gt;/sg;
375                 $label =~ s/\n/<br>\n/sg;
376                 print "<tr><td align=center colspan=2><b>$label</b></td></tr>\n";
377         } else {
378                 print "\n---=== $label ===---\n";
379         }
380 }
381
382 sub printh($$) # print header w/ given text
383 {
384         my ($header, $sub) = @_;
385         if ($opt_html) {
386                 $header =~ s/</\&lt;/sg;
387                 $header =~ s/>/\&gt;/sg;
388                 $header =~ s/\n/<br>\n/sg;
389                 $sub =~ s/</\&lt;/sg;
390                 $sub =~ s/>/\&gt;/sg;
391                 $sub =~ s/\n/<br>\n/sg;
392                 print "<h1>$header</h1>\n";
393                 print "<p>$sub</p>\n";
394         } else {
395                 print "\n$header\n$sub\n";
396         }
397 }
398
399 sub printc($) # print comment
400 {
401         my ($comment) = @_;
402         if ($opt_html) {
403                 $comment =~ s/</\&lt;/sg;
404                 $comment =~ s/>/\&gt;/sg;
405                 $comment =~ s/\n/<br>\n/sg;
406                 print "<!-- $comment -->\n";
407         } else {
408                 print "# $comment\n";
409         }
410 }
411
412 sub tns($) # print a time in ns
413 {
414         return sprintf("%3.2f ns", $_[0]);
415 }
416
417 # Parameter: bytes 0-63
418 sub decode_sdr_sdram($)
419 {
420         my $bytes = shift;
421         my ($l, $temp);
422
423 # SPD revision
424         printl "SPD Revision", $bytes->[62];
425
426 #size computation
427
428         prints "Memory Characteristics";
429
430         my $k = 0;
431         my $ii = 0;
432
433         $ii = ($bytes->[3] & 0x0f) + ($bytes->[4] & 0x0f) - 17;
434         if (($bytes->[5] <= 8) && ($bytes->[17] <= 8)) {
435                  $k = $bytes->[5] * $bytes->[17];
436         }
437
438         if ($ii > 0 && $ii <= 12 && $k > 0) {
439                 printl "Size", ((1 << $ii) * $k) . " MB";
440         } else {
441                 printl "INVALID SIZE", $bytes->[3] . "," . $bytes->[4] . "," .
442                                        $bytes->[5] . "," . $bytes->[17];
443         }
444
445         my @cas;
446         for ($ii = 0; $ii < 7; $ii++) {
447                 push(@cas, $ii + 1) if ($bytes->[18] & (1 << $ii));
448         }
449
450         my $trcd;
451         my $trp;
452         my $tras;
453         my $ctime = ($bytes->[9] >> 4) + ($bytes->[9] & 0xf) * 0.1;
454
455         $trcd = $bytes->[29];
456         $trp = $bytes->[27];;
457         $tras = $bytes->[30];
458
459         printl "tCL-tRCD-tRP-tRAS",
460                 $cas[$#cas] . "-" .
461                 ceil($trcd/$ctime) . "-" .
462                 ceil($trp/$ctime) . "-" .
463                 ceil($tras/$ctime);
464
465         $l = "Number of Row Address Bits";
466         if ($bytes->[3] == 0) { printl $l, "Undefined!"; }
467         elsif ($bytes->[3] == 1) { printl $l, "1/16"; }
468         elsif ($bytes->[3] == 2) { printl $l, "2/17"; }
469         elsif ($bytes->[3] == 3) { printl $l, "3/18"; }
470         else { printl $l, $bytes->[3]; }
471
472         $l = "Number of Col Address Bits";
473         if ($bytes->[4] == 0) { printl $l, "Undefined!"; }
474         elsif ($bytes->[4] == 1) { printl $l, "1/16"; }
475         elsif ($bytes->[4] == 2) { printl $l, "2/17"; }
476         elsif ($bytes->[4] == 3) { printl $l, "3/18"; }
477         else { printl $l, $bytes->[4]; }
478
479         $l = "Number of Module Rows";
480         if ($bytes->[5] == 0 ) { printl $l, "Undefined!"; }
481         else { printl $l, $bytes->[5]; }
482
483         $l = "Data Width";
484         if ($bytes->[7] > 1) {
485                 printl $l, "Undefined!"
486         } else {
487                 $temp = ($bytes->[7] * 256) + $bytes->[6];
488                 printl $l, $temp;
489         }
490
491         $l = "Module Interface Signal Levels";
492         if ($bytes->[8] == 0) { printl $l, "5.0 Volt/TTL"; }
493         elsif ($bytes->[8] == 1) { printl $l, "LVTTL"; }
494         elsif ($bytes->[8] == 2) { printl $l, "HSTL 1.5"; }
495         elsif ($bytes->[8] == 3) { printl $l, "SSTL 3.3"; }
496         elsif ($bytes->[8] == 4) { printl $l, "SSTL 2.5"; }
497         elsif ($bytes->[8] == 255) { printl $l, "New Table"; }
498         else { printl $l, "Undefined!"; }
499
500         $l = "Module Configuration Type";
501         if ($bytes->[11] == 0) { printl $l, "No Parity"; }
502         elsif ($bytes->[11] == 1) { printl $l, "Parity"; }
503         elsif ($bytes->[11] == 2) { printl $l, "ECC"; }
504         else { printl $l, "Undefined!"; }
505
506         $l = "Refresh Type";
507         if ($bytes->[12] > 126) { printl $l, "Self Refreshing"; }
508         else { printl $l, "Not Self Refreshing"; }
509
510         $l = "Refresh Rate";
511         $temp = $bytes->[12] & 0x7f;
512         if ($temp == 0) { printl $l, "Normal (15.625 us)"; }
513         elsif ($temp == 1) { printl $l, "Reduced (3.9 us)"; }
514         elsif ($temp == 2) { printl $l, "Reduced (7.8 us)"; }
515         elsif ($temp == 3) { printl $l, "Extended (31.3 us)"; }
516         elsif ($temp == 4) { printl $l, "Extended (62.5 us)"; }
517         elsif ($temp == 5) { printl $l, "Extended (125 us)"; }
518         else { printl $l, "Undefined!"; }
519
520         $l = "Primary SDRAM Component Bank Config";
521         if ($bytes->[13] > 126) { printl $l, "Bank2 = 2 x Bank1"; }
522         else { printl $l, "No Bank2 OR Bank2 = Bank1 width"; }
523
524         $l = "Primary SDRAM Component Widths";
525         $temp = $bytes->[13] & 0x7f;
526         if ($temp == 0) { printl $l, "Undefined!\n"; }
527         else { printl $l, $temp; }
528
529         $l = "Error Checking SDRAM Component Bank Config";
530         if ($bytes->[14] > 126) { printl $l, "Bank2 = 2 x Bank1"; }
531         else { printl $l, "No Bank2 OR Bank2 = Bank1 width"; }
532
533         $l = "Error Checking SDRAM Component Widths";
534         $temp = $bytes->[14] & 0x7f;
535         if ($temp == 0) { printl $l, "Undefined!"; }
536         else { printl $l, $temp; }
537
538         $l = "Min Clock Delay for Back to Back Random Access";
539         if ($bytes->[15] == 0) { printl $l, "Undefined!"; }
540         else { printl $l, $bytes->[15]; }
541
542         $l = "Supported Burst Lengths";
543         my @array;
544         for ($ii = 0; $ii < 4; $ii++) {
545                 push(@array, 1 << $ii) if ($bytes->[16] & (1 << $ii));
546         }
547         push(@array, "Page") if ($bytes->[16] & 128);
548         if (@array) { $temp = join ', ', @array; }
549         else { $temp = "None"; }
550         printl $l, $temp;
551
552         $l = "Number of Device Banks";
553         if ($bytes->[17] == 0) { printl $l, "Undefined/Reserved!"; }
554         else { printl $l, $bytes->[17]; }
555
556         $l = "Supported CAS Latencies";
557         printl $l, cas_latencies(@cas);
558
559         $l = "Supported CS Latencies";
560         @array = ();
561         for ($ii = 0; $ii < 7; $ii++) {
562                 push(@array, $ii) if ($bytes->[19] & (1 << $ii));
563         }
564         if (@array) { $temp = join ', ', @array; }
565         else { $temp = "None"; }
566         printl $l, $temp;
567
568         $l = "Supported WE Latencies";
569         @array = ();
570         for ($ii = 0; $ii < 7; $ii++) {
571                 push(@array, $ii) if ($bytes->[20] & (1 << $ii));
572         }
573         if (@array) { $temp = join ', ', @array; }
574         else { $temp = "None"; }
575         printl $l, $temp;
576