| @@ -1,133 +1,133 @@ | | | @@ -1,133 +1,133 @@ |
1 | $NetBSD: patch-decode-dimms,v 1.5 2018/07/25 02:36:08 pgoyette Exp $ | | 1 | $NetBSD: patch-decode-dimms,v 1.6 2018/07/25 02:37:11 pgoyette Exp $ |
2 | | | 2 | |
3 | Add NetBSD-specific ability to use spdmem(4)'s sysctl values as | | 3 | Add NetBSD-specific ability to use spdmem(4)'s sysctl values as |
4 | input. | | 4 | input. |
5 | | | 5 | |
6 | --- decode-dimms.after-patch 2018-07-25 10:33:01.055537617 +0800 | | 6 | --- eeprom/decode-dimms.orig 2018-07-25 10:33:01.055537617 +0800 |
7 | +++ decode-dimms.master 2018-05-31 13:53:29.771907986 +0800 | | 7 | +++ eeprom/decode-dimms 2018-05-31 13:53:29.771907986 +0800 |
8 | @@ -1,4 +1,4 @@ | | 8 | @@ -1,4 +1,4 @@ |
9 | -#!/usr/pkg/bin/perl -w | | 9 | -#!/usr/pkg/bin/perl -w |
10 | +#!/usr/bin/perl -w | | 10 | +#!/usr/bin/perl -w |
11 | # | | 11 | # |
12 | # EEPROM data decoder for SDRAM DIMM modules | | 12 | # EEPROM data decoder for SDRAM DIMM modules |
13 | # | | 13 | # |
14 | @@ -42,9 +42,8 @@ | | 14 | @@ -42,9 +42,8 @@ |
15 | use Fcntl qw(:DEFAULT :seek); | | 15 | use Fcntl qw(:DEFAULT :seek); |
16 | use File::Basename; | | 16 | use File::Basename; |
17 | use vars qw($opt_html $opt_bodyonly $opt_side_by_side $opt_merge | | 17 | use vars qw($opt_html $opt_bodyonly $opt_side_by_side $opt_merge |
18 | - $opt_igncheck $use_sysfs $use_hexdump $use_sysctl $sbs_col_width | | 18 | - $opt_igncheck $use_sysfs $use_hexdump $use_sysctl $sbs_col_width |
19 | - @vendors %decode_callback $revision @dimm $current %hexdump_cache | | 19 | - @vendors %decode_callback $revision @dimm $current %hexdump_cache |
20 | - %sysctl_cache); | | 20 | - %sysctl_cache); |
21 | + $opt_igncheck $use_sysfs $use_hexdump $sbs_col_width | | 21 | + $opt_igncheck $use_sysfs $use_hexdump $sbs_col_width |
22 | + @vendors %decode_callback $revision @dimm $current %hexdump_cache); | | 22 | + @vendors %decode_callback $revision @dimm $current %hexdump_cache); |
23 | | | 23 | |
24 | use constant LITTLEENDIAN => "little-endian"; | | 24 | use constant LITTLEENDIAN => "little-endian"; |
25 | use constant BIGENDIAN => "big-endian"; | | 25 | use constant BIGENDIAN => "big-endian"; |
26 | @@ -342,7 +341,6 @@ | | 26 | @@ -342,7 +341,6 @@ |
27 | ); | | 27 | ); |
28 | | | 28 | |
29 | $use_sysfs = -d '/sys/bus'; | | 29 | $use_sysfs = -d '/sys/bus'; |
30 | -$use_sysctl = 0; | | 30 | -$use_sysctl = 0; |
31 | | | 31 | |
32 | # We consider that no data was written to this area of the SPD EEPROM if | | 32 | # We consider that no data was written to this area of the SPD EEPROM if |
33 | # all bytes read 0x00 or all bytes read 0xff | | 33 | # all bytes read 0x00 or all bytes read 0xff |
34 | @@ -2254,26 +2252,6 @@ | | 34 | @@ -2254,26 +2252,6 @@ |
35 | } | | 35 | } |
36 | } | | 36 | } |
37 | | | 37 | |
38 | -# read data from a NetBSD (or equivalent) sysctl variable | | 38 | -# read data from a NetBSD (or equivalent) sysctl variable |
39 | - | | 39 | - |
40 | -sub read_sysctl($) | | 40 | -sub read_sysctl($) |
41 | -{ | | 41 | -{ |
42 | - | | 42 | - |
43 | - # Look in the cache first | | 43 | - # Look in the cache first |
44 | - return @{$sysctl_cache{$_[0]}} if exists $sysctl_cache{$_[0]}; | | 44 | - return @{$sysctl_cache{$_[0]}} if exists $sysctl_cache{$_[0]}; |
45 | - | | 45 | - |
46 | - my $sysctl_var = sprintf("hw.%s.spd_data", $_[0]); | | 46 | - my $sysctl_var = sprintf("hw.%s.spd_data", $_[0]); |
47 | - open(PIPE, "-|", "sysctl -r $sysctl_var") | | 47 | - open(PIPE, "-|", "sysctl -r $sysctl_var") |
48 | - or die "Cannot read sysctl variable $sysctl_var"; | | 48 | - or die "Cannot read sysctl variable $sysctl_var"; |
49 | - sysread(PIPE, my $eeprom, 512); # XXX Assumed maximum size! XXX | | 49 | - sysread(PIPE, my $eeprom, 512); # XXX Assumed maximum size! XXX |
50 | - close PIPE or die "sysctl returned $?"; | | 50 | - close PIPE or die "sysctl returned $?"; |
51 | - my @bytes = unpack("C*", $eeprom); | | 51 | - my @bytes = unpack("C*", $eeprom); |
52 | - | | 52 | - |
53 | - # Cache the data for later use | | 53 | - # Cache the data for later use |
54 | - $hexdump_cache{$_[0]} = \@bytes; | | 54 | - $hexdump_cache{$_[0]} = \@bytes; |
55 | - return @bytes; | | 55 | - return @bytes; |
56 | -} | | 56 | -} |
57 | - | | 57 | - |
58 | # Read bytes from SPD-EEPROM | | 58 | # Read bytes from SPD-EEPROM |
59 | # Note: offset must be a multiple of 16! | | 59 | # Note: offset must be a multiple of 16! |
60 | sub readspd($$$) | | 60 | sub readspd($$$) |
61 | @@ -2283,9 +2261,6 @@ | | 61 | @@ -2283,9 +2261,6 @@ |
62 | if ($use_hexdump) { | | 62 | if ($use_hexdump) { |
63 | @bytes = read_hexdump($dimm_i); | | 63 | @bytes = read_hexdump($dimm_i); |
64 | return @bytes[$offset..($offset + $size - 1)]; | | 64 | return @bytes[$offset..($offset + $size - 1)]; |
65 | - } elsif ($use_sysctl) { | | 65 | - } elsif ($use_sysctl) { |
66 | - @bytes = read_sysctl($dimm_i); | | 66 | - @bytes = read_sysctl($dimm_i); |
67 | - return @bytes[$offset..($offset + $size - 1)]; | | 67 | - return @bytes[$offset..($offset + $size - 1)]; |
68 | } elsif ($use_sysfs) { | | 68 | } elsif ($use_sysfs) { |
69 | # Kernel 2.6 with sysfs | | 69 | # Kernel 2.6 with sysfs |
70 | sysopen(HANDLE, "$dimm_i/eeprom", O_RDONLY) | | 70 | sysopen(HANDLE, "$dimm_i/eeprom", O_RDONLY) |
71 | @@ -2362,7 +2337,7 @@ | | 71 | @@ -2362,7 +2337,7 @@ |
72 | # Parse command-line | | 72 | # Parse command-line |
73 | foreach (@ARGV) { | | 73 | foreach (@ARGV) { |
74 | if ($_ eq '-h' || $_ eq '--help') { | | 74 | if ($_ eq '-h' || $_ eq '--help') { |
75 | - print "Usage: $0 [-c] [-f [-b]] [-x|-X|-s file [files..]]\n", | | 75 | - print "Usage: $0 [-c] [-f [-b]] [-x|-X|-s file [files..]]\n", |
76 | + print "Usage: $0 [-c] [-f [-b]] [-x|-X file [files..]]\n", | | 76 | + print "Usage: $0 [-c] [-f [-b]] [-x|-X file [files..]]\n", |
77 | " $0 -h\n\n", | | 77 | " $0 -h\n\n", |
78 | " -f, --format Print nice html output\n", | | 78 | " -f, --format Print nice html output\n", |
79 | " -b, --bodyonly Don't print html header\n", | | 79 | " -b, --bodyonly Don't print html header\n", |
80 | @@ -2376,8 +2351,6 @@ | | 80 | @@ -2376,8 +2351,6 @@ |
81 | " -x, Read data from hexdump files\n", | | 81 | " -x, Read data from hexdump files\n", |
82 | " -X, Same as -x except treat multibyte hex\n", | | 82 | " -X, Same as -x except treat multibyte hex\n", |
83 | " data as little endian\n", | | 83 | " data as little endian\n", |
84 | - " -s, Use NetBSD-compatible sysctl(8) to obtain\n", | | 84 | - " -s, Use NetBSD-compatible sysctl(8) to obtain\n", |
85 | - " EEPROM data\n", | | 85 | - " EEPROM data\n", |
86 | " -h, --help Display this usage summary\n"; | | 86 | " -h, --help Display this usage summary\n"; |
87 | print <<"EOF"; | | 87 | print <<"EOF"; |
88 | | | 88 | |
89 | @@ -2422,20 +2395,13 @@ | | 89 | @@ -2422,20 +2395,13 @@ |
90 | $use_hexdump = LITTLEENDIAN; | | 90 | $use_hexdump = LITTLEENDIAN; |
91 | next; | | 91 | next; |
92 | } | | 92 | } |
93 | - if ($_ eq '-s') { | | 93 | - if ($_ eq '-s') { |
94 | - if (-x "/sbin/sysctl") { | | 94 | - if (-x "/sbin/sysctl") { |
95 | - $use_sysctl = 1; | | 95 | - $use_sysctl = 1; |
96 | - } else { die "No /sbin/sysctl available for -s"; } | | 96 | - } else { die "No /sbin/sysctl available for -s"; } |
97 | - next; | | 97 | - next; |
98 | - } | | 98 | - } |
99 | | | 99 | |
100 | if (m/^-/) { | | 100 | if (m/^-/) { |
101 | print STDERR "Unrecognized option $_\n"; | | 101 | print STDERR "Unrecognized option $_\n"; |
102 | exit; | | 102 | exit; |
103 | } | | 103 | } |
104 | | | 104 | |
105 | - push @dimm, { eeprom => basename($_), file => $_ } | | 105 | - push @dimm, { eeprom => basename($_), file => $_ } |
106 | - if ($use_sysctl || $use_hexdump); | | 106 | - if ($use_sysctl || $use_hexdump); |
107 | + push @dimm, { eeprom => basename($_), file => $_ } if $use_hexdump; | | 107 | + push @dimm, { eeprom => basename($_), file => $_ } if $use_hexdump; |
108 | } | | 108 | } |
109 | | | 109 | |
110 | # Default values | | 110 | # Default values |
111 | @@ -2513,7 +2479,7 @@ | | 111 | @@ -2513,7 +2479,7 @@ |
112 | # * chk_spd: The checksum or CRC value found in the EEPROM | | 112 | # * chk_spd: The checksum or CRC value found in the EEPROM |
113 | # * chk_calc: The checksum or CRC computed from the EEPROM data | | 113 | # * chk_calc: The checksum or CRC computed from the EEPROM data |
114 | # Keys are added over time. | | 114 | # Keys are added over time. |
115 | -@dimm = get_dimm_list() unless ($use_sysctl || $use_hexdump); | | 115 | -@dimm = get_dimm_list() unless ($use_sysctl || $use_hexdump); |
116 | +@dimm = get_dimm_list() unless $use_hexdump; | | 116 | +@dimm = get_dimm_list() unless $use_hexdump; |
117 | | | 117 | |
118 | for my $i (0 .. $#dimm) { | | 118 | for my $i (0 .. $#dimm) { |
119 | my @bytes = readspd(0, 128, $dimm[$i]->{file}); | | 119 | my @bytes = readspd(0, 128, $dimm[$i]->{file}); |
120 | @@ -2565,7 +2531,7 @@ | | 120 | @@ -2565,7 +2531,7 @@ |
121 | printl("Decoding EEPROM", $dimm[$current]->{eeprom}); | | 121 | printl("Decoding EEPROM", $dimm[$current]->{eeprom}); |
122 | } | | 122 | } |
123 | | | 123 | |
124 | - if (!$use_hexdump && !$use_sysctl) { | | 124 | - if (!$use_hexdump && !$use_sysctl) { |
125 | + if (!$use_hexdump) { | | 125 | + if (!$use_hexdump) { |
126 | if ($dimm[$current]->{file} =~ /-([\da-f]+)$/i) { | | 126 | if ($dimm[$current]->{file} =~ /-([\da-f]+)$/i) { |
127 | my $dimm_num = hex($1) - 0x50 + 1; | | 127 | my $dimm_num = hex($1) - 0x50 + 1; |
128 | if ($dimm_num >= 1 && $dimm_num <= 8) { | | 128 | if ($dimm_num >= 1 && $dimm_num <= 8) { |
129 | @@ -2771,4 +2737,3 @@ | | 129 | @@ -2771,4 +2737,3 @@ |
130 | printl2("\n\nNumber of SDRAM DIMMs detected and decoded", scalar @dimm); | | 130 | printl2("\n\nNumber of SDRAM DIMMs detected and decoded", scalar @dimm); |
131 | | | 131 | |
132 | print "</body></html>\n" if ($opt_html && !$opt_bodyonly); | | 132 | print "</body></html>\n" if ($opt_html && !$opt_bodyonly); |
133 | - | | 133 | - |