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