Changeset 5830

Show
Ignore:
Timestamp:
03/08/10 15:00:52 (5 months ago)
Author:
khali
Message:

Add support for multiple dumps. This makes it easier to setup test
environments with more than one I2C chip.

Location:
i2c-tools/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • i2c-tools/trunk/CHANGES

    r5828 r5830  
    1818  i2c-stub-from-dump: Use udev settle to speed up initialization 
    1919                      Unload i2c-stub automatically if needed 
     20                      Add support for multiple dumps 
    2021 
    21223.0.2 (2008-11-29) 
  • i2c-tools/trunk/stub/i2c-stub-from-dump

    r5829 r5830  
    2323 
    2424use strict; 
    25 use vars qw($bus_nr $addr $err); 
     25use vars qw($bus_nr @addr $err); 
    2626 
    2727# Kernel version detection code by Mark M. Hoffman, 
     
    6565sub check_chip_addr { 
    6666        my $chip_addr_file = shift; 
    67         my $addr = shift; 
     67        my @addr = @{shift()}; 
    6868        local $_; 
    6969 
     
    7474        close(CHIP_ADDR); 
    7575 
    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                } 
    7982        } 
    8083} 
     
    8487{ 
    8588        local $_; 
    86         my $addr = oct shift; 
     89        my @addr = @{shift()}; 
    8790        my $nr; 
    8891 
    8992        # 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); 
    9194 
    9295        # Maybe everything is already loaded 
     
    9699        system("/sbin/modprobe", "i2c-dev") == 0 || exit 1; 
    97100        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; 
    99103        } else { 
    100104                system("/sbin/modprobe", "i2c-stub") == 0 || exit 1; 
     
    181185} 
    182186 
    183 if (@ARGV != 2) { 
    184         print STDERR "Usage: i2c-stub-from-dump <addr> <dump file>\n"; 
     187if (@ARGV < 2) { 
     188        print STDERR "Usage: i2c-stub-from-dump <addr>[,<addr>,...] <dump file> [<dump file> ...]\n"; 
    185189        exit 1; 
    186190} 
    187191 
    188192# 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); 
     194foreach (@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 
     202if (@addr < @ARGV) { 
     203        print STDERR "Fewer addresses than dumps provided\n"; 
     204        exit 4; 
    193205} 
    194206 
    195207initialize_kernel_version(); 
    196  
    197 $bus_nr = load_kernel_drivers($addr); 
     208if (@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); 
    198214 
    199215# We don't want to see the output of 256 i2cset 
    200216open(SAVEOUT, ">&STDOUT"); 
    201217open(STDOUT, ">/dev/null"); 
    202 $err = process_dump(oct $addr, $ARGV[1]); 
     218foreach (@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} 
    203227close(STDOUT); 
    204228 
  • 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" 
    22.SH NAME 
    3 i2c-stub-from-dump \- feed i2c-stub with a dump file 
     3i2c-stub-from-dump \- feed i2c-stub with dump files 
    44 
    55.SH SYNOPSIS 
    66.B i2c-stub-from-dump  
    7 .I address 
    8 .I dump-file 
     7.IR address [, address ,...] 
     8.IR dump-file " [" dump-file " ...]" 
    99 
    1010.SH DESCRIPTION 
    1111i2c-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 of 
    13 the chip you want to emulate. 
     12It lets you setup one or more fake I2C chips on the i2c-stub bus based on 
     13dumps of the chips you want to emulate. 
    1414 
    1515i2c-stub-from-dump requires i2cdetect and i2cset to be installed and 
    1616reachable 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. 
     17bus number, while the latter is used to write to the fake I2C chips. 
    1818 
    1919.SH EXAMPLE