Introduction
FPGAs are best known for their flexibility and versatility. Such flexibility allows FPGAs not only to be used for custom logic circuits but also implement a processor on it and even run Linux (or other operating system) on the processor. The possibilities are only limited by imagination, and also by FPGA speed grade and size. This article will discuss how to create/implement Microblaze processor and run Linux on Mimas Artix 7 FPGA Development Board. This series is based on our article series for Neso Artix 7 FPGA Module. So we highly recommend that you read the series for Neso and get yourself familiar with the steps. So let’s dive right in.
Structure To Run the Linux
- Section 1: Creating the Microblaze based design for Mimas A7
- Section 2: Generating Device Tree
- Section 3: Building Linux Image
- Section 4: Running Linux on Mimas A7
Prerequisites:
For following this article, you would require:
- Hardware:
- Mimas Artix 7 FPGA Development Board
- Xilinx Platform Cable JTAG debugger
- Software:
- Xilinx Vivado installed on either Windows or Linux system
- Linux system( Ubuntu 14.04 64-bit on a Virtual Machine)
- Good internet connectivity
Section 1: Creating the Microblaze based design for Mimas A7
Creating a Microblaze based design for Mimas A7 is very straight forward. Detailed steps for creating Microblaze based design is available in this article. Please go through this article and follow the steps to create a Microblaze based design. Make sure Hello World and Memory Test Program runs and passes all tests.
To run our Linux system, we will be modifying the above created Microblaze based design. We need to modify this Microblaze IP block to be able to run Linux on Mimas A7 board. Open the above created block design, double click on the Microblaze block and choose the Select Configuration as “Linux with MMU” as shown in the image below.
Also we have to change the baud rate of UART. Double click on “uartlite” IP and set the baud rate as “115200”.
Now, the Microblaze based Linux capable design is completed. Click “Genetrate Bitstream” in the program and debug. Once the bitstream is generated successfully, export the hardware along with the bitstream. We will launch Vitis classic in the next step.
Section 2: Generating Device Tree
On many platforms, Linux kernel depends on a data structure called Device Tree to discover and configure different hardware components available on the board. Kernel uses the device tree in binary format which is generated by using device tree compiler. The input to the device tree compiler is a text file (with extension .dts) that describes all the hardware and dependencies. This file can be edited manually by hand if necessary. But fortunately, there are tools available that can help us generate device tree from our Vivado/Vitis projects.
Having completed all the steps before, now download the device-tree repository from Xilinx’s github account: https://github.com/Xilinx/device-tree-xlnx. If you downloaded the zip file, extract it in the same location as your Vitis workspace. The author extracted it to “C:\mimasa7\Linux_Vitis\device-tree-xlnx-master” directory. To generate Device tree follow the steps below.
Step 1: Launch Vitis Classic.
Step 2: In Vitis , go to “Vitis” and click “Software Repositories”.
Step 3: In the dialog window, select “New” and select the device tree folder which you had downloaded and extracted to Vitis workspace in the “Local Repositories” section. Click “OK”.
Step 4: Click on “Create Platform Project“. In the “Create a new platform from hardware (XSA)” browse and select your XSA file. Select the “Operating system” as “device_tree” and click on “Finish“. This should generate a system.dts file along with a .dtsi file. We need both of them.
Step 5: We have to merge the ‘.dtsi’ and ‘.dts’ files. Merge these two files using text editor (like Notepad++ etc) and copy the contents of system-top.dts and paste them in the .dtsi file just after the line model = “Xilinx MicroBlaze”. Don’t forget to add “/dts-v1/;” at the top of .dtsi file also. The final content should look like this:
Now, save this modified file as “mimasa7.dts”. And copy “mimasa7.dts” file to your Linux System.
Section 3: Building Linux Image
Now we need a Linux system to build Linux Image. In this article, author used Ubuntu 20.04.6 LTS 64-bit for building Linux image.
Follow the Steps shown below to Build Linux image:
Step 1: After a clean installation of Ubuntu 20.04.6 , you will need a few packages to make Buildroot work. Run the following command in Linux terminal to install those:
sudo apt-get install build-essential bison flex gettext libncurses5-dev texinfo autoconf automake libtool
Step 2: Create a convenient folder on your linux system and ‘cd’ to that folder. The author created a directory with the name “mimasa7 _linux” in their “home” directory. Now download buildroot to the created directory, either manually or by using the following command:
wget http://buildroot.uclibc.org/downloads/buildroot-2018.11.tar.gz
You can use latest buildroot release instead of the above. Now, extract the downloaded tarball archive using following command:
tar -xvf buildroot-2018.11.tar.gz
All extracted files should be in the “buildroot-2018.11” folder.
Step 3: We need Linux kernel defconfig file for Mimas A7. Get the defconfig files from here.
mimasa7_defconfig file: place it under the directory “buildroot-2018.11/board/numato/mimasa7/” You will need to create respective directories named “numato” and “mimasa7”. Please note the kernel base address is set to 0x80000000 in the Linux kernel defconfig file. Please change it appropriately if the DDR3 base address is different in your Vivado project.
Now copy the “mimasa7.dts” to the same folder as well.
Now, buildroot defconfig file “numato_mimasa7_defconfig”: copy it to the “configs” folder inside buildroot root directory (i.e. “buildroot-2018.11/” ).
After setting up buildroot as mentioned above, change the directory to buildroot and execute the following command:
make numato_mimasa7_defconfig
This will create a .config file for buildroot. Next, execute the below command:
make
Before executing the above command, please make sure that Python and OpenSSL header files should be installed in the Ubuntu system. If these files are not installed in your system execute the following commands to install.
To install python files run the following command:
sudo apt install python
To install OpenSSL header files execute the below command:
sudo apt install libssl-dev
Note: In in the “dtc-lexer.lex.c” file located at “mimasa7_linux/buildroot-2018.11/output/build/linux-4.18.20/scripts/dtc/dtc-lexer.lex.c”, modify the line “YYLTYPR yylloc” to “extern YYLTYPR yylloc”.
After successful completion of installation of those files, execute the “make” command. This command will build the kernel and its file system. This downloads the kernel sources and lots of other tools from internet. It will take some time to finish building the kernel image, from 30 minutes to over an hour, or even more, depending on your machine’s capabilities and your internet speed.
After completion of the above steps, a linux image “simpleImage.mimasa7” will be created in the directory “buildroot-2018.11/output/images/”. This is the Linux kernel with root file attached to it. We will use this file to boot Linux on Mimas Artix 7 FPGA Development Board.
Section 4: Running Linux on Mimas A7
Step 1: Copy the Linux image and place it in a convenient directory. Now open Vitis and connect the Xilinx Platform Cable to the Mimas Artix 7 FPGA Development Board and power it up. Make sure the FT2232’s channel A is configured for RS232. Open any Serial terminal program (CoolTerm, PuTTY, Tera Term etc.) at baud rate 115200 and connect it to Mimas A7.
Step 2: First run Hello World program again to check everything is connected properly and to ensure that it works. Now, go to Vitis -> XSCT Console, type in a command “targets” it will show all the targets connected, note down the number where MicroBlaze 0 is connected (3 in this article), connect to MicroBlaze by giving the command:
targets 3
Now, ‘cd’ to the directory where your kernel image is located (…\\images). Download the kernel image by using the following command:
dow simpleImage.mimasa7
Wait for download to complete. If the kernel image is successfully downloaded, run the below command to continue the processor:
con
If all the above steps are completed successfully, you can observe Linux booting in the serial terminal as shown below:
You can login to Linux with username “root” and password as “mimasa7”. Now we have a successfully running Linux kernel in Mimas Artix 7 FPGA Board. Congratulations! In the next article, we will see how to flash kernel image to the onboard SPI Flash on Mimas A7!