diff --git a/sw/buildroot_overlay/etc/init.d/S90program_fpga.sh b/sw/buildroot_overlay/etc/init.d/S90program_fpga.sh new file mode 100755 index 0000000..0feae6f --- /dev/null +++ b/sw/buildroot_overlay/etc/init.d/S90program_fpga.sh @@ -0,0 +1,52 @@ +#!/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 + diff --git a/sw/buildroot_overlay/etc/init.d/S91puzzlefw_driver.sh b/sw/buildroot_overlay/etc/init.d/S91puzzlefw_driver.sh new file mode 100755 index 0000000..163cfb1 --- /dev/null +++ b/sw/buildroot_overlay/etc/init.d/S91puzzlefw_driver.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# +# Load puzzlefw kernel driver. +# + +start() { + + # Check that the FPGA is running. + # If the PuzzleFW firmware is not running on the FPGA, + # attempting to load the driver will crash the system. + read fpga_state &2 + exit 1 + fi + + # Load module. + echo "Loading puzzlefw driver ..." + insmod /opt/puzzlefw/driver/puzzlefw.ko +} + +stop() { + echo -n "Unloading puzzlefw driver ..." + rmmod puzzlefw +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart|reload) + stop + start + ;; + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 +esac + diff --git a/sw/buildroot_overlay/etc/profile.d/puzzlefw_path.sh b/sw/buildroot_overlay/etc/profile.d/puzzlefw_path.sh new file mode 100644 index 0000000..00f5d1b --- /dev/null +++ b/sw/buildroot_overlay/etc/profile.d/puzzlefw_path.sh @@ -0,0 +1 @@ +PATH="$PATH:/opt/puzzlefw/bin"