Program FPGA and load driver on boot
This commit is contained in:
parent
535b7a1a0a
commit
b78f9be35e
|
@ -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
|
||||
|
|
@ -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 </sys/class/fpga_manager/fpga0/state
|
||||
if [ "$fpga_state" != "operating" ]; then
|
||||
echo "ERROR: FPGA not operating" >&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
|
||||
|
|
@ -0,0 +1 @@
|
|||
PATH="$PATH:/opt/puzzlefw/bin"
|
Loading…
Reference in New Issue