Back | Next | Contents
Flashing the FPGA from SD Card
This document details how to update the FPGA design from Linux without having to reboot the machine.
NOTE - It is assumed that you followed the kernel configuration steps as detailed in the building kernel page. If not, please follow the configuration steps and copy the
zImagefile onto the SD Card. You will not be able to follow the steps otherwise.
The MSEL pins on the DE10-Nano should be all set to ON for this to work:
To explain the process, let's create a simple LED blinking design as follows:
module blink (
input clk,
output led
);
reg [26:0] counter;
always @(posedge clk) counter <= counter + 1'b1;
assign led = counter[26];
endmoduleCompile this design in quartus as you normally would and generate the .sof file. If you need a refresher, refer to this tutorial to compile the FPGA (no need to program it).
After the .sof is generated, we need to convert it to an .rbf file which will be used to program the FPGA in linux.
In quartus, go to File> Convert Programming Files and this will open the utility window. Set the options to match the screenshot below and hit generate.
Once generated, copy this over to the DE10-Nano using scp to the root folder:
scp blink.rbf root@<ipaddress>:~Device tree overlays are the way to flash an FPGA from Linux. We do this by creating an overlay for the FPGA region and then updating the device tree while Linux is running. This is not permanent, it will be reset if you reboot the system.
If you look in the device tree source file in $DEWD/u-boot/arch/arm/dts/socfpga.dtsi, you will see that there is a node called base_fpga_region which is a child of the node soc. We will create a device tree overlay to update this particular node.
Using ssh or the serial terminal, log onto the DE10-Nano and create a new file in the root folder and call it blink.dtso. Copy the content below and paste it in the file:
/dts-v1/;
/plugin/;
/{
fragment@0 {
target-path = "/soc/base_fpga_region";
__overlay__ {
#address-cells = <1>;
#size-cells = <1>;
firmware-name = "blink.rbf";
};
};
};In our case the binary that we want to flash on the FPGA is called blink.rbf. If your file is named something else, rename this accordingly.
We'll need the device tree compiler. Thankfully, since we're running debian, this is easy to install. Run the following command in the DE10-Nano
apt install device-tree-compilerOnce it completes, we can now compile the device tree with the following command:
dtc -O dtb -o blink.dtbo -b 0 -@ blink.dtsoThis will generate the device tree binary blink.dtbo.
Your root folder should now contain all three files:
blink.dtso
blink.dtbo
blink.rbfFor this to work, the .dtbo and the .rbf should both be copied to the folder /lib/firmware. If it doesn't exist, create it:
mkdir -p /lib/firmware
cp blink.dtbo /lib/firmware
cp blink.rbf /lib/firmwareNow let's mount the configfs to get access to the device tree. We'll do this in /config and will create it if it doesn't exist:
mkdir -p /config
mount -t configfs configfs /configWhen you look inside /config, you should see something similar to the following:
root@de10-nano:~# ls -lrthR /config
/config:
total 0
drwxr-xr-x 3 root root 0 Jan 1 1970 device-tree
/config/device-tree:
total 0
drwxr-xr-x 2 root root 0 Jan 1 1970 overlays
/config/device-tree/overlays:
total 0
root@de10-nano:~#Let's create a new folder in the overlays folder:
cd /config/device-tree/overlays
# The folder can be named anything.
mkdir blinkThe folder should now look like this:
root@de10-nano:/config/device-tree/overlays# ls -lrthR blink
blink:
total 0
-r--r--r-- 1 root root 4.0K Sep 14 16:45 status
-rw-r--r-- 1 root root 4.0K Sep 14 16:45 path
-rw-r--r-- 1 root root 0 Sep 14 16:45 dtbo
root@de10-nano:/config/device-tree/overlays#Now we pass the name of the device tree binary to the path file and if all goes well, our LED should now blink as expected:
echo -n "blink.dtbo" > blink/pathVerify that the design has been successfully applied:
root@de10-nano:/config/device-tree/overlays# cat blink/status
appliedTo update the design, we need to first remove the old node using rmdir. This can be run without deleting the files inside:
rmdir blinkThen follow the steps as per the previous section to flash the new design.
Zynq PL programming with FPGA Manager - This page has the details that work for version 5.5 of the kernel.
Next | Flashing the FPGA On Boot Up
Back | Overview
Flashing the FPGA from SD Card | Table of Contents

