# Do this once, this is for install as root.
# for Xilinx webpack
#
#mkdir /usr/local/lib/xilinx/
#cp ~/Xilinx/bin/lin/*.so /usr/local/lib/xilinx/
#cat /usr/local/lib/xilinx >> /etc/ld.so.conf
#ldconfig
#
# in /etc/bashrc or /root/.bashrc or if you use zsh in /etc/zsh/zshenv add at end:
#PLATFORM=lin
#XILINX=/root/Xilinx
#export XILINX
#PATH=/root/Xilinx/bin/lin:$PATH
#export PATH
#
# start a new shell, zsh or perhasps bash:
#zsh

# This script programs the FPGA on Digilent Digilab board with example BtnDemo.vhd, (button drives LED).
#
# In general:
# At least 3 input files are required:
# project.vhd (or project.v) is the source
# project.xst holds the xst options, modify the FPGA type and source filename in it, leave the rest for now.
# bitgen_options.ut  This sets the bitgen options, note the -g StartUpClk:JtagClk must be set!
#Also set the FPGA type in 'map' below.

# prevent pointless warnins
export LANGUAGE=usenglish

# for clock dll inputs
export XIL_MAP_ALLOW_ANY_DLL_INPUT=1

# set with project name
prog=p1
# Use this if you want litte info on screen
style=silent
# Use this if you can read very fast
#style=xflow


rm $prog.ngd $prog.ngc $prog.srp \
$prog.bld ngdbuild.log \
$prog.map.ngm $prog.pcf $prog.map.ncd $prog.map.mrp \
$prog_pad.csv $prog.pad $prog.unroutes $prog_pad.txt \
$prog.xpi $prog.par $prog.ncd $prog.drc \
$prog.bit $prog.bgn \
1> /dev/zero 2>/dev/zero


echo "starting xst"
xst -intstyle $style -ifn $prog.xst

echo "starting ndgbuild"
ngdbuild -intstyle $style -dd _ngo -uc $prog.ucf $prog > ngdbuild.log

echo "starting map"
map -intstyle $style -cm area -pr b -k 4 -c 100 -tx off \
-p xc2s200-pq208-6 \
$prog.ngd -o $prog.map.ncd $prog.pcf

echo "starting par"
par -intstyle $style -w -ol std -t 1 $prog.map.ncd $prog.ncd $prog.pcf

#rm $prog.bit
echo "starting bitgen"
bitgen -intstyle $style -f bitgen_options.ut $prog.ncd

echo "starting impact ;-)"
echo "connect FPGA board and power, then type ENTER."
read user_reply
p3j $prog.bit



