Lukasz Majewski | a4c86bb | 2014-06-18 11:38:56 +0200 | [diff] [blame^] | 1 | #! /bin/bash |
| 2 | set -e # any command return if not equal to zero |
| 3 | clear |
| 4 | |
| 5 | COLOUR_RED="\33[31m" |
| 6 | COLOUR_GREEN="\33[32m" |
| 7 | COLOUR_DEFAULT="\33[0m" |
| 8 | |
| 9 | DIR=./ |
| 10 | SUFFIX=img |
| 11 | RCV_DIR=rcv/ |
| 12 | LOG_FILE=./log/log-`date +%d-%m-%Y_%H-%M-%S` |
| 13 | |
| 14 | ./dfu_gadget_test_init.sh |
| 15 | |
| 16 | cleanup () { |
| 17 | rm -rf $RCV_DIR |
| 18 | } |
| 19 | |
| 20 | die () { |
| 21 | printf " $COLOUR_RED FAILED $COLOUR_DEFAULT \n" |
| 22 | cleanup |
| 23 | exit 1 |
| 24 | } |
| 25 | |
| 26 | calculate_md5sum () { |
| 27 | MD5SUM=`md5sum $1` |
| 28 | MD5SUM=`echo $MD5SUM | cut -d ' ' -f1` |
| 29 | echo "md5sum:"$MD5SUM |
| 30 | } |
| 31 | |
| 32 | dfu_test_file () { |
| 33 | printf "$COLOUR_GREEN ========================================================================================= $COLOUR_DEFAULT\n" |
| 34 | printf "File:$COLOUR_GREEN %s $COLOUR_DEFAULT\n" $1 |
| 35 | |
| 36 | dfu-util -D $1 -a $TARGET_ALT_SETTING >> $LOG_FILE 2>&1 || die $? |
| 37 | |
| 38 | echo -n "TX: " |
| 39 | calculate_md5sum $1 |
| 40 | |
| 41 | MD5_TX=$MD5SUM |
| 42 | |
| 43 | N_FILE=$DIR$RCV_DIR${1:2}"_rcv" |
| 44 | |
| 45 | dfu-util -U $N_FILE -a $TARGET_ALT_SETTING >> $LOG_FILE 2>&1 || die $? |
| 46 | |
| 47 | echo -n "RX: " |
| 48 | calculate_md5sum $N_FILE |
| 49 | MD5_RX=$MD5SUM |
| 50 | |
| 51 | if [ "$MD5_TX" == "$MD5_RX" ]; then |
| 52 | printf " $COLOUR_GREEN -------> OK $COLOUR_DEFAULT \n" |
| 53 | else |
| 54 | printf " $COLOUR_RED -------> FAILED $COLOUR_DEFAULT \n" |
| 55 | cleanup |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | } |
| 60 | |
| 61 | printf "$COLOUR_GREEN========================================================================================= $COLOUR_DEFAULT\n" |
| 62 | echo "DFU EP0 transmission test program" |
| 63 | echo "Trouble shoot -> disable DBG (even the KERN_DEBUG) in the UDC driver" |
| 64 | echo "@ -> TRATS2 # dfu 0 mmc 0" |
| 65 | mkdir -p $RCV_DIR |
| 66 | touch $LOG_FILE |
| 67 | |
| 68 | if [ $# -eq 0 ] |
| 69 | then |
| 70 | printf " $COLOUR_RED Please pass alt setting number!! $COLOUR_DEFAULT \n" |
| 71 | exit 0 |
| 72 | fi |
| 73 | |
| 74 | TARGET_ALT_SETTING=$1 |
| 75 | |
| 76 | if [ -n "$2" ] |
| 77 | then |
| 78 | dfu_test_file $2 |
| 79 | else |
| 80 | for file in $DIR*.$SUFFIX |
| 81 | do |
| 82 | dfu_test_file $file |
| 83 | done |
| 84 | fi |
| 85 | |
| 86 | cleanup |
| 87 | |
| 88 | exit 0 |