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 | 4c984c8 | 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 | a4c86bb | 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 | 7ad67e5 | 2014-06-10 16:28:10 -0600 | [diff] [blame] | 25 | cd `dirname $0` |
Lukasz Majewski | a4c86bb | 2014-06-18 11:38:56 +0200 | [diff] [blame] | 26 | ./dfu_gadget_test_init.sh |
| 27 | |
| 28 | cleanup () { |
Stephen Warren | 7ad67e5 | 2014-06-10 16:28:10 -0600 | [diff] [blame] | 29 | rm -rf $DIR$RCV_DIR |
Lukasz Majewski | a4c86bb | 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 | |
| 48 | dfu-util -D $1 -a $TARGET_ALT_SETTING >> $LOG_FILE 2>&1 || die $? |
| 49 | |
| 50 | echo -n "TX: " |
| 51 | calculate_md5sum $1 |
| 52 | |
| 53 | MD5_TX=$MD5SUM |
| 54 | |
Stephen Warren | 7ad67e5 | 2014-06-10 16:28:10 -0600 | [diff] [blame] | 55 | dfu-util -D ${DIR}/dfudummy.bin -a $TARGET_ALT_SETTING_B >> $LOG_FILE 2>&1 || die $? |
| 56 | |
Lukasz Majewski | a4c86bb | 2014-06-18 11:38:56 +0200 | [diff] [blame] | 57 | N_FILE=$DIR$RCV_DIR${1:2}"_rcv" |
| 58 | |
| 59 | dfu-util -U $N_FILE -a $TARGET_ALT_SETTING >> $LOG_FILE 2>&1 || die $? |
| 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 | c0e6663 | 2014-07-01 12:16:55 -0600 | [diff] [blame] | 79 | cleanup |
Stephen Warren | 7ad67e5 | 2014-06-10 16:28:10 -0600 | [diff] [blame] | 80 | mkdir -p $DIR$RCV_DIR |
Lukasz Majewski | a4c86bb | 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 | 7ad67e5 | 2014-06-10 16:28:10 -0600 | [diff] [blame] | 90 | TARGET_ALT_SETTING_B=$2 |
Lukasz Majewski | a4c86bb | 2014-06-18 11:38:56 +0200 | [diff] [blame] | 91 | |
Stephen Warren | 7ad67e5 | 2014-06-10 16:28:10 -0600 | [diff] [blame] | 92 | if [ -n "$3" ] |
Lukasz Majewski | a4c86bb | 2014-06-18 11:38:56 +0200 | [diff] [blame] | 93 | then |
Stephen Warren | 7ad67e5 | 2014-06-10 16:28:10 -0600 | [diff] [blame] | 94 | dfu_test_file $3 |
Lukasz Majewski | a4c86bb | 2014-06-18 11:38:56 +0200 | [diff] [blame] | 95 | else |
| 96 | for file in $DIR*.$SUFFIX |
| 97 | do |
| 98 | dfu_test_file $file |
| 99 | done |
| 100 | fi |
| 101 | |
| 102 | cleanup |
| 103 | |
| 104 | exit 0 |