#!/bin/sh

BITFILE=/usr/share/fpga.bin

case "$1" in
  start)
    if [ ! -e /dev/xdevcfg ]; then
      mknod /dev/xdevcfg c 259 0
    fi
    if [ ! -e "${BITFILE}" ]; then
      echo "FPGA bitfile ${BITFILE} does not exist"
      exit 1
    fi
    cat "${BITFILE}" > /dev/xdevcfg
    result=`cat /sys/class/xdevcfg/xdevcfg/device/prog_done`
    if [ $result -ne 1 ]; then
      echo "ERROR configuring FPGA, logic is not configured!"
      exit 1
    fi
    ;;
esac
