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

89 lines
2.3 KiB
Bash
Raw Permalink Normal View History

2024-09-22 11:35:58 +02:00
#!/bin/sh
#
# Load FPGA firmware from SD card and program FPGA.
#
. /opt/puzzlefw/lib/functions.sh
2024-09-22 11:35:58 +02:00
start() {
# Read hardware revision from EEPROM
read_eeprom
if [ "$eeprom_hw_rev" = "STEM_125-14_v1.0" ]; then
# Red Pitaya with XC7Z010 and 2 analog inputs
FIRMWARE_FILE="puzzlefw_top.bit.bin"
elif [ "$eeprom_hw_rev" = "STEM_125-14_Z7020_4IN_v1.3" ]; then
# Red Pitaya with XC7Z020 and 4 analog inputs
FIRMWARE_FILE="puzzlefw_top_4ch.bit.bin"
else
echo "ERROR: Unsupported hardware revision '$eeprom_hw_rev'" >&2
exit 1
fi
2024-09-22 11:35:58 +02:00
# 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
# Drive internal GPIO(0) low to reset FPGA.
# Note: EMIO GPIO(n) is gpio (n + 54) in Linux.
2024-10-05 00:34:40 +02:00
gpioset 0 54=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
if [ "$eeprom_hw_rev" = "STEM_125-14_v1.0" ]; then
# Drive internal GPIO(2) high to enable ADC duty cycle stabilizer.
gpioset 0 56=1
elif [ "$eeprom_hw_rev" = "STEM_125-14_Z7020_4IN_v1.3" ]; then
# Program ADCs for DDR data mode and enable duty cycle stabilizer.
/opt/puzzlefw/bin/puzzle-adccfg init --force --dcs
# Enable ADC output randomization.
/opt/puzzlefw/bin/puzzle-adccfg format --rand
# Drive internal GPIO(3) high to enable sample derandomization in FPGA.
gpioset 0 57=1
fi
# Drive internal GPIO(0) high to release FPGA reset.
2024-10-05 00:34:40 +02:00
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