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