1 | #!/bin/bash |
---|
2 | |
---|
3 | [ "$#" -ne 2 ] && { |
---|
4 | echo "This script acts as a wrapper around I2C commands in order to do direct memory reads of the GSC." |
---|
5 | echo "It will output the i2c response in an i2cdump type format." |
---|
6 | echo |
---|
7 | echo "Usage: $0 <offset> <length>" |
---|
8 | echo |
---|
9 | echo "Example usage to read all 2000(0x7d0) peripheral register values:" |
---|
10 | echo " $0 0x100 0x7d0" |
---|
11 | exit 1 |
---|
12 | } |
---|
13 | |
---|
14 | # Store inputs |
---|
15 | BUS=0 |
---|
16 | ADDR=0x5e |
---|
17 | OFFSET=$1 |
---|
18 | LENGTH=$2 |
---|
19 | |
---|
20 | # Misc variables |
---|
21 | COUNT=0 |
---|
22 | PAGE=0 |
---|
23 | PRINTVAL=0x0000 |
---|
24 | REMAINDER=0 |
---|
25 | HIGH= |
---|
26 | RETURN= |
---|
27 | |
---|
28 | # Calculate initial page number based on passed in offset |
---|
29 | PAGE=$((OFFSET / 0x100)) |
---|
30 | OFFSET=$((OFFSET % 0x100)) |
---|
31 | |
---|
32 | echo " 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef" |
---|
33 | while [[ $COUNT -ne $LENGTH ]]; do |
---|
34 | # Set the page number accordingly |
---|
35 | i2cset -f -y 0 0x20 0x16 $PAGE |
---|
36 | |
---|
37 | # Do either a full i2cdump or specify a range if bytes aren't a 0x100 aligned block |
---|
38 | if [[ $(($LENGTH - $COUNT)) -lt 0x100 || $OFFSET -ne 0 ]]; then |
---|
39 | HIGH=$(($LENGTH - $COUNT - 1 + $OFFSET)) |
---|
40 | # Record remainder for i2c 0x100 upper range limit |
---|
41 | if [[ $HIGH -gt 0x100 ]]; then |
---|
42 | REMAINDER=$(($HIGH + 1 - 0x100)) |
---|
43 | else |
---|
44 | REMAINDER=0 |
---|
45 | fi |
---|
46 | |
---|
47 | RETURN=$(i2cdump -f -y -r ${OFFSET}-$(($HIGH - $REMAINDER)) 0 $ADDR b | grep ':') |
---|
48 | COUNT=$(($HIGH - $REMAINDER - $OFFSET + 1 + $COUNT)) |
---|
49 | OFFSET=0 |
---|
50 | else |
---|
51 | RETURN=$(i2cdump -f -y 0 $ADDR b | grep ':') |
---|
52 | COUNT=$(($COUNT + 0x100)) |
---|
53 | fi |
---|
54 | |
---|
55 | if [[ "$RETURN" ]]; then # Only print reads |
---|
56 | # Format output to be continuous and account for page increase |
---|
57 | echo "$RETURN" | while read x; do |
---|
58 | printf "%04x" "$((0x$(echo $x | cut -d':' -f1) + $((PAGE * 0x100))))" |
---|
59 | echo ":${x##*:}" |
---|
60 | done |
---|
61 | fi |
---|
62 | |
---|
63 | # Increase the page count |
---|
64 | ((++PAGE)) |
---|
65 | done |
---|