Skip to content

Instantly share code, notes, and snippets.

@bartman
Created April 12, 2012 17:43
Show Gist options
  • Save bartman/2369552 to your computer and use it in GitHub Desktop.
Save bartman/2369552 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
base=$(dirname $0)
LSUSB=/usr/sbin/lsusb
FXLOAD=/sbin/fxload
declare -a rules=(
03fd:0007,03fd:0008,$base/xusbdfwu.hex
03fd:0009,03fd:0008,$base/xusb_xup.hex
03fd:000d,03fd:0008,$base/xusb_emb.hex
03fd:000f,03fd:0008,$base/xusb_xlp.hex
03fd:0013,03fd:0008,$base/xusb_xp2.hex
03fd:0015,03fd:0008,$base/xusb_xse.hex
)
dev_from_id() {
local id="$1"
${LSUSB} -d "$id" | sed -nre 's,^Bus (...) Device (...):.*,/dev/bus/usb/\1/\2,p'
}
declare -a look_for=( )
for spec in ${rules[*]} ; do
declare -a words=( ${spec//,/ } )
dev=$(dev_from_id "${words[0]}")
if [ -n "$dev" ] ; then
echo "programming ${words[0]} at $ev with ${words[2]}"
sudo ${FXLOAD} -t fx2 -I "${words[2]}" -D $dev
look_for=( ${look_for[*]} "${words[1]}" )
else
dev=$(dev_from_id "${words[1]}")
if [ -n "$dev" ] && [ -c "$dev" ] ; then
echo >&2 "found ${words[1]} programmer: $dev"
exit 0
fi
fi
done
if [ -z "$look_for" ] ; then
echo >&2 "didn't find a jtag programmer"
exit 1
fi
sleep 10
success=0
for dev in ${look_for[*]} ; do
echo >&2 "checking if $dev came up OK"
${LSUSB} -d "$dev" && success=$(( $success + 1 ))
done
echo >&2 "found $success devices"
[ "$success" -gt 0 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment