This is a quick guide how to program FPGA fabric on Microchip Polarfire, more specifically Beaglev-fire board.
Programming Link to heading
In 4, We need to get bitstream directory generated by gateware first. In this example, it’s called my_custom_fpga_design
.
change-gateway Link to heading
So, what is there? We need to the bitstream and dtb overlay.
- mpfs_bitstream.spi : spi bitstream
- mpfs_dtbo.spi : overlay device tree
Then we call change-gateway
script with my_custom_fpga_design
to copy the files above.
sudo /usr/share/beagleboard/gateware/change-gateware.sh ./my_custom_fpga_design
if ! id | grep -q root; then
echo "must be run as root"
exit
fi
if [ -d $1 ]
then
echo "Changing gateware."
if [ -e $1/LinuxProgramming/mpfs_bitstream.spi ]
then
if [ -e $1/LinuxProgramming/mpfs_dtbo.spi ]
then
cp -v $1/LinuxProgramming/mpfs_dtbo.spi /lib/firmware/mpfs_dtbo.spi
cp -v $1/LinuxProgramming/mpfs_bitstream.spi /lib/firmware/mpfs_bitstream.spi
sync
. /usr/share/microchip/gateware/update-gateware.sh
else
echo "No device tree overlay file found."
fi
else
echo "No gateware file found."
fi
else
echo "No directory found for this requested gateware."
fi
update-gatewate Link to heading
Looking deeper into update-gatewate
which uses mtd_debug
5 to write mpfs_dtbo.spi
.
The writing 1 to /sys/kernel/debug/fpga/microchip_exec_update
to write the
If successful, the console should display some messages indicating that the bistream image has been transferred to the SPI flash and the bitstream address has been copied to the spi flash directory. For more information on the SPI flash memory layout please refer to the SPI Directory Layout section. Finally, the system controller reads the bitstream from the SPI flash to verify its content.
#!/bin/bash
echo "================================================================================"
echo "| FPGA Gateware Update |"
echo "| |"
echo "| Please ensure that the mpfs_bitstream.spi file containing the gateware |"
echo "| update has been copied to directory /lib/firmware. |"
echo "| |"
echo "| !!! This will take a couple of minutes. !!! |"
echo "| |"
echo "| Give the system a few minutes to reboot itself |"
echo "| after Linux has shutdown. |"
echo "| |"
echo "================================================================================"
if [ ! -f /lib/firmware/mpfs_bitstream.spi ] ; then
echo "Missing: /lib/firmware/mpfs_bitstream.spi"
exit 2
fi
#read -rsp $'Press any key to continue...\n' -n1 key
if [ ! -f /sys/kernel/debug/fpga/microchip_exec_update ] ; then
/usr/bin/mount -t debugfs none /sys/kernel/debug
fi
# Trash exisitng device tree overlay in case the rest of the process fails:
/usr/sbin/mtd_debug erase /dev/mtd0 0x0 0x10000
# Write device tree overlay
dtbo_ls=$(ls -l /lib/firmware/mpfs_dtbo.spi)
dtbo_size=$(echo $dtbo_ls | cut -d " " -f 5)
echo "Writing mpfs_dtbo.spi to /dev/mtd0"
/usr/sbin/mtd_debug write /dev/mtd0 0x400 $dtbo_size /lib/firmware/mpfs_dtbo.spi > /dev/zero
# Fake the presence of a golden image for now.
/usr/sbin/mtd_debug write /dev/mtd0 0 4 /dev/zero > /dev/zero
# Initiate FPGA update.
echo "Triggering FPGA Gateware Update (/sys/kernel/debug/fpga/microchip_exec_update)"
echo 1 > /sys/kernel/debug/fpga/microchip_exec_update
# Reboot Linux for the gateware update to take effect.
# FPGA reprogramming takes places between Linux shut-down and HSS restarting the board.
/usr/sbin/reboot