2014-04-30 13:16:29 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2014-05-25 16:56:42 +00:00
|
|
|
CACHE=/var/cache/brcm43xx-mac
|
2014-04-30 13:16:29 +00:00
|
|
|
if [ -z "$MAC_ADDR" ]; then
|
2014-05-25 16:56:42 +00:00
|
|
|
if [ ! -f "$CACHE" ]; then
|
|
|
|
echo 43:29:B1$(od -txC -An -N3 /dev/random|tr \ : | tr '[:lower:]' '[:upper:]') >"$CACHE"
|
|
|
|
fi
|
|
|
|
MAC_ADDR=`cat "$CACHE"`
|
2014-05-25 19:44:25 +00:00
|
|
|
echo "Warning: Using self generated MAC address! MAC_ADDR should be defined in /etc/conf.d/bcm43xx."
|
2014-04-30 13:16:29 +00:00
|
|
|
else
|
2014-05-25 16:56:42 +00:00
|
|
|
[ -f "$CACHE" ] && rm "$CACHE"
|
2014-04-30 13:16:29 +00:00
|
|
|
fi
|
2014-05-25 19:44:25 +00:00
|
|
|
OPTIONS="$OPTIONS --bd_addr $MAC_ADDR"
|
2014-04-30 13:16:29 +00:00
|
|
|
|
2014-05-25 17:17:08 +00:00
|
|
|
# Find chip version
|
2014-05-25 19:23:59 +00:00
|
|
|
if [ -z "$HCD" ]; then
|
2014-05-25 19:44:25 +00:00
|
|
|
DEVS=($( cat /sys/class/mmc_host/mmc*/mmc?\:0001/mmc?\:0001:?/device ))
|
2014-05-25 19:23:59 +00:00
|
|
|
for DEV in "${DEVS[@]}"; do
|
|
|
|
if [ "${DEV:0:4}" = "0x43" ]; then
|
2014-05-25 19:44:25 +00:00
|
|
|
HCD="bcm${DEV:2}.hcd"
|
2014-05-25 19:23:59 +00:00
|
|
|
fi
|
|
|
|
done
|
2014-05-25 19:44:25 +00:00
|
|
|
if [ -z "$HCD" ]; then
|
2014-05-25 19:23:59 +00:00
|
|
|
echo "Failed: Unable to locate bluetooth device"
|
|
|
|
exit 1
|
2014-05-25 17:17:08 +00:00
|
|
|
fi
|
2014-05-25 19:44:25 +00:00
|
|
|
fi
|
|
|
|
HCD_BASE=$(basename "$HCD")
|
2014-04-30 13:16:29 +00:00
|
|
|
|
2014-05-25 19:44:25 +00:00
|
|
|
# Device specific options
|
2015-03-06 14:44:00 +00:00
|
|
|
[ "$HCD_BASE" = "bcm4330.hcd" ] && OPTIONS="--no2bytes --tosleep=50000 $OPTIONS"
|
2014-05-25 19:44:25 +00:00
|
|
|
|
|
|
|
[ ! -e "$HCD" ] && HCD="/lib/firmware/brcm/${HCD_BASE}"
|
|
|
|
if [ ! -e "$HCD" ]; then
|
|
|
|
echo "Failed: $HCD does not exist."
|
|
|
|
exit 1
|
2014-04-30 13:16:29 +00:00
|
|
|
fi
|
|
|
|
|
2014-05-25 18:34:15 +00:00
|
|
|
# UART TTY can be different for each board
|
|
|
|
# FIXME: Possibly test each port with hciattach (-n)?
|
|
|
|
# For now, just use the highest port as it works for current boards
|
|
|
|
if [ -z "$TTY" ]; then
|
|
|
|
TTYS=($( ls -r1 /dev/ttymxc? ))
|
|
|
|
for t in "${TTYS[@]}" ; do
|
|
|
|
ttynum=${t:0-1}
|
|
|
|
if [ $ttynum -eq 0 ]; then
|
|
|
|
echo "Abort: UART ttymcx0 does not seem right."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
TTY=$t
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2014-05-25 19:44:25 +00:00
|
|
|
[ ! -e "$TTY" ] && TTY="/dev/$(basename $TTY)"
|
|
|
|
if [ ! -e "$TTY" ]; then
|
|
|
|
echo "Failed: $TTY does not exist."
|
|
|
|
exit 1
|
2014-05-25 19:23:59 +00:00
|
|
|
fi
|
|
|
|
|
2014-05-25 19:44:25 +00:00
|
|
|
echo "Updating bluetooth firmware via $TTY from $HCD."
|
|
|
|
/usr/bin/brcm_patchram_plus --patchram $HCD --baudrate 3000000 --use_baudrate_for_download $TTY $OPTIONS
|
|
|
|
|
|
|
|
# Create a symlink to TTY for hci service
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
ln -sr "$TTY" /dev/brcm43xx
|
2014-04-30 13:16:29 +00:00
|
|
|
else
|
2014-05-25 19:44:25 +00:00
|
|
|
exit 1
|
2014-04-30 13:16:29 +00:00
|
|
|
fi
|