petalinux design entry guide. - xilinx · to build the image into an existing image, use the...
TRANSCRIPT
1 [email protected] | Xilinx
Petalinux Design Entry Guide.
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
Zynq - Step 1: Create the HW:
Launch Vivado 2014.2. In Vivado, source the Zc702_files/build_zc702.tcl from the TCL command:
Note: For the HW requirements for Zynq see page 7 of UG980
2 [email protected] | Xilinx
Generate the Output Products:
3 [email protected] | Xilinx
Next, Generate the Bitstream:
Note: This is not needed to create the application. Users can export hardware without a bitstream
Finally, Export Hardware:
File -> Export -> Export Hardware (Include bitstream)
This will create a HDF file in the <project_name>.sdk folder
Minimise Vivado
4 [email protected] | 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:
petalinux-create --type project --template zynq --name petalinux_test
This will create a default template project, which will be modified in the next step to reflect our
actual HW project:
petalinux-config --get-hw-description -p petalinux_test
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:
5 [email protected] | Xilinx
Then Select to enter the “Advanced bootable image storage settings”, and select “boot image
settings”, as shown below:
Select “image storage media”, as shown below:
Set this to “primary sd”, as shown below:
7 [email protected] | 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:
Save, and Exit to compile
8 [email protected] | Xilinx
To see the kernel configuration menu run the command below from the project root:
cd petalinux_test
petalinux-config –c kernel
Here, we shall enable the following device drivers:
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
Save, and Exit to compile
9 [email protected] | Xilinx
Finally, when we are happy with the configuration, we can build the image:
petalinux-build
We want to boot from the SD card,
Next, we can create the boot image.
petalinux-package --boot --fsbl images/linux/zynq_fsbl.elf –
fpga ../proc_system_wrapper_hw_platform/proc_system_wrapper.bit --uboot
The two files of note here are:
BOOT.BIN
Images/linux/image.ub
10 [email protected] | Xilinx
ZC702 – Step 3: Booting Linux:
Copy both the files below on the SD Card:
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.
11 [email protected] | 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:
The login, and password is “root”
12 [email protected] | 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
export gpiochip0 gpiochip252 unexport
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:
echo 252 > /sys/class/gpio/export
Now, we can set the direction of the pin. This can be either in, or out. For example:
echo out > /sys/class/gpio/gpio252/direction
Next, we can set the value of the pin. This can either be 1, or 0. For example:
echo 1 > /sys/class/gpio/gpio252/value
You should see the DS15 LED turn on.
Finally, we must check back the pin. This is so other processes can use it. For example:
echo 252 > /sys/class/gpio/unexport
13 [email protected] | Xilinx
With this in mind, we can create a software application based on the information we learned before.
We can use Petalinux to create a new C Application:
cd petalinux_test
petalinux-create --type apps --template c --name gpioapp
Enable the app in the rootfs:
petalinux-config -c rootfs
Select “Apps”, and select “Y” for the newly created gpioapp
Save, and Exit to compile.
This will create, a C template at:
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.
14 [email protected] | Xilinx
To run the gpioapp, run the command below on the Petalinux console:
gpioapp
Press Ctrl+c to exit.
15 [email protected] | 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
The device-tree structure for these files is as follows:
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:
So, we should now have:
system-top.dts
o system-conf.dtsi
o led_nodes.dtsi
pl.dtsi
ps.dtsi
16 [email protected] | 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:
For example, for the LED compatibility:
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.
Dual channel GPIO controller with configurable number of pins
(from 1 to 32 per channel). Every pin can be configured as
input/output/tristate.
Once the device-tree is updated, the image needs to be rebuilt:
cd petalinux_test
petalinux-build
17 [email protected] | 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:
cat /dev/input/event0 | hexdata
Then press SW13, or SW14:
18 [email protected] | 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:
Then select Change adapter settings:
19 [email protected] | Xilinx
Right Click on Local Area Connection, and select properties:
Select Internet Protocol Version 4 (TCP/IPv4), and select Properties:
Use the IP address: 192.168.1.1, and the Subnet mask 255.255.255.0
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.
20 [email protected] | Xilinx
Next, we need to assign an IP address to the board, in the Petalinux console use the command
below:
Ifconfig eth0 192.168.1.10 netmask 255.255.255.0
To test the connection, send a ping to your local machine using the command below on the
Petalinux console:
Ping 192.168.1.1
Press Ctrl+c to stop the ping
21 [email protected] | Xilinx
Next, we can launch SDK (locally) and create a workspace. The select new Application Project.
Name the app “gpio_test”, and for the Hardware Platform, Select New:
22 [email protected] | 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.
23 [email protected] | Xilinx
Then for OS Platform, selecting Linux and Next to continue:
24 [email protected] | Xilinx
Select Linux Empty Application, and Finish to Continue:
25 [email protected] | Xilinx
In the Project Explorer, right click on the gpio_test/src and select New Source File:
26 [email protected] | 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:
'Building target: gpio_test.elf' 'Invoking: ARM Linux gcc linker' arm-xilinx-linux-gnueabi-gcc -o "gpio_test.elf" ./src/gpio_test.o ./src/gpio_test.o: In function `main': C:\Cases\Projects\petalinux\test_ws\gpio_test\Debug/../src/gpio_test.c:60: undefined reference to `pthread_create' collect2.exe: error: ld returned 1 exit status make: *** [gpio_test.elf] Error 1
27 [email protected] | 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.
Select Apply, and OK to Exit.
Note: This can be added to the MAKEFILE if creating a Petalinux Application
28 [email protected] | 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:
29 [email protected] | 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:
30 [email protected] | Xilinx
In the Application tab, browse to the gpio_test project. In the Remote File Path, enter
“/tmp/gpio_test.elf”:
Select Apply and Debug to continue.
31 [email protected] | 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