Changeset 5149 for i2c-tools/trunk/stub
- Timestamp:
- 03/19/08 15:04:25 (4 years ago)
- Location:
- i2c-tools/trunk/stub
- Files:
-
- 2 modified
-
i2c-stub-from-dump (modified) (4 diffs)
-
i2c-stub-from-dump.8 (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
i2c-tools/trunk/stub/i2c-stub-from-dump
r5091 r5149 1 1 #!/usr/bin/perl -w 2 2 # 3 # Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>3 # Copyright (C) 2007-2008 Jean Delvare <khali@linux-fr.org> 4 4 # 5 5 # This program is free software; you can redistribute it and/or modify … … 23 23 24 24 use strict; 25 use vars qw($bus_nr $addr $ count);25 use vars qw($bus_nr $addr $bytes $words); 26 26 27 27 # Kernel version detection code by Mark M. Hoffman, … … 67 67 } 68 68 69 sub process_dump 70 { 71 my $dump = shift; 72 73 open(DUMP, $dump) || die "Can't open $dump: $!\n"; 74 OUTER_LOOP: 75 while (<DUMP>) { 76 if (m/^([0-9a-f]0):(( [0-9a-f]{2}){16})/) { 77 # Byte dump 78 my $offset = hex($1); 79 my @values = split(/ /, $2); 80 shift(@values); 81 for (my $i = 0; $i < 16 && (my $val = shift(@values)); $i++) { 82 last OUTER_LOOP if system("i2cset", "-y", 83 $bus_nr, $addr, 84 sprintf("0x\%02x", $offset+$i), 85 "0x$val", "b"); 86 $bytes++; 87 } 88 } elsif (m/^([0-9a-f][08]):(( [0-9a-f]{4}){8})/) { 89 # Word dump 90 my $offset = hex($1); 91 my @values = split(/ /, $2); 92 shift(@values); 93 for (my $i = 0; $i < 8 && (my $val = shift(@values)); $i++) { 94 last OUTER_LOOP if system("i2cset", "-y", 95 $bus_nr, $addr, 96 sprintf("0x\%02x", $offset+$i), 97 "0x$val", "w"); 98 $words++; 99 } 100 } 101 } 102 close(DUMP); 103 } 104 69 105 if ($>) { 70 106 print "You must be root to use this script\n"; … … 96 132 97 133 $bus_nr = get_i2c_stub_bus_number(); 134 $bytes = $words = 0; 98 135 99 136 # We don't want to see the output of 256 i2cset 100 137 open(SAVEOUT, ">&STDOUT"); 101 138 open(STDOUT, ">/dev/null"); 102 103 $count = 0; 104 open(DUMP, $ARGV[1]) || die "Can't open $ARGV[1]: $!\n"; 105 OUTER_LOOP: 106 while (<DUMP>) { 107 next unless m/^([0-9a-f]0):(( [0-9a-f]{2}){16})/; 108 my $offset = hex($1); 109 my @values = split(/ /, $2); 110 shift(@values); 111 for (my $i = 0; $i < 16 && (my $val = shift(@values)); $i++) { 112 last OUTER_LOOP if system("i2cset", "-y", 113 $bus_nr, $addr, 114 sprintf("0x\%02x", $offset+$i), 115 sprintf("0x\%02x", hex($val)), "b"); 116 $count++; 117 } 118 } 119 close(DUMP); 139 process_dump($ARGV[1]); 120 140 close(STDOUT); 121 141 122 if ($ count) {123 printf SAVEOUT "$ countbyte values written to \%d-\%04x\n",142 if ($bytes) { 143 printf SAVEOUT "$bytes byte values written to \%d-\%04x\n", 124 144 $bus_nr, oct($addr); 125 145 } 126 146 127 exit($count == 0); 147 if ($words) { 148 printf SAVEOUT "$words word values written to \%d-\%04x\n", 149 $bus_nr, oct($addr); 150 } 151 152 exit($bytes + $words == 0); -
i2c-tools/trunk/stub/i2c-stub-from-dump.8
r5005 r5149 1 .TH I2C-STUB-FROM-DUMP 8 " November 2007"1 .TH I2C-STUB-FROM-DUMP 8 "March 2008" 2 2 .SH NAME 3 3 i2c-stub-from-dump \- feed i2c-stub with a dump file … … 27 27 28 28 Adjust the bus number and chip address for your case. i2cdetect can help 29 you find out their values. 29 you find out their values. If the device uses word (16-bit) register 30 access instead of the traditional byte (8-bit) access, use mode \fBw\fR 31 instead of \fBb\fR. 30 32 31 33 Copy the dump file to system B. … … 41 43 .SH LIMITATIONS 42 44 There are some limitations to the kind of devices that can be handled: 43 .IP \(bu "\w'\(bu'u+1n"44 Device must only use byte register access. i2c-stub supports word45 access but i2c-stub-from-dump doesn't (yet).46 45 .IP \(bu 47 46 Device must not have banks (as most Winbond devices do). 48 47 49 48 .SH SEE ALSO 50 i2cdump(8), i2cdetect(8), i2cset(8)49 i2cdump(8), i2cdetect(8), i2cset(8) 51 50 52 51 .SH AUTHOR
