Browse Source

Add support for word register access mode.

git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5149 7894878c-1315-0410-8ee3-d5d059ff63e0
tags/v3.0.1
Jean Delvare 18 years ago
parent
commit
b8322b2fc5
  1. 69
      stub/i2c-stub-from-dump
  2. 9
      stub/i2c-stub-from-dump.8

69
stub/i2c-stub-from-dump

@ -1,6 +1,6 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
# Copyright (C) 2007-2008 Jean Delvare <khali@linux-fr.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -22,7 +22,7 @@
# a device you do not have access to, but of which you have a dump.
use strict;
use vars qw($bus_nr $addr $count);
use vars qw($bus_nr $addr $bytes $words);
# Kernel version detection code by Mark M. Hoffman,
# copied from sensors-detect.
@ -66,6 +66,42 @@ sub get_i2c_stub_bus_number
return $nr;
}
sub process_dump
{
my $dump = shift;
open(DUMP, $dump) || die "Can't open $dump: $!\n";
OUTER_LOOP:
while (<DUMP>) {
if (m/^([0-9a-f]0):(( [0-9a-f]{2}){16})/) {
# Byte dump
my $offset = hex($1);
my @values = split(/ /, $2);
shift(@values);
for (my $i = 0; $i < 16 && (my $val = shift(@values)); $i++) {
last OUTER_LOOP if system("i2cset", "-y",
$bus_nr, $addr,
sprintf("0x\%02x", $offset+$i),
"0x$val", "b");
$bytes++;
}
} elsif (m/^([0-9a-f][08]):(( [0-9a-f]{4}){8})/) {
# Word dump
my $offset = hex($1);
my @values = split(/ /, $2);
shift(@values);
for (my $i = 0; $i < 8 && (my $val = shift(@values)); $i++) {
last OUTER_LOOP if system("i2cset", "-y",
$bus_nr, $addr,
sprintf("0x\%02x", $offset+$i),
"0x$val", "w");
$words++;
}
}
}
close(DUMP);
}
if ($>) {
print "You must be root to use this script\n";
exit 1;
@ -95,33 +131,22 @@ if (kernel_version_at_least(2, 6, 19)) {
sleep(1); # udev may take some time to create the device node
$bus_nr = get_i2c_stub_bus_number();
$bytes = $words = 0;
# We don't want to see the output of 256 i2cset
open(SAVEOUT, ">&STDOUT");
open(STDOUT, ">/dev/null");
process_dump($ARGV[1]);
close(STDOUT);
$count = 0;
open(DUMP, $ARGV[1]) || die "Can't open $ARGV[1]: $!\n";
OUTER_LOOP:
while (<DUMP>) {
next unless m/^([0-9a-f]0):(( [0-9a-f]{2}){16})/;
my $offset = hex($1);
my @values = split(/ /, $2);
shift(@values);
for (my $i = 0; $i < 16 && (my $val = shift(@values)); $i++) {
last OUTER_LOOP if system("i2cset", "-y",
$bus_nr, $addr,
sprintf("0x\%02x", $offset+$i),
sprintf("0x\%02x", hex($val)), "b");
$count++;
}
if ($bytes) {
printf SAVEOUT "$bytes byte values written to \%d-\%04x\n",
$bus_nr, oct($addr);
}
close(DUMP);
close(STDOUT);
if ($count) {
printf SAVEOUT "$count byte values written to \%d-\%04x\n",
if ($words) {
printf SAVEOUT "$words word values written to \%d-\%04x\n",
$bus_nr, oct($addr);
}
exit($count == 0);
exit($bytes + $words == 0);

9
stub/i2c-stub-from-dump.8

@ -1,4 +1,4 @@
.TH I2C-STUB-FROM-DUMP 8 "November 2007"
.TH I2C-STUB-FROM-DUMP 8 "March 2008"
.SH NAME
i2c-stub-from-dump \- feed i2c-stub with a dump file
@ -26,7 +26,9 @@ chip in question lives at address 0x4c on I2C bus 0, you would run:
i2cdump -y 0 0x4c b > chip.dump
Adjust the bus number and chip address for your case. i2cdetect can help
you find out their values.
you find out their values. If the device uses word (16-bit) register
access instead of the traditional byte (8-bit) access, use mode \fBw\fR
instead of \fBb\fR.
Copy the dump file to system B.
@ -40,9 +42,6 @@ Again, adjust the address as needed.
.SH LIMITATIONS
There are some limitations to the kind of devices that can be handled:
.IP \(bu "\w'\(bu'u+1n"
Device must only use byte register access. i2c-stub supports word
access but i2c-stub-from-dump doesn't (yet).
.IP \(bu
Device must not have banks (as most Winbond devices do).

Loading…
Cancel
Save