For many applications in this blog and my Hackster projects, I use a bare metal approach.

However, sometimes we need the capabilities provided by a operating system, e.g. networking, working with higher level languages and frameworks, file management, etc.

Initial hardware design

I recently had to create an PetaLinux for the Cora board, and as it one of the smaller Z7010 devices, I thought it would make a good compliment to the Building PetaLinux for the MiniZed blog — especially as there is no pre-existing PetaLinux BSP for the Cora.

The first thing we need is a Vivado design. For this example, I want to be able to use the Pmods, the RGB LEDs ,and the push buttons. As such, my Vivado design includes the following IP:

AXI GPIO — Configured as an output for RGB LEDs.

AXI GPIO — Configured as an input for the push button switches.

IOP MicroBlaze Processors — These are connected to the Pmod A and B and come from the Pynq Z2 base design.

You can find the completed Vivado design on my GitHub.

Once we have the design implemented, the next stage is to build the Vivado hardware and export the Hardware Definition File (HDF).

It is this file we will use to to customize the PetaLinux build.

To create the Petalinx OS, I used a virtual machine onto which I have installed PetaLinux 2018.2

Now this is where our development is different to previous examples. In those examples, we had a PetaLinux board support package (BSP) to work with; however in this example, there is no Cora BSP so we have to start from scratch.

The first thing we need to do in PetaLinux is to create a project. We can do this using the command:

$petalinux-create — type project — template zynq — name cora

This creates a project which will can be targeted at a Zynq 7000 series device. Of course, we need to be able to customize it for our hardware design.

To do this, we import the HDF and apply it to the project using the command:

$petalinux-config — get-hw-description=

Once this has been imported, you will see a PetaLinux configuration box appear. Here is where we would make any changes we desire. For this example, though, we will not change anything. If prompted to save the new configuration as you exit, select yes.

PetaLinux configuration

Once you exit the configuration menu, bitbake will run and generate all of the files we need. Please note that this might take several minutes.

Generation of PetaLinux

Once this is completed, we can build the project using:

$ petalinux-build

Again this will take a few minutes.

Once this is built, we have all of the constituent parts required to run Petalinux. The final stage is to create the Boot.BIN which contains the first stage boot loader (FSBL) and the programmable logic configuration.

To do this, we need to change directory into the /images/linux directory and run the command:

$petalinux-package — boot — fsbl zynq_fsbl.elf — u-boot u-boot.elf— fpga system.bit

This will generate the boot.bin fie, which along with the image.ub, we can use to boot up the Cora running PetaLinux.

PetaLinux booting

When the board boots, if asked for a login and password use root for both.

Now we need to ensure the PL element is included correctly in this design. The easiest way is to double check on the AXI GPIO which are included in the PL.

We can find these by using the command line to change directory to:

$ cd /sys/class/gpio/

When in this directory, examine the contents of the directory using and you will see three GPIOChips. They will be in the following format GPIOChipXXXX

In order to find out which one of these chips is associated with AXI GPIO and which one is connected to the PS MIO, we can issue the command:

$cat /sys/class/gpio/gpiochipXXX/label

If it belongs to the PS MIO, you will see the label is defined as Zynq_GPIO, otherwise it will respond with the AMBA_PL and address.

Two AXI GPIO and the Zynq MIO

Should we desire we test the LEDs and switches, we can drive them using the export / unexport option.

$ echo 1018 > /sys/class/gpio/export

$ echo out > /sys/class/gpio/gpio1018/direction

$ echo 1 > /sys/class/gpio/gpio1018/value

I have bigger plans for the PetaLinux build, so keep an eye on my Hackster projects over the coming weeks. You can find all the project here

See My FPGA / SoC Projects: Adam Taylor on Hackster.io

Get the Code: ATaylorCEngFIET (Adam Taylor)

Access the MicroZed Chronicles Archives with over 270 articles on the Zynq / Zynq MpSoC updated weekly at MicroZed Chronicles.