Browse Source

Stop on i2cset error.

git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5293 7894878c-1315-0410-8ee3-d5d059ff63e0
tags/v3.0.2
Jean Delvare 17 years ago
parent
commit
6a2f709549
  1. 1
      CHANGES
  2. 31
      stub/i2c-stub-from-dump

1
CHANGES

@ -23,6 +23,7 @@ SVN
i2c-stub-from-dump: Add support for partial dumps i2c-stub-from-dump: Add support for partial dumps
Report if only garbage is found in dump file Report if only garbage is found in dump file
Behave properly when i2c-stub is already loaded Behave properly when i2c-stub is already loaded
Stop on i2cset error
3.0.1 (2008-04-04) 3.0.1 (2008-04-04)
Drop the trailing .pl from all perl script names Drop the trailing .pl from all perl script names

31
stub/i2c-stub-from-dump

@ -22,7 +22,7 @@
# a device you do not have access to, but of which you have a dump. # a device you do not have access to, but of which you have a dump.
use strict; use strict;
use vars qw($bus_nr $addr $bytes $words);
use vars qw($bus_nr $addr $bytes $words $err);
# Kernel version detection code by Mark M. Hoffman, # Kernel version detection code by Mark M. Hoffman,
# copied from sensors-detect. # copied from sensors-detect.
@ -108,6 +108,7 @@ sub load_kernel_drivers
sub process_dump sub process_dump
{ {
my $dump = shift; my $dump = shift;
my $err = 0;
open(DUMP, $dump) || die "Can't open $dump: $!\n"; open(DUMP, $dump) || die "Can't open $dump: $!\n";
OUTER_LOOP: OUTER_LOOP:
@ -119,10 +120,12 @@ sub process_dump
shift(@values); shift(@values);
for (my $i = 0; $i < 16 && (my $val = shift(@values)); $i++) { for (my $i = 0; $i < 16 && (my $val = shift(@values)); $i++) {
next if $val =~ m/X/; next if $val =~ m/X/;
last OUTER_LOOP if system("i2cset", "-y",
$bus_nr, $addr,
sprintf("0x\%02x", $offset+$i),
"0x$val", "b");
if (system("i2cset", "-y", $bus_nr, $addr,
sprintf("0x\%02x", $offset+$i),
"0x$val", "b")) {
$err = 3;
last OUTER_LOOP;
}
$bytes++; $bytes++;
} }
} elsif (m/^([0-9a-f][08]):(( [0-9a-fX]{4}){8})/) { } elsif (m/^([0-9a-f][08]):(( [0-9a-fX]{4}){8})/) {
@ -132,15 +135,19 @@ sub process_dump
shift(@values); shift(@values);
for (my $i = 0; $i < 8 && (my $val = shift(@values)); $i++) { for (my $i = 0; $i < 8 && (my $val = shift(@values)); $i++) {
next if $val =~ m/X/; next if $val =~ m/X/;
last OUTER_LOOP if system("i2cset", "-y",
$bus_nr, $addr,
sprintf("0x\%02x", $offset+$i),
"0x$val", "w");
if (system("i2cset", "-y", $bus_nr, $addr,
sprintf("0x\%02x", $offset+$i),
"0x$val", "w")) {
$err = 3;
last OUTER_LOOP;
}
$words++; $words++;
} }
} }
} }
close(DUMP); close(DUMP);
return $err;
} }
if ($>) { if ($>) {
@ -168,7 +175,7 @@ $bytes = $words = 0;
# We don't want to see the output of 256 i2cset # We don't want to see the output of 256 i2cset
open(SAVEOUT, ">&STDOUT"); open(SAVEOUT, ">&STDOUT");
open(STDOUT, ">/dev/null"); open(STDOUT, ">/dev/null");
process_dump($ARGV[1]);
$err = process_dump($ARGV[1]);
close(STDOUT); close(STDOUT);
if ($bytes) { if ($bytes) {
@ -181,9 +188,9 @@ if ($words) {
$bus_nr, oct($addr); $bus_nr, oct($addr);
} }
if ($bytes + $words == 0) {
if (!$err && ($bytes + $words == 0)) {
printf SAVEOUT "Only garbage found in dump file $ARGV[1]\n"; printf SAVEOUT "Only garbage found in dump file $ARGV[1]\n";
exit(1); exit(1);
} }
exit(0);
exit($err);
Loading…
Cancel
Save