53 lines
1.1 KiB
Bash
Executable File
53 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Load FPGA firmware from SD card and program FPGA.
|
|
#
|
|
|
|
FIRMWARE_FILE="puzzlefw_top.bit.bin"
|
|
|
|
start() {
|
|
|
|
# If firmware is not on rootfs, copy it from the SD card.
|
|
if [ ! -f /lib/firmware/$FIRMWARE_FILE ]; then
|
|
|
|
mkdir -p /lib/firmware
|
|
|
|
mkdir -p /mnt/tmp_sdcard
|
|
mount -t vfat -o fmask=0177 -r /dev/mmcblk0p1 /mnt/tmp_sdcard
|
|
|
|
if ! cp /mnt/tmp_sdcard/$FIRMWARE_FILE /lib/firmware ; then
|
|
echo "ERROR: Failed to copy FPGA firmware from SD card" >&2
|
|
fi
|
|
|
|
umount /mnt/tmp_sdcard
|
|
rmdir /mnt/tmp_sdcard
|
|
|
|
fi
|
|
|
|
# Check that firmware is in place.
|
|
if [ ! -f /lib/firmware/$FIRMWARE_FILE ]; then
|
|
echo "ERROR: FPGA firmware not found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Program FPGA.
|
|
echo "Programming FPGA ..."
|
|
echo 0 > /sys/class/fpga_manager/fpga0/flags
|
|
echo $FIRMWARE_FILE > /sys/class/fpga_manager/fpga0/firmware
|
|
|
|
# Wait until FPGA programmed.
|
|
sleep 5
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
start
|
|
;;
|
|
stop|restart|reload)
|
|
;;
|
|
*)
|
|
echo "Usage: $0 start"
|
|
exit 1
|
|
esac
|
|
|