#!/bin/sh

if [ "$1" == "" -o "$2" == "" ]; then
  echo "This procedure is for flashing the EPROM on an ICEPIC card."
  echo "Syntax:   ./flashpic <devno> <loadfile>"
  echo "  or       ice flash <devno> <loadfile>"
  echo "where <devno> is the zero-based index of the PIC card, and <loadfile> is "
  echo "the filename to load including the signature suffix (eg. icepic6_hh)."
  exit
fi

picno=$1 ; 
if [ $picno == "" ]; then picno=0 ; fi
picsig=$2 ; if [ $picsig == "" ]; then picsig="bogus"; fi

if [ ! -n "$ICEROOT" ]; then export ICEROOT=`readlink -f $0 | sed 's/\/test\/flashpic//'` ; fi

echo -n "Loading SIG=$picsig from ICEROOT=$ICEROOT on PIC=$picno.  Are you sure [Y/N]? " ; read ans

if [ "$ans" != "y" -a "$ans" != 'Y' ]; then
  echo "Aborting loadflash ... "
  exit
fi

cd $ICEROOT/test

if [ ! -e test ]; then
  ./build.lnx
fi

./test pic $picno loadflash $picsig

