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