From 18de72569113ee86b6dcefa1005d33a93665e5cd Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 31 Aug 2011 13:20:43 +0000 Subject: [PATCH] Add data if SPD CRC checksum is invalid to rinv git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10412 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/SPD.pm | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/perl-xCAT/xCAT/SPD.pm b/perl-xCAT/xCAT/SPD.pm index 3ef173927..322bb76e7 100644 --- a/perl-xCAT/xCAT/SPD.pm +++ b/perl-xCAT/xCAT/SPD.pm @@ -6,6 +6,26 @@ require Exporter; our @ISA=qw/Exporter/; our @EXPORT_OK=qw/decode_spd/; +sub do_crc16 { + my @data = @_; + my $crc = 0; + while (@data) { + my $byte = shift @data; + $crc = $crc ^ $byte<<8; + my $loopcount=8; + while ($loopcount--) { + if ($crc & 0x8000) { + $crc = $crc <<1 ^ 0x1021; + } else { + $crc = $crc << 1; + } + } + } + return $crc & 0xffff;;;; +} + + + sub decode_manufacturer { my $jedec_ids = [ { @@ -720,7 +740,23 @@ sub decode_spd { unless ($rethash->{product}->{model}) { $rethash->{product}->{model}=pack("C*",@spd[128..145]); } - } + if ($spd[0] & 0b10000000) { #crc is to exclude 117-125, crc 0 to 116 + unless (do_crc16(@spd[0..116]) == ($spd[126]+($spd[127]<<8))) { + push @{$rethash->{product}->{extra}},"SPD CRC Invalid!"; + } + } else { #crc for 0 to 125 + unless (do_crc16(@spd[0..125]) == ($spd[126]+($spd[127]<<8))) { + push @{$rethash->{product}->{extra}},"CRC Invalid!"; + } + } + my $rawspd="SPD Dump: "; + foreach (@spd) { + $rawspd .= sprintf("%02X ",$_); + } + push @{$rethash->{product}->{extra}},$rawspd; + } else { + $rethash->{product}->{model}="Unrecognized SPD"; + } return $rethash; }