#!/bin/bash # eetool v0.03 - script to ease programming of i2c eeproms using eeprog # needs: eeprog, test, find, split, diff # assumptions: /tmp is writable, eeprog is in cwd. # (c) 2004-08-13 Christian van den Bosch # released under GNU Public Licence (GPL) - # see http://www.gnu.org/copyleft/gpl.html for details nbytes=2048 if [ $# -ne 2 ] then echo Usage: $0 w file : write specified file to eeprom, then verify. echo Usage: $0 v file : verify eeprom against specified file. echo Usage: $0 r file : read from eeprom to specified file. echo For write and verify, file is expected to exist and be $nbytes bytes. echo For read, file is expected not to exist, and will be created. exit 1 fi cmd=$1 fn=$2 if [ "$cmd" == "w" -o "$cmd" == "v" ] then # check that file we're writing to or verifying against eeprom exists and is right size if [ ! -f $fn ] then echo $0 exiting: $fn not found! exit 1 fi if [ `find $fn -printf "%s"` -ne 2048 ] then echo $0 exiting: $fn is wrong size! Should be $nbytes bytes. exit 1 fi elif [ "$cmd" == "r" ] then if [ -f $fn ] then echo $0 exiting: $fn exists, will not overwrite. exit 1 fi else $0 exit 1 fi if [ "$cmd" == "w" ] then split -b 256 $fn /tmp/w2k-part-$$- j=0 progress= for i in a b c d e f g h do ./eeprog -f -w 0:0x100 /dev/i2c-0 0x5$j < /tmp/w2k-part-$$-a$i 2>>/tmp/w2k-err-$$ progress=$progress$? echo -n . rm /tmp/w2k-part-$$-a$i let j=j+1 done if [ "$progress" != "00000000" ] then echo " write failed; see /tmp/w2k-err-$$ for details." exit 1 fi echo -n " write returned ok; verifying: " cmd=v fi if [ "$cmd" == "r" -o "$cmd" == "v" ] then progress= for i in `seq 0 7` do ./eeprog -f -r 0:0x100 /dev/i2c-0 0x5$i >> /tmp/w2k-img-$$ 2>>/tmp/w2k-err-$$ progress=$progress$? echo -n . done if [ $progress != 00000000 ] then echo " read failed; see /tmp/w2k-err-$$ for details." rm /tmp/w2k-img-$$ exit 1 fi if [ "$cmd" == "r" ] then mv /tmp/w2k-img-$$ $fn echo " read successful." else diff -b /tmp/w2k-img-$$ $fn if [ $? -eq 0 ] then echo " verify successful." else echo " verify FAILED!" fi rm /tmp/w2k-img-$$ fi fi rm /tmp/w2k-err-$$