In last week’s blog, we implemented the Vivado design and proved the basic hardware design using bare-metal SW for a MicroBlaze on which we can run PetaLinux.
In this blog, we are going build the PetaLinux image and download it into the Artix FPGA, so that we can use the PetaLinux kernel.
To do this, I am going to be using a Virtual Machine, running Ubuntu, with Vivado webpack 2018.3 and PetaLinux 2018.3 installed as well. I also have a shared drive between the host windows 10 OS and the VM.
To create the PetaLinux project, we will need to use the hardware definition file (HDF) we exported from Vivado.
The first thing to do in a Linux terminal window is to create a PetaLinux project — we do this using the command below:
petalinux-create — type project — template microblaze — name linux_mb
This generates a PetaLinux project with the name of linux_mb and configures the project for a MicroBlaze processor.
However, the project does not yet include the configuration of our MicroBlaze design. To configure the PetaLinux for our hardware design, we use the command below:
petalinux-config — get-hw-description ../
Point the hardware description to the directory containing the HDF of our MicroBlaze solution. Ensure there is only one HDF in the directory; otherwise, you may get a different configuration to what you may think.
This configuration will bring up the PetaLinux configuration window:
You do not need to change anything here, but you may want to look around and check that the processor is a MicroBlaze.
Once you exit this dialog, you will see the bitbake recipes running.
Once the configuration has completed, as we do not want to make any changes to the kernel or root file system, we can build the image.
Use the command:
This may take a little while, but by the time it is completed, we will have all the files necessary to run PetaLinux on the Artix using either a JTAG download or from the QSPI memory.
However, before I run the image on the hardware itself, I first want to check it will run okay. To do this, I used QEMU which allows me to test the kernel image in the virtual machine.
We can run QEMU using the command:
petalinux-boot –-QEMU –-kernel
This may take a few minutes to boot up, but eventually you should see a log-in screen as below in the terminal window.
The next thing to do is connect the target board to the virtual machine, and then we can download the FPGA image and the kernel image.
We to do this we use the command:
petalinux-boot –-jtag –-fpga
petalinux-boot –-jtag –-kernel
The FPGA download is pretty quick; although the image download can take some time (several minutes) so please be patient unless you see an error reported it is downloading.
With the image downloaded, the next thing is to connect a terminal window and log in to PetaLinux running on the board.
The credentials for both login and password is root.
The board I am using to test this image on is an Arty A7 — it has four LEDS, as such to test the image is working, I am going to toggle one of the LEDs.
In ordder to do this, we need to know the GPIO ID. Change directory into the /sys/class/gpio directory and then examine the contents of the directory.
As there is only one AXI GPIO in the design connected to the LEDs, we know the ident is gpiochip508.
The four LEDs will therefore be numbered 508 to 511. To drive the first LED from the console, I am going to export that GPIO before setting its direction and a value which will illuminate the LED
In a terminal, I used the following commands to set the first LED on:
$ echo 508 > /sys/class/gpio/export
$ echo out > /sys/class/gpio/gpio508/direction
$ echo 1 > /sys/class/gpio/gpio508/value
Entering these commands turn on the LED on the board.
Now that we have Linux running on our MicroBlaze, we can use this to help us with our networking and communication with the Internet of Things, which is something we will look at in another blog soon.
See My FPGA / SoC Projects: Adam Taylor on Hackster.io
Get the Code: ATaylorCEngFIET (Adam Taylor)
Access the MicroZed Chronicles Archives with over 280 articles on the Zynq / Zynq MpSoC updated weekly at MicroZed Chronicles.