summaryrefslogtreecommitdiff
path: root/scripts/wearable/bt-dev-start-e4412.sh
blob: a7af98bf15c4e04f4389d9652d985432bb727c6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh

#
# Script for registering Broadcom UART BT device
#
BT_UART_DEVICE=/dev/ttySAC0
BT_CHIP_TYPE=bcm2035
BCM_TOOL=/usr/bin/bcmtool_4330b1

BT_ADDR=/csa/bluetooth/.bd_addr

UART_SPEED=3000000
TIMEOUT=24

# defult firmware
# SEMCO external LNA, I2S slave, fix high sleep current
BCM_FIRMWARE=BCM20710A1_001.002.014.0059.0060.hcd

#B2 - REV_01 - 4334W SEMCO B58 module with iPA(internal PA)
#B2 - REV_02 - 4334W SEMCO B58 module with ePA(external PA)
BCM_B2_FIRMWARE=BCM4334B0_002.001.013.1675.1676_B2_ORC.hcd
BCM_B2_SEC_FIRMWARE_REV_01=BCM4334W_Rinato_TestOnly.hcd
BCM_B2_SEC_FIRMWARE_REV_02=BCM4334W_001.002.003.0997.1027_B58_ePA.hcd

HOST_NAME=`grep Hardware /proc/cpuinfo | awk "{print \\$3}"`
REVISION_NUM=`grep Revision /proc/cpuinfo | awk "{print \\$3}"`

if [ "$HOST_NAME" == "B2" ]; then
	if [ "$REVISION_NUM" == "0000" ]; then
		BCM_FIRMWARE=$BCM_B2_FIRMWARE
	else
		if [ "$REVISION_NUM" == "0001" ]; then
			BCM_FIRMWARE=$BCM_B2_SEC_FIRMWARE_REV_01
		else
			BCM_FIRMWARE=$BCM_B2_SEC_FIRMWARE_REV_02
		fi
	fi
fi

echo $BCM_FIRMWARE

if [ ! -e "$BT_UART_DEVICE" ]
then
	mknod $BT_UART_DEVICE c 204 64
fi

# Set BT address: This will internally check for the file presence
/usr/bin/setbd

#if the setbd return non 0, which means incorrect bd address file, then exit
if [ $? -ne 0 ]
then
	exit 1
fi

rfkill unblock bluetooth

echo "Check for Bluetooth device status"
if (/usr/bin/hciconfig | grep hci); then
	echo "Bluetooth device is UP"
	/usr/bin/hciconfig hci0 up
else
	echo "Bluetooth device is DOWN"
	echo "Registering Bluetooth device"

	# In tizenW hardware first time bcmtool download may not success, hence we need to try more times
	MAXBCMTOOLTRY=5
	flag=0
	for (( c=1; c<=$MAXBCMTOOLTRY; c++))
	do
		echo "******* Bcmtool download attempt $c ********"

	$BCM_TOOL $BT_UART_DEVICE -FILE=/usr/etc/bluetooth/$BCM_FIRMWARE -BAUD=$UART_SPEED -ADDR=$BT_ADDR -SETSCO=0,0,0,0,0,0,0,3,3,0 -LP &
		bcmtool_pid=$!
		#Check next timeout seconds for bcmtool success
		for (( i=1; i<=$TIMEOUT; i++))
		do
			sleep 0.1
			kill -0 $bcmtool_pid
			bcmtool_alive=$?

			if [ $i -eq $TIMEOUT ]
			then
				echo "time expired happen $i"
				kill -TERM $bcmtool_pid
				break
#				rfkill block bluetooth
#				exit 1
			fi

			if [ $bcmtool_alive -eq 0 ]
			then
				echo "Continue....$i"
				continue
			else
				echo "Break.......$i"
				flag=1
				break
			fi
		done

		if [ $flag -eq 1 ]
		then
			echo "Break bcmtool download loop on $c attempt"
			break
		else
			sleep 1
			echo "sleep done"
		fi


		if [ $c -eq $MAXBCMTOOLTRY ]
		then
			echo "***** No Chance to activate, count=$c ******"
			rfkill block bluetooth
			exit 1
		fi

	done

	echo "Try for hciattach"

	# Attaching Broadcom device
	if (/usr/bin/hciattach $BT_UART_DEVICE -s $UART_SPEED $BT_CHIP_TYPE $UART_SPEED flow); then
		sleep 0.1
		echo "HCIATTACH success"
	else
		echo "HCIATTACH failed"
		rfkill block bluetooth
		cp /var/log/messages /var/lib/bluetooth/
	fi
fi

#/usr/bin/hciconfig hci0 down