blob: 9c7942257b44f76a7892fcd264a1a559b659b438 [file] [log] [blame]
Lukasz Majewski98ffe742014-06-18 11:38:56 +02001#! /bin/bash
Stephen Warrenb1c384c2014-06-10 16:28:10 -06002
Lukasz Majewski458934e2014-08-18 12:12:27 +02003# 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 Majewski98ffe742014-06-18 11:38:56 +020013set -e # any command return if not equal to zero
14clear
15
16COLOUR_RED="\33[31m"
17COLOUR_GREEN="\33[32m"
18COLOUR_DEFAULT="\33[0m"
19
20DIR=./
21SUFFIX=img
22RCV_DIR=rcv/
23LOG_FILE=./log/log-`date +%d-%m-%Y_%H-%M-%S`
24
Stephen Warrenb1c384c2014-06-10 16:28:10 -060025cd `dirname $0`
Lukasz Majewski98ffe742014-06-18 11:38:56 +020026./dfu_gadget_test_init.sh
27
28cleanup () {
Stephen Warrenb1c384c2014-06-10 16:28:10 -060029 rm -rf $DIR$RCV_DIR
Lukasz Majewski98ffe742014-06-18 11:38:56 +020030}
31
32die () {
33 printf " $COLOUR_RED FAILED $COLOUR_DEFAULT \n"
34 cleanup
35 exit 1
36}
37
38calculate_md5sum () {
39 MD5SUM=`md5sum $1`
40 MD5SUM=`echo $MD5SUM | cut -d ' ' -f1`
41 echo "md5sum:"$MD5SUM
42}
43
44dfu_test_file () {
45 printf "$COLOUR_GREEN ========================================================================================= $COLOUR_DEFAULT\n"
46 printf "File:$COLOUR_GREEN %s $COLOUR_DEFAULT\n" $1
47
Lukasz Majewski56d62ca2015-08-15 11:23:45 +020048 dfu-util $USB_DEV -D $1 -a $TARGET_ALT_SETTING >> $LOG_FILE 2>&1 || die $?
Lukasz Majewski98ffe742014-06-18 11:38:56 +020049
50 echo -n "TX: "
51 calculate_md5sum $1
52
53 MD5_TX=$MD5SUM
54
Lukasz Majewski56d62ca2015-08-15 11:23:45 +020055 dfu-util $USB_DEV -D ${DIR}/dfudummy.bin -a $TARGET_ALT_SETTING_B >> $LOG_FILE 2>&1 || die $?
Stephen Warrenb1c384c2014-06-10 16:28:10 -060056
Lukasz Majewski98ffe742014-06-18 11:38:56 +020057 N_FILE=$DIR$RCV_DIR${1:2}"_rcv"
58
Lukasz Majewski56d62ca2015-08-15 11:23:45 +020059 dfu-util $USB_DEV -U $N_FILE -a $TARGET_ALT_SETTING >> $LOG_FILE 2>&1 || die $?
Lukasz Majewski98ffe742014-06-18 11:38:56 +020060
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
75printf "$COLOUR_GREEN========================================================================================= $COLOUR_DEFAULT\n"
76echo "DFU EP0 transmission test program"
77echo "Trouble shoot -> disable DBG (even the KERN_DEBUG) in the UDC driver"
78echo "@ -> TRATS2 # dfu 0 mmc 0"
Stephen Warrenfaacd3e2014-07-01 12:16:55 -060079cleanup
Stephen Warrenb1c384c2014-06-10 16:28:10 -060080mkdir -p $DIR$RCV_DIR
Lukasz Majewski98ffe742014-06-18 11:38:56 +020081touch $LOG_FILE
82
83if [ $# -eq 0 ]
84then
85 printf " $COLOUR_RED Please pass alt setting number!! $COLOUR_DEFAULT \n"
86 exit 0
87fi
88
89TARGET_ALT_SETTING=$1
Stephen Warrenb1c384c2014-06-10 16:28:10 -060090TARGET_ALT_SETTING_B=$2
Lukasz Majewski98ffe742014-06-18 11:38:56 +020091
Lukasz Majewski56d62ca2015-08-15 11:23:45 +020092file=$3
93[[ $3 == *':'* ]] && USB_DEV="-d $3" && file=""
94[ $# -eq 4 ] && USB_DEV="-d $4"
95
96if [ -n "$file" ]
Lukasz Majewski98ffe742014-06-18 11:38:56 +020097then
Lukasz Majewski56d62ca2015-08-15 11:23:45 +020098 dfu_test_file $file
Lukasz Majewski98ffe742014-06-18 11:38:56 +020099else
Lukasz Majewski56d62ca2015-08-15 11:23:45 +0200100 for f in $DIR*.$SUFFIX
Lukasz Majewski98ffe742014-06-18 11:38:56 +0200101 do
Lukasz Majewski56d62ca2015-08-15 11:23:45 +0200102 dfu_test_file $f
Lukasz Majewski98ffe742014-06-18 11:38:56 +0200103 done
104fi
105
106cleanup
107
108exit 0