Add the default path in the script file
[platform/adaptation/bluetooth-firmware-bcm.git] / scripts / bt-dev-start-artik.sh
1 #!/bin/sh
2 PATH=/bin:/usr/bin:/sbin:/usr/sbin
3
4 # Script for registering Broadcom UART BT device
5 BT_UART_DEVICE=/dev/ttySAC3
6 BT_CHIP_TYPE=bcm2035
7 BCM_TOOL=/usr/bin/brcm_patchram_plus
8
9 BT_PLATFORM_DEFAULT_HCI_NAME="TIZEN-Mobile"
10 UART_SPEED=3000000
11 TIMEOUT=24
12
13 #set default firmware
14 BCM_FIRMWARE=BT_FW_BCM4358A1_001.002.005.0032.0066.hcd
15
16 REVISION_NUM=`grep Revision /proc/cpuinfo | awk "{print \\$3}"`
17 REVISION_HIGH=`echo $REVISION_NUM| cut -c1-2`
18 REVISION_LOW=`echo $REVISION_NUM| cut -c3-`
19
20 HARDWARE=`grep Hardware /proc/cpuinfo | awk "{print \\$3}"`
21
22 check_hw_dt()
23 {
24         HARDWARE=`cat /proc/device-tree/model | awk "{print \\$2}"`
25
26         case $HARDWARE in
27
28                 "ARTIK10")
29                         BT_UART_DEVICE=/dev/ttySAC2
30                         BCM_TOOL=/usr/bin/brcm_patchram_plus
31                         BCM_FIRMWARE=BCM4354_003.001.012.0353.0745_Samsung_Artik_ORC.hcd
32                         ;;
33
34                 "ARTIK5")
35                         BT_UART_DEVICE=/dev/ttySAC0
36                         BCM_TOOL=/usr/bin/brcm_patchram_plus
37                         BCM_FIRMWARE=BCM4354_003.001.012.0353.0745_Samsung_Artik_ORC.hcd
38                         ;;
39         esac
40 }
41
42 parse_bd_addr()
43 {
44         for x in $(cat /proc/cmdline); do
45                 case $x in
46                         bd_addr=*)
47                                 BD_ADDR=${x#bd_addr=}
48                                 ;;
49                 esac
50         done
51 }
52
53 check_hw_dt
54 if [ -z "${HARDWARE##ARTIK*}" ]; then
55         parse_bd_addr
56 fi
57
58 if [ ! -e "$BT_UART_DEVICE" ]
59 then
60         mknod $BT_UART_DEVICE c 204 64
61 fi
62
63 if [ ! -e /opt/etc/.bd_addr ]
64 then
65         # Set BT address
66         /usr/bin/setbd
67 fi
68
69 # Trun-on Bluetooth Chip
70 /usr/sbin/rfkill unblock bluetooth
71
72 echo "Check for Bluetooth device status"
73 if (/usr/bin/hciconfig | grep hci); then
74         echo "Bluetooth device is UP"
75         /usr/bin/hciconfig hci0 up
76 else
77         echo "Bluetooth device is DOWN"
78         echo "Registering Bluetooth device"
79         echo "change auth of brodcom tool"
80         chmod 755 $BCM_TOOL
81
82         # In tizenW hardware first time bcmtool download may not success, hence we need to try more times
83         MAXBCMTOOLTRY=5
84         flag=0
85         for (( c=1; c<=$MAXBCMTOOLTRY; c++))
86         do
87                 echo "******* Bcmtool download attempt $c ********"
88
89         $BCM_TOOL $BT_UART_DEVICE --patchram /usr/etc/bluetooth/$BCM_FIRMWARE --no2bytes --baudrate $UART_SPEED --use_baudrate_for_download $BT_UART_DEVICE --bd_addr ${BD_ADDR} > /dev/null 2>&1 &
90                 bcmtool_pid=$!
91                 #Check next timeout seconds for bcmtool success
92                 for (( i=1; i<=$TIMEOUT; i++))
93                 do
94                         /bin/sleep 0.1
95                         kill -0 $bcmtool_pid
96                         bcmtool_alive=$?
97
98                         if [ $i -eq $TIMEOUT ]
99                         then
100                                 echo "time expired happen $i"
101                                 kill -TERM $bcmtool_pid
102                                 break
103 #                               ${RFKILL} block bluetooth
104 #                               exit 1
105                         fi
106
107                         if [ $bcmtool_alive -eq 0 ]
108                         then
109                                 echo "Continue....$i"
110                                 continue
111                         else
112                                 echo "Break.......$i"
113                                 flag=1
114                                 break
115                         fi
116                 done
117
118                 if [ $flag -eq 1 ]
119                 then
120                         echo "Break bcmtool download loop on $c attempt"
121                         break
122                 else
123                         /bin/sleep 1
124                         echo "sleep done"
125                 fi
126
127
128                 if [ $c -eq $MAXBCMTOOLTRY ]
129                 then
130                         echo "***** No Chance to activate, count=$c ******"
131                         ${RFKILL} block bluetooth
132                         exit 1
133                 fi
134
135         done
136
137         echo "Try for hciattach"
138
139         # Attaching Broadcom device
140         if (/usr/bin/hciattach $BT_UART_DEVICE -s $UART_SPEED $BT_CHIP_TYPE $UART_SPEED flow); then
141                 sleep 0.1
142                 /usr/bin/hciconfig hci0 up
143                 /usr/bin/hciconfig hci0 name $BT_PLATFORM_DEFAULT_HCI_NAME
144                 /usr/bin/hciconfig hci0 sspmode 1
145                 echo "HCIATTACH success"
146         else
147                 echo "HCIATTACH failed"
148                 /usr/sbin/rfkill block bluetooth
149         fi
150 fi