redpitaya-puzzlefw/sw/buildroot_overlay/etc/init.d/S90program_fpga.sh

64 lines
1.4 KiB
Bash
Raw Normal View History

2024-09-22 11:35:58 +02:00
#!/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
2024-10-05 00:34:40 +02:00
# Drive internal GPIO line 0 low to reset FPGA.
# Note: EMIO GPIO line n is gpio (n + 54) in Linux.
gpioset 0 54=0
# Drive internal GPIO line 2 high to enable ADC duty cycle stabilizer.
gpioset 0 56=0
2024-09-22 11:35:58 +02:00
# 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
2024-10-05 00:34:40 +02:00
# Drive internal GPIO line 0 high to release FPGA reset.
gpioset 0 54=1
sleep 1
2024-09-22 11:35:58 +02:00
}
case "$1" in
start)
start
;;
stop|restart|reload)
;;
*)
echo "Usage: $0 start"
exit 1
esac