Professional Documents
Culture Documents
This guide is used as an entry point into the Petalinux tool. This demo shows the following:
How to create a Linux Image for a Zc702 in Petalinux and boot from the SD card
How to use the SYSFS to control the LEDs via the Petalinux Console, and User Applications
How to add device drivers to the Device-Tree
How to debug a simple GPIO application in SDK
Demo files: Attached to this demo, there is a petalinux.zip file. This contains:
Zc702_files
o Zc702_build.tcl
o proc_system_wrapper.vhd
o ledapp.c
o gpioapp.c
Launch Vivado 2014.2. In Vivado, source the Zc702_files/build_zc702.tcl from the TCL command:
1 stephenm@xilinx.com | Xilinx
Generate the Output Products:
2 stephenm@xilinx.com | Xilinx
Next, Generate the Bitstream:
Note: This is not needed to create the application. Users can export hardware without a bitstream
Minimise Vivado
3 stephenm@xilinx.com | Xilinx
Zynq - Step 2: Create the Petalinux Project
Launch Petalinux (on GUUP m1 2014.2) and change directory to the directory where the HDF from
steps 1 was written to (<project_name>.sdk) and run the Petalinux command below:
This will create a default template project, which will be modified in the next step to reflect our
actual HW project:
The resulting pop up box , in the Subsytem AUTO Hardware Settings will contain all the options
based upon the XML file for your Hardware System.
We shall be booting from the SD Card. In “subsystem AUTO Hardware Settings” “Advanced
Bootable images storage Settings”. Select “Y” to include this:
4 stephenm@xilinx.com | Xilinx
Then Select to enter the “Advanced bootable image storage settings”, and select “boot image
settings”, as shown below:
5 stephenm@xilinx.com | Xilinx
Repeat this for the kernel image settings:
6 stephenm@xilinx.com | Xilinx
To see the rootfs configuration menu run the command below from the project root
cd petalinux_test
petalinux-config –c rootfs
If debugging from SDK is required, a TCF agent will need to be running on the ZC702 board. To add
the TCF agent, go to “Filesystem Packages” ”base” ”tcf-agent” and “Y” to add this:
7 stephenm@xilinx.com | Xilinx
To see the kernel configuration menu run the command below from the project root:
cd petalinux_test
petalinux-config –c kernel
GPIO Support
o Xilinx GPIO support
o Xilinx Zynq GPIO Support
LED Support
o LED Class Support
o LED Support for GPIO connected LEDs
o LED Trigger support
all triggers
Input device support
o Keyboards
GPIO Buttons
Polled GPIO buttons
8 stephenm@xilinx.com | Xilinx
Finally, when we are happy with the configuration, we can build the image:
petalinux-build
BOOT.BIN
Images/linux/image.ub
9 stephenm@xilinx.com | Xilinx
ZC702 – Step 3: Booting Linux:
BOOT.BIN
Images/linux/image.ub
Place the SD card in the SD slot on the board, insert the USB UART, and the PHY cable and set the
Mode pins to M1:5 = 00110 and power on the board.
10 stephenm@xilinx.com | Xilinx
Open a Tera Term, and set the BAUD Rate to 115200:
Finally, press the POR_B button on the board and monitor the Tera Term:
11 stephenm@xilinx.com | Xilinx
ZC702 – Step 4: Access AXI GPIO from Linux User Space
Next we will attempt to turn on the LED on the ZC702 via the GPIO. In the Petalinux, the GPIO SYSFS
is mounted by default. This interface allows us to access the GPIO pins easily. To see a list of the
GPIO pins, type “ls /sys/class/gpio” from the root (to get to the root type “cd ~”):
root@petalinux_test:~# ls /sys/class/gpio
So, here gpiochip252 is the base pin. Since we are using a 5 bit GPIO, the range of pins are 252:256.
To use a pin, the user will need to checkout this pin so it cannot be used by any other processes on
the kernel. This is done by using the export. For example:
Now, we can set the direction of the pin. This can be either in, or out. For example:
Next, we can set the value of the pin. This can either be 1, or 0. For example:
Finally, we must check back the pin. This is so other processes can use it. For example:
12 stephenm@xilinx.com | Xilinx
With this in mind, we can create a software application based on the information we learned before.
cd petalinux_test
petalinux-create --type apps --template c --name gpioapp
petalinux-config -c rootfs
Select “Apps”, and select “Y” for the newly created gpioapp
petalinux_test\components\apps\gpioapp
Copy the code in Zc702_files/gpio_test.c into gpioapp.c. This code replicates what we did in the last
step in a C application. This toggles the LED.
To build the image into an existing image, use the command below:
cd petalinux_test
petalinux-build -c rootfs/gpioapp
petalinux-build -x package
Update the image.ub on the SD card with the newly created image.ub in Images/linux/image.ub and
press the POR_B push button on the ZC202 to reboot.
13 stephenm@xilinx.com | Xilinx
To run the gpioapp, run the command below on the Petalinux console:
gpioapp
14 stephenm@xilinx.com | Xilinx
ZC702 – Step 5: Access AXI GPIO using device drivers
In this section we will be updating the device-tree to include device nodes for the LED, and GPIO
Key’s. The device-tree files can be found at:
petalinux_test\subsystems\linux\configs\device-tree
system-top.dts
o system-conf.dtsi
pl.dtsi
ps.dtsi
It is not recommended to update the dtsi files directly. So, we can create our own dtsi file, and add it
to the device-tree structure. Create a led_nodes.dtsi file and place this into the device-tree structure
by adding this as an include into system-top.dts as shown below:
system-top.dts
o system-conf.dtsi
o led_nodes.dtsi
pl.dtsi
ps.dtsi
15 stephenm@xilinx.com | Xilinx
Open the led_nodes.dtsi file, and populate this as shown below:
Make sure that the properties are set correctly. All this information can be obtained from
leds_gpio.txt, gpio-xilinx.txt and gpio-keys.txt:
Required properties:
- compatible : should be "gpio-leds".
The string < gpios = <&axi_gpio_0 0 0>, &axi_gpio_0 refers to the GPIO name given in the pl.dtsi, and
states that led-ds15 is on pin 0, and that the device is active low.
cd petalinux_test
petalinux-build
16 stephenm@xilinx.com | Xilinx
We can also verify that the device-tree has been updated correctly using the command below:
cd petalinux_test/images/linux
../../build/linux/kernel/xlnx-3.14/scripts/dtc/dtc -I dtb -O dts -o system.dts system.dtb
This will create a system.dts in the petalinux_test/images/linux folder. You should see the two driver
nodes under the AXI Interconnect.
When you are happy with the changes, copy the image.ub onto the SD card. Next, Plug the SD card
back into the ZC702, and press the POR_B pushbutton. Let the Linux boot, and enter the login (root),
and password (login).
The LED at DS15 should be beating. To test the GPIO-KEYS, type the command below onto the
Petalinux console:
17 stephenm@xilinx.com | Xilinx
ZC702 – Step 6: Using SDK to debug Linux Applications
Now that we have the hardware built, the Linux system build, and our drivers added, we can now
create some applications in Linux using the SDK tool.
In Step 2, we added the TCF agent in the Kernel. We shall be connecting to this TCF agent via the
Ethernet port. So, first we need to set up the LAN between our local machine, and the board.
To set up the LAN connect the PHY cable into your local machine and go to Start Control Panel
Network and Internet Network and Sharing Center:
18 stephenm@xilinx.com | Xilinx
Right Click on Local Area Connection, and select properties:
Note: When this tutorial is over, and you are wondering why you have no internet connect. This is
why. Change it back to Obtain an IP address automatically.
19 stephenm@xilinx.com | Xilinx
Next, we need to assign an IP address to the board, in the Petalinux console use the command
below:
To test the connection, send a ping to your local machine using the command below on the
Petalinux console:
Ping 192.168.1.1
Name the app “gpio_test”, and for the Hardware Platform, Select New:
21 stephenm@xilinx.com | Xilinx
Browse for your HDF file that you used when exporting from Vivado in Step 1:
Select Finish.
Note: We technically do not need to build the HW Platform, as this is built already in Linux.
22 stephenm@xilinx.com | Xilinx
Then for OS Platform, selecting Linux and Next to continue:
23 stephenm@xilinx.com | Xilinx
Select Linux Empty Application, and Finish to Continue:
24 stephenm@xilinx.com | Xilinx
In the Project Explorer, right click on the gpio_test/src and select New Source File:
25 stephenm@xilinx.com | Xilinx
Name that source file “gpio_test.c”, and finish to continue:
Copy the code in Zc702_files/ledapp.c into src/gpio_test.c. This code uses the led-gpio and gpio-keys
drivers to allow the user to control the LED from the pushbuttons.
When you build the application is SDK (Project Build All), you will see an error:
26 stephenm@xilinx.com | Xilinx
This is due to a missing linker flag “-lphread”. To add this, right click on the gpio_test in Project
explorer, and select C/C++ Build Properties. Under ARM Linux gcc linker Inferred Options
Software Platform. Select the Ad symbol, and add the –lphread option.
27 stephenm@xilinx.com | Xilinx
Next, set up the Target connection. Select the icon highlighted below:
Give the target the name “zc702” and enter the IP address and the port number as shown below:
28 stephenm@xilinx.com | Xilinx
Next, right click on the “hello” application and select Debug As Debug Configurations:
Create a new Debug Configuration (by double clicking on the Xilinx C/C++ application System
Debugger). For Debug Type, select Linux Application Debug. For Connection, select the target
connection we created previously (zc702). Select Apply and Debug to proceed:
29 stephenm@xilinx.com | Xilinx
In the Application tab, browse to the gpio_test project. In the Remote File Path, enter
“/tmp/gpio_test.elf”:
30 stephenm@xilinx.com | Xilinx
You can either step through the application, or run it all using the debug options seen below:
To test, you should see DS15 beating, you can control the speed of the blinking via the SW13, and
SW14 push-buttons. You will also see the speed displayed on the serial port in SDK:
Note: on the Petalinux console, you can also run the application by using the command below:
/tmp/gpio_test.elf
31 stephenm@xilinx.com | Xilinx