#! /bin/sh

# Installing Packages
sudo apt-get install eclipse eclipse-cdt eclipse-egit git doxygen g++ ckermit libftdi1 libftdi-dev lv librxtx-java python-serial libperl4-corelibs-perl 

# Installing GNU Toolchain
 
rm -f blackfin-toolchain-2011R1-RC4.i386.tar.bz2
rm -f blackfin-toolchain-elf-gcc-4.3-2011R1-RC4.i386.tar.bz2
rm -f blackfin-toolchain-uclibc-full-2011R1-RC4.i386.tar.bz2

wget http://blackfin.uclinux.org/gf/download/frsrelease/531/9509/blackfin-toolchain-2011R1-RC4.i386.tar.bz2
wget http://blackfin.uclinux.org/gf/download/frsrelease/531/9513/blackfin-toolchain-elf-gcc-4.3-2011R1-RC4.i386.tar.bz2
wget http://blackfin.uclinux.org/gf/download/frsrelease/531/9517/blackfin-toolchain-uclibc-full-2011R1-RC4.i386.tar.bz2

tar xvjf blackfin-toolchain-2011R1-RC4.i386.tar.bz2
tar xvjf blackfin-toolchain-elf-gcc-4.3-2011R1-RC4.i386.tar.bz2
tar xvjf blackfin-toolchain-uclibc-full-2011R1-RC4.i386.tar.bz2

# Adding stepping information of BF592
echo '0010	bf592		2' >> opt/uClinux/bfin-elf/share/urjtag/analog/bf592/STEPPINGS

sudo rm /opt/uClinux -f
sudo mv opt/uClinux/ /opt/uClinux2011R1RC4 -f
sudo ln -s /opt/uClinux2011R1RC4 /opt/uClinux
rm opt -f -r


rm -f blackfin-toolchain-2011R1-RC4.i386.tar.bz2
rm -f blackfin-toolchain-elf-gcc-4.3-2011R1-RC4.i386.tar.bz2
rm -f blackfin-toolchain-uclibc-full-2011R1-RC4.i386.tar.bz2

echo
echo The Blackfin toolchain 2011R1RC4  have been installed on /opt/uClinux 
echo 


#	set search path into the PATH environment variable
# 	Run this program from some temporal directory
echo 'export PATH=$PATH:/opt/uClinux/bfin-elf/bin:/opt/uClinux/bfin-uclinux/bin' >> ~/.bashrc
echo 'export PATH=$PATH:/opt/uClinux/bfin-elf/bin:/opt/uClinux/bfin-uclinux/bin' >> ~/.profile

# Setup Kermit initialize file
echo 'set line /dev/ttyUSB0' > ~/.kermrc
echo 'set speed 57600' >> ~/.kermrc
echo 'set parity none' >> ~/.kermrc
echo 'set flow-control none' >> ~/.kermrc
echo 'set carrier-watch off' >> ~/.kermrc

# Add access right to JTAG ice for gdbproxy
echo \# FT2232 based JTAG ICE > 50-ft2232.rules
echo ATTRS{idVendor}==\"0403\", ATTRS{idProduct}==\"6010\", GROUP=\"jtag\" >> 50-ft2232.rules
echo ATTRS{idVendor}==\"0403\", ATTRS{idProduct}==\"BAF8\", GROUP=\"jtag\" >> 50-ft2232.rules

sudo mv 50-ft2232.rules /etc/udev/rules.d
sudo groupadd jtag
sudo gpasswd -a `whoami` jtag

# Add access right to serial device
sudo gpasswd -a `whoami` dialout
