#!/bin/bash
FILE_VERSION=0b
FPGA_VERSION=`/usr/bin/head -2 /proc/system/fpga |
 /usr/bin/tail -1 |
 /usr/bin/cut -d' ' -f2`
echo "The current FPGA version is ${FPGA_VERSION}."
if [ "$FPGA_VERSION" = "$FILE_VERSION" ]
then
 echo "FPGA is up to date. No further action is required."
 exit 0
fi
echo "FPGA version $FILE_VERSION is available."
echo "You should update the FPGA to the new version."
echo "Warning: FPGA update will disrupt traffic flowing through this switch."
echo "It will also cause the switch to restart."
PROMPT="Do you want to update the FPGA to version ${FILE_VERSION}? [N] "
while true
do
 read -ep "$PROMPT" REPLY
 case `echo $REPLY | /usr/bin/tr [:lower:] [:upper:]` in
  N|NO|"") exit 0 ;;
  Y|YES) break ;;
 esac
done
echo "Please avoid powering off this switch during programming."
echo ""
/fabos/share/jtagpgm -f /fabos/share/pharos_sysfpga_r0b.xsvf
echo ""
echo "The new FPGA image will not become active until you cycle Power Domain 1."
echo "Therefore you should turn off PD1 and then turn the power back on."
echo "For example, you could remove and re-insert the switch."
