Changeset 5830
- Timestamp:
- 03/08/10 15:00:52 (5 months ago)
- Location:
- i2c-tools/trunk
- Files:
-
- 3 modified
-
CHANGES (modified) (1 diff)
-
stub/i2c-stub-from-dump (modified) (6 diffs)
-
stub/i2c-stub-from-dump.8 (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
i2c-tools/trunk/CHANGES
r5828 r5830 18 18 i2c-stub-from-dump: Use udev settle to speed up initialization 19 19 Unload i2c-stub automatically if needed 20 Add support for multiple dumps 20 21 21 22 3.0.2 (2008-11-29) -
i2c-tools/trunk/stub/i2c-stub-from-dump
r5829 r5830 23 23 24 24 use strict; 25 use vars qw($bus_nr $addr $err);25 use vars qw($bus_nr @addr $err); 26 26 27 27 # Kernel version detection code by Mark M. Hoffman, … … 65 65 sub check_chip_addr { 66 66 my $chip_addr_file = shift; 67 my $addr = shift;67 my @addr = @{shift()}; 68 68 local $_; 69 69 … … 74 74 close(CHIP_ADDR); 75 75 76 unless (exists $stub_addr{$addr}) { 77 print STDERR "Cycling i2c-stub to get the address we need\n"; 78 system("/sbin/rmmod", "i2c-stub"); 76 foreach my $addr (@addr) { 77 unless (exists $stub_addr{$addr}) { 78 print STDERR "Cycling i2c-stub to get the address we need\n"; 79 system("/sbin/rmmod", "i2c-stub"); 80 return; 81 } 79 82 } 80 83 } … … 84 87 { 85 88 local $_; 86 my $addr = oct shift;89 my @addr = @{shift()}; 87 90 my $nr; 88 91 89 92 # i2c-stub may be loaded without the address we want 90 check_chip_addr("/sys/module/i2c_stub/parameters/chip_addr", $addr);93 check_chip_addr("/sys/module/i2c_stub/parameters/chip_addr", \@addr); 91 94 92 95 # Maybe everything is already loaded … … 96 99 system("/sbin/modprobe", "i2c-dev") == 0 || exit 1; 97 100 if (kernel_version_at_least(2, 6, 19)) { 98 system("/sbin/modprobe", "i2c-stub", "chip_addr=$addr") == 0 || exit 1; 101 system("/sbin/modprobe", "i2c-stub", 102 "chip_addr=".join(',', @addr)) == 0 || exit 1; 99 103 } else { 100 104 system("/sbin/modprobe", "i2c-stub") == 0 || exit 1; … … 181 185 } 182 186 183 if (@ARGV !=2) {184 print STDERR "Usage: i2c-stub-from-dump <addr> <dump file>\n";187 if (@ARGV < 2) { 188 print STDERR "Usage: i2c-stub-from-dump <addr>[,<addr>,...] <dump file> [<dump file> ...]\n"; 185 189 exit 1; 186 190 } 187 191 188 192 # Check the parameters 189 $addr = $ARGV[0]; 190 if ($addr !~ m/^0x[0-7][0-9a-f]$/i) { 191 print STDERR "Invalid address $addr\n"; 192 exit 1; 193 @addr = split(/,/, shift @ARGV); 194 foreach (@addr) { 195 unless (m/^0x[0-7][0-9a-f]$/i) { 196 print STDERR "Invalid address $_\n"; 197 exit 1; 198 } 199 $_ = oct $_; 200 } 201 202 if (@addr < @ARGV) { 203 print STDERR "Fewer addresses than dumps provided\n"; 204 exit 4; 193 205 } 194 206 195 207 initialize_kernel_version(); 196 197 $bus_nr = load_kernel_drivers($addr); 208 if (@addr > 1 && !kernel_version_at_least(2, 6, 24)) { 209 print STDERR "Multiple addresses not supported by this kernel version\n"; 210 exit 5; 211 } 212 213 $bus_nr = load_kernel_drivers(\@addr); 198 214 199 215 # We don't want to see the output of 256 i2cset 200 216 open(SAVEOUT, ">&STDOUT"); 201 217 open(STDOUT, ">/dev/null"); 202 $err = process_dump(oct $addr, $ARGV[1]); 218 foreach (@addr) { 219 if (!@ARGV) { 220 printf STDERR "Skipping \%d-\%04x, no dump file privided\n", 221 $bus_nr, $_; 222 next; 223 } 224 $err = process_dump($_, shift @ARGV); 225 last if $err; 226 } 203 227 close(STDOUT); 204 228 -
i2c-tools/trunk/stub/i2c-stub-from-dump.8
r5165 r5830 1 .TH I2C-STUB-FROM-DUMP 8 " April 2008"1 .TH I2C-STUB-FROM-DUMP 8 "March 2010" 2 2 .SH NAME 3 i2c-stub-from-dump \- feed i2c-stub with a dump file3 i2c-stub-from-dump \- feed i2c-stub with dump files 4 4 5 5 .SH SYNOPSIS 6 6 .B i2c-stub-from-dump 7 .I address8 .I dump-file7 .IR address [, address ,...] 8 .IR dump-file " [" dump-file " ...]" 9 9 10 10 .SH DESCRIPTION 11 11 i2c-stub-from-dump is a small helper script for the i2c-stub kernel driver. 12 It lets you setup a fake I2C chip on the i2c-stub bus based on a dump of13 the chipyou want to emulate.12 It lets you setup one or more fake I2C chips on the i2c-stub bus based on 13 dumps of the chips you want to emulate. 14 14 15 15 i2c-stub-from-dump requires i2cdetect and i2cset to be installed and 16 16 reachable through the user's PATH. The former is used to find out the i2c-stub 17 bus number, while the latter is used to write to the fake I2C chip .17 bus number, while the latter is used to write to the fake I2C chips. 18 18 19 19 .SH EXAMPLE
